Search in sources :

Example 11 with NodeTypeIterator

use of javax.jcr.nodetype.NodeTypeIterator in project jackrabbit by apache.

the class DescendantNodeTest method testDescendantNodesDoNotMatchSelector.

public void testDescendantNodesDoNotMatchSelector() throws RepositoryException, NotExecutableException {
    testRootNode.addNode(nodeName1, testNodeType);
    superuser.save();
    NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager();
    NodeTypeIterator it = ntMgr.getPrimaryNodeTypes();
    NodeType testNt = ntMgr.getNodeType(testNodeType);
    while (it.hasNext()) {
        NodeType nt = it.nextNodeType();
        if (!testNt.isNodeType(nt.getName())) {
            // perform test
            QueryObjectModel qom = qf.createQuery(qf.selector(nt.getName(), "s"), qf.descendantNode("s", testRoot), null, null);
            checkQOM(qom, new Node[] {});
            return;
        }
    }
    throw new NotExecutableException("No suitable node type found to " + "perform test against '" + testNodeType + "' nodes");
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) NodeType(javax.jcr.nodetype.NodeType) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator) QueryObjectModel(javax.jcr.query.qom.QueryObjectModel)

Example 12 with NodeTypeIterator

use of javax.jcr.nodetype.NodeTypeIterator in project jackrabbit by apache.

the class ChildNodeTest method testChildNodesDoNotMatchSelector.

public void testChildNodesDoNotMatchSelector() throws RepositoryException, NotExecutableException {
    testRootNode.addNode(nodeName1, testNodeType);
    superuser.save();
    NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager();
    NodeTypeIterator it = ntMgr.getPrimaryNodeTypes();
    NodeType testNt = ntMgr.getNodeType(testNodeType);
    while (it.hasNext()) {
        NodeType nt = it.nextNodeType();
        if (!testNt.isNodeType(nt.getName())) {
            // perform test
            QueryObjectModel qom = qf.createQuery(qf.selector(nt.getName(), "s"), qf.childNode("s", testRoot), null, null);
            checkQOM(qom, new Node[] {});
            return;
        }
    }
    throw new NotExecutableException("No suitable node type found to " + "perform test against '" + testNodeType + "' nodes");
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) NodeType(javax.jcr.nodetype.NodeType) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator) QueryObjectModel(javax.jcr.query.qom.QueryObjectModel)

Example 13 with NodeTypeIterator

use of javax.jcr.nodetype.NodeTypeIterator in project jackrabbit by apache.

the class NodeStateMergerTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    Reader cnd = new InputStreamReader(getClass().getClassLoader().getResourceAsStream(TEST_NODETYPES));
    CndImporter.registerNodeTypes(cnd, superuser);
    cnd.close();
    NodeTypeIterator it = superuser.getWorkspace().getNodeTypeManager().getMixinNodeTypes();
    while (it.hasNext()) {
        NodeType nt = it.nextNodeType();
        if (nt.getName().startsWith("test:")) {
            testMixins.add(nt.getName());
        }
    }
    testNode = testRootNode.addNode(nodeName1, "nt:unstructured");
    superuser.save();
    sessionB = getHelper().getSuperuserSession();
    testNodeB = sessionB.getNode(testNode.getPath());
}
Also used : InputStreamReader(java.io.InputStreamReader) NodeType(javax.jcr.nodetype.NodeType) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator)

Example 14 with NodeTypeIterator

use of javax.jcr.nodetype.NodeTypeIterator in project jackrabbit by apache.

the class NodeTypeUtil method locatePropertyDef.

/**
     * Locate a property def parsing all node types
     *
     * @param session      the session to access the node types
     * @param propertyType the type of the returned property. -1 indicates to
     *                     return a property of any type but not UNDEFIEND
     * @param multiple     if true, the returned <code>PropertyDef</code> is
     *                     multiple, else not
     * @param isProtected  if true, the returned <code>PropertyDef</code> is
     *                     protected, else not
     * @param residual     if true, the returned <code>PropertyDef</code> is of
     *                     the residual name "*", else not
     * @return the first <code>PropertyDef</code> found fitting the
     *         requirements
     */
