comparison src/org/eclipse/jetty/server/handler/ResourceHandler.java @ 994:4e9d373bf6e9

remove ContextHandler.Context
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 18 Oct 2016 16:34:18 -0600
parents 0608a6664bee
children 7d28be82ab75
comparison
equal deleted inserted replaced
993:d9d95acded81 994:4e9d373bf6e9
57 */ 57 */
58 public final 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;
63 Resource _baseResource; 62 Resource _baseResource;
64 Resource _defaultStylesheet; 63 Resource _defaultStylesheet;
65 Resource _stylesheet; 64 Resource _stylesheet;
66 String[] _welcomeFiles={"index.html"}; 65 String[] _welcomeFiles={"index.html"};
67 MimeTypes _mimeTypes = new MimeTypes(); 66 MimeTypes _mimeTypes = new MimeTypes();
130 /* ------------------------------------------------------------ */ 129 /* ------------------------------------------------------------ */
131 @Override 130 @Override
132 public void doStart() 131 public void doStart()
133 throws Exception 132 throws Exception
134 { 133 {
135 _context = ContextHandler.getCurrentContext();
136
137 if (!_aliases && !FileResource.getCheckAliases()) 134 if (!_aliases && !FileResource.getCheckAliases())
138 throw new IllegalStateException("Alias checking disabled"); 135 throw new IllegalStateException("Alias checking disabled");
139 136
140 super.doStart(); 137 super.doStart();
141 } 138 }
188 LOG.debug("",e); 185 LOG.debug("",e);
189 throw new IllegalArgumentException(resourceBase); 186 throw new IllegalArgumentException(resourceBase);
190 } 187 }
191 } 188 }
192 189
193 /* ------------------------------------------------------------ */ 190 private Resource getStylesheet()
194 /**
195 * @return Returns the stylesheet as a Resource.
196 */
197 public Resource getStylesheet()
198 { 191 {
199 if(_stylesheet != null) 192 if(_stylesheet != null)
200 { 193 {
201 return _stylesheet; 194 return _stylesheet;
202 } 195 }
257 public void setCacheControl(String cacheControl) 250 public void setCacheControl(String cacheControl)
258 { 251 {
259 _cacheControl=cacheControl==null?null:new ByteArrayBuffer(cacheControl); 252 _cacheControl=cacheControl==null?null:new ByteArrayBuffer(cacheControl);
260 } 253 }
261 254
262 private Resource getResource(String path) throws MalformedURLException 255 private Resource getResource(Request request,String path) throws MalformedURLException
263 { 256 {
264 if (path==null || !path.startsWith("/")) 257 if (path==null || !path.startsWith("/"))
265 throw new MalformedURLException(path); 258 throw new MalformedURLException(path);
266 259
267 Resource base = _baseResource; 260 Resource base = _baseResource;
268 if (base==null) 261 if (base==null)
269 { 262 {
270 if (_context==null) 263 ContextHandler ch = request._contextHandler;
264 if (ch==null)
271 return null; 265 return null;
272 base = _context.getBaseResource(); 266 base = ch.getBaseResource();
273 if (base==null) 267 if (base==null)
274 return null; 268 return null;
275 } 269 }
276 270
277 try 271 try
285 } 279 }
286 280
287 return null; 281 return null;
288 } 282 }
289 283
290 private Resource getResource(HttpServletRequest request) throws MalformedURLException 284 private Resource getResource(Request request) throws MalformedURLException
291 { 285 {
292 String servletPath; 286 String servletPath;
293 String pathInfo; 287 String pathInfo;
294 Boolean included = request.getAttribute(RequestDispatcher.INCLUDE_REQUEST_URI) != null; 288 Boolean included = request.getAttribute(RequestDispatcher.INCLUDE_REQUEST_URI) != null;
295 if (included != null && included.booleanValue()) 289 if (included != null && included.booleanValue())
308 servletPath = request.getServletPath(); 302 servletPath = request.getServletPath();
309 pathInfo = request.getPathInfo(); 303 pathInfo = request.getPathInfo();
310 } 304 }
311 305
312 String pathInContext = URIUtil.addPaths(servletPath,pathInfo); 306 String pathInContext = URIUtil.addPaths(servletPath,pathInfo);
313 return getResource(pathInContext); 307 return getResource(request,pathInContext);
314 } 308 }
315 309
316 310
317 /* ------------------------------------------------------------ */ 311 /* ------------------------------------------------------------ */
318 public String[] getWelcomeFiles() 312 public String[] getWelcomeFiles()
359 return; 353 return;
360 } 354 }
361 skipContentBody = true; 355 skipContentBody = true;
362 } 356 }
363 357
364 Resource resource = getResource(request); 358 Resource resource = getResource(baseRequest);
365 359
366 if (resource==null || !resource.exists()) 360 if (resource==null || !resource.exists())
367 { 361 {
368 if (target.endsWith("/jetty-dir.css")) 362 if (target.endsWith("/jetty-dir.css"))
369 { 363 {