@Override public boolean apply(NodeDefinition nodeDefinition) { return nodeDefinition.isMandatory(); } });
@Override public boolean apply(NodeDefinition nodeDefinition) { return nodeDefinition.isMandatory(); } });
@Override public boolean apply(NodeDefinition nodeDefinition) { return nodeDefinition.isMandatory(); } });
public boolean canRemoveNode(String s) { boolean canRemoveNd = true; Iterator it = ntd.getNodeDefinitionTemplates().iterator(); NodeDefinition nd = null; while (it.hasNext()) { nd = (NodeDefinitionTemplate) it.next(); if ((nd != null) && (nd.getName().equals(s)) && (nd.isProtected() || nd.isMandatory())) { canRemoveNd = false; return canRemoveNd; } } return canRemoveNd; }
private void processChildNodeDefinition( Node nodeTypeNode, NodeDefinition childNodeDefinition ) throws RepositoryException { Node childNode = nodeTypeNode.addNode(CHILD_NODE_DEFINITION, CHILD_NODE_DEFINITION); if (!RESIDUAL_ITEM_NAME.equals(childNodeDefinition.getName())) { childNode.setProperty(NAME, childNodeDefinition.getName()); } childNode.setProperty(AUTO_CREATED, childNodeDefinition.isAutoCreated()); childNode.setProperty(MANDATORY, childNodeDefinition.isMandatory()); childNode.setProperty(ON_PARENT_VERSION, OnParentVersionAction.nameFromValue(childNodeDefinition.getOnParentVersion())); childNode.setProperty(PROTECTED, childNodeDefinition.isProtected()); String[] requiredPrimaryTypeNames = childNodeDefinition.getRequiredPrimaryTypeNames(); childNode.setProperty(REQUIRED_PRIMARY_TYPES, requiredPrimaryTypeNames != null ? requiredPrimaryTypeNames : new String[0]); childNode.setProperty(SAME_NAME_SIBLINGS, childNodeDefinition.allowsSameNameSiblings()); childNode.setProperty(DEFAULT_PRIMARY_TYPE, childNodeDefinition.getDefaultPrimaryTypeName()); }
private void processChildNodeDefinition( Node nodeTypeNode, NodeDefinition childNodeDefinition ) throws RepositoryException { Node childNode = nodeTypeNode.addNode(CHILD_NODE_DEFINITION, CHILD_NODE_DEFINITION); if (!RESIDUAL_ITEM_NAME.equals(childNodeDefinition.getName())) { childNode.setProperty(NAME, childNodeDefinition.getName()); } childNode.setProperty(AUTO_CREATED, childNodeDefinition.isAutoCreated()); childNode.setProperty(MANDATORY, childNodeDefinition.isMandatory()); childNode.setProperty(ON_PARENT_VERSION, OnParentVersionAction.nameFromValue(childNodeDefinition.getOnParentVersion())); childNode.setProperty(PROTECTED, childNodeDefinition.isProtected()); String[] requiredPrimaryTypeNames = childNodeDefinition.getRequiredPrimaryTypeNames(); childNode.setProperty(REQUIRED_PRIMARY_TYPES, requiredPrimaryTypeNames != null ? requiredPrimaryTypeNames : new String[0]); childNode.setProperty(SAME_NAME_SIBLINGS, childNodeDefinition.allowsSameNameSiblings()); childNode.setProperty(DEFAULT_PRIMARY_TYPE, childNodeDefinition.getDefaultPrimaryTypeName()); }
/** * Checks if mandatory node definitions are respected. */ private void checkMandatoryConstraint(Node node, NodeType type) throws RepositoryException { // test if node contains all mandatory nodes of current type NodeDefinition nodeDefs[] = type.getChildNodeDefinitions(); for (int i = 0; i < nodeDefs.length; i++) { NodeDefinition nodeDef = nodeDefs[i]; if (nodeDef.isMandatory()) { foundMandatoryNode = true; try { node.getNode(nodeDef.getName()); } catch (PathNotFoundException e) { fail("Mandatory child " + nodeDef.getName() + " for " + node.getPath() + " does not exist."); } } } }
/** * @see org.apache.jackrabbit.commons.predicate.DepthPredicate#matches(javax.jcr.Item) */ protected boolean matches(Item item) throws RepositoryException { if (item.isNode()) { return ((Node) item).getDefinition().isMandatory() == isMandatory; } return ((Property) item).getDefinition().isMandatory() == isMandatory; } }
public boolean matches(Item item) throws RepositoryException { if (item.isNode()) { return ((Node) item).getDefinition().isMandatory() == isMandatory; } else { return ((Property) item).getDefinition().isMandatory() == isMandatory; } }
/** * @see org.apache.jackrabbit.commons.predicate.DepthPredicate#matches(javax.jcr.Item) */ @Override protected boolean matches(Item item) throws RepositoryException { if (item.isNode()) { return ((Node) item).getDefinition().isMandatory() == isMandatory; } return ((Property) item).getDefinition().isMandatory() == isMandatory; } }
/** * @see org.apache.jackrabbit.commons.predicate.DepthPredicate#matches(javax.jcr.Item) */ @Override protected boolean matches(Item item) throws RepositoryException { if (item.isNode()) { return ((Node) item).getDefinition().isMandatory() == isMandatory; } return ((Property) item).getDefinition().isMandatory() == isMandatory; } }
/** * @see org.apache.jackrabbit.commons.predicate.DepthPredicate#matches(javax.jcr.Item) */ @Override protected boolean matches(Item item) throws RepositoryException { if (item.isNode()) { return ((Node) item).getDefinition().isMandatory() == isMandatory; } return ((Property) item).getDefinition().isMandatory() == isMandatory; } }
private JcrNodeDefinition childNodeDefinitionFrom( NodeDefinition childNodeDefn ) { Name childNodeName = nameFactory.create(childNodeDefn.getName()); Name defaultPrimaryTypeName = nameFactory.create(childNodeDefn.getDefaultPrimaryTypeName()); int onParentVersion = childNodeDefn.getOnParentVersion(); boolean mandatory = childNodeDefn.isMandatory(); boolean allowsSns = childNodeDefn.allowsSameNameSiblings(); boolean autoCreated = childNodeDefn.isAutoCreated(); boolean isProtected = childNodeDefn.isProtected(); Name[] requiredTypes; String[] requiredTypeNames = childNodeDefn.getRequiredPrimaryTypeNames(); if (requiredTypeNames != null) { List<Name> names = new ArrayList<Name>(requiredTypeNames.length); for (String typeName : requiredTypeNames) { names.add(nameFactory.create(typeName)); } requiredTypes = names.toArray(new Name[names.size()]); } else { requiredTypes = new Name[0]; } NodeKey prototypeKey = repository.repositoryCache().getSystemKey(); return new JcrNodeDefinition(this.context, null, prototypeKey, childNodeName, onParentVersion, autoCreated, mandatory, isProtected, allowsSns, defaultPrimaryTypeName, requiredTypes); }
protected void assertChild( String nodeTypeName, String childName, String[] requiredTypes, String defaultPrimaryType, ChildOptions[] childOptions, OnParentVersion onParentVersioning ) { Set<ChildOptions> options = new HashSet<ChildOptions>(); for (ChildOptions option : childOptions) options.add(option); NodeTypeDefinition defn = defn(nodeTypeName); NodeDefinition childDefn = childDefn(defn, childName); assertThat(childDefn.getName(), is(childName)); assertThat(childDefn.getDefaultPrimaryTypeName(), is(defaultPrimaryType)); assertThat(childDefn.isMandatory(), is(options.contains(ChildOptions.Mandatory))); assertThat(childDefn.isAutoCreated(), is(options.contains(ChildOptions.Autocreated))); assertThat(childDefn.isProtected(), is(options.contains(ChildOptions.Protected))); assertThat(childDefn.allowsSameNameSiblings(), is(options.contains(ChildOptions.Sns))); assertThat(childDefn.getOnParentVersion(), is(opv(onParentVersioning))); assertThat(childDefn.getRequiredPrimaryTypeNames(), is(requiredTypes)); } }
@Override public void checkMandatoryItems(Tree tree) throws ConstraintViolationException { for (NodeType nodeType : nodeTypes.values()) { for (PropertyDefinition pd : nodeType.getPropertyDefinitions()) { String name = pd.getName(); if (pd.isMandatory() && !pd.isProtected() && tree.getProperty(name) == null) { throw new ConstraintViolationException( "Property '" + name + "' in '" + nodeType.getName() + "' is mandatory"); } } for (NodeDefinition nd : nodeType.getChildNodeDefinitions()) { String name = nd.getName(); if (nd.isMandatory() && !nd.isProtected() && !tree.hasChild(name)) { throw new ConstraintViolationException( "Node '" + name + "' in '" + nodeType.getName() + "' is mandatory"); } } } }
@Override public void checkMandatoryItems(Tree tree) throws ConstraintViolationException { for (NodeType nodeType : nodeTypes.values()) { for (PropertyDefinition pd : nodeType.getPropertyDefinitions()) { String name = pd.getName(); if (pd.isMandatory() && !pd.isProtected() && tree.getProperty(name) == null) { throw new ConstraintViolationException( "Property '" + name + "' in '" + nodeType.getName() + "' is mandatory"); } } for (NodeDefinition nd : nodeType.getChildNodeDefinitions()) { String name = nd.getName(); if (nd.isMandatory() && !nd.isProtected() && !tree.hasChild(name)) { throw new ConstraintViolationException( "Node '" + name + "' in '" + nodeType.getName() + "' is mandatory"); } } } }
@Override public void checkMandatoryItems(Tree tree) throws ConstraintViolationException { for (NodeType nodeType : nodeTypes.values()) { for (PropertyDefinition pd : nodeType.getPropertyDefinitions()) { String name = pd.getName(); if (pd.isMandatory() && !pd.isProtected() && tree.getProperty(name) == null) { throw new ConstraintViolationException( "Property '" + name + "' in '" + nodeType.getName() + "' is mandatory"); } } for (NodeDefinition nd : nodeType.getChildNodeDefinitions()) { String name = nd.getName(); if (nd.isMandatory() && !nd.isProtected() && !tree.hasChild(name)) { throw new ConstraintViolationException( "Node '" + name + "' in '" + nodeType.getName() + "' is mandatory"); } } } }
/** * Creates a new node definition based on a JCR <code>NodeDefinition</code>. * * @param nodeDef the node definition. * @param resolver the name/path resolver of the session that provided the * node definition * @throws NameException if <code>nodeDef</code> contains an illegal * name. * @throws NamespaceException if <code>nodeDef</code> contains a name with * an namespace prefix that is unknown to * <code>resolver</code>. */ public QNodeDefinitionImpl(NodeDefinition nodeDef, NamePathResolver resolver) throws NameException, NamespaceException { this(nodeDef.getName().equals(NameConstants.ANY_NAME.getLocalName()) ? NameConstants.ANY_NAME : resolver.getQName(nodeDef.getName()), nodeDef.getDeclaringNodeType() != null ? resolver.getQName(nodeDef.getDeclaringNodeType().getName()) : null, nodeDef.isAutoCreated(), nodeDef.isMandatory(), nodeDef.getOnParentVersion(), nodeDef.isProtected(), nodeDef.getDefaultPrimaryType() != null ? resolver.getQName(nodeDef.getDefaultPrimaryType().getName()) : null, getNodeTypeNames(nodeDef.getRequiredPrimaryTypes(), resolver), nodeDef.allowsSameNameSiblings()); }
/** * Creates a new node definition based on a JCR <code>NodeDefinition</code>. * * @param nodeDef the node definition. * @param resolver the name/path resolver of the session that provided the * node definition * @throws NameException if <code>nodeDef</code> contains an illegal * name. * @throws NamespaceException if <code>nodeDef</code> contains a name with * an namespace prefix that is unknown to * <code>resolver</code>. */ public QNodeDefinitionImpl(NodeDefinition nodeDef, NamePathResolver resolver) throws NameException, NamespaceException { this(nodeDef.getName().equals(NameConstants.ANY_NAME.getLocalName()) ? NameConstants.ANY_NAME : resolver.getQName(nodeDef.getName()), nodeDef.getDeclaringNodeType() != null ? resolver.getQName(nodeDef.getDeclaringNodeType().getName()) : null, nodeDef.isAutoCreated(), nodeDef.isMandatory(), nodeDef.getOnParentVersion(), nodeDef.isProtected(), nodeDef.getDefaultPrimaryType() != null ? resolver.getQName(nodeDef.getDefaultPrimaryType().getName()) : null, getNodeTypeNames(nodeDef.getRequiredPrimaryTypes(), resolver), nodeDef.allowsSameNameSiblings()); }
@Override protected void setUp() throws Exception { super.setUp(); NodeType nt = superuser.getWorkspace().getNodeTypeManager().getNodeType(testNodeType); NodeDefinition[] ndefs = nt.getChildNodeDefinitions(); for (int i = 0; i < ndefs.length; i++) { if (ndefs[i].isMandatory() && !ndefs[i].isProtected() && !ndefs[i].isAutoCreated()) { childNodeDef = ndefs[i]; break; } } PropertyDefinition[] pdefs = nt.getPropertyDefinitions(); for (int i = 0; i < pdefs.length; i++) { if (pdefs[i].isMandatory() && !pdefs[i].isProtected() && !pdefs[i].isAutoCreated()) { childPropDef = pdefs[i]; break; } } if (childPropDef == null && childNodeDef == null) { cleanUp(); throw new NotExecutableException(); } }