jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From resc...@apache.org
Subject svn commit: r1462166 - in /jackrabbit/branches/2.6: ./ jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/URIResolverImpl.java
Date Thu, 28 Mar 2013 15:50:01 GMT
Author: reschke
Date: Thu Mar 28 15:50:01 2013
New Revision: 1462166

URL: http://svn.apache.org/r1462166
Log:
JCR-3554: RepositoryService.getReferences needs to deal with absolute paths in hrefs (ported
to 2.6)

Modified:
    jackrabbit/branches/2.6/   (props changed)
    jackrabbit/branches/2.6/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
    jackrabbit/branches/2.6/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/URIResolverImpl.java

Propchange: jackrabbit/branches/2.6/
------------------------------------------------------------------------------
  Merged /jackrabbit/trunk:r1462153

Modified: jackrabbit/branches/2.6/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.6/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java?rev=1462166&r1=1462165&r2=1462166&view=diff
==============================================================================
--- jackrabbit/branches/2.6/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
(original)
+++ jackrabbit/branches/2.6/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
Thu Mar 28 15:50:01 2013
@@ -22,6 +22,7 @@ import java.io.InputStreamReader;
 import java.io.Reader;
 import java.io.StringWriter;
 import java.io.UnsupportedEncodingException;
+import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -361,6 +362,20 @@ public class RepositoryServiceImpl imple
         }
     }
 
+    /**
+     * Resolve the given URI against a base URI (usually the request URI of an HTTP request)
+     */
+    private static String resolve(String baseUri, String relUri) throws RepositoryException
{
+        try {
+            java.net.URI base = new java.net.URI(baseUri);
+            java.net.URI rel = new java.net.URI(relUri);
+            return base.resolve(rel).toString();
+        }
+        catch (URISyntaxException ex) {
+            throw new RepositoryException(ex);
+        }
+    }
+
     private static void checkSubscription(Subscription subscription) throws RepositoryException
{
         if (!(subscription instanceof EventSubscriptionImpl)) {
             throw new RepositoryException("Unknown Subscription implementation.");
@@ -434,11 +449,15 @@ public class RepositoryServiceImpl imple
     }
 
     private static boolean isSameResource(String requestURI, MultiStatusResponse response)
{
-        String href = response.getHref();
-        if (href.endsWith("/") && !requestURI.endsWith("/")) {
-            href = href.substring(0, href.length() - 1);
+        try {
+            String href = resolve(requestURI, response.getHref());
+            if (href.endsWith("/") && !requestURI.endsWith("/")) {
+                href = href.substring(0, href.length() - 1);
+            }
+            return requestURI.equals(href);
+        } catch (RepositoryException e) {
+            return false;
         }
-        return requestURI.equals(href);
     }
 
     private String saveGetIdString(ItemId id, SessionInfo sessionInfo) {
@@ -554,7 +573,7 @@ public class RepositoryServiceImpl imple
         return parentUri + Text.escape(resolver.getJCRName(childName));
     }
 
-    private NodeId getParentId(DavPropertySet propSet, SessionInfo sessionInfo)
+    private NodeId getParentId(String baseUri, DavPropertySet propSet, SessionInfo sessionInfo)
         throws RepositoryException {
         NodeId parentId = null;
         DavProperty<?> p = propSet.get(JcrRemotingConstants.JCR_PARENT_LN, ItemResourceConstants.NAMESPACE);
@@ -562,7 +581,7 @@ public class RepositoryServiceImpl imple
             HrefProperty parentProp = new HrefProperty(p);
             String parentHref = parentProp.getHrefs().get(0);
             if (parentHref != null && parentHref.length() > 0) {
-                parentId = uriResolver.getNodeId(parentHref, sessionInfo);
+                parentId = uriResolver.getNodeId(resolve(baseUri, parentHref), sessionInfo);
             }
         }
         return parentId;
@@ -1016,9 +1035,9 @@ public class RepositoryServiceImpl imple
             }
 
             NamePathResolver resolver = getNamePathResolver(sessionInfo);
-            NodeId parentId = getParentId(propSet, sessionInfo);
+            NodeId parentId = getParentId(uri, propSet, sessionInfo);
 
-            NodeInfoImpl nInfo = buildNodeInfo(nodeResponse, parentId, propSet, sessionInfo,
resolver);
+            NodeInfoImpl nInfo = buildNodeInfo(uri, nodeResponse, parentId, propSet, sessionInfo,
resolver);
 
             for (MultiStatusResponse resp : childResponses) {
                 DavPropertySet childProps = resp.getProperties(DavServletResponse.SC_OK);
@@ -1068,11 +1087,11 @@ public class RepositoryServiceImpl imple
         }
     }
 
-    private NodeInfoImpl buildNodeInfo(MultiStatusResponse nodeResponse,
+    private NodeInfoImpl buildNodeInfo(String baseUri, MultiStatusResponse nodeResponse,
                                        NodeId parentId, DavPropertySet propSet,
                                        SessionInfo sessionInfo,
                                        NamePathResolver resolver) throws NameException, RepositoryException
{
-        NodeId id = uriResolver.buildNodeId(parentId, nodeResponse, sessionInfo.getWorkspaceName(),
getNamePathResolver(sessionInfo));
+        NodeId id = uriResolver.buildNodeId(parentId, baseUri, nodeResponse, sessionInfo.getWorkspaceName(),
getNamePathResolver(sessionInfo));
         NodeInfoImpl nInfo = new NodeInfoImpl(id, propSet, resolver);
         DavProperty p = propSet.get(JcrRemotingConstants.JCR_REFERENCES_LN, ItemResourceConstants.NAMESPACE);
         if (p != null) {
@@ -1185,12 +1204,9 @@ public class RepositoryServiceImpl imple
     public Iterator<PropertyId> getReferences(SessionInfo sessionInfo, NodeId nodeId,
Name propertyName, boolean weakReferences) throws ItemNotFoundException, RepositoryException
{
         // set of properties to be retrieved
         DavPropertyNameSet nameSet = new DavPropertyNameSet();
-        if (weakReferences) {
-            nameSet.add(JcrRemotingConstants.JCR_WEAK_REFERENCES_LN, ItemResourceConstants.NAMESPACE);
-        } else {
-            nameSet.add(JcrRemotingConstants.JCR_REFERENCES_LN, ItemResourceConstants.NAMESPACE);
-        }
-
+        String refType = weakReferences ? JcrRemotingConstants.JCR_WEAK_REFERENCES_LN : JcrRemotingConstants.JCR_REFERENCES_LN;
+        nameSet.add(refType, ItemResourceConstants.NAMESPACE);
+ 
         DavMethodBase method = null;
         try {
             String uri = getItemUri(nodeId, sessionInfo);
@@ -1207,18 +1223,13 @@ public class RepositoryServiceImpl imple
             for (MultiStatusResponse resp : responses) {
                 if (isSameResource(uri, resp)) {
                     DavPropertySet props = resp.getProperties(DavServletResponse.SC_OK);
-                    DavProperty<?> p;
-                    if (weakReferences) {
-                        p = props.get(JcrRemotingConstants.JCR_WEAK_REFERENCES_LN, ItemResourceConstants.NAMESPACE);
-                    } else {
-                        p = props.get(JcrRemotingConstants.JCR_REFERENCES_LN, ItemResourceConstants.NAMESPACE);
-                    }
+                    DavProperty<?> p = props.get(refType, ItemResourceConstants.NAMESPACE);
 
                     if (p != null) {
                         refIds = new ArrayList<PropertyId>();
                         HrefProperty hp = new HrefProperty(p);
                         for (String propHref : hp.getHrefs()) {
-                            PropertyId propId = uriResolver.getPropertyId(propHref, sessionInfo);
+                            PropertyId propId = uriResolver.getPropertyId(resolve(uri, propHref),
sessionInfo);
                             if (propertyName == null || propertyName.equals(propId.getName()))
{
                                 refIds.add(propId);
                             }
@@ -1511,7 +1522,7 @@ public class RepositoryServiceImpl imple
             if (ps.contains(DavPropertyName.LOCKDISCOVERY)) {
                 DavProperty<?> p = ps.get(DavPropertyName.LOCKDISCOVERY);
                 LockDiscovery ld = LockDiscovery.createFromXml(p.toXml(DomUtil.createDocument()));
-                NodeId parentId = getParentId(ps, sessionInfo);
+                NodeId parentId = getParentId(uri, ps, sessionInfo);
                 return retrieveLockInfo(ld, sessionInfo, nodeId, parentId);
             }  else {
                 // no lock present

Modified: jackrabbit/branches/2.6/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/URIResolverImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.6/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/URIResolverImpl.java?rev=1462166&r1=1462165&r2=1462166&view=diff
==============================================================================
--- jackrabbit/branches/2.6/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/URIResolverImpl.java
(original)
+++ jackrabbit/branches/2.6/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/URIResolverImpl.java
Thu Mar 28 15:50:01 2013
@@ -137,8 +137,6 @@ class URIResolverImpl implements URIReso
                         throw new RepositoryException(e.getMessage());
                     } catch (DavException e) {
                         throw ExceptionConverter.generate(e);
-                    } catch (URISyntaxException e) {
-                        throw new RepositoryException(e.getMessage());
                     } finally {
                         if (rm != null) {
                             rm.releaseConnection();
@@ -168,16 +166,21 @@ class URIResolverImpl implements URIReso
     /**
      * Resolve the given href obtained from multistatus against base URI
      */
-    private static String resolve(String wspUri, String href) throws URISyntaxException {
-        java.net.URI base = new java.net.URI(wspUri);
-        java.net.URI rel = new java.net.URI(href);
-        return base.resolve(rel).toASCIIString();
+    private static String resolve(String wspUri, String href) throws RepositoryException
{
+        try {
+            java.net.URI base = new java.net.URI(wspUri);
+            java.net.URI rel = new java.net.URI(href);
+            return base.resolve(rel).toString();
+        }
+        catch (URISyntaxException ex) {
+            throw new RepositoryException(ex);
+        }
     }
 
-    NodeId buildNodeId(NodeId parentId, MultiStatusResponse response,
+    protected NodeId buildNodeId(NodeId parentId, String baseUri, MultiStatusResponse response,
                        String workspaceName, NamePathResolver resolver) throws RepositoryException
{
         IdURICache cache = getCache(workspaceName);
-        
+
         NodeId nodeId;
         DavPropertySet propSet = response.getProperties(DavServletResponse.SC_OK);
 
@@ -194,7 +197,7 @@ class URIResolverImpl implements URIReso
             }
         }
         // cache
-        cache.add(response.getHref(), nodeId);
+        cache.add(resolve(baseUri, response.getHref()), nodeId);
         return nodeId;
     }
 
@@ -246,6 +249,7 @@ class URIResolverImpl implements URIReso
     }
 
     private NodeId getNodeId(String uri, SessionInfo sessionInfo, boolean nodeIsGone) throws
RepositoryException {
+
         IdURICache cache = getCache(sessionInfo.getWorkspaceName());
         if (cache.containsUri(uri)) {
             // id has been accessed before and is cached
@@ -281,7 +285,7 @@ class URIResolverImpl implements URIReso
             if (responses.length != 1) {
                 throw new ItemNotFoundException("Unable to retrieve the node with id " +
uri);
             }
-            return buildNodeId(parentId, responses[0], sessionInfo.getWorkspaceName(), service.getNamePathResolver(sessionInfo));
+            return buildNodeId(parentId, uri, responses[0], sessionInfo.getWorkspaceName(),
service.getNamePathResolver(sessionInfo));
 
         } catch (IOException e) {
             throw new RepositoryException(e);



Mime
View raw message