This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to annotated tag org.apache.sling.fsresource-1.1.0 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-fsresource.git
commit 195c76dc52a12b0f6a7fece1af0d922b563c4de7 Author: Carsten Ziegeler <[email protected]> AuthorDate: Thu Oct 25 09:17:34 2012 +0000 SLING-2541 : General mechanism to chain resource providers git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/fsresource@1402037 13f79535-47bb-0310-9956-ffa450edef68 --- pom.xml | 4 --- .../sling/fsprovider/internal/FsResource.java | 18 ++++++---- .../fsprovider/internal/FsResourceProvider.java | 41 +++++++--------------- 3 files changed, 23 insertions(+), 40 deletions(-) diff --git a/pom.xml b/pom.xml index e8bc922..f241e8e 100644 --- a/pom.xml +++ b/pom.xml @@ -89,10 +89,6 @@ <artifactId>servlet-api</artifactId> </dependency> <dependency> - <groupId>javax.jcr</groupId> - <artifactId>jcr</artifactId> - </dependency> - <dependency> <groupId>org.apache.sling</groupId> <artifactId>org.apache.sling.api</artifactId> <version>2.2.5-SNAPSHOT</version> diff --git a/src/main/java/org/apache/sling/fsprovider/internal/FsResource.java b/src/main/java/org/apache/sling/fsprovider/internal/FsResource.java index a0f68f7..bcc8bb1 100644 --- a/src/main/java/org/apache/sling/fsprovider/internal/FsResource.java +++ b/src/main/java/org/apache/sling/fsprovider/internal/FsResource.java @@ -110,6 +110,9 @@ public class FsResource extends AbstractResource implements Resource { metaData.setContentLength(file.length()); metaData.setModificationTime(file.lastModified()); metaData.setResolutionPath(resourcePath); + if ( this.file.isDirectory() ) { + metaData.put(ResourceMetadata.INTERNAL_CONTINUE_RESOLVING, Boolean.TRUE); + } } return metaData; } @@ -138,7 +141,7 @@ public class FsResource extends AbstractResource implements Resource { if (resourceType == null) { resourceType = file.isFile() ? RESOURCE_TYPE_FILE - : RESOURCE_TYPE_FOLDER; + : RESOURCE_TYPE_FOLDER; } return resourceType; @@ -149,6 +152,7 @@ public class FsResource extends AbstractResource implements Resource { * <code>File</code>, <code>InputStream</code> and <code>URL</code> * plus those supported by the adapter manager. */ + @Override @SuppressWarnings("unchecked") public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) { if (type == File.class) { @@ -163,8 +167,8 @@ public class FsResource extends AbstractResource implements Resource { return (AdapterType) new FileInputStream(file); } catch (IOException ioe) { getLog().info( - "adaptTo: Cannot open a stream on the file " + file, - ioe); + "adaptTo: Cannot open a stream on the file " + file, + ioe); } } else { @@ -179,12 +183,12 @@ public class FsResource extends AbstractResource implements Resource { return (AdapterType) file.toURI().toURL(); } catch (MalformedURLException mue) { getLog().info( - "adaptTo: Cannot convert the file path " + file + "adaptTo: Cannot convert the file path " + file + " to an URL", mue); } } else if (type == ValueMap.class) { - + // this resource simulates nt:file/nt:folder behavior by returning it as resource type // we should simulate the corresponding JCR properties in a value map as well if (file.exists() && file.canRead()) { @@ -196,9 +200,9 @@ public class FsResource extends AbstractResource implements Resource { props.put("jcr:created", lastModifed); return (AdapterType) new ValueMapDecorator(props); } - + } - + return super.adaptTo(type); } diff --git a/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java b/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java index f261e50..780ebaa 100644 --- a/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java +++ b/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java @@ -24,8 +24,6 @@ import java.util.Iterator; import java.util.Map; import java.util.NoSuchElementException; -import javax.jcr.RepositoryException; -import javax.jcr.Session; import javax.servlet.http.HttpServletRequest; import org.apache.felix.scr.annotations.Component; @@ -54,18 +52,18 @@ import org.osgi.service.event.EventAdmin; * resource ({@link #PROP_PROVIDER_FILE}). */ @Component( - name="org.apache.sling.fsprovider.internal.FsResourceProvider", - label="%resource.resolver.name", - description="%resource.resolver.description", - configurationFactory=true, - policy=ConfigurationPolicy.REQUIRE, - metatype=true -) + name="org.apache.sling.fsprovider.internal.FsResourceProvider", + label="%resource.resolver.name", + description="%resource.resolver.description", + configurationFactory=true, + policy=ConfigurationPolicy.REQUIRE, + metatype=true + ) @Service(ResourceProvider.class) @Properties({ @Property(name="service.description", value="Sling Filesystem Resource Provider"), @Property(name="service.vendor", value="The Apache Software Foundation"), - @Property(name=ResourceProvider.ROOTS) + @Property(name=ResourceProvider.ROOTS) }) public class FsResourceProvider implements ResourceProvider { @@ -148,8 +146,8 @@ public class FsResourceProvider implements ResourceProvider { String relPath = providerRoot.substring(parentPath.length()); if (relPath.indexOf('/') < 0) { Resource res = getResource( - parent.getResourceResolver(), providerRoot, - providerFile); + parent.getResourceResolver(), providerRoot, + providerFile); if (res != null) { return Collections.singletonList(res).iterator(); } @@ -220,7 +218,7 @@ public class FsResourceProvider implements ResourceProvider { String providerFileName = (String) props.get(PROP_PROVIDER_FILE); if (providerFileName == null || providerFileName.length() == 0) { throw new IllegalArgumentException(PROP_PROVIDER_FILE - + " property must be set"); + + " property must be set"); } this.providerRoot = providerRoot; @@ -282,7 +280,7 @@ public class FsResourceProvider implements ResourceProvider { // if the provider file does not exist, create an empty new folder if (!providerFile.exists() && !providerFile.mkdirs()) { throw new IllegalArgumentException( - "Cannot create provider file root " + providerFile); + "Cannot create provider file root " + providerFile); } return providerFile; @@ -314,21 +312,6 @@ public class FsResourceProvider implements ResourceProvider { if (file != null) { - // if the file is a directory, and a repository item exists for - // the path, do not return the directory here - if (file.isDirectory()) { - Session session = resourceResolver.adaptTo(Session.class); - if (session != null) { - try { - if (session.itemExists(resourcePath)) { - return null; - } - } catch (RepositoryException re) { - // don't care - } - } - } - // if the file exists, but is not a directory or no repository entry // exists, return it as a resource if (file.exists()) { -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
