incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jus...@apache.org
Subject svn commit: r951545 - in /sling/trunk/bundles/jcr/resource/src: main/java/org/apache/sling/jcr/resource/internal/ main/java/org/apache/sling/jcr/resource/internal/helper/jcr/ test/java/org/apache/sling/jcr/resource/internal/
Date Fri, 04 Jun 2010 19:51:47 GMT
Author: justin
Date: Fri Jun  4 19:51:47 2010
New Revision: 951545

URL: http://svn.apache.org/viewvc?rev=951545&view=rev
Log:
SLING-1546 - disabling multi workspace stuff by default more thoroughly

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/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProviderEntry.java
    sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceListenerTest.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=951545&r1=951544&r2=951545&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  4 19:51:47 2010
@@ -107,14 +107,18 @@ public class JcrResourceResolver
     /** a resolver with the workspace which was specifically requested via a request attribute.
*/
     private ResourceResolver requestBoundResolver;
 
+    private final boolean useMultiWorkspaces;
+
     public JcrResourceResolver(final JcrResourceProviderEntry rootProvider,
                                final JcrResourceResolverFactoryImpl factory,
                                final boolean isAdmin,
-                               final Map<String, Object> originalAuthInfo) {
+                               final Map<String, Object> originalAuthInfo,
+                               boolean useMultiWorkspaces) {
         this.rootProvider = rootProvider;
         this.factory = factory;
         this.isAdmin = isAdmin;
         this.originalAuthInfo = originalAuthInfo;
+        this.useMultiWorkspaces = useMultiWorkspaces;
     }
 
     /**
@@ -175,33 +179,36 @@ public class JcrResourceResolver
         // check for special namespace prefix treatment
         absPath = unmangleNamespaces(absPath);
 
-        // check for workspace info
-        final String workspaceName = (request == null ? null :
-            (String)request.getAttribute(ResourceResolver.REQUEST_ATTR_WORKSPACE_INFO));
-        if ( workspaceName != null && !workspaceName.equals(getSession().getWorkspace().getName()))
{
-            LOGGER.debug("Delegating resolving to resolver for workspace {}", workspaceName);
-            try {
-                final ResourceResolver wsResolver = getResolverForWorkspace(workspaceName);
-                requestBoundResolver = wsResolver;
-                return wsResolver.resolve(request, absPath);
-            } catch (LoginException e) {
-                // requested a resource in a workspace I don't have access to.
-                // we treat this as a not found resource
-                LOGGER.debug(
-                    "resolve: Path {} does not resolve, returning NonExistingResource",
-                       absPath);
+        String workspaceName = null;
+        if (useMultiWorkspaces) {
+            // check for workspace info
+            workspaceName = (request == null ? null :
+                (String)request.getAttribute(ResourceResolver.REQUEST_ATTR_WORKSPACE_INFO));
+            if ( workspaceName != null && !workspaceName.equals(getSession().getWorkspace().getName()))
{
+                LOGGER.debug("Delegating resolving to resolver for workspace {}", workspaceName);
+                try {
+                    final ResourceResolver wsResolver = getResolverForWorkspace(workspaceName);
+                    requestBoundResolver = wsResolver;
+                    return wsResolver.resolve(request, absPath);
+                } catch (LoginException e) {
+                    // requested a resource in a workspace I don't have access to.
+                    // we treat this as a not found resource
+                    LOGGER.debug(
+                        "resolve: Path {} does not resolve, returning NonExistingResource",
+                           absPath);
 
-                final Resource res = new NonExistingResource(this, absPath);
-                // SLING-864: if the path contains a dot we assume this to be
-                // the start for any selectors, extension, suffix, which may be
-                // used for further request processing.
-                int index = absPath.indexOf('.');
-                if (index != -1) {
-                    res.getResourceMetadata().setResolutionPathInfo(absPath.substring(index));
+                    final Resource res = new NonExistingResource(this, absPath);
+                    // SLING-864: if the path contains a dot we assume this to be
+                    // the start for any selectors, extension, suffix, which may be
+                    // used for further request processing.
+                    int index = absPath.indexOf('.');
+                    if (index != -1) {
+                        res.getResourceMetadata().setResolutionPathInfo(absPath.substring(index));
+                    }
+                    return this.factory.getResourceDecoratorTracker().decorate(res, workspaceName,
request);
                 }
-                return this.factory.getResourceDecoratorTracker().decorate(res, workspaceName,
request);
-            }
 
+            }
         }
         // Assume http://localhost:80 if request is null
         String[] realPathList = { absPath };
@@ -528,19 +535,21 @@ public class JcrResourceResolver
     public Resource getResource(String path) {
         checkClosed();
 
-        final int wsSepPos = path.indexOf(":/");
-        if (wsSepPos != -1) {
-            final String workspaceName = path.substring(0, wsSepPos);
-            if (workspaceName.equals(getSession().getWorkspace().getName())) {
-                path = path.substring(wsSepPos + 1);
-            } else {
-                try {
-                    ResourceResolver wsResolver = getResolverForWorkspace(workspaceName);
-                    return wsResolver.getResource(path.substring(wsSepPos + 1));
-                } 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 (useMultiWorkspaces) {
+            final int wsSepPos = path.indexOf(":/");
+            if (wsSepPos != -1) {
+                final String workspaceName = path.substring(0, wsSepPos);
+                if (workspaceName.equals(getSession().getWorkspace().getName())) {
+                    path = path.substring(wsSepPos + 1);
+                } else {
+                    try {
+                        ResourceResolver wsResolver = getResolverForWorkspace(workspaceName);
+                        return wsResolver.getResource(path.substring(wsSepPos + 1));
+                    } 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;
+                    }
                 }
             }
         }
@@ -601,17 +610,23 @@ public class JcrResourceResolver
         if (wsSepPos != -1) {
             final String workspaceName = path.substring(0, wsSepPos);
             if (!workspaceName.equals(getSession().getWorkspace().getName())) {
-                try {
-                    ResourceResolver wsResolver = getResolverForWorkspace(workspaceName);
-                    return wsResolver.listChildren(parent);
-                } catch (LoginException e) {
-                    // requested a resource in a workspace I don't have access to.
-                    // we treat this as a not found resource
+                if (useMultiWorkspaces) {
+                    try {
+                        ResourceResolver wsResolver = getResolverForWorkspace(workspaceName);
+                        return wsResolver.listChildren(parent);
+                    } catch (LoginException e) {
+                        // requested a resource in a workspace I don't have access to.
+                        // we treat this as a not found resource
+                        return Collections.EMPTY_LIST.iterator();
+                    }
+                } else {
+                    // this is illegal
                     return Collections.EMPTY_LIST.iterator();
                 }
             }
         }
 
+
         String workspacePrefix = null;
         if ( !getSession().getWorkspace().getName().equals(this.factory.getDefaultWorkspaceName())
) {
             workspacePrefix = getSession().getWorkspace().getName();

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=951545&r1=951544&r2=951545&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  4 19:51:47 2010
@@ -208,6 +208,8 @@ public class JcrResourceResolverFactoryI
     // whether to mangle paths with namespaces or not
     private boolean mangleNamespacePrefixes;
 
+    private boolean useMultiWorkspaces;
+
     /** The resource listeners for the observation events. */
     private Set<JcrResourceListener> resourceListeners;
 
