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