[jboss-svn-commits] JBL Code SVN: r5074 - in labs/shotoku/trunk: shotoku-base/src/java/org/jboss/shotoku/web shotoku-file-access shotoku-file-access/src/java/org/jboss/shotoku/fileaccess shotoku-file-access/src/java/org/jboss/shotoku/fileaccess/monitors shotoku-file-access/src/web/WEB-INF

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Jul 13 14:40:13 EDT 2006


Author: adamw
Date: 2006-07-13 14:40:09 -0400 (Thu, 13 Jul 2006)
New Revision: 5074

Added:
   labs/shotoku/trunk/shotoku-file-access/src/java/org/jboss/shotoku/fileaccess/ClosedContentInformation.java
   labs/shotoku/trunk/shotoku-file-access/src/java/org/jboss/shotoku/fileaccess/monitors/
   labs/shotoku/trunk/shotoku-file-access/src/java/org/jboss/shotoku/fileaccess/monitors/ListingMonitor.java
Modified:
   labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/web/FilesFromRepoFilter.java
   labs/shotoku/trunk/shotoku-file-access/project.xml
   labs/shotoku/trunk/shotoku-file-access/src/java/org/jboss/shotoku/fileaccess/ContentInformation.java
   labs/shotoku/trunk/shotoku-file-access/src/java/org/jboss/shotoku/fileaccess/FileAccessMonitor.java
   labs/shotoku/trunk/shotoku-file-access/src/java/org/jboss/shotoku/fileaccess/FileAccessServlet.java
   labs/shotoku/trunk/shotoku-file-access/src/web/WEB-INF/web.xml
Log:
http://jira.jboss.org/jira/browse/JBSHOTOKU-90

Modified: labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/web/FilesFromRepoFilter.java
===================================================================
--- labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/web/FilesFromRepoFilter.java	2006-07-13 18:17:50 UTC (rev 5073)
+++ labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/web/FilesFromRepoFilter.java	2006-07-13 18:40:09 UTC (rev 5074)
@@ -75,9 +75,15 @@
             // Constructing the path of the requested path as relative to the
             // content's repository root.
             String requestURI = httpRequest.getRequestURI();
-            String requestedFile = requestURI.substring(requestURI
-                    .indexOf(repoAccessDir) + repoAccessDirLength + 1);
+            int indexOfRepoAccessDir = requestURI.indexOf(repoAccessDir);
+            if (indexOfRepoAccessDir == -1) {
+                chain.doFilter(request, response);
+                return;
+            }
 
+            String requestedFile = requestURI.substring(indexOfRepoAccessDir +
+                    repoAccessDirLength + 1);
+
             Node requestedNode;
             try {
                 requestedNode = contentManager.getNode(requestedFile);

Modified: labs/shotoku/trunk/shotoku-file-access/project.xml
===================================================================
--- labs/shotoku/trunk/shotoku-file-access/project.xml	2006-07-13 18:17:50 UTC (rev 5073)
+++ labs/shotoku/trunk/shotoku-file-access/project.xml	2006-07-13 18:40:09 UTC (rev 5074)
@@ -33,6 +33,26 @@
             <artifactId>javax.servlet</artifactId>
             <jar>javax.servlet.jar</jar>
         </dependency>
+
+        <dependency>
+            <groupId>taglibs</groupId>
+            <artifactId>jstl</artifactId>
+            <version>1.0</version>
+            <jar>jstl.jar</jar>
+            <properties>
+                <war.bundle>true</war.bundle>
+            </properties>
+        </dependency>
+
+        <dependency>
+            <groupId>taglibs</groupId>
+            <artifactId>standard</artifactId>
+            <version>1.0</version>
+            <jar>standard.jar</jar>
+            <properties>
+                <war.bundle>true</war.bundle>
+            </properties>
+        </dependency>
     </dependencies>
 
     <build>

Added: labs/shotoku/trunk/shotoku-file-access/src/java/org/jboss/shotoku/fileaccess/ClosedContentInformation.java
===================================================================
--- labs/shotoku/trunk/shotoku-file-access/src/java/org/jboss/shotoku/fileaccess/ClosedContentInformation.java	2006-07-13 18:17:50 UTC (rev 5073)
+++ labs/shotoku/trunk/shotoku-file-access/src/java/org/jboss/shotoku/fileaccess/ClosedContentInformation.java	2006-07-13 18:40:09 UTC (rev 5074)
@@ -0,0 +1,16 @@
+package org.jboss.shotoku.fileaccess;
+
+import java.io.InputStream;
+
+/**
+ * @author Adam Warski (adamw at aster.pl)
+ */
+public class ClosedContentInformation extends ContentInformation {
+    public ClosedContentInformation() {
+        super(null, 0, null);
+    }
+
+    public boolean isResponseDone() {
+        return true;
+    }
+}

Modified: labs/shotoku/trunk/shotoku-file-access/src/java/org/jboss/shotoku/fileaccess/ContentInformation.java
===================================================================
--- labs/shotoku/trunk/shotoku-file-access/src/java/org/jboss/shotoku/fileaccess/ContentInformation.java	2006-07-13 18:17:50 UTC (rev 5073)
+++ labs/shotoku/trunk/shotoku-file-access/src/java/org/jboss/shotoku/fileaccess/ContentInformation.java	2006-07-13 18:40:09 UTC (rev 5074)
@@ -27,4 +27,8 @@
     public InputStream getIs() {
         return is;
     }
+
+    public boolean isResponseDone() {
+        return false;
+    }
 }