@@ -390,8 +392,8 @@ public class JcrResourceResolverFactoryI
             this.resourceListeners.add(new JcrResourceListener(null, this, "/", "/", this.eventAdminTracker));
 
             // check if multi workspace support is enabled
-            final boolean useMultiWorkspaces = OsgiUtil.toBoolean(properties.get(PROP_MULTIWORKSPACE),
DEFAULT_MULTIWORKSPACE);
-            if (useMultiWorkspaces) {
+            this.useMultiWorkspaces = OsgiUtil.toBoolean(properties.get(PROP_MULTIWORKSPACE),
DEFAULT_MULTIWORKSPACE);
+            if (this.useMultiWorkspaces) {
                 final String[] listenerWorkspaces = getAllWorkspaces();
                 for (final String wspName : listenerWorkspaces) {
                     if (!wspName.equals(this.repository.getDefaultWorkspace())) {
@@ -489,10 +491,9 @@ public class JcrResourceResolverFactoryI
                                                  final boolean isAdmin,
                                                  final Map<String, Object> authenticationInfo)
{
         final JcrResourceProviderEntry sessionRoot = new JcrResourceProviderEntry(
-            session, rootProviderEntry,
-            this.getDynamicClassLoader());
+            session, rootProviderEntry, this.getDynamicClassLoader(), useMultiWorkspaces);
 
-        return new JcrResourceResolver(sessionRoot, this, isAdmin, authenticationInfo);
+        return new JcrResourceResolver(sessionRoot, this, isAdmin, authenticationInfo, useMultiWorkspaces);
     }
 
     /**

Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java?rev=951545&r1=951544&r2=951545&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java
(original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java
Fri Jun  4 19:51:47 2010
@@ -48,11 +48,14 @@ public class JcrResourceProvider impleme
 
     private final Session session;
     private final ClassLoader dynamicClassLoader;
+    private final boolean useMultiWorkspaces;
 
     public JcrResourceProvider(final Session session,
-                               final ClassLoader dynamicClassLoader) {
+                               final ClassLoader dynamicClassLoader,
+                               boolean useMultiWorkspaces) {
         this.session = session;
         this.dynamicClassLoader = dynamicClassLoader;
+        this.useMultiWorkspaces = useMultiWorkspaces;
     }
 
     // ---------- ResourceProvider interface ----------------------------------
@@ -128,18 +131,19 @@ public class JcrResourceProvider impleme
      */
     private JcrItemResource createResource(ResourceResolver resourceResolver,
             String path) throws RepositoryException {
-        final int wsSepPos = path.indexOf(":/");
-        if (wsSepPos != -1) {
-            final String workspaceName = path.substring(0, wsSepPos);
-            final String expectedWorkspaceName = getSession().getWorkspace().getName();
-            if (workspaceName.equals(expectedWorkspaceName)) {
-                path = path.substring(wsSepPos + 1);
-        } else {
-            throw new RepositoryException("Unexpected workspace name. Expected " +
-                    expectedWorkspaceName + ". Actual " + workspaceName);
+        if (useMultiWorkspaces) {
+            final int wsSepPos = path.indexOf(":/");
+                if (wsSepPos != -1) {
+                    final String workspaceName = path.substring(0, wsSepPos);
+                    final String expectedWorkspaceName = getSession().getWorkspace().getName();
+                    if (workspaceName.equals(expectedWorkspaceName)) {
+                        path = path.substring(wsSepPos + 1);
+                } else {
+                    throw new RepositoryException("Unexpected workspace name. Expected "
+
+                            expectedWorkspaceName + ". Actual " + workspaceName);
+                }
+            }
         }
-    }
-
 
         if (itemExists(path)) {
             Item item = getSession().getItem(path);

Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProviderEntry.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProviderEntry.java?rev=951545&r1=951544&r2=951545&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProviderEntry.java
(original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProviderEntry.java
Fri Jun  4 19:51:47 2010
@@ -40,9 +40,10 @@ public class JcrResourceProviderEntry ex
 
     public JcrResourceProviderEntry(Session session,
             ResourceProviderEntry delegatee,
-            final ClassLoader dynamicClassLoader) {
+            final ClassLoader dynamicClassLoader,
+            boolean useMultiWorkspaces) {
         super("/", new ResourceProvider[] { new JcrResourceProvider(session,
-                dynamicClassLoader) });
+                dynamicClassLoader, useMultiWorkspaces) });
 
         this.delegatee = delegatee;
         this.session = session;

Modified: sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceListenerTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceListenerTest.java?rev=951545&r1=951544&r2=951545&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceListenerTest.java
(original)
+++ sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceListenerTest.java
Fri Jun  4 19:51:47 2010
@@ -126,6 +126,7 @@ public class JcrResourceListenerTest ext
 
         JcrResourceResolverFactoryImpl factory = new JcrResourceResolverFactoryImpl();
         PrivateAccessor.setField(factory, "repository", getRepository());
+        PrivateAccessor.setField(factory, "useMultiWorkspaces", Boolean.TRUE);
 
         final EventAdmin mockEA = new EventAdmin() {
 

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=951545&r1=951544&r2=951545&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  4 19:51:47 2010
@@ -36,6 +36,8 @@ import javax.servlet.http.Cookie;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpSession;
 
+import junitx.util.PrivateAccessor;
+
 import org.apache.sling.api.SlingConstants;
 import org.apache.sling.api.resource.NonExistingResource;
 import org.apache.sling.api.resource.Resource;
@@ -63,6 +65,8 @@ public class JcrResourceResolverTest ext
 
     private ResourceResolver resResolver;
 
+    private ResourceResolver mwResResolver;
+
     private MapEntries mapEntries;
 
     private Session ws2Session;
@@ -137,6 +141,9 @@ public class JcrResourceResolverTest ext
 
         resResolver = resFac.getResourceResolver(session);
 
+        PrivateAccessor.setField(resFac, "useMultiWorkspaces", Boolean.TRUE);
+        mwResResolver = resFac.getResourceResolver(session);
+
         try {
             getSession().getWorkspace().createWorkspace("ws2");
         } catch (Exception e) {
@@ -254,7 +261,12 @@ public class JcrResourceResolverTest ext
 
     public void testGetResourceFromWs2ViaDefaultResolver() throws Exception {
         // existing resource
-        Resource res = resResolver.getResource("ws2:" + rootPath);
+        String ws2Path = "ws2:" + rootPath;
+        Resource res = resResolver.getResource(ws2Path);
+        assertNull(res);
+
+        res = mwResResolver.getResource(ws2Path);
+
         assertNotNull(res);
         assertEquals("ws2:" + rootPath, res.getPath());
         assertEquals(rootWs2Node.getPrimaryNodeType().getName(),
@@ -311,27 +323,52 @@ public class JcrResourceResolverTest ext
     }
 
     public void testResolveResourceWithWS2() throws Exception {
+        // before resolution, all resolvers adapt to sessions in the
+        // default workspace
+        assertEquals("default", resResolver.adaptTo(Session.class).getWorkspace().getName());
+        assertEquals("default", mwResResolver.adaptTo(Session.class).getWorkspace().getName());
+
         // existing resource
         HttpServletRequest request = new ResourceResolverTestRequest(rootPath);
         request.setAttribute(ResourceResolver.REQUEST_ATTR_WORKSPACE_INFO, "ws2");
         Resource res = resResolver.resolve(request, rootPath);
         assertNotNull(res);
-        assertEquals("ws2:" + rootPath, res.getPath());
+
+        // because multi-workspace is disabled, this should return the resource from the
+        // default workspace
+        assertEquals(rootPath, res.getPath());
+        assertEquals("default", res.adaptTo(Node.class).getSession().getWorkspace().getName());
+
+        // and the request-bound session still isn't set
+        assertEquals("default", resResolver.adaptTo(Session.class).getWorkspace().getName());
+
+        // now for the multi-workspace enabled resolver
+        Resource ws2Res = mwResResolver.resolve(request, rootPath);
+
+        // now the request-bound session is set
+        assertEquals("ws2", mwResResolver.adaptTo(Session.class).getWorkspace().getName());
+
+        assertEquals("ws2:" + rootPath, ws2Res.getPath());
         assertEquals(rootWs2Node.getPrimaryNodeType().getName(),
-            res.getResourceType());
+            ws2Res.getResourceType());
 
-        assertNotNull(res.adaptTo(Node.class));
-        assertTrue(rootWs2Node.isSame(res.adaptTo(Node.class)));
+        assertNotNull(ws2Res.adaptTo(Node.class));
+        assertTrue(rootWs2Node.isSame(ws2Res.adaptTo(Node.class)));
+
+        // shouldn't be able to resolve non-default workspace
+        // children from a non-multiworkspace resolver
+        Iterator<Resource> children = resResolver.listChildren(ws2Res);
+        assertFalse(children.hasNext());
 
-        // should be able to list children
-        Iterator<Resource> children = resResolver.listChildren(res);
+        // should also be able to list children from the mw
+        children = mwResResolver.listChildren(ws2Res);
         assertTrue(children.hasNext());
         Resource child = children.next();
         assertNotNull(child);
         assertEquals("ws2:" + rootPath + "/child1", child.getPath());
 
         // should be able to list children of a child
-        Iterator<Resource> children2 = resResolver.listChildren(child);
+        Iterator<Resource>children2 = mwResResolver.listChildren(child);
         assertTrue(children2.hasNext());
         Resource child2 = children2.next();
         assertNotNull(child2);
@@ -340,7 +377,7 @@ public class JcrResourceResolverTest ext
         // should also be able to list children of a synthetic resource
         SyntheticResource synth = new SyntheticResource(null, "ws2:" +
                 rootPath+"/child1", "res/synth");
-        children2 = resResolver.listChildren(synth);
+        children2 = mwResResolver.listChildren(synth);
         assertTrue(children2.hasNext());
         child2 = children2.next();
         assertNotNull(child2);
@@ -350,7 +387,7 @@ public class JcrResourceResolverTest ext
         String path = rootPath + "/missing";
         request = new ResourceResolverTestRequest(path);
         request.setAttribute(ResourceResolver.REQUEST_ATTR_WORKSPACE_INFO, "ws2");
-        res = resResolver.resolve(request, path);
+        res = mwResResolver.resolve(request, path);
         assertNotNull(res);
         assertEquals("ws2:" + path, res.getPath());
         assertEquals(Resource.RESOURCE_TYPE_NON_EXISTING, res.getResourceType());
@@ -361,7 +398,7 @@ public class JcrResourceResolverTest ext
         path = rootPath + ".print.a4.html";
         request = new ResourceResolverTestRequest(path);
         request.setAttribute(ResourceResolver.REQUEST_ATTR_WORKSPACE_INFO, "ws2");
-        res = resResolver.resolve(request, path);
+        res = mwResResolver.resolve(request, path);
         assertNotNull(res);
         assertEquals("ws2:" + rootPath, res.getPath());
         assertEquals(rootWs2Node.getPrimaryNodeType().getName(),
@@ -374,7 +411,7 @@ public class JcrResourceResolverTest ext
         path = rootPath + System.currentTimeMillis();
         request = new ResourceResolverTestRequest(path);
         request.setAttribute(ResourceResolver.REQUEST_ATTR_WORKSPACE_INFO, "ws2");
-        res = resResolver.resolve(request, path);
+        res = mwResResolver.resolve(request, path);
         assertNotNull(res);
         assertTrue(ResourceUtil.isNonExistingResource(res));
         assertEquals("ws2:" + path, res.getPath());



Mime
View raw message