Author: justin
Date: Fri May 21 14:34:52 2010
New Revision: 947026
URL: http://svn.apache.org/viewvc?rev=947026&view=rev
Log:
SLING-1527 - fixing listChildren() issue by both checking for WrappedResources
and removing the workspace prefix if necessary. Unit tests use
SyntheticResource to excercise the last bit.
Modified:
sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.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/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=947026&r1=947025&r2=947026&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 May 21 14:34:52 2010
@@ -31,6 +31,7 @@ import org.apache.sling.api.SlingExcepti
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceProvider;
import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.resource.ResourceWrapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -86,6 +87,9 @@ public class JcrResourceProvider impleme
parentItemResource = (JcrItemResource) parent;
+ } else if (parent instanceof ResourceWrapper) {
+
+ parentItemResource = (JcrItemResource) ((ResourceWrapper)
parent).getResource();
} else {
// try to get the JcrItemResource for the parent path to list
@@ -124,6 +128,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 (itemExists(path)) {
Item item = getSession().getItem(path);
if (item.isNode()) {
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=947026&r1=947025&r2=947026&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 May 21 14:34:52 2010
@@ -23,6 +23,7 @@ import java.lang.reflect.Field;
import java.security.Principal;
import java.util.Enumeration;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
@@ -40,6 +41,7 @@ import org.apache.sling.api.resource.Non
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceUtil;
+import org.apache.sling.api.resource.SyntheticResource;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.commons.testing.jcr.RepositoryTestBase;
import org.apache.sling.commons.testing.jcr.RepositoryUtil;
@@ -146,6 +148,8 @@ public class JcrResourceResolverTest ext
ws2Session = getRepository().loginAdministrative("ws2");
rootWs2Node = ws2Session.getRootNode().addNode(rootPath.substring(1),
"nt:unstructured");
+ Node child = rootWs2Node.addNode("child1");
+ child.addNode("child2");
ws2Session.save();
}
@@ -319,6 +323,29 @@ public class JcrResourceResolverTest ext
assertNotNull(res.adaptTo(Node.class));
assertTrue(rootWs2Node.isSame(res.adaptTo(Node.class)));
+ // should be able to list children
+ Iterator<Resource> children = resResolver.listChildren(res);
+ 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);
+ assertTrue(children2.hasNext());
+ Resource child2 = children2.next();
+ assertNotNull(child2);
+ assertEquals("ws2:" + rootPath + "/child1/child2", child2.getPath());
+
+ // 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);
+ assertTrue(children2.hasNext());
+ child2 = children2.next();
+ assertNotNull(child2);
+ assertEquals("ws2:" + rootPath + "/child1/child2", child2.getPath());
+
// missing resource below root should resolve "missing resource"
String path = rootPath + "/missing";
request = new ResourceResolverTestRequest(path);