use of javax.jcr.nodetype.NodeTypeManager in project jackrabbit by apache.
the class NodeMixinUtil method getNotAssignedMixinName.
public static String getNotAssignedMixinName(Session session, Node node) throws RepositoryException {
NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
NodeTypeIterator mixins = manager.getMixinNodeTypes();
Set<String> existingMixins = new HashSet<String>();
for (NodeType nt : node.getMixinNodeTypes()) {
existingMixins.add(nt.getName());
}
while (mixins.hasNext()) {
String ntName = mixins.nextNodeType().getName();
if (!existingMixins.contains(ntName)) {
return ntName;
}
}
return null;
}
use of javax.jcr.nodetype.NodeTypeManager in project jackrabbit by apache.
the class NodeMixinUtil method getAddableMixinName.
/**
* @return the name of a mixin node type that can be added by the requested
* <code>node</code>
*/
public static String getAddableMixinName(Session session, Node node) throws RepositoryException {
NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
NodeTypeIterator mixins = manager.getMixinNodeTypes();
// Skip mix:shareable since not supported by removeMixin
String mixShareable = session.getNamespacePrefix(AbstractJCRTest.NS_MIX_URI) + ":shareable";
while (mixins.hasNext()) {
String name = mixins.nextNodeType().getName();
if (node.canAddMixin(name) && !node.isNodeType(name) && !mixShareable.equals(name)) {
return name;
}
}
return null;
}
use of javax.jcr.nodetype.NodeTypeManager in project jackrabbit by apache.
the class LostFromCacheIssueTest method setUp.
public void setUp() throws Exception {
super.setUp();
Workspace workspace = superuser.getWorkspace();
NamespaceRegistry namespaceRegistry = workspace.getNamespaceRegistry();
NodeTypeManager ntmgr = workspace.getNodeTypeManager();
NodeTypeRegistry nodetypeRegistry = ((NodeTypeManagerImpl) ntmgr).getNodeTypeRegistry();
try {
namespaceRegistry.registerNamespace(NAMESPACE_PREFIX, NAMESPACE_URI);
} catch (NamespaceException ignore) {
//already exists
}
QNodeTypeDefinition nodeTypeDefinition = new QNodeTypeDefinitionImpl(((SessionImpl) superuser).getQName(NODETYPE_1), Name.EMPTY_ARRAY, Name.EMPTY_ARRAY, true, false, true, false, null, QPropertyDefinition.EMPTY_ARRAY, QNodeDefinition.EMPTY_ARRAY);
try {
nodetypeRegistry.registerNodeType(nodeTypeDefinition);
} catch (InvalidNodeTypeDefException ignore) {
//already exists
}
nodeTypeDefinition = new QNodeTypeDefinitionImpl(((SessionImpl) superuser).getQName(NODETYPE_2), Name.EMPTY_ARRAY, Name.EMPTY_ARRAY, true, false, true, false, null, QPropertyDefinition.EMPTY_ARRAY, QNodeDefinition.EMPTY_ARRAY);
try {
nodetypeRegistry.registerNodeType(nodeTypeDefinition);
} catch (InvalidNodeTypeDefException ignore) {
//already exists
}
getOrCreate(superuser.getRootNode(), TESTNODE_PATH);
superuser.save();
}
use of javax.jcr.nodetype.NodeTypeManager in project jackrabbit by apache.
the class AbstractRepositoryOperationTest method testRegisterNodeTypeWithPrivilege.
public void testRegisterNodeTypeWithPrivilege() throws Exception {
assertDefaultPrivileges(NameConstants.JCR_NODE_TYPE_DEFINITION_MANAGEMENT);
assertPermission(Permission.NODE_TYPE_DEF_MNGMT, false);
modifyPrivileges(null, NameConstants.JCR_NODE_TYPE_DEFINITION_MANAGEMENT.toString(), true);
assertPrivilege(NameConstants.JCR_NODE_TYPE_DEFINITION_MANAGEMENT, true);
assertPermission(Permission.NODE_TYPE_DEF_MNGMT, true);
try {
Workspace testWsp = getTestWorkspace();
NodeTypeManager ntm = testWsp.getNodeTypeManager();
NodeTypeTemplate ntd = ntm.createNodeTypeTemplate();
ntd.setName("testNodeType");
ntd.setMixin(true);
ntm.registerNodeType(ntd, true);
NodeTypeTemplate[] ntds = new NodeTypeTemplate[2];
ntds[0] = ntd;
ntds[1] = ntm.createNodeTypeTemplate();
ntds[1].setName("anotherNodeType");
ntds[1].setDeclaredSuperTypeNames(new String[] { "nt:file" });
ntm.registerNodeTypes(ntds, true);
} finally {
modifyPrivileges(null, NameConstants.JCR_NODE_TYPE_DEFINITION_MANAGEMENT.toString(), false);
}
assertPrivilege(NameConstants.JCR_NODE_TYPE_DEFINITION_MANAGEMENT, false);
assertPermission(Permission.NODE_TYPE_DEF_MNGMT, false);
}
use of javax.jcr.nodetype.NodeTypeManager in project jackrabbit by apache.
the class AbstractRepositoryOperationTest method testUnRegisterNodeType.
public void testUnRegisterNodeType() throws Exception {
assertDefaultPrivileges(NameConstants.JCR_NODE_TYPE_DEFINITION_MANAGEMENT);
assertPermission(Permission.NODE_TYPE_DEF_MNGMT, false);
NodeTypeManager ntm = superuser.getWorkspace().getNodeTypeManager();
NodeTypeTemplate ntd = ntm.createNodeTypeTemplate();
ntd.setName("testNodeType");
ntd.setMixin(true);
ntm.registerNodeType(ntd, true);
Workspace testWsp = getTestWorkspace();
try {
try {
NodeTypeManager testNtm = testWsp.getNodeTypeManager();
testNtm.unregisterNodeType(ntd.getName());
fail("Namespace unregistration should be denied.");
} catch (AccessDeniedException e) {
// success
}
try {
NodeTypeManager testNtm = testWsp.getNodeTypeManager();
testNtm.unregisterNodeTypes(new String[] { ntd.getName() });
fail("Namespace unregistration should be denied.");
} catch (AccessDeniedException e) {
// success
}
} finally {
// clean up (not supported by jackrabbit-core)
try {
ntm.unregisterNodeType(ntd.getName());
} catch (Exception e) {
// ns unregistration is not supported by jackrabbit-core.
}
}
}
Aggregations