use of javax.jcr.nodetype.PropertyDefinition in project jackrabbit-oak by apache.
the class PropertyTest method testMixTitleOnUnstructured2.
public void testMixTitleOnUnstructured2() throws Exception {
Node n = testRootNode.addNode("unstructured", JcrConstants.NT_UNSTRUCTURED);
n.addMixin("mix:title");
superuser.save();
// create jcr:title as STRING => declaring NT is mix:title
Property title = n.setProperty("jcr:title", "str");
assertEquals(PropertyType.STRING, title.getType());
PropertyDefinition def = title.getDefinition();
assertEquals("mix:title", def.getDeclaringNodeType().getName());
assertEquals(PropertyType.STRING, def.getRequiredType());
// changing value to BOOLEAN => value is converted
title.setValue(true);
assertEquals(PropertyType.STRING, title.getType());
def = title.getDefinition();
assertEquals("mix:title", def.getDeclaringNodeType().getName());
assertEquals(PropertyType.STRING, def.getRequiredType());
// re-setting property to type BOOLEAN => declaring NT is nt:unstructured
title = n.setProperty("jcr:title", true);
def = title.getDefinition();
assertEquals(JcrConstants.NT_UNSTRUCTURED, def.getDeclaringNodeType().getName());
assertEquals(PropertyType.UNDEFINED, def.getRequiredType());
// same if property is set to type DOUBLE
title = n.setProperty("jcr:title", superuser.getValueFactory().createValue(2.3));
assertEquals(PropertyType.DOUBLE, title.getType());
def = title.getDefinition();
assertEquals(JcrConstants.NT_UNSTRUCTURED, def.getDeclaringNodeType().getName());
assertEquals(PropertyType.UNDEFINED, def.getRequiredType());
// setting property to STRING => declaring NT is back to mix:title
title = n.setProperty("jcr:title", "str");
assertEquals(PropertyType.STRING, title.getType());
def = title.getDefinition();
assertEquals("mix:title", def.getDeclaringNodeType().getName());
assertEquals(PropertyType.STRING, def.getRequiredType());
}
use of javax.jcr.nodetype.PropertyDefinition in project jackrabbit-oak by apache.
the class NodeDefinitionTest method getAggregatedPropertyDefinitionss.
public static PropertyDefinition[] getAggregatedPropertyDefinitionss(Node node) throws RepositoryException {
Set<PropertyDefinition> pDefs = newHashSet();
PropertyDefinition[] pd = node.getPrimaryNodeType().getPropertyDefinitions();
pDefs.addAll(Arrays.asList(pd));
NodeType[] mixins = node.getMixinNodeTypes();
for (NodeType mixin : mixins) {
pd = mixin.getPropertyDefinitions();
pDefs.addAll(Arrays.asList(pd));
}
return pDefs.toArray(new PropertyDefinition[pDefs.size()]);
}
use of javax.jcr.nodetype.PropertyDefinition in project jackrabbit-oak by apache.
the class NodeTypeDefinitionTest method testIndexedPropertyDefinition.
public void testIndexedPropertyDefinition() throws Exception {
String ntPath = NodeTypeConstants.NODE_TYPES_PATH + '/' + NodeTypeConstants.NT_VERSION;
assertTrue(superuser.nodeExists(ntPath + "/jcr:propertyDefinition"));
assertTrue(superuser.nodeExists(ntPath + "/jcr:propertyDefinition[1]"));
Node pdNode = superuser.getNode(ntPath + "/jcr:propertyDefinition[1]");
assertEquals(ntPath + "/jcr:propertyDefinition", pdNode.getPath());
List<String> defNames = new ArrayList();
NodeType nt = superuser.getWorkspace().getNodeTypeManager().getNodeType(NodeTypeConstants.NT_VERSION);
for (PropertyDefinition nd : nt.getDeclaredPropertyDefinitions()) {
defNames.add(nd.getName());
}
Node ntNode = superuser.getNode(ntPath);
NodeIterator it = ntNode.getNodes("jcr:propertyDefinition*");
while (it.hasNext()) {
Node def = it.nextNode();
int index = getIndex(def);
String name = (def.hasProperty(NodeTypeConstants.JCR_NAME)) ? def.getProperty(NodeTypeConstants.JCR_NAME).getString() : NodeTypeConstants.RESIDUAL_NAME;
assertEquals(name, defNames.get(index - 1));
}
}
use of javax.jcr.nodetype.PropertyDefinition in project jackrabbit-oak by apache.
the class CompatibilityIssuesTest method testBinaryCoercion.
@Test
public void testBinaryCoercion() throws RepositoryException, IOException {
Session session = getAdminSession();
// node type with default child-node type of to nt:base
String ntName = "binaryCoercionTest";
NodeTypeManager ntm = session.getWorkspace().getNodeTypeManager();
NodeTypeTemplate ntt = ntm.createNodeTypeTemplate();
ntt.setName(ntName);
PropertyDefinitionTemplate propertyWithType = ntm.createPropertyDefinitionTemplate();
propertyWithType.setName("javaObject");
propertyWithType.setRequiredType(PropertyType.STRING);
PropertyDefinitionTemplate unnamed = ntm.createPropertyDefinitionTemplate();
unnamed.setName("*");
unnamed.setRequiredType(PropertyType.UNDEFINED);
List<PropertyDefinition> properties = ntt.getPropertyDefinitionTemplates();
properties.add(propertyWithType);
properties.add(unnamed);
ntm.registerNodeType(ntt, false);
Node node = session.getRootNode().addNode("testNodeForBinary", ntName);
ByteArrayOutputStream bos = serializeObject("testValue");
node.setProperty("javaObject", session.getValueFactory().createBinary(new ByteArrayInputStream(bos.toByteArray())));
Assert.assertTrue(IOUtils.contentEquals(new ByteArrayInputStream(bos.toByteArray()), node.getProperty("javaObject").getStream()));
}
use of javax.jcr.nodetype.PropertyDefinition 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.");
}
}
Aggregations