📄 webxmlconfiguration.java
字号:
if(!(listener instanceof EventListener)) { Log.warn("Not an EventListener: "+listener); return; } _listeners=LazyList.add(_listeners, listener); } catch(Exception e) { Log.warn("Could not instantiate listener "+className,e); return; } } /* ------------------------------------------------------------ */ protected Object newListenerInstance(Class clazz) throws InstantiationException, IllegalAccessException { return clazz.newInstance(); } /* ------------------------------------------------------------ */ protected void initDistributable(XmlParser.Node node) { // the element has no content, so its simple presence // indicates that the webapp is distributable... WebAppContext wac=getWebAppContext(); if (!wac.isDistributable()) wac.setDistributable(true); } /* ------------------------------------------------------------ */ protected void initSessionConfig(XmlParser.Node node) { XmlParser.Node tNode=node.get("session-timeout"); if(tNode!=null) { int timeout=Integer.parseInt(tNode.toString(false,true)); getWebAppContext().getSessionHandler().getSessionManager().setMaxInactiveInterval(timeout*60); } } /* ------------------------------------------------------------ */ protected void initMimeConfig(XmlParser.Node node) { String extension=node.getString("extension",false,true); if(extension!=null&&extension.startsWith(".")) extension=extension.substring(1); String mimeType=node.getString("mime-type",false,true); getWebAppContext().getMimeTypes().addMimeMapping(extension, mimeType); } /* ------------------------------------------------------------ */ protected void initWelcomeFileList(XmlParser.Node node) { if (_defaultWelcomeFileList) _welcomeFiles=null; // erase welcome files from default web.xml _defaultWelcomeFileList=false; Iterator iter=node.iterator("welcome-file"); while(iter.hasNext()) { XmlParser.Node indexNode=(XmlParser.Node)iter.next(); String welcome=indexNode.toString(false,true); _welcomeFiles=LazyList.add(_welcomeFiles,welcome); } } /* ------------------------------------------------------------ */ protected void initLocaleEncodingList(XmlParser.Node node) { Iterator iter=node.iterator("locale-encoding-mapping"); while(iter.hasNext()) { XmlParser.Node mapping=(XmlParser.Node)iter.next(); String locale=mapping.getString("locale",false,true); String encoding=mapping.getString("encoding",false,true); getWebAppContext().addLocaleEncoding(locale,encoding); } } /* ------------------------------------------------------------ */ protected void initErrorPage(XmlParser.Node node) { String error=node.getString("error-code",false,true); if(error==null||error.length()==0) error=node.getString("exception-type",false,true); String location=node.getString("location",false,true); if (_errorPages==null) _errorPages=new HashMap(); _errorPages.put(error,location); } /* ------------------------------------------------------------ */ protected void initTagLib(XmlParser.Node node) { String uri=node.getString("taglib-uri",false,true); String location=node.getString("taglib-location",false,true); getWebAppContext().setResourceAlias(uri,location); } /* ------------------------------------------------------------ */ protected void initJspConfig(XmlParser.Node node) { for (int i=0;i<node.size();i++) { Object o=node.get(i); if (o instanceof XmlParser.Node && "taglib".equals(((XmlParser.Node)o).getTag())) initTagLib((XmlParser.Node)o); } // Map URLs from jsp property groups to JSP servlet. // this is more JSP stupidness creaping into the servlet spec Iterator iter=node.iterator("jsp-property-group"); Object paths=null; while(iter.hasNext()) { XmlParser.Node group=(XmlParser.Node)iter.next(); Iterator iter2 = group.iterator("url-pattern"); while (iter2.hasNext()) { String url = ((XmlParser.Node) iter2.next()).toString(false, true); url=normalizePattern(url); paths=LazyList.add(paths,url); } } if (LazyList.size(paths)>0) { String jspName=getJSPServletName(); if (jspName!=null) { ServletMapping mapping = new ServletMapping(); mapping.setServletName(jspName); mapping.setPathSpecs(LazyList.toStringArray(paths)); _servletMappings=LazyList.add(_servletMappings,mapping); } } } /* ------------------------------------------------------------ */ protected void initSecurityConstraint(XmlParser.Node node) { Constraint scBase = new Constraint(); try { XmlParser.Node auths = node.get("auth-constraint"); if (auths != null) { scBase.setAuthenticate(true); // auth-constraint Iterator iter = auths.iterator("role-name"); Object roles=null; while (iter.hasNext()) { String role = ((XmlParser.Node) iter.next()).toString(false, true); roles=LazyList.add(roles,role); } scBase.setRoles(LazyList.toStringArray(roles)); } XmlParser.Node data = node.get("user-data-constraint"); if (data != null) { data = data.get("transport-guarantee"); String guarantee = data.toString(false, true).toUpperCase(); if (guarantee == null || guarantee.length() == 0 || "NONE".equals(guarantee)) scBase.setDataConstraint(Constraint.DC_NONE); else if ("INTEGRAL".equals(guarantee)) scBase.setDataConstraint(Constraint.DC_INTEGRAL); else if ("CONFIDENTIAL".equals(guarantee)) scBase.setDataConstraint(Constraint.DC_CONFIDENTIAL); else { Log.warn("Unknown user-data-constraint:" + guarantee); scBase.setDataConstraint(Constraint.DC_CONFIDENTIAL); } } Iterator iter = node.iterator("web-resource-collection"); while (iter.hasNext()) { XmlParser.Node collection = (XmlParser.Node) iter.next(); String name = collection.getString("web-resource-name", false, true); Constraint sc = (Constraint) scBase.clone(); sc.setName(name); Iterator iter2 = collection.iterator("url-pattern"); while (iter2.hasNext()) { String url = ((XmlParser.Node) iter2.next()).toString(false, true); url=normalizePattern(url); Iterator iter3 = collection.iterator("http-method"); if (iter3.hasNext()) { while (iter3.hasNext()) { String method=((XmlParser.Node) iter3.next()).toString(false, true); ConstraintMapping mapping = new ConstraintMapping(); mapping.setMethod(method); mapping.setPathSpec(url); mapping.setConstraint(sc); _constraintMappings=LazyList.add(_constraintMappings,mapping); } } else { ConstraintMapping mapping = new ConstraintMapping(); mapping.setPathSpec(url); mapping.setConstraint(sc); _constraintMappings=LazyList.add(_constraintMappings,mapping); } } } } catch (CloneNotSupportedException e) { Log.warn(e); } } /* ------------------------------------------------------------ */ protected void initLoginConfig(XmlParser.Node node) { XmlParser.Node method=node.get("auth-method"); FormAuthenticator _formAuthenticator=null; if(method!=null) { Authenticator authenticator=null; String m=method.toString(false,true); if(Constraint.__FORM_AUTH.equals(m)) authenticator=_formAuthenticator=new FormAuthenticator(); else if(Constraint.__BASIC_AUTH.equals(m)) authenticator=new BasicAuthenticator(); else if(Constraint.__DIGEST_AUTH.equals(m)) authenticator=new DigestAuthenticator(); else if(Constraint.__CERT_AUTH.equals(m)) authenticator=new ClientCertAuthenticator(); else if(Constraint.__CERT_AUTH2.equals(m)) authenticator=new ClientCertAuthenticator(); else Log.warn("UNKNOWN AUTH METHOD: "+m); getWebAppContext().getSecurityHandler().setAuthenticator(authenticator); } XmlParser.Node name=node.get("realm-name"); UserRealm[] realms=ContextHandler.getCurrentContext().getContextHandler().getServer().getUserRealms(); String realm_name=name==null?"default":name.toString(false,true); UserRealm realm=getWebAppContext().getSecurityHandler().getUserRealm(); for (int i=0;realm==null && realms!=null && i<realms.length; i++) { if (realms[i]!=null && realm_name.equals(realms[i].getName())) realm=realms[i]; } if (realm==null) { String msg = "Unknown realm: "+realm_name; Log.warn(msg); } else getWebAppContext().getSecurityHandler().setUserRealm(realm); XmlParser.Node formConfig=node.get("form-login-config"); if(formConfig!=null) { if(_formAuthenticator==null) Log.warn("FORM Authentication miss-configured"); else { XmlParser.Node loginPage=formConfig.get("form-login-page"); if(loginPage!=null) _formAuthenticator.setLoginPage(loginPage.toString(false,true)); XmlParser.Node errorPage=formConfig.get("form-error-page"); if(errorPage!=null) { String ep=errorPage.toString(false,true); _formAuthenticator.setErrorPage(ep); } } } } /* ------------------------------------------------------------ */ protected void initSecurityRole(XmlParser.Node node) {} /* ------------------------------------------------------------ */ protected String getJSPServletName() { if (_jspServletName==null) { Map.Entry entry= _context.getServletHandler().getHolderEntry("test.jsp"); if (entry!=null) { ServletHolder holder=(ServletHolder)entry.getValue(); _jspServletName=holder.getName(); } } return _jspServletName; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -