This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to annotated tag org.apache.sling.fsresource-1.0.0 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-fsresource.git
commit 2051b5fe42720f7167c6024761b2abd508fbf46c Author: Felix Meschberger <[email protected]> AuthorDate: Sun Nov 15 15:07:00 2009 +0000 SLING-1187 Remove FsProviderConstants (moved constants to FsResource) and FsFolderServlet (duplicate code from default GET Servlet) git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/fsresource@836370 13f79535-47bb-0310-9956-ffa450edef68 --- .../sling/fsprovider/internal/FsFolderServlet.java | 161 --------------------- .../fsprovider/internal/FsProviderConstants.java | 46 ------ .../sling/fsprovider/internal/FsResource.java | 28 +++- 3 files changed, 24 insertions(+), 211 deletions(-) diff --git a/src/main/java/org/apache/sling/fsprovider/internal/FsFolderServlet.java b/src/main/java/org/apache/sling/fsprovider/internal/FsFolderServlet.java deleted file mode 100644 index 784e9cf..0000000 --- a/src/main/java/org/apache/sling/fsprovider/internal/FsFolderServlet.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.sling.fsprovider.internal; - -import java.io.File; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.Arrays; -import java.util.Comparator; -import java.util.Date; - -import org.apache.sling.api.SlingHttpServletRequest; -import org.apache.sling.api.SlingHttpServletResponse; -import org.apache.sling.api.resource.Resource; -import org.apache.sling.api.resource.ResourceNotFoundException; -import org.apache.sling.api.resource.ResourceUtil; -import org.apache.sling.api.servlets.SlingSafeMethodsServlet; - -/** - * The <code>FsFolderServlet</code> lists the files and folders of a folder - * mapped into the Sling resource tree. The listing produced is similar to the - * default index listing produced by Apache httpd. - * - * @scr.component immediate="true" metatype="no" - * @scr.service interface="javax.servlet.Servlet" - * @scr.property name="service.description" value="FileSystem Folder Servlet" - * @scr.property name="service.vendor" value="The Apache Software Foundation" - * @scr.property name="sling.servlet.methods" value="GET" - * @scr.property name="sling.servlet.resourceTypes" - * valueRef="FsProviderConstants.RESOURCE_TYPE_FOLDER" - */ -public class FsFolderServlet extends SlingSafeMethodsServlet { - - // a number of blanks used to format the listing of folder entries - private static final String NAME_BLANKS = " "; - - @Override - protected void doGet(SlingHttpServletRequest request, - SlingHttpServletResponse response) throws IOException { - - // if the request URL is not terminated with a slash, redirect to the - // same URL with a trailing slash (this makes preparing the response - // easier - if (!request.getRequestURI().endsWith("/")) { - response.sendRedirect(request.getRequestURL() + "/"); - return; - } - - // ensure the resource adapts to a filesystem folder; generally - // this should be the case, but we never know whether someone really - // creates a JCR resource with the fs provider folder resource type - Resource res = request.getResource(); - File file = res.adaptTo(File.class); - if (file == null || !file.isDirectory()) { - throw new ResourceNotFoundException( - request.getResource().getPath(), - "Resource is not a file system folder"); - } - - response.setContentType("text/html"); - response.setCharacterEncoding("UTF-8"); - PrintWriter pw = response.getWriter(); - - pw.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\"> <html>"); - - pw.printf("<head><title>Index of %s</title></head><body>%n", - res.getPath()); - pw.printf("<h1>Index of %s</h1>%n", res.getPath()); - - pw.println("<pre>"); - pw.println("Name Last modified Size Description"); - pw.println("<hr>"); - - // only draw parent link if the parent is also a fs resource - Resource parent = ResourceUtil.getParent(res); - if (parent != null && parent.adaptTo(File.class) != null) { - pw.println("<a href='..'>Parent Directory</a>"); - } - - // render the children - renderChildren(pw, file); - - pw.println("</pre>"); - pw.println("</body></html>"); - } - - // ---------- internal - - /** - * Renders the children of the <code>parent</code> folder to the output. - */ - private void renderChildren(PrintWriter pw, File parent) { - File[] children = parent.listFiles(); - if (children != null && children.length > 0) { - Arrays.sort(children, FileNameComparator.INSTANCE); - - for (File child : children) { - - String name = child.getName(); - if (child.isDirectory()) { - name = name.concat("/"); - } - - String displayName = name; - if (displayName.length() >= 32) { - displayName = displayName.substring(0, 29).concat("..."); - pw.printf("<a href='%s'>%s</a>", name, displayName); - } else { - String blanks = NAME_BLANKS.substring(0, - 32 - displayName.length()); - pw.printf("<a href='%s'>%s</a>%s", name, displayName, - blanks); - } - - pw.print(" " + new Date(child.lastModified())); - - pw.print(" "); - if (child.isFile()) { - pw.print(child.length()); - } else { - pw.print("-"); - } - - pw.println(); - } - } - } - - // order files by type (folder before files) and name (case insensitive) - private static class FileNameComparator implements Comparator<File> { - - public static final FileNameComparator INSTANCE = new FileNameComparator(); - - public int compare(File f1, File f2) { - if (f1.isDirectory() && !f2.isDirectory()) { - return -1; - } else if (!f1.isDirectory() && f2.isDirectory()) { - return 1; - } - - return f1.getName().compareToIgnoreCase(f2.getName()); - } - } - -} diff --git a/src/main/java/org/apache/sling/fsprovider/internal/FsProviderConstants.java b/src/main/java/org/apache/sling/fsprovider/internal/FsProviderConstants.java deleted file mode 100644 index 96e3db6..0000000 --- a/src/main/java/org/apache/sling/fsprovider/internal/FsProviderConstants.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.sling.fsprovider.internal; - -/** - * The <code>FsProviderConstants</code> interface defines public constants for - * the {@link FsResourceProvider}. - */ -public interface FsProviderConstants { - - /** - * The common resource super type for files and folders mapped into the - * resource tree by the {@link FsResourceProvider} (value is - * "sling/fs/resource"). - */ - static final String RESOURCE_TYPE_ROOT = "sling/fs/resource"; - - /** - * The resource type for file system files mapped into the resource tree by - * the {@link FsResourceProvider} (value is "sling/fs/file"). - */ - static final String RESOURCE_TYPE_FILE = "sling/fs/file"; - - /** - * The resource type for file system folders mapped into the resource tree - * by the {@link FsResourceProvider} (value is "sling/fs/folder"). - */ - static final String RESOURCE_TYPE_FOLDER = "sling/fs/folder"; - -} 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 ee3d567..6d2d424 100644 --- a/src/main/java/org/apache/sling/fsprovider/internal/FsResource.java +++ b/src/main/java/org/apache/sling/fsprovider/internal/FsResource.java @@ -38,6 +38,26 @@ import org.slf4j.LoggerFactory; */ public class FsResource extends SlingAdaptable implements Resource { + + /** + * The common resource super type for files and folders mapped into the + * resource tree by the {@link FsResourceProvider} (value is + * "sling/fs/resource"). + */ + private static final String RESOURCE_TYPE_ROOT = "sling/fs/resource"; + + /** + * The resource type for file system files mapped into the resource tree by + * the {@link FsResourceProvider} (value is "sling/fs/file"). + */ + private static final String RESOURCE_TYPE_FILE = "sling/fs/file"; + + /** + * The resource type for file system folders mapped into the resource tree + * by the {@link FsResourceProvider} (value is "sling/fs/folder"). + */ + private static final String RESOURCE_TYPE_FOLDER = "sling/fs/folder"; + // default log, assigned on demand private Logger log; @@ -58,7 +78,7 @@ public class FsResource extends SlingAdaptable implements Resource { /** * Creates an instance of this Filesystem resource. - * + * * @param resolver The owning resource resolver * @param resourcePath The resource path in the resource tree * @param file The wrapped file @@ -103,7 +123,7 @@ public class FsResource extends SlingAdaptable implements Resource { * Returns {@link FsProviderConstants#RESOURCE_TYPE_ROOT} */ public String getResourceSuperType() { - return FsProviderConstants.RESOURCE_TYPE_ROOT; + return RESOURCE_TYPE_ROOT; } /** @@ -114,8 +134,8 @@ public class FsResource extends SlingAdaptable implements Resource { public String getResourceType() { if (resourceType == null) { resourceType = file.isFile() - ? FsProviderConstants.RESOURCE_TYPE_FILE - : FsProviderConstants.RESOURCE_TYPE_FOLDER; + ? RESOURCE_TYPE_FILE + : RESOURCE_TYPE_FOLDER; } return resourceType; -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
