/** * Get the {@link SharedSet} for the given shareable node. * * @param shareableNode the shareable node * @return the SharedSet; never null */ public SharedSet getSharedSet( AbstractJcrNode shareableNode ) { NodeKey shareableNodeKey = shareableNode.key(); return sharedSets.computeIfAbsent(shareableNodeKey, key -> new SharedSet(shareableNode)); }
/** * Find all of the {@link javax.jcr.Node}s that make up the shared set. * * @return the iterator over the nodes in the node set; never null, but possibly empty if this is not shareable, or of * size 1 if the node is shareable but hasn't been shared * @throws RepositoryException if there is a problem finding the nodes in the set */ public NodeIterator getSharedNodes() throws RepositoryException { // Obtain the set of keys for all parents ... final SessionCache cache = session().cache(); Set<NodeKey> additionalParents = shareableNode.node().getAdditionalParentKeys(cache); // Obtain the Node objects for each of these ... final NodeKey key = shareableNode.key(); final String workspaceKey = key.getWorkspaceKey(); Collection<AbstractJcrNode> sharedNodes = new ArrayList<AbstractJcrNode>(additionalParents.size() + 1); sharedNodes.add(shareableNode); // add the shareable node for (NodeKey parentKey : additionalParents) { if (!workspaceKey.equals(parentKey.getWorkspaceKey())) { // The parent node has to be in this workspace ... continue; } if (session.nodeExists(parentKey)) { sharedNodes.add(getOrCreateSharedNode(parentKey)); } } // Return an iterator ... return new JcrNodeListIterator(sharedNodes.iterator(), sharedNodes.size()); } }
if (sharedSet.getSize() != 1) { NodeIterator sharedSetNodes = sharedSet.getSharedNodes(); List<AbstractJcrNode> shared = new ArrayList<AbstractJcrNode>(); while (sharedSetNodes.hasNext()) {
AbstractJcrNode existingShare = sharedSet.getSharedNodeAtOrBelow(destParent); if (existingShare != null) { String msg = JcrI18n.shareAlreadyExistsWithinParent.text(destAbsPath, existingShare.getPath());
AbstractJcrNode existingShare = sharedSet.getSharedNodeAtOrBelow(destParent); if (existingShare != null) { String msg = JcrI18n.shareAlreadyExistsWithinParent.text(destAbsPath, existingShare.getPath());
if (destAncestor.isShareable()) { SharedSet sharedSet = destAncestor.sharedSet(); AbstractJcrNode sharedNodeThatCreatesCircularity = sharedSet.getSharedNodeAtOrBelow(srcPath); if (sharedNodeThatCreatesCircularity != null) { Path badPath = sharedNodeThatCreatesCircularity.path();
if (destAncestor.isShareable()) { SharedSet sharedSet = destAncestor.sharedSet(); AbstractJcrNode sharedNodeThatCreatesCircularity = sharedSet.getSharedNodeAtOrBelow(srcPath); if (sharedNodeThatCreatesCircularity != null) { Path badPath = sharedNodeThatCreatesCircularity.path();
node = node.sharedSet().getSharedNode(cachedNode, parentKey);
node = node.sharedSet().getSharedNode(cachedNode, parentKey);
if (sharedSet.getSize() != 1) { NodeIterator sharedSetNodes = sharedSet.getSharedNodes(); List<AbstractJcrNode> shared = new ArrayList<AbstractJcrNode>(); while (sharedSetNodes.hasNext()) {
if (sharedSet.getSize() <= 1) {
if (sharedSet.getSize() <= 1) {
/** * Find all of the {@link javax.jcr.Node}s that make up the shared set. * * @return the iterator over the nodes in the node set; never null, but possibly empty if this is not shareable, or of * size 1 if the node is shareable but hasn't been shared * @throws RepositoryException if there is a problem finding the nodes in the set */ public NodeIterator getSharedNodes() throws RepositoryException { // Obtain the set of keys for all parents ... final SessionCache cache = session().cache(); Set<NodeKey> additionalParents = shareableNode.node().getAdditionalParentKeys(cache); // Obtain the Node objects for each of these ... final NodeKey key = shareableNode.key(); final String workspaceKey = key.getWorkspaceKey(); Collection<AbstractJcrNode> sharedNodes = new ArrayList<AbstractJcrNode>(additionalParents.size() + 1); sharedNodes.add(shareableNode); // add the shareable node for (NodeKey parentKey : additionalParents) { if (!workspaceKey.equals(parentKey.getWorkspaceKey())) { // The parent node has to be in this workspace ... continue; } if (session.nodeExists(parentKey)) { sharedNodes.add(getOrCreateSharedNode(parentKey)); } } // Return an iterator ... return new JcrNodeListIterator(sharedNodes.iterator(), sharedNodes.size()); } }
/** * Get the {@link JcrSharedNode shared Node instance} that is a child of the specified parent. * * @param cachedNode the cached node; may not be null * @param parentKey the key of the parent node; may not b enull * @return the shared node instance; never null */ public AbstractJcrNode getSharedNode( CachedNode cachedNode, NodeKey parentKey ) { assert parentKey != null; try { NodeKey actualParentKey = shareableNode.parentKey(); assert actualParentKey != null; if (!actualParentKey.equals(parentKey)) { // Obtain the set of keys for all parents ... final SessionCache cache = session.cache(); Set<NodeKey> additionalParents = cachedNode.getAdditionalParentKeys(cache); // And get the shared node for the parent key, first making sure the parent exists ... if (additionalParents.contains(parentKey) && session.nodeExists(parentKey)) { return getOrCreateSharedNode(parentKey); } } return shareableNode; } catch (RepositoryException e) { throw new RuntimeException(e); } }
/** * Get the {@link JcrSharedNode shared Node instance} that is a child of the specified parent. * * @param cachedNode the cached node; may not be null * @param parentKey the key of the parent node; may not b enull * @return the shared node instance; never null */ public AbstractJcrNode getSharedNode( CachedNode cachedNode, NodeKey parentKey ) { assert parentKey != null; try { NodeKey actualParentKey = shareableNode.parentKey(); assert actualParentKey != null; if (!actualParentKey.equals(parentKey)) { // Obtain the set of keys for all parents ... final SessionCache cache = session.cache(); Set<NodeKey> additionalParents = cachedNode.getAdditionalParentKeys(cache); // And get the shared node for the parent key, first making sure the parent exists ... if (additionalParents.contains(parentKey) && session.nodeExists(parentKey)) { return getOrCreateSharedNode(parentKey); } } return shareableNode; } catch (RepositoryException e) { throw new RuntimeException(e); } }
/** * Determine and return the first of any nodes in the shared set exist at a location that is at or below the supplied * path. * * @param path the path; may not be null * @return the node in the shared set that exists at or below the supplied path; or null if none of the nodes in the * shared set are at or below the supplied path * @throws ItemNotFoundException * @throws InvalidItemStateException * @throws RepositoryException */ public AbstractJcrNode getSharedNodeAtOrBelow( Path path ) throws RepositoryException, ItemNotFoundException, InvalidItemStateException { NodeIterator iter = getSharedNodes(); while (iter.hasNext()) { AbstractJcrNode shared = (AbstractJcrNode)iter.nextNode(); if (shared.path().isAtOrBelow(path)) return shared; } return null; }
/** * Signal that the supplied node was removed from it's parent. This method will adjust the corresponding {@link SharedSet} * even if the removed node was the original shareable node. * * @param shareableNode the shareable node that was removed from its shared set * @throws RepositoryException if there is a problem */ public void removed( AbstractJcrNode shareableNode ) throws RepositoryException { NodeKey shareableNodeKey = shareableNode.key(); SharedSet sharedSet = getSharedSet(shareableNode); if (sharedSet.shareableNode == shareableNode) { // We're removing the original shareable node, so we need to recreate the SharedSet after // we figure out the new parent ... session().releaseCachedNode(shareableNode); AbstractJcrNode newShared = session().node(shareableNodeKey, null); SharedSet newSharedSet = new SharedSet(newShared); sharedSets.put(shareableNodeKey, newSharedSet); } else { assert shareableNode instanceof JcrSharedNode; sharedSet.remove((JcrSharedNode)shareableNode); } }
/** * Signal that the supplied node was removed from it's parent. This method will adjust the corresponding {@link SharedSet} * even if the removed node was the original shareable node. * * @param shareableNode the shareable node that was removed from its shared set * @throws RepositoryException if there is a problem */ public void removed( AbstractJcrNode shareableNode ) throws RepositoryException { NodeKey shareableNodeKey = shareableNode.key(); SharedSet sharedSet = getSharedSet(shareableNode); if (sharedSet.shareableNode == shareableNode) { // We're removing the original shareable node, so we need to recreate the SharedSet after // we figure out the new parent ... session().releaseCachedNode(shareableNode); AbstractJcrNode newShared = session().node(shareableNodeKey, null); SharedSet newSharedSet = new SharedSet(newShared); sharedSets.put(shareableNodeKey, newSharedSet); } else { assert shareableNode instanceof JcrSharedNode; sharedSet.remove((JcrSharedNode)shareableNode); } }
/** * Determine and return the first of any nodes in the shared set exist at a location that is at or below the supplied * path. * * @param path the path; may not be null * @return the node in the shared set that exists at or below the supplied path; or null if none of the nodes in the * shared set are at or below the supplied path * @throws ItemNotFoundException * @throws InvalidItemStateException * @throws RepositoryException */ public AbstractJcrNode getSharedNodeAtOrBelow( Path path ) throws RepositoryException, ItemNotFoundException, InvalidItemStateException { NodeIterator iter = getSharedNodes(); while (iter.hasNext()) { AbstractJcrNode shared = (AbstractJcrNode)iter.nextNode(); if (shared.path().isAtOrBelow(path)) return shared; } return null; }
final AbstractJcrNode node( CachedNode node, Path path ) throws PathNotFoundException, AccessDeniedException, RepositoryException { CachedNode child = cachedNode(cache, node, path, ModeShapePermissions.READ); AbstractJcrNode result = node(child, (Type)null, null); if (result.isShareable()) { // Find the shared node with the desired path ... AbstractJcrNode atOrBelow = result.sharedSet().getSharedNodeAtOrBelow(path); if (atOrBelow != null) result = atOrBelow; } return result; }