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.");
}
}
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");
}
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");
}
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");
}
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]);
}
Aggregations