You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by fm...@apache.org on 2008/04/01 15:05:37 UTC
svn commit: r643386 - in
/incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/bundle:
BundleResource.java BundleResourceIterator.java BundleResourceProvider.java
Author: fmeschbe
Date: Tue Apr 1 06:04:33 2008
New Revision: 643386
URL: http://svn.apache.org/viewvc?rev=643386&view=rev
Log:
SLING-349 BundleResource.listChildren(Resource) should also be implemented
by BundleResourceIterator if the Resource is not a BundleResource.
Also fix a glitch in the BundleResource.createResource method which creates
a file resource if the resource in fact is a folder resource and does not
hide a JCR item.
Modified:
incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/bundle/BundleResource.java
incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/bundle/BundleResourceIterator.java
incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/bundle/BundleResourceProvider.java
Modified: incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/bundle/BundleResource.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/bundle/BundleResource.java?rev=643386&r1=643385&r2=643386&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/bundle/BundleResource.java (original)
+++ incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/bundle/BundleResource.java Tue Apr 1 06:04:33 2008
@@ -61,7 +61,7 @@
// repository contains an item with the same path. If so, we
// don't create a BundleResource but instead return null to be
// able to return an item-based resource
- URL entry = bundle.getEntry(path + "/");
+ URL entry = bundle.getEntry(path.concat("/"));
if (entry != null) {
Session session = resourceResolver.adaptTo(Session.class);
if (session != null) {
@@ -73,6 +73,9 @@
// don't care
}
}
+
+ // append the slash to path for next steps
+ path = path.concat("/");
}
// if there is no entry with a trailing slash, try plain name
Modified: incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/bundle/BundleResourceIterator.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/bundle/BundleResourceIterator.java?rev=643386&r1=643385&r2=643386&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/bundle/BundleResourceIterator.java (original)
+++ incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/bundle/BundleResourceIterator.java Tue Apr 1 06:04:33 2008
@@ -70,7 +70,7 @@
} else {
// trailing slash to enumerate children
- String parentPath = parent.getPath() + "/";
+ String parentPath = parent.getPath().concat("/");
this.resourceResolver = parent.getResourceResolver();
this.bundle = parent.getBundle();
@@ -79,6 +79,22 @@
this.prefixLength = parentPath.length();
this.nextResult = seek();
}
+ }
+
+ @SuppressWarnings("unchecked")
+ BundleResourceIterator(ResourceResolver resourceResolver, Bundle bundle, String parentPath) {
+ // trailing slash to enumerate children
+ if (!parentPath.endsWith("/")) {
+ parentPath = parentPath.concat("/");
+ }
+
+ this.resourceResolver = resourceResolver;
+ this.bundle = bundle;
+ // unchecked cast
+ this.entries = bundle.getEntryPaths(parentPath);
+ this.prefixLength = parentPath.length();
+ this.nextResult = (entries != null) ? seek() : null;
+
}
/** Returns true if there is another Resource available */
Modified: incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/bundle/BundleResourceProvider.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/bundle/BundleResourceProvider.java?rev=643386&r1=643385&r2=643386&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/bundle/BundleResourceProvider.java (original)
+++ incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/bundle/BundleResourceProvider.java Tue Apr 1 06:04:33 2008
@@ -19,12 +19,9 @@
package org.apache.sling.jcr.resource.internal.helper.bundle;
import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashSet;
+import java.util.Collections;
import java.util.Iterator;
import java.util.List;
-import java.util.NoSuchElementException;
-import java.util.Set;
import java.util.StringTokenizer;
import javax.servlet.http.HttpServletRequest;
@@ -33,7 +30,6 @@
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.SyntheticResource;
import org.osgi.framework.Bundle;
public class BundleResourceProvider implements ResourceProvider {
@@ -90,74 +86,19 @@
return ((BundleResource) parent).listChildren();
}
- // otherwise create an iterator which builds the entries based on
- // the contents of the roots list
- return new Iterator<Resource>() {
- private final String parentPath;
-
- private final ResourceResolver resolver;
-
- private final Iterator<String> roots;
-
- private Resource nextResult;
-
- private final Set<String> visited = new HashSet<String>();
- {
- String pp = parent.getPath();
- if (!pp.endsWith("/")) {
- pp = pp.concat("/");
- }
- parentPath = pp;
- resolver = parent.getResourceResolver();
- roots = Arrays.asList(getRoots()).iterator();
- nextResult = seek();
+ // ensure this provider may have children of the parent
+ String parentPath = parent.getPath();
+ for (String rootPath : getRoots()) {
+ if (parentPath.equals(rootPath)
+ || parentPath.startsWith(rootPath.concat("/"))) {
+ return new BundleResourceIterator(parent.getResourceResolver(),
+ bundle, parent.getPath());
}
+ }
- public boolean hasNext() {
- return nextResult != null;
- }
-
- public Resource next() {
- if (nextResult == null) {
- throw new NoSuchElementException();
- }
-
- Resource result = nextResult;
- nextResult = seek();
- return result;
- }
-
- public void remove() {
- throw new UnsupportedOperationException("remove");
- }
-
- private Resource seek() {
- Resource result = null;
- while (result == null && roots.hasNext()) {
- String path = roots.next();
- if (path.startsWith(parentPath)) {
- int nextSlash = path.indexOf('/', parentPath.length());
- if (nextSlash < 0) {
- result = BundleResource.getResource(resolver,
- bundle, path);
- } else {
-
- path = path.substring(0, nextSlash);
- if (!visited.contains(path)) {
- visited.add(path);
- if (resolver.getResource(path) == null) {
- result = new SyntheticResource(resolver,
- path, RESOURCE_TYPE_SYNTHETIC);
- }
- }
- }
- }
-
- }
-
- return result;
- }
- };
-
+ // the parent resource cannot have children in this provider,
+ // though this is basically not expected, we still have to
+ // be prepared for such a situation
+ return Collections.<Resource>emptyList().iterator();
}
}