Package org.apache.tomcat.util.xml

Examples of org.apache.tomcat.util.xml.XmlMapper


      if( ! f.exists() ) {
    ctx.log( "File not found " + f + ", using only defaults" );
    return;
      }
      if( ctx.getDebug() > 0 ) ctx.log("Reading " + file );
      XmlMapper xh=new XmlMapper();
      WebXmlErrorHandler xeh=null;
      File v=new File( ctx.getWorkDir(), "webxmlval.txt" );
      if( validate ) {
    if( ! v.exists() ||
        v.lastModified() < f.lastModified() ) {
        ctx.log("Validating web.xml");
        xh.setValidating(true);
        xeh=new WebXmlErrorHandler( xh, ctx );
        xh.setErrorHandler( xeh );
    }
      }

      // By using dtdURL you brake most parsers ( at least xerces )
      xh.registerDTDRes("-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN",
            "org/apache/tomcat/resources/web.dtd");

      xh.addRule("web-app/context-param", xh.methodSetter("addInitParameter", 2) );
      xh.addRule("web-app/context-param/param-name", xh.methodParam(0) );
      xh.addRule("web-app/context-param/param-value", xh.methodParam(1) );

      xh.addRule("web-app/description", xh.methodSetter("setDescription", 0) );
      xh.addRule("web-app/icon/small-icon", xh.methodSetter("setIcon", 0) );
      xh.addRule("web-app/distributable", xh.methodSetter("setDistributable", 0) );

      xh.addRule("web-app/servlet-mapping", xh.methodSetter("addServletMapping", 2) );
      xh.addRule("web-app/servlet-mapping/servlet-name", xh.methodParam(1) );
      xh.addRule("web-app/servlet-mapping/url-pattern", xh.methodParam(0) );

      xh.addRule("web-app/taglib", xh.methodSetter("addTaglib", 2) );
      xh.addRule("web-app/taglib/taglib-uri", xh.methodParam(0) );
      xh.addRule("web-app/taglib/taglib-location", xh.methodParam(1) );

      xh.addRule("web-app/env-entry", xh.methodSetter("addEnvEntry", 4) );
      xh.addRule("web-app/env-entry/env-entry-name", xh.methodParam(0) );
      xh.addRule("web-app/env-entry/env-entry-type", xh.methodParam(1) );
      xh.addRule("web-app/env-entry/env-entry-value", xh.methodParam(2) );
      xh.addRule("web-app/env-entry/description", xh.methodParam(3) );

      xh.addRule("web-app/login-config", xh.methodSetter("setLoginConfig", 4) );
      xh.addRule("web-app/login-config/auth-method", xh.methodParam(0) );
      xh.addRule("web-app/login-config/realm-name", xh.methodParam(1) );
      xh.addRule("web-app/login-config/form-login-config/form-login-page", xh.methodParam(2) );
      xh.addRule("web-app/login-config/form-login-config/form-error-page", xh.methodParam(3) );

      xh.addRule("web-app/mime-mapping", xh.methodSetter("addContentType", 2) );
      xh.addRule("web-app/mime-mapping/extension", xh.methodParam(0) );
      xh.addRule("web-app/mime-mapping/mime-type", xh.methodParam(1) );

      xh.addRule("web-app/welcome-file-list/welcome-file", xh.methodSetter("addWelcomeFile", 0) );

      xh.addRule("web-app/error-page", xh.methodSetter("addErrorPage",2) );
      xh.addRule("web-app/error-page/error-code", xh.methodParam(0) );
      xh.addRule("web-app/error-page/exception-type", xh.methodParam(0) );
      xh.addRule("web-app/error-page/location", xh.methodParam(1) );

      xh.addRule("web-app/session-config", xh.methodSetter("setSessionTimeOut", 1, new String[]{"int"}));
      xh.addRule("web-app/session-config/session-timeout", xh.methodParam(0));

      // Servlet
      xh.addRule("web-app/servlet", xh.objectCreate("org.apache.tomcat.facade.ServletInfo") ); // servlet-wrapper
      xh.addRule("web-app/servlet", xh.setParent( "setContext") ); // remove it from stack when done
      //      xh.addRule("web-app/servlet", xh.addChild("addServlet", "org.apache.tomcat.core.Handler") );

      final WebXmlReader wxr=this;
      xh.addRule("web-app/servlet", new XmlAction() {
         public void end( SaxContext xctx)
             throws Exception {
             ServletInfo sw=(ServletInfo)
           xctx.currentObject();
             Context cctx=(Context)xctx.previousObject();
             sw.addServlet(cctx, wxr);
         }
           }
       );
      // remove it from stack when done
      xh.addRule("web-app/servlet/servlet-name", xh.methodSetter("setServletName",0) );
      xh.addRule("web-app/servlet/servlet-class", xh.methodSetter("setServletClassName",0));
      xh.addRule("web-app/servlet/jsp-file",
           xh.methodSetter("setJspFile",0));

      xh.addRule("web-app/servlet/security-role-ref", xh.methodSetter("addSecurityMapping", 3) );
      xh.addRule("web-app/servlet/security-role-ref/role-name", xh.methodParam(0) );
      xh.addRule("web-app/servlet/security-role-ref/role-link", xh.methodParam(1) );
      xh.addRule("web-app/servlet/security-role-ref/description", xh.methodParam(2) );

      xh.addRule("web-app/servlet/init-param", xh.methodSetter("addInitParam", 2) ); // addXXX
      xh.addRule("web-app/servlet/init-param/param-name", xh.methodParam(0) );
      xh.addRule("web-app/servlet/init-param/param-value", xh.methodParam(1) );

      xh.addRule("web-app/servlet/icon/small-icon", xh.methodSetter("setIcon",0 )); // icon, body
      xh.addRule("web-app/servlet/description", xh.methodSetter("setDescription", 0) ); // description, body
      xh.addRule("web-app/servlet/load-on-startup", xh.methodSetter("setLoadOnStartUp", 0 ));


      addSecurity( xh );

            Object ctx1=null;

            xh.useLocalLoader( false ); // we'll use our own parser for web.xml
           
            // Perform the reading with the context privs
            Object pd=ctx.getAttribute( Context.ATTRIB_PROTECTION_DOMAIN);
            //            System.out.println("Protection domain " + pd);

            if( pd!=null ) {
                // Do the action in a sandbox, with context privs
                PriviledgedAction di = new PriviledgedAction(xh, f, ctx);
                try {
                    ctx1=jdk11Compat.doPrivileged(di, pd);
                } catch( TomcatException ex1 ) {
                    throw ex1;
                } catch( Exception ex ) {
                    throw new TomcatException( ex );
                }
            } else {
                ctx1=xh.readXml(f, ctx);
            }

      if( validate && xeh != null && xeh.isOk() ) {
    // don't create the validation mark if an error was detected
    try {
View Full Code Here

TOP

Related Classes of org.apache.tomcat.util.xml.XmlMapper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.