Search in sources :

Example 31 with NodeDefinition

use of javax.jcr.nodetype.NodeDefinition in project sling by apache.

the class NodeTypeConfigurationPrinter method printConfiguration.

/**
     * {@inheritDoc}
     */
public void printConfiguration(PrintWriter pw, String mode) {
    if (slingRepository != null) {
        Session session = null;
        try {
            session = slingRepository.loginAdministrative(null);
            NodeTypeManager ntm = session.getWorkspace().getNodeTypeManager();
            NodeTypeIterator it = ntm.getAllNodeTypes();
            List<NodeType> sortedTypes = sortTypes(it);
            for (NodeType nt : sortedTypes) {
                pw.printf("[%s]", nt.getName());
                printSuperTypes(pw, nt);
                if (nt.hasOrderableChildNodes()) {
                    pw.print(" orderable");
                }
                if (nt.isMixin()) {
                    pw.print(" mixin");
                }
                linebreak(pw, mode);
                for (PropertyDefinition prop : nt.getPropertyDefinitions()) {
                    if (prop.getDeclaringNodeType() == nt) {
                        startBold(pw, mode);
                    }
                    pw.printf("- %s", prop.getName());
                    printDefaultValues(pw, prop);
                    if (prop.getName().equals(nt.getPrimaryItemName())) {
                        pw.print(" primary");
                    }
                    if (prop.isMandatory()) {
                        pw.print(" mandatory");
                    }
                    if (prop.isAutoCreated()) {
                        pw.print(" autocreated");
                    }
                    if (prop.isProtected()) {
                        pw.print(" protected");
                    }
                    if (prop.isMultiple()) {
                        pw.print(" multiple");
                    }
                    pw.printf(" %s", OnParentVersionAction.nameFromValue(prop.getOnParentVersion()));
                    printConstraints(pw, prop);
                    if (prop.getDeclaringNodeType() == nt) {
                        stopBold(pw, mode);
                    }
                    linebreak(pw, mode);
                }
                for (NodeDefinition child : nt.getChildNodeDefinitions()) {
                    if (child.getDeclaringNodeType() == nt) {
                        startBold(pw, mode);
                    }
                    pw.printf("+ %s", child.getName());
                    printRequiredChildTypes(pw, child);
                    if (child.getDefaultPrimaryType() != null) {
                        pw.printf(" = %s", child.getDefaultPrimaryType().getName());
                    }
                    if (child.isMandatory()) {
                        pw.print(" mandatory");
                    }
                    if (child.isAutoCreated()) {
                        pw.print(" autocreated");
                    }
                    if (child.isProtected()) {
                        pw.print(" protected");
                    }
                    if (child.allowsSameNameSiblings()) {
                        pw.print(" multiple");
                    }
                    pw.printf(" %s", OnParentVersionAction.nameFromValue(child.getOnParentVersion()));
                    if (child.getDeclaringNodeType() == nt) {
                        stopBold(pw, mode);
                    }
                    linebreak(pw, mode);
                }
                linebreak(pw, mode);
            }
        } catch (RepositoryException e) {
            pw.println("Unable to output namespace mappings.");
            e.printStackTrace(pw);
        } finally {
            if (session != null) {
                session.logout();
            }
        }
    } else {
        pw.println("SlingRepository is not available.");
    }
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NodeType(javax.jcr.nodetype.NodeType) NodeDefinition(javax.jcr.nodetype.NodeDefinition) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator) RepositoryException(javax.jcr.RepositoryException) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition) Session(javax.jcr.Session)

Example 32 with NodeDefinition

use of javax.jcr.nodetype.NodeDefinition in project sling by apache.

the class ChildNodeDefGenerationTest method testOneSimpleChildNodeDefinition.

@Test
public void testOneSimpleChildNodeDefinition() throws ServletException, IOException, JSONException {
    NodeType ntWithChildNodeDefs = getSimpleNodeTypeWithName("ntWithChildNodeDefs");
    NodeDefinition[] childNodeDefs = { getSimpleChildNodeDef("childNodeDef1") };
    when(ntWithChildNodeDefs.getDeclaredChildNodeDefinitions()).thenReturn(childNodeDefs);
    when(nodeTypeIterator.nextNodeType()).thenReturn(ntWithChildNodeDefs);
    when(nodeTypeIterator.hasNext()).thenReturn(Boolean.TRUE, Boolean.FALSE);
    assertEqualsWithServletResult("testOneSimpleChildNodeDefinition");
}
Also used : NodeType(javax.jcr.nodetype.NodeType) NodeDefinition(javax.jcr.nodetype.NodeDefinition) Test(org.junit.Test)

Example 33 with NodeDefinition

use of javax.jcr.nodetype.NodeDefinition in project sling by apache.

the class ChildNodeDefGenerationTest method testResidualChildNodeDefinitions.

@Test
public void testResidualChildNodeDefinitions() throws JSONException, ServletException, IOException {
    NodeType ntWithChildNOdeDefs = getSimpleNodeTypeWithName("ntWithChildNodeDefs");
    NodeDefinition childNodeDef1 = getSimpleChildNodeDef("*");
    NodeDefinition childNodeDef2 = getSimpleChildNodeDef("*");
    NodeDefinition childNodeDef3 = getSimpleChildNodeDef("childNodeDef");
    NodeDefinition[] childNodeDefs = { childNodeDef1, childNodeDef2, childNodeDef3 };
    when(ntWithChildNOdeDefs.getDeclaredChildNodeDefinitions()).thenReturn(childNodeDefs);
    when(nodeTypeIterator.nextNodeType()).thenReturn(ntWithChildNOdeDefs);
    when(nodeTypeIterator.hasNext()).thenReturn(Boolean.TRUE, Boolean.FALSE);
    assertEqualsWithServletResult("testResidualChildNodeDefinitions");
}
Also used : NodeType(javax.jcr.nodetype.NodeType) NodeDefinition(javax.jcr.nodetype.NodeDefinition) Test(org.junit.Test)

Example 34 with NodeDefinition

use of javax.jcr.nodetype.NodeDefinition in project sling by apache.

the class NodeTypeGenerationTest method testCompleteNodeTypes.

@Test
public void testCompleteNodeTypes() throws JSONException, ServletException, IOException, ValueFormatException, IllegalStateException, RepositoryException {
    NodeType nt1 = getSimpleNodeTypeWithName("testNodeType");
    NodeType[] superTypes = { getSimpleNodeTypeWithName("superType1"), getSimpleNodeTypeWithName("superType2"), getSimpleNodeTypeWithName("superType3") };
    NodeType nt2 = getSimpleNodeTypeWithName(null);
    when(nt1.getDeclaredSupertypes()).thenReturn(superTypes);
    when(nodeTypeIterator.nextNodeType()).thenReturn(nt1, nt2);
    when(nodeTypeIterator.hasNext()).thenReturn(Boolean.TRUE, Boolean.TRUE, Boolean.TRUE, Boolean.FALSE);
    NodeDefinition childNodeDef1 = getCompleteChildNodeDef("childNodeDef1");
    NodeDefinition childNodeDef2 = getCompleteChildNodeDef("childNodeDef2");
    NodeDefinition[] childNodeDefs = { childNodeDef1, childNodeDef2 };
    when(nt1.getDeclaredChildNodeDefinitions()).thenReturn(childNodeDefs);
    String propertyName = "stringPropertyDef";
    PropertyDefinition propertyDef = mock(PropertyDefinition.class);
    when(propertyDef.getOnParentVersion()).thenReturn(OnParentVersionAction.VERSION);
    when(propertyDef.getName()).thenReturn(propertyName);
    when(propertyDef.getRequiredType()).thenReturn(PropertyType.STRING);
    when(propertyDef.getValueConstraints()).thenReturn(new String[] { GenerationConstants.CONSTRAINT_STRING });
    when(propertyDef.isMultiple()).thenReturn(Boolean.TRUE);
    when(propertyDef.isProtected()).thenReturn(Boolean.TRUE);
    Value defaultValue = mock(Value.class);
    when(defaultValue.getType()).thenReturn(PropertyType.STRING);
    when(defaultValue.getString()).thenReturn(GenerationConstants.DEFAULT_VALUE_STRING);
    when(propertyDef.getDefaultValues()).thenReturn(new Value[] { defaultValue });
    when(propertyDef.isAutoCreated()).thenReturn(Boolean.TRUE);
    when(propertyDef.isMandatory()).thenReturn(Boolean.TRUE);
    when(nt1.getDeclaredPropertyDefinitions()).thenReturn(new PropertyDefinition[] { propertyDef });
    assertEqualsWithServletResult("testCompleteNodeTypes");
}
Also used : NodeType(javax.jcr.nodetype.NodeType) NodeDefinition(javax.jcr.nodetype.NodeDefinition) Value(javax.jcr.Value) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition) Test(org.junit.Test)

Example 35 with NodeDefinition

use of javax.jcr.nodetype.NodeDefinition in project sling by apache.

the class VltNodeType method getChildNodeDefinitions.

@Override
public NodeDefinition[] getChildNodeDefinitions() {
    List<NodeDefinition> childNodeDefs = new LinkedList<>();
    childNodeDefs.addAll(Arrays.asList(getDeclaredChildNodeDefinitions()));
    NodeType[] supers = getSupertypes();
    if (supers != null) {
        for (int i = 0; i < supers.length; i++) {
            NodeType aSuperNodeType = supers[i];
            NodeDefinition[] superChildNodeDefs = aSuperNodeType.getChildNodeDefinitions();
            if (superChildNodeDefs != null) {
                childNodeDefs.addAll(Arrays.asList(superChildNodeDefs));
            }
        }
    }
    return childNodeDefs.toArray(new NodeDefinition[0]);
}
Also used : NodeType(javax.jcr.nodetype.NodeType) NodeDefinition(javax.jcr.nodetype.NodeDefinition) LinkedList(java.util.LinkedList)

Aggregations

NodeDefinition (javax.jcr.nodetype.NodeDefinition)77 NodeType (javax.jcr.nodetype.NodeType)44 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)29 Node (javax.jcr.Node)17 ItemExistsException (javax.jcr.ItemExistsException)14 NodeTypeIterator (javax.jcr.nodetype.NodeTypeIterator)13 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)13 Version (javax.jcr.version.Version)12 Test (org.junit.Test)11 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)8 RepositoryException (javax.jcr.RepositoryException)7 HashSet (java.util.HashSet)5 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)5 Name (org.apache.jackrabbit.spi.Name)5 QNodeDefinition (org.apache.jackrabbit.spi.QNodeDefinition)5 NodeDefinitionImpl (org.apache.jackrabbit.spi.commons.nodetype.NodeDefinitionImpl)5 ArrayList (java.util.ArrayList)4 NodeState (org.apache.jackrabbit.core.state.NodeState)4 QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)4 Session (javax.jcr.Session)3