Modified: labs/shotoku/trunk/shotoku-file-access/src/java/org/jboss/shotoku/fileaccess/FileAccessMonitor.java
===================================================================
--- labs/shotoku/trunk/shotoku-file-access/src/java/org/jboss/shotoku/fileaccess/FileAccessMonitor.java	2006-07-13 18:17:50 UTC (rev 5073)
+++ labs/shotoku/trunk/shotoku-file-access/src/java/org/jboss/shotoku/fileaccess/FileAccessMonitor.java	2006-07-13 18:40:09 UTC (rev 5074)
@@ -2,9 +2,8 @@
 
 import org.jboss.shotoku.ContentManager;
 
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import java.io.InputStream;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpServletRequest;
 import java.io.FileNotFoundException;
 
 /**
@@ -15,12 +14,15 @@
      * Invoked when the given resource is requested. Can return information about
      * content to transmit.
      * @param path Path requested.
+     * @param request Servlet request.
+     * @param response Servlet response.
      * @param cm Associated content manager.
-     * @param request Servlet request.
      * @return Null, if content to transmit should be read from Shotoku in the
      * normal way. If not null, content from the returned content information will be
      * transmitted.
      */
-    public ContentInformation resourceRequested(String path, ServletRequest request,
+    public ContentInformation resourceRequested(String path,
+                                                HttpServletRequest request,
+                                                HttpServletResponse response,
                                                 ContentManager cm) throws FileNotFoundException;
 }

Modified: labs/shotoku/trunk/shotoku-file-access/src/java/org/jboss/shotoku/fileaccess/FileAccessServlet.java
===================================================================
--- labs/shotoku/trunk/shotoku-file-access/src/java/org/jboss/shotoku/fileaccess/FileAccessServlet.java	2006-07-13 18:17:50 UTC (rev 5073)
+++ labs/shotoku/trunk/shotoku-file-access/src/java/org/jboss/shotoku/fileaccess/FileAccessServlet.java	2006-07-13 18:40:09 UTC (rev 5074)
@@ -12,7 +12,6 @@
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletResponse;
 import java.io.*;
-import java.util.Properties;
 
 /**
  * A filter that enables to download files which are stored in a working copy of
@@ -34,6 +33,7 @@
     private ContentManager contentManager;
     private Pair<String, String> confKey;
 
+    @SuppressWarnings({"UNUSED_SYMBOL"})
     @CacheItem
     private FileAccessConfigurationWatcher conf;
 
@@ -62,20 +62,14 @@
         * want to get the part /path/to/resource.
         */
         String requestedResTokens[] = requestURI.split("[/]", 3);
+
+        String path;
         if (requestedResTokens.length < 2) {
-            writeErrorMessage(response);
-            return;
+            path = "";
+        } else {
+            path = requestedResTokens[2];
         }
 
