Search in sources :

Example 11 with Digester

use of org.apache.tomcat.util.digester.Digester in project tomcat by apache.

the class TestSchemaValidation method testWebapp_2_5.

@Test
public void testWebapp_2_5() throws Exception {
    XmlErrorHandler handler = new XmlErrorHandler();
    Digester digester = DigesterFactory.newDigester(true, true, new WebRuleSet(false), true);
    digester.setErrorHandler(handler);
    digester.push(new WebXml());
    WebXml desc = (WebXml) digester.parse(new File("test/webapp-2.5/WEB-INF/web.xml"));
    Assert.assertEquals("2.5", desc.getVersion());
    Assert.assertEquals(0, handler.getErrors().size());
    Assert.assertEquals(0, handler.getWarnings().size());
}
Also used : WebXml(org.apache.tomcat.util.descriptor.web.WebXml) Digester(org.apache.tomcat.util.digester.Digester) XmlErrorHandler(org.apache.tomcat.util.descriptor.XmlErrorHandler) WebRuleSet(org.apache.tomcat.util.descriptor.web.WebRuleSet) File(java.io.File) Test(org.junit.Test)

Example 12 with Digester

use of org.apache.tomcat.util.digester.Digester in project tomcat by apache.

the class TestSchemaValidation method testWebapp_2_2.

@Test
public void testWebapp_2_2() throws Exception {
    XmlErrorHandler handler = new XmlErrorHandler();
    Digester digester = DigesterFactory.newDigester(true, true, new WebRuleSet(false), true);
    digester.setErrorHandler(handler);
    digester.push(new WebXml());
    WebXml desc = (WebXml) digester.parse(new File("test/webapp-2.2/WEB-INF/web.xml"));
    Assert.assertEquals("2.2", desc.getVersion());
    Assert.assertEquals(XmlIdentifiers.WEB_22_PUBLIC, desc.getPublicId());
    Assert.assertEquals(0, handler.getErrors().size());
    Assert.assertEquals(0, handler.getWarnings().size());
}
Also used : WebXml(org.apache.tomcat.util.descriptor.web.WebXml) Digester(org.apache.tomcat.util.digester.Digester) XmlErrorHandler(org.apache.tomcat.util.descriptor.XmlErrorHandler) WebRuleSet(org.apache.tomcat.util.descriptor.web.WebRuleSet) File(java.io.File) Test(org.junit.Test)

Example 13 with Digester

use of org.apache.tomcat.util.digester.Digester in project tomcat by apache.

the class PersistentProviderRegistrations method loadProviders.