public static PropertyDefinition locatePropertyDef(Session session, int propertyType, boolean multiple, boolean isProtected, boolean constraints, boolean residual) throws RepositoryException {
    NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
    NodeTypeIterator types = manager.getAllNodeTypes();
    while (types.hasNext()) {
        NodeType type = types.nextNodeType();
        PropertyDefinition[] propDefs = type.getDeclaredPropertyDefinitions();
        for (int i = 0; i < propDefs.length; i++) {
            PropertyDefinition propDef = propDefs[i];
            if (propertyType != ANY_PROPERTY_TYPE && propDef.getRequiredType() != propertyType) {
                continue;
            }
            if (propertyType == ANY_PROPERTY_TYPE && propDef.getRequiredType() == PropertyType.UNDEFINED) {
                continue;
            }
            if (multiple && !propDef.isMultiple()) {
                continue;
            }
            if (!multiple && propDef.isMultiple()) {
                continue;
            }
            if (isProtected && !propDef.isProtected()) {
                continue;
            }
            if (!isProtected && propDef.isProtected()) {
                continue;
            }
            String[] vc = propDef.getValueConstraints();
            if (!constraints && vc != null && vc.length > 0) {
                continue;
            }
            if (constraints) {
                // property def with constraints requested
                if (vc == null || vc.length == 0) {
                    // property def has no constraints
                    continue;
                }
            }
            if (!residual && propDef.getName().equals("*")) {
                continue;
            }
            if (residual && !propDef.getName().equals("*")) {
                continue;
            }
            // is another residual definition
            if (residual) {
                // check if there is another residual property def
                if (getNumResidualPropDefs(type) > 1) {
                    continue;
                }
            }
            if (!residual) {
                // type
                if (getNumResidualPropDefs(type) > 0) {
                    continue;
                }
            }
            return propDef;
        }
    }
    return null;
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NodeType(javax.jcr.nodetype.NodeType) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition)

Example 15 with NodeTypeIterator

use of javax.jcr.nodetype.NodeTypeIterator in project jackrabbit by apache.

the class NodeTypeUtil method locatePropertyDef.

/**
     * Locate a property def parsing all node types
     *
     * @param session     the session to access the node types
     * @param isProtected if true, the returned <code>PropertyDef</code> is
     *                    protected, else not
     * @param mandatory   if true, the returned <code>PropertyDef</code> is
     *                    mandatory, else not
     * @return the first <code>PropertyDef</code> found fitting the
     *         requirements
     */
public static PropertyDefinition locatePropertyDef(Session session, boolean isProtected, boolean mandatory) throws RepositoryException {
    NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
    NodeTypeIterator types = manager.getAllNodeTypes();
    while (types.hasNext()) {
        NodeType type = types.nextNodeType();
        PropertyDefinition[] propDefs = type.getDeclaredPropertyDefinitions();
        for (int i = 0; i < propDefs.length; i++) {
            PropertyDefinition propDef = propDefs[i];
            if (propDef.getName().equals("*")) {
                continue;
            }
            if (isProtected && !propDef.isProtected()) {
                continue;
            }
            if (!isProtected && propDef.isProtected()) {
                continue;
            }
            if (mandatory && !propDef.isMandatory()) {
                continue;
            }
            if (!mandatory && propDef.isMandatory()) {
                continue;
            }
            return propDef;
        }
    }
    return null;
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NodeType(javax.jcr.nodetype.NodeType) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition)

Aggregations

NodeTypeIterator (javax.jcr.nodetype.NodeTypeIterator)65 NodeType (javax.jcr.nodetype.NodeType)53 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)28 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)15 NodeDefinition (javax.jcr.nodetype.NodeDefinition)13 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)11 Node (javax.jcr.Node)9 RepositoryException (javax.jcr.RepositoryException)9 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)8 ArrayList (java.util.ArrayList)6 Session (javax.jcr.Session)6 HashSet (java.util.HashSet)4 Value (javax.jcr.Value)3 QueryObjectModel (javax.jcr.query.qom.QueryObjectModel)3 NodeTypeIteratorAdapter (org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 Property (javax.jcr.Property)2