Examples of XMLMapper


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

            if( ! f.exists() ) {
                log( "File not found  " + f );
                return;
            }
            XmlMapper xh=new XmlMapper();
            if( getDebug() > 5 ) xh.setDebug( 2 );

            // call addUser using attributes as parameters
            xh.addRule("tomcat-users/user",
                       new XmlAction() {
                               public void start(SaxContext sctx) throws Exception {
                                   int top=sctx.getTagCount()-1;
                                   MemoryRealm mr=(MemoryRealm)sctx.getRoot();
                                   AttributeList attributes = sctx.getAttributeList( top );
                                   String user=attributes.getValue("name");
                                   String pass=attributes.getValue("password");
                                   String group=attributes.getValue("roles");

                                   mr.addUser( user, pass, group );
                               }
                           }
                       );

            xh.readXml( f, this );
        }
View Full Code Here

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

             BaseInterceptor module)
  throws TomcatException
    {
  if( this != module ) return;

  XmlMapper xh=new XmlMapper();
  xh.setDebug( debug );

  addProfileRules( xh );
  addTagRules( cm, ctx, xh );
 
  if (configFile == null)
      configFile=DEFAULT_CONFIG;
 
        File f=new File(configFile);
        if ( !f.isAbsolute())
      f=new File( cm.getHome(), File.separator + configFile);

  if( f.exists() ){
      try {
    xh.readXml(f, this );
      } catch( Exception ex ) {
    ex.printStackTrace();
    throw new TomcatException(ex);
      }
        }
View Full Code Here

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

    public void loadInterceptors( Context ctx, File modulesF, Vector modulesV )
  throws TomcatException
    {

  XmlMapper xh=new XmlMapper();
  xh.setClassLoader( ctx.getClassLoader());
  //xh.setDebug( debug );

  // no backward compat rules. The file must be self-contained,
  // with <module> definition and the module itself
  setTagRules( xh );
View Full Code Here

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

Examples of org.jboss.staxmapper.XMLMapper

        }
        return servers;
    }

    private static String writeModel(final String element, final XMLContentWriter content) throws Exception, FactoryConfigurationError {
        final XMLMapper mapper = XMLMapper.Factory.create();
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        final BufferedOutputStream bos = new BufferedOutputStream(baos);
        final XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(bos);
        try {
            mapper.deparseDocument(new RootElementWriter(element, content), writer);
        }
        catch (XMLStreamException e) {
            // Dump some diagnostics
            stdout.println("XML Content that was written prior to exception:");
            stdout.println(writer.toString());
View Full Code Here

Examples of org.jboss.staxmapper.XMLMapper

    private static final String namespace = "urn:jboss:domain:webservices:1.0";
    private static final WSSubsystemReader parser = WSSubsystemReader.getInstance();

    public void testParse() throws Exception {              
        final List<ModelNode> operations = new ArrayList<ModelNode>();
        XMLMapper mapper = XMLMapper.Factory.create();
        mapper.registerRootElement(new QName(namespace, "subsystem"), parser);

        URL configURL = getClass().getResource("ws-subsystem.xml");
        Assert.assertNotNull("url is not null", configURL);

        BufferedReader reader = new BufferedReader(new InputStreamReader(configURL.openStream()));
        mapper.parseDocument(operations, XMLInputFactory.newInstance().createXMLStreamReader(reader));
        assertEquals(9090, operations.get(0).get(Constants.WSDL_PORT).asInt());
        assertEquals(9443, operations.get(0).get(Constants.WSDL_SECURE_PORT).asInt());
        assertEquals("localhost", operations.get(0).get(Constants.WSDL_HOST).asString());
        assertTrue(operations.get(0).get(Constants.MODIFY_WSDL_ADDRESS).asBoolean());
    }
View Full Code Here

Examples of org.jboss.staxmapper.XMLMapper

                + "      </subsystem>"; // +

        final Reader reader = new StringReader(xmlContent);
        XMLStreamReader xmlReader = XMLInputFactory.newInstance().createXMLStreamReader(reader);

        XMLMapper xmlMapper = XMLMapper.Factory.create();
        xmlMapper.registerRootElement(new QName(namespace.getUriString(), "subsystem"),
                ThreadsParser.INSTANCE);

        List<ModelNode> updates = new ArrayList<ModelNode>();
        xmlMapper.parseDocument(updates, xmlReader);

        // Process subsystems
        for (final ModelNode update : updates) {
            // Process relative subsystem path address
            final ModelNode subsystemAddress = profileAddress.clone();
View Full Code Here

Examples of org.jboss.staxmapper.XMLMapper

        writer.flush();
        return strWriter.toString();
    }

    public static List<ModelNode> xmlToModelOperations(String xml, String nameSpaceUriString, XMLElementReader<List<ModelNode>> parser) throws Exception {
        XMLMapper mapper = XMLMapper.Factory.create();
        mapper.registerRootElement(new QName(nameSpaceUriString, "subsystem"), parser);

        StringReader strReader = new StringReader(xml);

        XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StreamSource(strReader));
        List<ModelNode> newList = new ArrayList<ModelNode>();
        mapper.parseDocument(newList, reader);

        return newList;
    }
View Full Code Here

Examples of org.jboss.staxmapper.XMLMapper

                "    </deployments>" +
                "</server>";
        final XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(xml));
        final StandaloneXml parser = new StandaloneXml(null, null, null);
        final List<ModelNode> operationList = new ArrayList<ModelNode>();
        final XMLMapper mapper = XMLMapper.Factory.create();
        mapper.registerRootElement(new QName(namespace, "server"), parser);
        mapper.parseDocument(operationList, reader);
        final ModelNode content = operationList.get(1).get("content");
        assertArrayEquals(new byte[] { 0x12, 0x34 }, content.get(0).get("hash").asBytes());
    }
View Full Code Here

Examples of org.jboss.staxmapper.XMLMapper

                "    </deployments>" +
                "</server>";
        final XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(xml));
        final StandaloneXml parser = new StandaloneXml(null, null, null);
        final List<ModelNode> operationList = new ArrayList<ModelNode>();
        final XMLMapper mapper = XMLMapper.Factory.create();
        mapper.registerRootElement(new QName(namespace, "server"), parser);
        mapper.parseDocument(operationList, reader);
        System.out.println(operationList.get(1));
        final ModelNode content = operationList.get(1).get("content");
        assertEquals(true, content.get(0).get("archive").asBoolean());
        assertEquals("${jboss.home}/content/welcome.jar", content.get(0).get("path").asString());
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.