comparison src/org/eclipse/jetty/server/handler/ResourceHandler.java @ 992:0608a6664bee

minor
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 18 Oct 2016 15:23:25 -0600
parents 688c39c50ee3
children 4e9d373bf6e9
comparison
equal deleted inserted replaced
991:688c39c50ee3 992:0608a6664bee
53 * Requests for resources that do not exist are let pass (Eg no 404's). 53 * Requests for resources that do not exist are let pass (Eg no 404's).
54 * 54 *
55 * 55 *
56 * @org.apache.xbean.XBean 56 * @org.apache.xbean.XBean
57 */ 57 */
58 public class ResourceHandler extends HandlerWrapper 58 public final class ResourceHandler extends HandlerWrapper
59 { 59 {
60 private static final Logger LOG = LoggerFactory.getLogger(ResourceHandler.class); 60 private static final Logger LOG = LoggerFactory.getLogger(ResourceHandler.class);
61 61
62 ContextHandler _context; 62 ContextHandler _context;
63 Resource _baseResource; 63 Resource _baseResource;
257 public void setCacheControl(String cacheControl) 257 public void setCacheControl(String cacheControl)
258 { 258 {
259 _cacheControl=cacheControl==null?null:new ByteArrayBuffer(cacheControl); 259 _cacheControl=cacheControl==null?null:new ByteArrayBuffer(cacheControl);
260 } 260 }
261 261
262 /* ------------------------------------------------------------ */ 262 private Resource getResource(String path) throws MalformedURLException
263 /*
264 */
265 public Resource getResource(String path) throws MalformedURLException
266 { 263 {
267 if (path==null || !path.startsWith("/")) 264 if (path==null || !path.startsWith("/"))
268 throw new MalformedURLException(path); 265 throw new MalformedURLException(path);
269 266
270 Resource base = _baseResource; 267 Resource base = _baseResource;
271 if (base==null) 268 if (base==null)
272 { 269 {
273 if (_context==null) 270 if (_context==null)
274 return null; 271 return null;
275 base=_context.getBaseResource(); 272 base = _context.getBaseResource();
276 if (base==null) 273 if (base==null)
277 return null; 274 return null;
278 } 275 }
279 276
280 try 277 try
281 { 278 {
282 path=URIUtil.canonicalPath(path); 279 path = URIUtil.canonicalPath(path);
283 return base.addPath(path); 280 return base.addPath(path);
284 } 281 }
285 catch(Exception e) 282 catch(Exception e)
286 { 283 {
287 LOG.trace("",e); 284 LOG.trace("",e);
288 } 285 }
289 286
290 return null; 287 return null;
291 } 288 }
292 289
293 /* ------------------------------------------------------------ */ 290 private Resource getResource(HttpServletRequest request) throws MalformedURLException
294 protected Resource getResource(HttpServletRequest request) throws MalformedURLException
295 { 291 {
296 String servletPath; 292 String servletPath;
297 String pathInfo; 293 String pathInfo;
298 Boolean included = request.getAttribute(RequestDispatcher.INCLUDE_REQUEST_URI) != null; 294 Boolean included = request.getAttribute(RequestDispatcher.INCLUDE_REQUEST_URI) != null;
299 if (included != null && included.booleanValue()) 295 if (included != null && included.booleanValue())
311 { 307 {
312 servletPath = request.getServletPath(); 308 servletPath = request.getServletPath();
313 pathInfo = request.getPathInfo(); 309 pathInfo = request.getPathInfo();
314 } 310 }
315 311
316 String pathInContext=URIUtil.addPaths(servletPath,pathInfo); 312 String pathInContext = URIUtil.addPaths(servletPath,pathInfo);
317 return getResource(pathInContext); 313 return getResource(pathInContext);
318 } 314 }
319 315
320 316
321 /* ------------------------------------------------------------ */ 317 /* ------------------------------------------------------------ */