Search in sources :

Example 21 with Digester

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

the class JAASMemoryLoginModule method load.

// ---------------------------------------------------------- Realm Methods
// ------------------------------------------------------ Protected Methods
/**
     * Load the contents of our configuration file.
     */
protected void load() {
    // Validate the existence of our configuration file
    File file = new File(pathname);
    if (!file.isAbsolute()) {
        String catalinaBase = getCatalinaBase();
        if (catalinaBase == null) {
            log.warn("Unable to determine Catalina base to load file " + pathname);
            return;
        } else {
            file = new File(catalinaBase, pathname);
        }
    }
    if (!file.canRead()) {
        log.warn("Cannot load configuration file " + file.getAbsolutePath());
        return;
    }
    // Load the contents of our configuration file
    Digester digester = new Digester();
    digester.setValidating(false);
    digester.addRuleSet(new MemoryRuleSet());
    try {
        digester.push(this);
        digester.parse(file);
    } catch (Exception e) {
        log.warn("Error processing configuration file " + file.getAbsolutePath(), e);
        return;
    } finally {
        digester.reset();
    }
}
Also used : Digester(org.apache.tomcat.util.digester.Digester) File(java.io.File) LoginException(javax.security.auth.login.LoginException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) IOException(java.io.IOException) FailedLoginException(javax.security.auth.login.FailedLoginException)

Example 22 with Digester

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

the class DigesterFactory method newDigester.

/**
     * Create a <code>Digester</code> parser.
     * @param xmlValidation turn on/off xml validation
     * @param xmlNamespaceAware turn on/off namespace validation
     * @param rule an instance of <code>RuleSet</code> used for parsing the xml.
     * @param blockExternal turn on/off the blocking of external resources
     * @return a new digester
     */
public static Digester newDigester(boolean xmlValidation, boolean xmlNamespaceAware, RuleSet rule, boolean blockExternal) {
    Digester digester = new Digester();
    digester.setNamespaceAware(xmlNamespaceAware);
    digester.setValidating(xmlValidation);
    digester.setUseContextClassLoader(true);
    EntityResolver2 resolver = new LocalResolver(SERVLET_API_PUBLIC_IDS, SERVLET_API_SYSTEM_IDS, blockExternal);
    digester.setEntityResolver(resolver);
    if (rule != null) {
        digester.addRuleSet(rule);
    }
    return digester;
}
Also used : Digester(org.apache.tomcat.util.digester.Digester) EntityResolver2(org.xml.sax.ext.EntityResolver2)

Example 23 with Digester

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

the class TestSchemaValidation method testWebapp_3_1.

@Test
public void testWebapp_3_1() 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-3.1/WEB-INF/web.xml"));
    Assert.assertEquals("3.1", 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 24 with Digester

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

the class TestSchemaValidation method testWebapp_4_0.

@Test
public void testWebapp_4_0() 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-4.0/WEB-INF/web.xml"));
    Assert.assertEquals("4.0", 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 25 with Digester

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

the class TestSchemaValidation method testWebapp.

@Test
public void testWebapp() 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/WEB-INF/web.xml"));
    Assert.assertEquals("4.0", 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)

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