-        String requestedRes = requestedResTokens[2];
-
-        // Now we get rid of any query strings.
-        String path = requestedRes;
-        int qmPos = requestedRes.indexOf('?');
-        if (qmPos != -1) {
-            path = requestedRes.substring(0, qmPos);
-        }
-
         try {
             // Checking if we can allow access to this resource.
             if (!fac.checkPath(path)) {
@@ -85,17 +79,21 @@
 
             ContentInformation ci = null;
 
-            // Notifying each monitor. Also checking, if any information about content
-            // to transmit is returned.
+            // Notifying each monitor. Also checking, if any information about
+            // content to transmit is returned.
             for (FileAccessMonitor fam : fac.getMonitors()) {
-                ContentInformation ciTemp = fam.resourceRequested(path, request, contentManager);
+                ContentInformation ciTemp = fam.resourceRequested(path, request,
+                        response, contentManager);
                 if (ciTemp != null) {
                     ci = ciTemp;
+                    if (ci.isResponseDone()) {
+                        return;
+                    }
                 }
             }
 
             if (ci == null) {
-                Node requestedNode = contentManager.getNode(requestedRes);
+                Node requestedNode = contentManager.getNode(path);
                 ci = new ContentInformation(requestedNode.getMimeType(),
                         requestedNode.getLength(),
                         requestedNode.getContentInputStream());

Added: labs/shotoku/trunk/shotoku-file-access/src/java/org/jboss/shotoku/fileaccess/monitors/ListingMonitor.java
===================================================================
--- labs/shotoku/trunk/shotoku-file-access/src/java/org/jboss/shotoku/fileaccess/monitors/ListingMonitor.java	2006-07-13 18:17:50 UTC (rev 5073)
+++ labs/shotoku/trunk/shotoku-file-access/src/java/org/jboss/shotoku/fileaccess/monitors/ListingMonitor.java	2006-07-13 18:40:09 UTC (rev 5074)
@@ -0,0 +1,82 @@
+package org.jboss.shotoku.fileaccess.monitors;
+
+import org.jboss.shotoku.fileaccess.FileAccessMonitor;
+import org.jboss.shotoku.fileaccess.ContentInformation;
+import org.jboss.shotoku.fileaccess.FileAccessServlet;
+import org.jboss.shotoku.fileaccess.ClosedContentInformation;
+import org.jboss.shotoku.ContentManager;
+import org.jboss.shotoku.Directory;
+import org.jboss.shotoku.Node;
+import org.jboss.shotoku.exceptions.ResourceDoesNotExist;
+import org.apache.log4j.Logger;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+/**
+ * @author Adam Warski (adamw at aster.pl)
+ */
+public class ListingMonitor implements FileAccessMonitor {
+    private static final Logger log = Logger.getLogger(FileAccessServlet.class);
+
+    private Node getIndexNode(Directory d) {
+        try {
+            return d.getNode("index.htm");
+        } catch (ResourceDoesNotExist resourceDoesNotExist) {
+            try {
+                return d.getNode("index.html");
+            } catch (ResourceDoesNotExist resourceDoesNotExist1) {
+                return null;
+            }
+        }
+    }
+
+    public ContentInformation resourceRequested(String path,
+                                                HttpServletRequest request,
+                                                HttpServletResponse response,
+                                                ContentManager cm)
+            throws FileNotFoundException {
+        try {
+            // Checking if the path is a directory.
+            Directory d = cm.getDirectory(path);
+
+            // Checking if there is a / at the end of the directory name.
+            String requestURI = request.getRequestURI();
+
+            if (!requestURI.endsWith("/")) {
+                // Redirecting to a path with a / at the end, so local
+                // references work.
+                try {
+                    response.sendRedirect(requestURI + "/");
+                    return new ClosedContentInformation();
+                } catch (IOException e) {
+                    log.error(e);
+                    return null;
+                }
+            }
+                                     
+            Node indexNode = getIndexNode(d);
+            if (indexNode == null) {
+                try {
+
+                    request.setAttribute("directory", d);
+                    response.setContentType("text/html");
+                    request.getRequestDispatcher("/repo-access/listing.jsp")
+                            .forward(request, response);
+                    return new ClosedContentInformation();
+                } catch (Exception e) {
+                    log.error(e);
+
+                    return null;
+                }
+            } else {
+                return new ContentInformation(indexNode.getMimeType(),
+                        indexNode.getLength(), indexNode.getContentInputStream());
+            }
+        } catch (ResourceDoesNotExist e) {
+            return null;
+        }
+    }
+}

Modified: labs/shotoku/trunk/shotoku-file-access/src/web/WEB-INF/web.xml
===================================================================
--- labs/shotoku/trunk/shotoku-file-access/src/web/WEB-INF/web.xml	2006-07-13 18:17:50 UTC (rev 5073)
+++ labs/shotoku/trunk/shotoku-file-access/src/web/WEB-INF/web.xml	2006-07-13 18:40:09 UTC (rev 5074)
@@ -4,7 +4,26 @@
          xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
             http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
          version="2.4">
+    <filter>
+        <filter-name>filesFromRepoFilter</filter-name>
+        <filter-class>org.jboss.shotoku.web.FilesFromRepoFilter</filter-class>
+        <init-param>
+            <param-name>repoAccessDir</param-name>
+            <param-value>repo-access</param-value>
+        </init-param>
+        <init-param>
+            <param-name>contentManagerPrefix</param-name>
+            <param-value>default/file-access</param-value>
+        </init-param>
+    </filter>
 
+    <filter-mapping>
+        <filter-name>filesFromRepoFilter</filter-name>
+        <url-pattern>/repo-access/*</url-pattern>
+        <dispatcher>INCLUDE</dispatcher>
+        <dispatcher>FORWARD</dispatcher>
+    </filter-mapping>
+
     <servlet>
         <servlet-name>fileAccessServlet</servlet-name>
         <servlet-class>org.jboss.shotoku.fileaccess.FileAccessServlet</servlet-class>
@@ -24,6 +43,6 @@
 
     <servlet-mapping>
         <servlet-name>fileAccessServlet</servlet-name>
-        <url-pattern>/*</url-pattern>
+        <url-pattern>/</url-pattern>
     </servlet-mapping>
 </web-app>
\ No newline at end of file




More information about the jboss-svn-commits mailing list