Changeset 7787

Show
Ignore:
Timestamp:
07/16/09 11:36:58 (13 months ago)
Author:
dragisak
Message:

Remove override for find method. Static resources are now handled by JournalStaticResourceFilter?. See #919

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • head/ambra/webapp/src/main/java/org/topazproject/ambra/struts2/AmbraStruts2Dispatcher.java

    r7771 r7787  
    1919package org.topazproject.ambra.struts2; 
    2020 
    21 import java.io.IOException; 
    22  
    23 import java.net.URL; 
    24  
    2521import java.util.Enumeration; 
    2622import java.util.HashMap; 
     
    2824 
    2925import javax.servlet.FilterConfig; 
    30 import javax.servlet.http.HttpServletRequest; 
    31 import javax.servlet.http.HttpServletResponse; 
    3226 
    3327import org.apache.commons.configuration.Configuration; 
     
    3832import org.apache.struts2.dispatcher.Dispatcher; 
    3933import org.apache.struts2.dispatcher.FilterDispatcher; 
    40 import org.apache.struts2.util.ClassLoaderUtils; 
    4134 
    4235 
    4336import org.topazproject.ambra.configuration.ConfigurationStore; 
    44 import org.topazproject.ambra.web.HttpResourceServer; 
    4537 
    4638/** 
    4739 * Override the Struts Constants configurations from our Commons config files. This adds one 
    4840 * more override to the Struts constant configuration hierarchy specified in 
    49  * http://struts.apache.org/2.0.9/docs/constant-configuration.html So the overrides order now is 
     41 * http://struts.apache.org/2.0.14/docs/constant-configuration.html So the overrides order now is 
    5042 * struts-defaults.xml,struts-plugin.xml,struts.xml,struts.properties,commons-config. This also 
    5143 * means that struts constants now can be specified as a system property. (eg. 
     
    8173    StrutsConstants.STRUTS_XWORKTEXTPROVIDER, StrutsConstants.STRUTS_ID_PARAMETER_NAME, 
    8274  }; 
    83   private HttpResourceServer    server       = new HttpResourceServer(); 
    84   private String[]              pathPrefixes; 
    8575 
    86   /* 
    87    * inherited javadoc 
    88    */ 
    8976  @Override 
    9077  protected Dispatcher createDispatcher(FilterConfig filterConfig) { 
     
    11198    } 
    11299 
    113   /** 
    114    * Create a string array from a comma-delimited list of packages. 
    115    * 
    116    * @param packages A comma-delimited String listing packages 
    117    * 
    118    * @return A string array of packages 
    119    */ 
    120   @Override 
    121   protected String[] parse(String packages) { 
    122     pathPrefixes = super.parse(packages); 
    123     return pathPrefixes; 
    124   } 
    125  
    126   /** 
    127    * Locate a static resource and copy directly to the response, setting the appropriate 
    128    * caching headers. 
    129    * 
    130    * @param name The resource name 
    131    * @param request The request 
    132    * @param response The response 
    133    * 
    134    * @throws IOException If anything goes wrong 
    135    */ 
    136   @Override 
    137   protected void findStaticResource(String name, HttpServletRequest request, 
    138                                     HttpServletResponse response) 
    139                              throws IOException { 
    140     if (!name.endsWith(".class")) { 
    141       for (String pathPrefix : pathPrefixes) { 
    142         URL url = findResource(name, pathPrefix); 
    143  
    144         if (url != null) { 
    145           server.serveResource(request, response, new HttpResourceServer.URLResource(url)); 
    146  
    147           return; 
    148         } 
    149       } 
    150     } 
    151  
    152     response.sendError(HttpServletResponse.SC_NOT_FOUND); 
    153   } 
    154  
    155   /** 
    156    * Look for a static resource in the classpath. 
    157    * 
    158    * @param name The resource name 
    159    * @param packagePrefix The package prefix to use to locate the resource 
    160    * 
    161    * @return The inputstream of the resource 
    162    * 
    163    * @throws IOException If there is a problem locating the resource 
    164    */ 
    165   protected URL findResource(String name, String packagePrefix) 
    166                       throws IOException { 
    167     String resourcePath; 
    168  
    169     if (packagePrefix.endsWith("/") && name.startsWith("/")) { 
    170       resourcePath = packagePrefix + name.substring(1); 
    171     } else { 
    172       resourcePath = packagePrefix + name; 
    173     } 
    174  
    175     /* 
    176      * Hmm. No need to decode again. Bug in struts? 
    177      * resourcePath = URLDecoder.decode(resourcePath, encoding); 
    178      */ 
    179     return ClassLoaderUtils.getResource(resourcePath, getClass()); 
    180   } 
    181100}