📄 contexthandler.java
字号:
base_request.setContext(old_context); base_request.setContextPath(old_context_path); base_request.setServletPath(old_servlet_path); base_request.setPathInfo(old_path_info); } } } /* ------------------------------------------------------------ */ /** Check the target. * Called by {@link #handle(String, HttpServletRequest, HttpServletResponse, int)} when a * target within a context is determined. If the target is protected, 404 is returned. * The default implementation always returns false. * @see org.mortbay.jetty.webapp.WebAppContext#isProtectedTarget(String) */ /* ------------------------------------------------------------ */ protected boolean isProtectedTarget(String target) { return false; } /* ------------------------------------------------------------ */ /* * @see javax.servlet.ServletContext#removeAttribute(java.lang.String) */ public void removeAttribute(String name) { setManagedAttribute(name,null); _attributes.removeAttribute(name); } /* ------------------------------------------------------------ */ /* Set a context attribute. * Attributes set via this API cannot be overriden by the ServletContext.setAttribute API. * Their lifecycle spans the stop/start of a context. No attribute listener events are * triggered by this API. * @see javax.servlet.ServletContext#setAttribute(java.lang.String, java.lang.Object) */ public void setAttribute(String name, Object value) { setManagedAttribute(name,value); _attributes.setAttribute(name,value); } /* ------------------------------------------------------------ */ /** * @param attributes The attributes to set. */ public void setAttributes(Attributes attributes) { if (attributes instanceof AttributesMap) { _attributes = (AttributesMap)attributes; Enumeration e = _attributes.getAttributeNames(); while (e.hasMoreElements()) { String name = (String)e.nextElement(); setManagedAttribute(name,attributes.getAttribute(name)); } } else { _attributes=new AttributesMap(); Enumeration e = attributes.getAttributeNames(); while (e.hasMoreElements()) { String name = (String)e.nextElement(); Object value=attributes.getAttribute(name); setManagedAttribute(name,value); _attributes.setAttribute(name,value); } } } /* ------------------------------------------------------------ */ public void clearAttributes() { Enumeration e = _attributes.getAttributeNames(); while (e.hasMoreElements()) { String name = (String)e.nextElement(); setManagedAttribute(name,null); } _attributes.clearAttributes(); } /* ------------------------------------------------------------ */ private void setManagedAttribute(String name, Object value) { if (_managedAttributes!=null && _managedAttributes.contains(name)) { Object o =_scontext.getAttribute(name); if (o!=null) getServer().getContainer().removeBean(o); if (value!=null) getServer().getContainer().addBean(value); } } /* ------------------------------------------------------------ */ /** * @param classLoader The classLoader to set. */ public void setClassLoader(ClassLoader classLoader) { _classLoader = classLoader; } /* ------------------------------------------------------------ */ /** * @param contextPath The _contextPath to set. */ public void setContextPath(String contextPath) { if (contextPath!=null && contextPath.length()>1 && contextPath.endsWith("/")) throw new IllegalArgumentException("ends with /"); _contextPath = contextPath; if (getServer()!=null && (getServer().isStarting() || getServer().isStarted())) { Handler[] contextCollections = getServer().getChildHandlersByClass(ContextHandlerCollection.class); for (int h=0;contextCollections!=null&& h<contextCollections.length;h++) ((ContextHandlerCollection)contextCollections[h]).mapContexts(); } } /* ------------------------------------------------------------ */ /** * @param initParams The initParams to set. */ public void setInitParams(Map initParams) { if (initParams == null) return; _initParams = new HashMap(initParams); } /* ------------------------------------------------------------ */ /** * @param servletContextName The servletContextName to set. */ public void setDisplayName(String servletContextName) { _displayName = servletContextName; if (_classLoader!=null && _classLoader instanceof WebAppClassLoader) ((WebAppClassLoader)_classLoader).setName(servletContextName); } /* ------------------------------------------------------------ */ /** * @return Returns the resourceBase. */ public Resource getBaseResource() { if (_baseResource==null) return null; return _baseResource; } /* ------------------------------------------------------------ */ /** * @return Returns the base resource as a string. */ public String getResourceBase() { if (_baseResource==null) return null; return _baseResource.toString(); } /* ------------------------------------------------------------ */ /** * @param base The resourceBase to set. */ public void setBaseResource(Resource base) { _baseResource=base; } /* ------------------------------------------------------------ */ /** * @param resourceBase The base resource as a string. */ public void setResourceBase(String resourceBase) { try { setBaseResource(Resource.newResource(resourceBase)); } catch (Exception e) { Log.warn(e); throw new IllegalArgumentException(resourceBase); } } /* ------------------------------------------------------------ */ /** * @return Returns the mimeTypes. */ public MimeTypes getMimeTypes() { return _mimeTypes; } /* ------------------------------------------------------------ */ /** * @param mimeTypes The mimeTypes to set. */ public void setMimeTypes(MimeTypes mimeTypes) { _mimeTypes = mimeTypes; } /* ------------------------------------------------------------ */ /** */ public void setWelcomeFiles(String[] files) { _welcomeFiles=files; } /* ------------------------------------------------------------ */ /** * @return The names of the files which the server should consider to be welcome files in this context. * @see <a href="http://jcp.org/aboutJava/communityprocess/final/jsr154/index.html">The Servlet Specification</a> * @see #setWelcomeFiles */ public String[] getWelcomeFiles() { return _welcomeFiles; } /* ------------------------------------------------------------ */ /** * @return Returns the errorHandler. */ public ErrorHandler getErrorHandler() { return _errorHandler; } /* ------------------------------------------------------------ */ /** * @param errorHandler The errorHandler to set. */ public void setErrorHandler(ErrorHandler errorHandler) { if (errorHandler!=null) errorHandler.setServer(getServer()); if (getServer()!=null) getServer().getContainer().update(this, _errorHandler, errorHandler, "errorHandler",true); _errorHandler = errorHandler; } /* ------------------------------------------------------------ */ public int getMaxFormContentSize() { return _maxFormContentSize; } /* ------------------------------------------------------------ */ public void setMaxFormContentSize(int maxSize) { _maxFormContentSize=maxSize; } /* ------------------------------------------------------------ */ /** * @return True if URLs are compacted to replace multiple '/'s with a single '/' */ public boolean isCompactPath() { return _compactPath; } /* ------------------------------------------------------------ */ /** * @param compactPath True if URLs are compacted to replace multiple '/'s with a single '/' */ public void setCompactPath(boolean compactPath) { _compactPath=compactPath; } /* ------------------------------------------------------------ */ public String toString() { return this.getClass().getName()+"@"+Integer.toHexString(hashCode())+"{"+getContextPath()+","+getBaseResource()+"}"; } /* ------------------------------------------------------------ */ public synchronized Class loadClass(String className) throws ClassNotFoundException { if (className==null) return null; if (_classLoader==null) return Loader.loadClass(this.getClass(), className); return _classLoader.loadClass(className); } /* ------------------------------------------------------------ */ public void addLocaleEncoding(String locale,String encoding) { if (_localeEncodingMap==null) _localeEncodingMap=new HashMap(); _localeEncodingMap.put(locale, encoding); } /* ------------------------------------------------------------ */ /** * Get the character encoding for a locale. The full locale name is first * looked up in the map of encodings. If no encoding is found, then the * locale language is looked up. * * @param locale a <code>Locale</code> value * @return a <code>String</code> representing the character encoding for * the locale or null if none found. */ public String getLocaleEncoding(Locale locale) { if (_localeEncodingMap==null) return null; String encoding = (String)_localeEncodingMap.get(locale.toString()); if (encoding==null) encoding = (String)_localeEncodingMap.get(locale.getLanguage()); return encoding; } /* ------------------------------------------------------------ */ /* */ public Resource getResource(String path) throws MalformedURLException { if (path==null || !path.startsWith(URIUtil.SLASH)) throw new MalformedURLException(path); if (_baseResource==null) return null; try { path=URIUtil.canonicalPath(path); Resource resource=_baseResource.addPath(path); return resource; } catch(Exception e) { Log.ignore(e); } return null; } /* ------------------------------------------------------------ */ /* */ public Set getResourcePaths(String path) { try { path=URIUtil.canonicalPath(path); Resource resource=getResource(path); if (resource!=null && resource.exists()) { if (!path.endsWith(URIUtil.SLASH)) path=path+URIUtil.SLASH; String[] l=resource.list(); if (l!=null) { HashSet set = new HashSet(); for(int i=0;i<l.length;i++) set.add(path+l[i]); return set; } } } catch(Exception e) { Log.ignore(e); } return Collections.EMPTY_SET; } /* ------------------------------------------------------------ */ /** Context. * <p> * Implements {@link javax.servlet.ServletContext} from the {@link javax.servlet} package.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -