incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jus...@apache.org
Subject svn commit: r953547 - in /sling/trunk/bundles/jcr/resource/src: main/java/org/apache/sling/jcr/resource/internal/ test/java/org/apache/sling/jcr/resource/internal/
Date Fri, 11 Jun 2010 03:17:15 GMT
Author: justin
Date: Fri Jun 11 03:17:13 2010
New Revision: 953547

URL: http://svn.apache.org/viewvc?rev=953547&view=rev
Log:
SLING-1551 - fixing JcrResourceResolver.map() and multi-workspace compatibility

Modified:
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver.java
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverFactoryImpl.java
    sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverTest.java

Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver.java?rev=953547&r1=953546&r2=953547&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver.java
(original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver.java
Fri Jun 11 03:17:13 2010
@@ -99,7 +99,7 @@ public class JcrResourceResolver
     private final Map<String, Object> originalAuthInfo;
 
     /** Resolvers for different workspaces. */
-    private Map<String,ResourceResolver> createdResolvers;
+    private Map<String,JcrResourceResolver> createdResolvers;
 
     /** Closed marker. */
     private volatile boolean closed = false;
@@ -399,7 +399,33 @@ public class JcrResourceResolver
 
         }
 
-        Resource res = resolveInternal(mappedPath);
+        Resource res = null;
+        String workspaceName = null;
+
+        if (useMultiWorkspaces) {
+            final int wsSepPos = mappedPath.indexOf(":/");
+            if (wsSepPos != -1) {
+                workspaceName = mappedPath.substring(0, wsSepPos);
+                if (workspaceName.equals(getSession().getWorkspace().getName())) {
+                    mappedPath = mappedPath.substring(wsSepPos + 1);
+                } else {
+                    try {
+                        JcrResourceResolver wsResolver = getResolverForWorkspace(workspaceName);
+                        mappedPath = mappedPath.substring(wsSepPos + 1);
+                        res = wsResolver.resolveInternal(mappedPath);
+                    } catch (LoginException e) {
+                        // requested a resource in a workspace I don't have access to.
+                        // we treat this as a not found resource
+                        return null;
+                    }
+                }
+            }
+        }
+
+        if (res == null) {
+            res = resolveInternal(mappedPath);
+        }
+
         if (res != null) {
 
             // keep, what we might have cut off in internal resolution
@@ -415,7 +441,7 @@ public class JcrResourceResolver
                 if (alias == null) {
                     alias = ResourceUtil.getName(res);
                 }
-                if (alias != null && alias.length() > 0) {
+                if (alias != null && alias.length() > 0 && !alias.endsWith(":"))
{
                     names.add(alias);
                 }
                 res = ResourceUtil.getParent(res);
@@ -747,11 +773,11 @@ public class JcrResourceResolver
     /**
      * Get a resolver for the workspace.
      */
-    private synchronized ResourceResolver getResolverForWorkspace(final String workspaceName)
throws LoginException {
+    private synchronized JcrResourceResolver getResolverForWorkspace(final String workspaceName)
throws LoginException {
         if ( createdResolvers == null ) {
-            createdResolvers = new HashMap<String,ResourceResolver>();
+            createdResolvers = new HashMap<String,JcrResourceResolver>();
         }
-        ResourceResolver wsResolver = createdResolvers.get(workspaceName);
+        JcrResourceResolver wsResolver = createdResolvers.get(workspaceName);
         if (wsResolver == null) {
             final Map<String,Object> newAuthInfo =
                 originalAuthInfo == null ? new HashMap<String, Object>() : new HashMap<String,Object>(originalAuthInfo);

Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverFactoryImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverFactoryImpl.java?rev=953547&r1=953546&r2=953547&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverFactoryImpl.java
(original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverFactoryImpl.java
Fri Jun 11 03:17:13 2010
@@ -238,7 +238,7 @@ public class JcrResourceResolverFactoryI
      *
      * @see org.apache.sling.jcr.resource.JcrResourceResolverFactory#getResourceResolver(javax.jcr.Session)
      */
-    public ResourceResolver getResourceResolver(Session session) {
+    public JcrResourceResolver getResourceResolver(Session session) {
         return getResourceResolver(session, true, null);
     }
 
@@ -471,7 +471,7 @@ public class JcrResourceResolverFactoryI
     /**
      * @see org.apache.sling.api.resource.ResourceResolverFactory#getAdministrativeResourceResolver(java.util.Map)
      */
-    public ResourceResolver getAdministrativeResourceResolver(final Map<String, Object>
authenticationInfo)
+    public JcrResourceResolver getAdministrativeResourceResolver(final Map<String, Object>
authenticationInfo)
     throws LoginException {
         final String workspace = getWorkspace(authenticationInfo);
         final Session session;
@@ -487,7 +487,7 @@ public class JcrResourceResolverFactoryI
      * Create a new ResourceResolver wrapping a Session object. Carries map of
      * authentication info in order to create a new resolver as needed.
      */
-    private ResourceResolver getResourceResolver(final Session session,
+    private JcrResourceResolver getResourceResolver(final Session session,
                                                  final boolean isAdmin,
                                                  final Map<String, Object> authenticationInfo)
{
         final JcrResourceProviderEntry sessionRoot = new JcrResourceProviderEntry(
@@ -499,7 +499,7 @@ public class JcrResourceResolverFactoryI
     /**
      * @see org.apache.sling.api.resource.ResourceResolverFactory#getResourceResolver(java.util.Map)
      */
-    public ResourceResolver getResourceResolver(final Map<String, Object> authenticationInfo)
+    public JcrResourceResolver getResourceResolver(final Map<String, Object> authenticationInfo)
     throws LoginException {
         final Credentials credentials = getCredentials(authenticationInfo);
         final String workspace = getWorkspace(authenticationInfo);

Modified: sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverTest.java?rev=953547&r1=953546&r2=953547&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverTest.java
(original)
+++ sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverTest.java
Fri Jun 11 03:17:13 2010
@@ -1056,6 +1056,9 @@ public class JcrResourceResolverTest ext
         path = "/child";
         mapped = resResolver.map(child.getPath());
         assertEquals(path, mapped);
+
+        mapped = mwResResolver.map("ws2:" + rootWs2Node.getPath());
+        assertEquals(rootWs2Node.getPath(), mapped);
     }
 
     public void testMapURLEscaping() throws Exception {



Mime
View raw message