use of javax.jcr.nodetype.NodeTypeTemplate in project jackrabbit by apache.
the class AddMixinTest method testAddItemsDefinedByMixin.
public void testAddItemsDefinedByMixin() throws NotExecutableException, RepositoryException {
// register mixin
NodeTypeManager ntm = superuser.getWorkspace().getNodeTypeManager();
NodeTypeTemplate ntd = ntm.createNodeTypeTemplate();
ntd.setName("testMixin");
ntd.setMixin(true);
NodeDefinitionTemplate nodeDef = ntm.createNodeDefinitionTemplate();
nodeDef.setName("child");
nodeDef.setRequiredPrimaryTypeNames(new String[] { "nt:folder" });
ntd.getNodeDefinitionTemplates().add(nodeDef);
ntm.registerNodeType(ntd, true);
// create node and add mixin
Node node = testRootNode.addNode(nodeName1, "nt:resource");
node.setProperty("jcr:data", "abc");
node.addMixin("testMixin");
superuser.save();
// create a child node defined by the mixin
node.addNode("child", "nt:folder");
node.save();
}
use of javax.jcr.nodetype.NodeTypeTemplate in project jackrabbit by apache.
the class AddMixinTest method testAddItemsDefinedByMixin3.
public void testAddItemsDefinedByMixin3() throws NotExecutableException, RepositoryException {
// register mixin
NodeTypeManager ntm = superuser.getWorkspace().getNodeTypeManager();
NodeTypeTemplate ntd = ntm.createNodeTypeTemplate();
ntd.setName("testMixin");
ntd.setMixin(true);
NodeDefinitionTemplate nodeDef = ntm.createNodeDefinitionTemplate();
nodeDef.setName("child");
nodeDef.setRequiredPrimaryTypeNames(new String[] { "nt:folder" });
nodeDef.setDefaultPrimaryTypeName("nt:folder");
ntd.getNodeDefinitionTemplates().add(nodeDef);
ntm.registerNodeType(ntd, true);
// create node and add mixin
Node node = testRootNode.addNode(nodeName1, "nt:resource");
node.setProperty("jcr:data", "abc");
node.addMixin("testMixin");
superuser.save();
// create a child node defined by the mixin without specifying the
// node type -> must succeed since default primary type is specified
// in the child node def
Node c = node.addNode("child");
assertEquals("nt:folder", c.getPrimaryNodeType().getName());
superuser.save();
}
use of javax.jcr.nodetype.NodeTypeTemplate in project jackrabbit by apache.
the class AddMixinTest method testAddItemsDefinedByMixin2.
public void testAddItemsDefinedByMixin2() throws NotExecutableException, RepositoryException {
// register mixin
NodeTypeManager ntm = superuser.getWorkspace().getNodeTypeManager();
NodeTypeTemplate ntd = ntm.createNodeTypeTemplate();
ntd.setName("testMixin");
ntd.setMixin(true);
NodeDefinitionTemplate nodeDef = ntm.createNodeDefinitionTemplate();
nodeDef.setName("child");
nodeDef.setRequiredPrimaryTypeNames(new String[] { "nt:folder" });
ntd.getNodeDefinitionTemplates().add(nodeDef);
ntm.registerNodeType(ntd, true);
// create node and add mixin
Node node = testRootNode.addNode(nodeName1, "nt:resource");
node.setProperty("jcr:data", "abc");
node.addMixin("testMixin");
superuser.save();
// node type
try {
node.addNode("child");
fail();
} catch (ConstraintViolationException e) {
// success as ChildNode Definition doesn't specify a default primary
// type -> see comment in ItemDefinitionProvider#getQNodeDefinition
}
}
use of javax.jcr.nodetype.NodeTypeTemplate in project jackrabbit by apache.
the class NodeTypeCreationTest method testInvalidJCRNames.
public void testInvalidJCRNames() throws Exception {
String invalidName = ":ab[2]";
// invalid name(s) passed to NT-template methods
NodeTypeTemplate ntt = ntm.createNodeTypeTemplate();
try {
ntt.setName(invalidName);
fail("ConstraintViolationException expected. Nt-name is invalid");
} catch (ConstraintViolationException e) {
// success
}
try {
ntt.setDeclaredSuperTypeNames(new String[] { "{" + NS_MIX_URI + "}" + "littlemixin", invalidName });
fail("ConstraintViolationException expected. One of the super type names is invalid");
} catch (ConstraintViolationException e) {
// success
}
try {
ntt.setPrimaryItemName(invalidName);
fail("ConstraintViolationException expected. Primary item name is invalid");
} catch (ConstraintViolationException e) {
// success
}
// invalid name(s) passed to NodeDefinitionTemplate
NodeDefinitionTemplate ndt = ntm.createNodeDefinitionTemplate();
try {
ndt.setName(invalidName);
fail("ConstraintViolationException expected. Name is invalid");
} catch (ConstraintViolationException e) {
// success
}
try {
ndt.setRequiredPrimaryTypeNames(new String[] { "{" + NS_MIX_URI + "}" + "littlemixin", invalidName });
fail("ConstraintViolationException expected. One of the required primary type names is invalid");
} catch (ConstraintViolationException e) {
// success
}
try {
ndt.setDefaultPrimaryTypeName(invalidName);
fail("ConstraintViolationException expected. Default primary type name is invalid");
} catch (ConstraintViolationException e) {
// success
}
// invalid name(s) passed to PropertyDefinitionTemplate
PropertyDefinitionTemplate pdt = ntm.createPropertyDefinitionTemplate();
try {
pdt.setName(invalidName);
fail("ConstraintViolationException expected. Name is invalid");
} catch (ConstraintViolationException e) {
// success
}
}
use of javax.jcr.nodetype.NodeTypeTemplate in project jackrabbit by apache.
the class NodeTypeDefinitionFactory method create.
/**
* Create a new JCR node type definition from the given
* <code>QNodeTypeDefinition</code>.
*
* @param qNtd A SPI node type definition.
* @return the corresponding JCR node type definition.
* @throws RepositoryException if an error occurs.
*/
@SuppressWarnings("unchecked")
public NodeTypeDefinition create(QNodeTypeDefinition qNtd) throws RepositoryException {
NodeTypeTemplate nt = ntMgr.createNodeTypeTemplate();
nt.setName(getJCRName(qNtd.getName()));
nt.setDeclaredSuperTypeNames(getJCRNames(qNtd.getSupertypes()));
nt.setAbstract(qNtd.isAbstract());
nt.setMixin(qNtd.isMixin());
nt.setOrderableChildNodes(qNtd.hasOrderableChildNodes());
nt.setPrimaryItemName(getJCRName(qNtd.getPrimaryItemName()));
nt.setQueryable(qNtd.isQueryable());
List nodeDefs = nt.getNodeDefinitionTemplates();
for (QNodeDefinition qNd : qNtd.getChildNodeDefs()) {
nodeDefs.add(create(qNd));
}
List propDefs = nt.getPropertyDefinitionTemplates();
for (QPropertyDefinition qPd : qNtd.getPropertyDefs()) {
propDefs.add(create(qPd));
}
return nt;
}
Aggregations