batcheditemoperations.java
来自「jsr170接口的java实现。是个apache的开源项目。」· Java 代码 · 共 1,596 行 · 第 1/5 页
JAVA
1,596 行
* @throws ConstraintViolationException * @throws AccessDeniedException * @throws VersionException * @throws LockException * @throws ItemNotFoundException * @throws ReferentialIntegrityException * @throws RepositoryException */ public void checkRemoveNode(NodeState targetState, int options) throws ConstraintViolationException, AccessDeniedException, VersionException, LockException, ItemNotFoundException, ReferentialIntegrityException, RepositoryException { checkRemoveNode(targetState, targetState.getParentId(), options); } /** * Checks if removing the given target node from the specifed parent * is allowed in the current context. * * @param targetState * @param parentId * @param options bit-wise OR'ed flags specifying the checks that should be * performed; any combination of the following constants: * <ul> * <li><code>{@link #CHECK_ACCESS}</code>: make sure * current session is granted read access on parent * and remove privilege on target node</li> * <li><code>{@link #CHECK_LOCK}</code>: make sure * there's no foreign lock on parent node</li> * <li><code>{@link #CHECK_VERSIONING}</code>: make sure * parent node is checked-out</li> * <li><code>{@link #CHECK_CONSTRAINTS}</code>: * make sure no node type constraints would be violated</li> * <li><code>{@link #CHECK_REFERENCES}</code>: * make sure no references exist on target node</li> * </ul> * @throws ConstraintViolationException * @throws AccessDeniedException * @throws VersionException * @throws LockException * @throws ItemNotFoundException * @throws ReferentialIntegrityException * @throws RepositoryException */ public void checkRemoveNode(NodeState targetState, NodeId parentId, int options) throws ConstraintViolationException, AccessDeniedException, VersionException, LockException, ItemNotFoundException, ReferentialIntegrityException, RepositoryException { if (targetState.getParentId() == null) { // root or orphaned node throw new ConstraintViolationException("cannot remove root node"); } NodeId targetId = targetState.getNodeId(); NodeState parentState = getNodeState(parentId); Path parentPath = hierMgr.getPath(parentId); // 1. locking status if ((options & CHECK_LOCK) == CHECK_LOCK) { // make sure there's no foreign lock on parent node verifyUnlocked(parentPath); } // 2. versioning status if ((options & CHECK_VERSIONING) == CHECK_VERSIONING) { // make sure parent node is checked-out verifyCheckedOut(parentPath); } // 3. access rights if ((options & CHECK_ACCESS) == CHECK_ACCESS) { AccessManager accessMgr = session.getAccessManager(); try { // make sure current session is granted read access on parent node if (!accessMgr.isGranted(targetId, AccessManager.READ)) { throw new PathNotFoundException(safeGetJCRPath(targetId)); } // make sure current session is allowed to remove target node if (!accessMgr.isGranted(targetId, AccessManager.REMOVE)) { throw new AccessDeniedException(safeGetJCRPath(targetId) + ": not allowed to remove node"); } } catch (ItemNotFoundException infe) { String msg = "internal error: failed to check access rights for " + safeGetJCRPath(targetId); log.debug(msg); throw new RepositoryException(msg, infe); } } // 4. node type constraints if ((options & CHECK_CONSTRAINTS) == CHECK_CONSTRAINTS) { NodeDef parentDef = ntReg.getNodeDef(parentState.getDefinitionId()); if (parentDef.isProtected()) { throw new ConstraintViolationException(safeGetJCRPath(parentId) + ": cannot remove child node of protected parent node"); } NodeDef targetDef = ntReg.getNodeDef(targetState.getDefinitionId()); if (targetDef.isMandatory()) { throw new ConstraintViolationException(safeGetJCRPath(targetId) + ": cannot remove mandatory node"); } if (targetDef.isProtected()) { throw new ConstraintViolationException(safeGetJCRPath(targetId) + ": cannot remove protected node"); } } // 5. referential integrity if ((options & CHECK_REFERENCES) == CHECK_REFERENCES) { EffectiveNodeType ent = getEffectiveNodeType(targetState); if (ent.includesNodeType(QName.MIX_REFERENCEABLE)) { NodeReferencesId refsId = new NodeReferencesId(targetState.getNodeId()); if (stateMgr.hasNodeReferences(refsId)) { try { NodeReferences refs = stateMgr.getNodeReferences(refsId); if (refs.hasReferences()) { throw new ReferentialIntegrityException(safeGetJCRPath(targetId) + ": cannot remove node with references"); } } catch (ItemStateException ise) { String msg = "internal error: failed to check references on " + safeGetJCRPath(targetId); log.error(msg, ise); throw new RepositoryException(msg, ise); } } } } } /** * Verifies that the node at <code>nodePath</code> is writable. The * following conditions must hold true: * <ul> * <li>the node must exist</li> * <li>the current session must be granted read & write access on it</li> * <li>the node must not be locked by another session</li> * <li>the node must not be checked-in</li> * <li>the node must not be protected</li> * </ul> * * @param nodePath path of node to check * @throws PathNotFoundException if no node exists at * <code>nodePath</code> of the current * session is not granted read access * to the specified path * @throws AccessDeniedException if write access to the specified * path is not allowed * @throws ConstraintViolationException if the node at <code>nodePath</code> * is protected * @throws VersionException if the node at <code>nodePath</code> * is checked-in * @throws LockException if the node at <code>nodePath</code> * is locked by another session * @throws RepositoryException if another error occurs */ public void verifyCanWrite(Path nodePath) throws PathNotFoundException, AccessDeniedException, ConstraintViolationException, VersionException, LockException, RepositoryException { NodeState node = getNodeState(nodePath); // access rights AccessManager accessMgr = session.getAccessManager(); // make sure current session is granted read access on node if (!accessMgr.isGranted(node.getNodeId(), AccessManager.READ)) { throw new PathNotFoundException(safeGetJCRPath(node.getNodeId())); } // make sure current session is granted write access on node if (!accessMgr.isGranted(node.getNodeId(), AccessManager.WRITE)) { throw new AccessDeniedException(safeGetJCRPath(node.getNodeId()) + ": not allowed to modify node"); } // locking status verifyUnlocked(nodePath); // node type constraints verifyNotProtected(nodePath); // versioning status verifyCheckedOut(nodePath); } /** * Verifies that the node at <code>nodePath</code> can be read. The * following conditions must hold true: * <ul> * <li>the node must exist</li> * <li>the current session must be granted read access on it</li> * </ul> * * @param nodePath path of node to check * @throws PathNotFoundException if no node exists at * <code>nodePath</code> of the current * session is not granted read access * to the specified path * @throws RepositoryException if another error occurs */ public void verifyCanRead(Path nodePath) throws PathNotFoundException, RepositoryException { NodeState node = getNodeState(nodePath); // access rights AccessManager accessMgr = session.getAccessManager(); // make sure current session is granted read access on node if (!accessMgr.isGranted(node.getNodeId(), AccessManager.READ)) { throw new PathNotFoundException(safeGetJCRPath(node.getNodeId())); } } /** * Helper method that finds the applicable definition for a child node with * the given name and node type in the parent node's node type and * mixin types. * * @param name * @param nodeTypeName * @param parentState * @return a <code>NodeDef</code> * @throws ConstraintViolationException if no applicable child node definition * could be found * @throws RepositoryException if another error occurs */ public NodeDef findApplicableNodeDefinition(QName name, QName nodeTypeName, NodeState parentState) throws RepositoryException, ConstraintViolationException { EffectiveNodeType entParent = getEffectiveNodeType(parentState); return entParent.getApplicableChildNodeDef(name, nodeTypeName, ntReg); } /** * Helper method that finds the applicable definition for a property with * the given name, type and multiValued characteristic in the parent node's * node type and mixin types. If there more than one applicable definitions * then the following rules are applied: * <ul> * <li>named definitions are preferred to residual definitions</li> * <li>definitions with specific required type are preferred to definitions * with required type UNDEFINED</li> * </ul> * * @param name * @param type * @param multiValued * @param parentState * @return a <code>PropDef</code> * @throws ConstraintViolationException if no applicable property definition * could be found * @throws RepositoryException if another error occurs */ public PropDef findApplicablePropertyDefinition(QName name, int type, boolean multiValued, NodeState parentState) throws RepositoryException, ConstraintViolationException { EffectiveNodeType entParent = getEffectiveNodeType(parentState); return entParent.getApplicablePropertyDef(name, type, multiValued); } /** * Helper method that finds the applicable definition for a property with * the given name, type in the parent node's node type and mixin types. * Other than <code>{@link #findApplicablePropertyDefinition(QName, int, boolean, NodeState)}</code> * this method does not take the multiValued flag into account in the * selection algorithm. If there more than one applicable definitions then * the following rules are applied: * <ul> * <li>named definitions are preferred to residual definitions</li> * <li>definitions with specific required type are preferred to definitions * with required type UNDEFINED</li> * <li>single-value definitions are preferred to multiple-value definitions</li> * </ul> * * @param name * @param type * @param parentState * @return a <code>PropDef</code> * @throws ConstraintViolationException if no applicable property definition * could be found * @throws RepositoryException if another error occurs */ public PropDef findApplicablePropertyDefinition(QName name, int type, NodeState parentState) throws RepositoryException, ConstraintViolationException { EffectiveNodeType entParent = getEffectiveNodeType(parentState); return entParent.getApplicablePropertyDef(name, type); } //--------------------------------------------< low-level item operations > /** * Creates a new node. * <p/> * Note that access rights are <b><i>not</i></b> enforced! * <p/> * <b>Precondition:</b> the state manager needs to be in edit mode. * * @param parent * @param nodeName * @param nodeTypeName * @param mixinNames * @param id * @return * @throws ItemExistsException * @throws ConstraintViolationException * @throws RepositoryException * @throws IllegalStateException if the state mananger is not in edit mode */ public NodeState createNodeState(NodeState parent, QName nodeName,
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?