struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From musa...@apache.org
Subject svn commit: r687425 - in /struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher: DefaultStaticContentLoader.java StaticContentLoader.java
Date Wed, 20 Aug 2008 18:59:02 GMT
Author: musachy
Date: Wed Aug 20 11:59:01 2008
New Revision: 687425

URL: http://svn.apache.org/viewvc?rev=687425&view=rev
Log:
Improve static resource handling

Modified:
    struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/DefaultStaticContentLoader.java
    struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/StaticContentLoader.java

Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/DefaultStaticContentLoader.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/DefaultStaticContentLoader.java?rev=687425&r1=687424&r2=687425&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/DefaultStaticContentLoader.java
(original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/DefaultStaticContentLoader.java
Wed Aug 20 11:59:01 2008
@@ -24,13 +24,13 @@
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.UnsupportedEncodingException;
+import java.net.URL;
 import java.net.URLDecoder;
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.List;
 import java.util.StringTokenizer;
 
-import javax.servlet.FilterConfig;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
@@ -161,9 +161,21 @@
     public void findStaticResource(String path, HttpServletRequest request, HttpServletResponse
response)
             throws IOException {
         String name = cleanupPath(path);
-        if (!name.endsWith(".class")) {
-            for (String pathPrefix : pathPrefixes) {
-                InputStream is = findInputStream(buildPath(name, pathPrefix));
+        for (String pathPrefix : pathPrefixes) {
+            URL resourceUrl = findResource(buildPath(name, pathPrefix));
+            if (resourceUrl != null) {
+                InputStream is = null;
+                try {
+                    //check that the resource path is under the pathPrefix path
+                    String pathEnding = buildPath(name, pathPrefix);
+                    if (resourceUrl.getFile().endsWith(pathEnding))
+                        is = resourceUrl.openStream();
+                } catch (Exception ex) {
+                    // just ignore it
+                    continue;
+                }
+
+                //not inside the try block, as this could throw IOExceptions also
                 if (is != null) {
                     process(is, path, request, response);
                     return;
@@ -258,8 +270,8 @@
      * @return The inputstream of the resource
      * @throws IOException If there is a problem locating the resource
      */
-    protected InputStream findInputStream(String path) throws IOException {
-        return ClassLoaderUtil.getResourceAsStream(path, getClass());
+    protected URL findResource(String path) throws IOException {
+        return ClassLoaderUtil.getResource(path, getClass());
     }
 
     /**

Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/StaticContentLoader.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/StaticContentLoader.java?rev=687425&r1=687424&r2=687425&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/StaticContentLoader.java
(original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/StaticContentLoader.java
Wed Aug 20 11:59:01 2008
@@ -20,14 +20,13 @@
  */
 package org.apache.struts2.dispatcher;
 
-import org.apache.struts2.dispatcher.ng.HostConfig;
-
 import java.io.IOException;
 
-import javax.servlet.FilterConfig;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.struts2.dispatcher.ng.HostConfig;
+
 /**
  * Interface for loading static resources, based on a path
  *



Mime
View raw message