jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dpfis...@apache.org
Subject svn commit: r790127 - in /jackrabbit/trunk/jackrabbit-core: pom.xml src/main/java/org/apache/jackrabbit/core/ItemManager.java src/main/java/org/apache/jackrabbit/core/NodeImpl.java
Date Wed, 01 Jul 2009 11:37:48 GMT
Author: dpfister
Date: Wed Jul  1 11:37:48 2009
New Revision: 790127

URL: http://svn.apache.org/viewvc?rev=790127&view=rev
Log:
JCR-1773 - shareable nodes: wrong path returned, causes remove() to delete wrong node

Modified:
    jackrabbit/trunk/jackrabbit-core/pom.xml
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemManager.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java

Modified: jackrabbit/trunk/jackrabbit-core/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/pom.xml?rev=790127&r1=790126&r2=790127&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/pom.xml (original)
+++ jackrabbit/trunk/jackrabbit-core/pom.xml Wed Jul  1 11:37:48 2009
@@ -88,7 +88,6 @@
               <name>known.issues</name>
               <value>
                 org.apache.jackrabbit.core.xml.DocumentViewTest#testMultiValue
-                org.apache.jackrabbit.test.api.ShareableNodeTest#testSharedNodePath
               </value>
             </property>
           </systemProperties>

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemManager.java?rev=790127&r1=790126&r2=790127&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemManager.java
Wed Jul  1 11:37:48 2009
@@ -430,14 +430,19 @@
      * @throws AccessDeniedException
      * @throws RepositoryException
      */
