| 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 | | } |