static Providers loadProviders(File configFile) {
    try (InputStream is = new FileInputStream(configFile)) {
        // Construct a digester to read the XML input file
        Digester digester = new Digester();
        try {
            digester.setFeature("http://apache.org/xml/features/allow-java-encodings", true);
            digester.setValidating(true);
            digester.setNamespaceAware(true);
        } catch (Exception e) {
            throw new SecurityException(e);
        }
        // Create an object to hold the parse results and put it on the top
        // of the digester's stack
        Providers result = new Providers();
        digester.push(result);
        // Configure the digester
        digester.addObjectCreate("jaspic-providers/provider", Provider.class.getName());
        digester.addSetProperties("jaspic-providers/provider");
        digester.addSetNext("jaspic-providers/provider", "addProvider", Provider.class.getName());
        digester.addObjectCreate("jaspic-providers/provider/property", Property.class.getName());
        digester.addSetProperties("jaspic-providers/provider/property");
        digester.addSetNext("jaspic-providers/provider/property", "addProperty", Property.class.getName());
        // Parse the input
        digester.parse(is);
        return result;
    } catch (IOException | SAXException e) {
        throw new SecurityException(e);
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Digester(org.apache.tomcat.util.digester.Digester) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) SAXException(org.xml.sax.SAXException)

Example 14 with Digester

use of org.apache.tomcat.util.digester.Digester in project tomcat by apache.

the class StoreLoader method createDigester.

/**
     * Create and configure the Digester we will be using for setup store
     * registry.
     * @return the XML digester that will be used to parse the configuration
     */
protected static Digester createDigester() {
    long t1 = System.currentTimeMillis();
    // Initialize the digester
    Digester digester = new Digester();
    digester.setValidating(false);
    digester.setClassLoader(StoreRegistry.class.getClassLoader());
    // Configure the actions we will be using
    digester.addObjectCreate("Registry", "org.apache.catalina.storeconfig.StoreRegistry", "className");
    digester.addSetProperties("Registry");
    digester.addObjectCreate("Registry/Description", "org.apache.catalina.storeconfig.StoreDescription", "className");
    digester.addSetProperties("Registry/Description");
    digester.addRule("Registry/Description", new StoreFactoryRule("org.apache.catalina.storeconfig.StoreFactoryBase", "storeFactoryClass", "org.apache.catalina.storeconfig.StoreAppender", "storeAppenderClass"));
    digester.addSetNext("Registry/Description", "registerDescription", "org.apache.catalina.storeconfig.StoreDescription");
    digester.addCallMethod("Registry/Description/TransientAttribute", "addTransientAttribute", 0);
    digester.addCallMethod("Registry/Description/TransientChild", "addTransientChild", 0);
    long t2 = System.currentTimeMillis();
    if (log.isDebugEnabled())
        log.debug("Digester for server-registry.xml created " + (t2 - t1));
    return (digester);
}
Also used : Digester(org.apache.tomcat.util.digester.Digester)

Example 15 with Digester

use of org.apache.tomcat.util.digester.Digester in project tomcat by apache.

the class WebXmlParser method parseWebXml.

public boolean parseWebXml(InputSource source, WebXml dest, boolean fragment) {
    boolean ok = true;
    if (source == null) {
        return ok;
    }
    XmlErrorHandler handler = new XmlErrorHandler();
    Digester digester;
    WebRuleSet ruleSet;
    if (fragment) {
        digester = webFragmentDigester;
        ruleSet = webFragmentRuleSet;
    } else {
        digester = webDigester;
        ruleSet = webRuleSet;
    }
    digester.push(dest);
    digester.setErrorHandler(handler);
    if (log.isDebugEnabled()) {
        log.debug(sm.getString("webXmlParser.applicationStart", source.getSystemId()));
    }
    try {
        digester.parse(source);
        if (handler.getWarnings().size() > 0 || handler.getErrors().size() > 0) {
            ok = false;
            handler.logFindings(log, source.getSystemId());
        }
    } catch (SAXParseException e) {
        log.error(sm.getString("webXmlParser.applicationParse", source.getSystemId()), e);
        log.error(sm.getString("webXmlParser.applicationPosition", "" + e.getLineNumber(), "" + e.getColumnNumber()));
        ok = false;
    } catch (Exception e) {
        log.error(sm.getString("webXmlParser.applicationParse", source.getSystemId()), e);
        ok = false;
    } finally {
        InputSourceUtil.close(source);
        digester.reset();
        ruleSet.recycle();
    }
    return ok;
}
Also used : SAXParseException(org.xml.sax.SAXParseException) Digester(org.apache.tomcat.util.digester.Digester) XmlErrorHandler(org.apache.tomcat.util.descriptor.XmlErrorHandler) SAXParseException(org.xml.sax.SAXParseException) IOException(java.io.IOException)

Aggregations

Digester (org.apache.tomcat.util.digester.Digester)28 File (java.io.File)14 XmlErrorHandler (org.apache.tomcat.util.descriptor.XmlErrorHandler)11 IOException (java.io.IOException)8 WebRuleSet (org.apache.tomcat.util.descriptor.web.WebRuleSet)8 WebXml (org.apache.tomcat.util.descriptor.web.WebXml)8 Test (org.junit.Test)8 InputStream (java.io.InputStream)6 FileInputStream (java.io.FileInputStream)5 InputSource (org.xml.sax.InputSource)5 LifecycleException (org.apache.catalina.LifecycleException)4 SAXParseException (org.xml.sax.SAXParseException)3 ConnectException (java.net.ConnectException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 BufferedInputStream (java.io.BufferedInputStream)1 OutputStream (java.io.OutputStream)1 StringReader (java.io.StringReader)1 Socket (java.net.Socket)1