-    public ItemImpl getItem(Path path)
-            throws PathNotFoundException, AccessDeniedException, RepositoryException {
+    public ItemImpl getItem(Path path) throws PathNotFoundException,
+            AccessDeniedException, RepositoryException {
         ItemId id = hierMgr.resolvePath(path);
         if (id == null) {
             throw new PathNotFoundException(safeGetJCRPath(path));
         }
         try {
-            return getItem(id, path);
+            ItemImpl item = getItem(id, path);
+            // Test, if this item is a shareable node.
+            if (item.isNode() && ((NodeImpl) item).isShareable()) {
+                return getNode(path);
+            }
+            return item;
         } catch (ItemNotFoundException infe) {
             throw new PathNotFoundException(safeGetJCRPath(path));
         }
@@ -450,14 +455,23 @@
      * @throws AccessDeniedException
      * @throws RepositoryException
      */
-    public NodeImpl getNode(Path path)
-            throws PathNotFoundException, AccessDeniedException, RepositoryException {
+    public NodeImpl getNode(Path path) throws PathNotFoundException,
+            AccessDeniedException, RepositoryException {
         NodeId id = hierMgr.resolveNodePath(path);
         if (id == null) {
             throw new PathNotFoundException(safeGetJCRPath(path));
         }
+        NodeId parentId = null;
+        if (!path.denotesRoot()) {
+            parentId = hierMgr.resolveNodePath(path.getAncestor(1));
+        }
         try {
-            return (NodeImpl) getItem(id, path);
+            if (parentId == null) {
+                return (NodeImpl) getItem(id, path);
+            }
+            // if the node is shareable, it now returns the node with the right
+            // parent
+            return getNode(id, parentId);
         } catch (ItemNotFoundException infe) {
             throw new PathNotFoundException(safeGetJCRPath(path));
         }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java?rev=790127&r1=790126&r2=790127&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
Wed Jul  1 11:37:48 2009
@@ -206,36 +206,23 @@
      */
     protected NodeId resolveRelativeNodePath(String relPath)
             throws RepositoryException {
+
+        Path p = resolveRelativePath(relPath);
+        return getNodeId(p);
+    }
+
+    /**
+     * Resolve a relative path given as string into a <code>Path</code>. If
+     * a <code>NameException</code> occurs, it will be rethrown embedded
+     * into a <code>RepositoryException</code>
+     *
+     * @param relPath relative path
+     * @return <code>Path</code> object
+     * @throws RepositoryException if an error occurs
+     */
+    private Path resolveRelativePath(String relPath) throws RepositoryException {
         try {
-            /**
-             * first check if relPath is just a name (in which case we don't
-             * have to build & resolve absolute path)
-             */
-            Path p = session.getQPath(relPath);
-            if (p.getLength() == 1) {
-                Path.Element pe = p.getNameElement();
-                if (pe.denotesName()) {
-                    // check if node entry exists
-                    NodeState thisState = data.getNodeState();
-                    int index = pe.getIndex();
-                    if (index == 0) {
-                        index = 1;
-                    }
-                    ChildNodeEntry cne =
-                            thisState.getChildNodeEntry(pe.getName(), index);
-                    if (cne != null) {
-                        return cne.getId();
-                    } else {
-                        // there's no child node with that name
-                        return null;
-                    }
-                }
-            }
-            /**
-             * build and resolve absolute path
-             */
-            p = PathFactoryImpl.getInstance().create(getPrimaryPath(), p, true);
-            return session.getHierarchyManager().resolveNodePath(p);
+            return session.getQPath(relPath);
         } catch (NameException e) {
             String msg = "failed to resolve path " + relPath + " relative to " + this;
             log.debug(msg);
@@ -244,6 +231,45 @@
     }
 
     /**
+     * Returns the id of the node at <code>p</code> or <code>null</code>
+     * if no node exists at <code>p</code>.
+     * <p/>
+     * Note that access rights are not checked.
+     *
+     * @param p relative path of a (possible) node
+     * @return the id of the node at <code>p</code> or
+     *         <code>null</code> if no node exists at <code>p</code>
+     * @throws RepositoryException if <code>relPath</code> is not a valid
+     *                             relative path
+     */
+    private NodeId getNodeId(Path p) throws RepositoryException {
+        if (p.getLength() == 1) {
+            Path.Element pe = p.getNameElement();
+            if (pe.denotesName()) {
+                // check if node entry exists
+                NodeState thisState = data.getNodeState();
+                int index = pe.getIndex();
+                if (index == 0) {
+                    index = 1;
+                }
+                ChildNodeEntry cne =
+                        thisState.getChildNodeEntry(pe.getName(), index);
+                if (cne != null) {
+                    return cne.getId();
+                } else {
+                    // there's no child node with that name
+                    return null;
+                }
+            }
+        }
+        /**
+         * build and resolve absolute path
+         */
+        p = PathFactoryImpl.getInstance().create(getPrimaryPath(), p, true);
+        return session.getHierarchyManager().resolveNodePath(p);
+    }
+
+    /**
      * Determines if there are pending unsaved changes either on <i>this</i>
      * node or on any node or property in the subtree below it.
      *
@@ -2627,17 +2653,28 @@
      */
     public Node getNode(String relPath)
             throws PathNotFoundException, RepositoryException {
+
         // check state of this instance
         sanityCheck();
-        NodeId id = resolveRelativeNodePath(relPath);
+
+        Path p = resolveRelativePath(relPath);
+        NodeId id = getNodeId(p);
         if (id == null) {
             throw new PathNotFoundException(relPath);
         }
+
+        // determine parent as mandated by path
+        NodeId parentId = null;
+        if (!p.denotesRoot()) {
+            parentId = getNodeId(p.getAncestor(1));
+        }
         try {
-            if (data.getNodeState().hasChildNodeEntry(id)) {
-                return itemMgr.getNode(id, getNodeId());
-            }
-            return (NodeImpl) itemMgr.getItem(id);
+            if (parentId == null) {
+                return (NodeImpl) itemMgr.getItem(id);
+            }
+            // if the node is shareable, it now returns the node with the right
+            // parent
+            return itemMgr.getNode(id, parentId);
         } catch (AccessDeniedException ade) {
             throw new PathNotFoundException(relPath);
         } catch (ItemNotFoundException infe) {



Mime
View raw message