@Override public final NodeTypeIterator registerNodeTypes( NodeTypeDefinition[] ntds, boolean allowUpdate) throws RepositoryException { Root root = getWriteRoot(); try { Tree tree = getOrCreateNodeTypes(root); for (NodeTypeDefinition ntd : ntds) { NodeTypeTemplateImpl template; if (ntd instanceof NodeTypeTemplateImpl) { template = (NodeTypeTemplateImpl) ntd; } else { // some external template implementation, copy before proceeding template = new NodeTypeTemplateImpl(getNamePathMapper(), ntd); } template.writeTo(tree, allowUpdate); } root.commit(); refresh(); List<NodeType> types = new ArrayList<NodeType>(ntds.length); for (NodeTypeDefinition ntd : ntds) { types.add(getNodeType(ntd.getName())); } return new NodeTypeIteratorAdapter(types); } catch (CommitFailedException e) { String message = "Failed to register node types."; throw e.asRepositoryException(message); } }
@NotNull @Override public NodeDefinition perform() throws RepositoryException { NodeDelegate parent = node.getParent(); if (parent == null) { return getNodeTypeManager().getRootDefinition(); } else { return getNodeTypeManager().getDefinition( parent.getTree(), node.getTree()); } } });
private EffectiveNodeType getEffectiveNodeType() throws RepositoryException { return getNodeTypeManager().getEffectiveNodeType(dlg.getTree()); }
@Override public void unregisterNodeType(String name) throws RepositoryException { Root root = getWriteRoot(); Tree type = root.getTree(NODE_TYPES_PATH).getChild(getOakName(name)); if (!type.exists()) { throw new NoSuchNodeTypeException("Node type " + name + " can not be unregistered."); } try { type.remove(); root.commit(); refresh(); } catch (CommitFailedException e) { String message = "Failed to unregister node type " + name; throw e.asRepositoryException(message); } }
@NotNull @Override public NodeType perform() throws RepositoryException { Tree tree = node.getTree(); String primaryTypeName = getPrimaryTypeName(tree); if (primaryTypeName != null) { return getNodeTypeManager().getNodeType(sessionContext.getJcrName(primaryTypeName)); } else { throw new RepositoryException("Unable to retrieve primary type for Node " + getNodePath()); } } });
@Test public void testNodeTypeWithCugNames() throws Exception { ReadWriteNodeTypeManager ntMgr = new ReadWriteNodeTypeManager() { @NotNull @Override protected Root getWriteRoot() { return root; } @Nullable @Override protected Tree getTypes() { return root.getTree(NODE_TYPES_PATH); } }; NodeTypeTemplate ntTemplate = ntMgr.createNodeTypeTemplate(); ntTemplate.setName("testNT"); NodeDefinitionTemplate ndt = ntMgr.createNodeDefinitionTemplate(); ndt.setName(REP_CUG_POLICY); ndt.setRequiredPrimaryTypeNames(new String[] {JcrConstants.NT_BASE}); ntTemplate.getNodeDefinitionTemplates().add(ndt); ntMgr.registerNodeType(ntTemplate, true); } }
@Override public NodeTypeTemplate createNodeTypeTemplate(NodeTypeDefinition ntd) throws ConstraintViolationException { return new NodeTypeTemplateImpl(getNamePathMapper(), ntd); }
@Before public void before() throws Exception { super.before(); ntMgr = new ReadWriteNodeTypeManager() { @NotNull @Override protected Root getWriteRoot() { return root; } @Override protected Tree getTypes() { return root.getTree(NODE_TYPES_PATH); } }; if (!ntMgr.hasNodeType(NT_NAME)) { NodeTypeTemplate tmpl = ntMgr.createNodeTypeTemplate(); tmpl.setName(NT_NAME); tmpl.setDeclaredSuperTypeNames(new String[]{JcrConstants.MIX_REFERENCEABLE, JcrConstants.NT_UNSTRUCTURED}); ntMgr.registerNodeType(tmpl, true); } NodeUtil a = new NodeUtil(root.getTree("/a")); NodeUtil test = a.addChild("referenceable", NT_NAME); test.setString(JcrConstants.JCR_UUID, UUIDUtils.generateUUID()); referenceablePath = test.getTree().getPath(); }
private int getOPV(Tree nodeTree, PropertyState property) throws RepositoryException { return getNodeTypeManager().getDefinition(nodeTree, property, false).getOnParentVersion(); }
@Nonnull @Override public Boolean perform() throws RepositoryException { Tree tree = node.getTree(); return getNodeTypeManager().isNodeType(getPrimaryTypeName(tree), getMixinTypeNames(tree), oakName); } });
@Override public void unregisterNodeType(String name) throws RepositoryException { Root root = getWriteRoot(); Tree type = root.getTree(NODE_TYPES_PATH).getChild(getOakName(name)); if (!type.exists()) { throw new NoSuchNodeTypeException("Node type " + name + " can not be unregistered."); } try { type.remove(); root.commit(); refresh(); } catch (CommitFailedException e) { String message = "Failed to unregister node type " + name; throw e.asRepositoryException(message); } }
@NotNull @Override public NodeType perform() throws RepositoryException { Tree tree = node.getTree(); String primaryTypeName = getPrimaryTypeName(tree); if (primaryTypeName != null) { return getNodeTypeManager().getNodeType(sessionContext.getJcrName(primaryTypeName)); } else { throw new RepositoryException("Unable to retrieve primary type for Node " + getNodePath()); } } });
@Override public NodeTypeTemplate createNodeTypeTemplate(NodeTypeDefinition ntd) throws ConstraintViolationException { return new NodeTypeTemplateImpl(getNamePathMapper(), ntd); }
private int getOPV(Tree nodeTree, PropertyState property) throws RepositoryException { return getNodeTypeManager().getDefinition(nodeTree, property, false).getOnParentVersion(); }
@NotNull @Override public Boolean perform() throws RepositoryException { Tree tree = node.getTree(); return getNodeTypeManager().isNodeType(getPrimaryTypeName(tree), getMixinTypeNames(tree), oakName); } });
@Override public final NodeTypeIterator registerNodeTypes( NodeTypeDefinition[] ntds, boolean allowUpdate) throws RepositoryException { Root root = getWriteRoot(); try { Tree tree = getOrCreateNodeTypes(root); for (NodeTypeDefinition ntd : ntds) { NodeTypeTemplateImpl template; if (ntd instanceof NodeTypeTemplateImpl) { template = (NodeTypeTemplateImpl) ntd; } else { // some external template implementation, copy before proceeding template = new NodeTypeTemplateImpl(getNamePathMapper(), ntd); } template.writeTo(tree, allowUpdate); } root.commit(); refresh(); List<NodeType> types = new ArrayList<NodeType>(ntds.length); for (NodeTypeDefinition ntd : ntds) { types.add(getNodeType(ntd.getName())); } return new NodeTypeIteratorAdapter(types); } catch (CommitFailedException e) { String message = "Failed to register node types."; throw e.asRepositoryException(message); } }
@Override public void unregisterNodeType(String name) throws RepositoryException { Root root = getWriteRoot(); Tree type = root.getTree(NODE_TYPES_PATH).getChild(getOakName(name)); if (!type.exists()) { throw new NoSuchNodeTypeException("Node type " + name + " can not be unregistered."); } try { type.remove(); root.commit(); refresh(); } catch (CommitFailedException e) { String message = "Failed to unregister node type " + name; throw e.asRepositoryException(message); } }
@NotNull @Override public NodeDefinition perform() throws RepositoryException { NodeDelegate parent = node.getParent(); if (parent == null) { return getNodeTypeManager().getRootDefinition(); } else { return getNodeTypeManager().getDefinition( parent.getTree(), node.getTree()); } } });
@Nonnull @Override public NodeType perform() throws RepositoryException { Tree tree = node.getTree(); String primaryTypeName = getPrimaryTypeName(tree); if (primaryTypeName != null) { return getNodeTypeManager().getNodeType(sessionContext.getJcrName(primaryTypeName)); } else { throw new RepositoryException("Unable to retrieve primary type for Node " + getNodePath()); } } });
@Override public NodeTypeTemplate createNodeTypeTemplate() { return new NodeTypeTemplateImpl(getNamePathMapper()); }