jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r516352 - /jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java
Date Fri, 09 Mar 2007 10:18:36 GMT
Author: angela
Date: Fri Mar  9 02:18:35 2007
New Revision: 516352

URL: http://svn.apache.org/viewvc?view=rev&rev=516352
Log:
- exists must also catch PathNotFoundException
- restore(NodeId, VersionId, boolean) must also cover Node.restore taking a relative path
that may point to a non-existing node.

Modified:
    jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java

Modified: jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java?view=diff&rev=516352&r1=516351&r2=516352
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java
(original)
+++ jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java
Fri Mar  9 02:18:35 2007
@@ -40,6 +40,7 @@
 import org.apache.jackrabbit.name.PathFormat;
 import org.apache.jackrabbit.name.NoPrefixDeclaredException;
 import org.apache.jackrabbit.name.NameFormat;
+import org.apache.jackrabbit.name.MalformedPathException;
 import org.apache.jackrabbit.value.QValueFactoryImpl;
 import org.apache.jackrabbit.value.ValueFormat;
 
@@ -274,6 +275,8 @@
             }
         } catch (ItemNotFoundException e) {
             return false;
+        } catch (PathNotFoundException e) {
+            return false;
         }
         return true;
     }
@@ -565,9 +568,42 @@
         final SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
         executeWithLocalEvents(new Callable() {
             public Object run() throws RepositoryException {
-                Node n = getNode(nodeId, sInfo);
-                Node v = getNode(versionId, sInfo);
-                n.restore(v.getName(), removeExisting);
+                Version v = (Version) getNode(versionId, sInfo);
+                if (exists(sessionInfo, nodeId)) {
+                    Node n = getNode(nodeId, sInfo);
+                    n.restore(v, removeExisting);
+                } else {
+                    try {
+                        // restore with rel-Path part
+                        Node n = null;
+                        Path relPath = null;
+                        Path path = nodeId.getPath();
+                        if (nodeId.getUniqueID() != null) {
+                            n = getNode(idFactory.createNodeId(nodeId.getUniqueID()), sInfo);
+                            relPath = (path.isAbsolute()) ? Path.ROOT.computeRelativePath(nodeId.getPath())
: path;
+                        } else {
+                            int degree = 0;
+                            while (degree < path.getLength()) {
+                                Path ancestorPath = path.getAncestor(degree);
+                                NodeId parentId = idFactory.createNodeId(nodeId.getUniqueID(),
ancestorPath);
+                                if (exists(sessionInfo, parentId)) {
+                                    n = getNode(parentId, sInfo);
+                                    relPath = ancestorPath.computeRelativePath(path);
+                                }
+                                degree++;
+                            }
+                        }
+                        if (n == null) {
+                            throw new PathNotFoundException("Path not found " + nodeId);
+                        } else {
+                            n.restore(v, PathFormat.format(relPath, sInfo.getNamespaceResolver()),
removeExisting);
+                        }
+                    } catch (MalformedPathException e) {
+                        throw new RepositoryException(e);
+                    } catch (NoPrefixDeclaredException e) {
+                        throw new RepositoryException(e);
+                    }
+                }
                 return null;
             }
         }, sInfo);



Mime
View raw message