Java Code Examples for org.apache.tomcat.util.digester.Digester#setErrorHandler()

The following examples show how to use org.apache.tomcat.util.digester.Digester#setErrorHandler() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestSchemaValidation.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Test
public void testWebapp_2_3() 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.3/WEB-INF/web.xml"));
    Assert.assertEquals("2.3", desc.getVersion());
    Assert.assertEquals(XmlIdentifiers.WEB_23_PUBLIC, desc.getPublicId());
    Assert.assertEquals(0, handler.getErrors().size());
    Assert.assertEquals(0, handler.getWarnings().size());
}
 
Example 2
Source File: TestSchemaValidation.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Test
public void testWebapp_3_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-3.0/WEB-INF/web.xml"));
    Assert.assertEquals("3.0", desc.getVersion());
    Assert.assertEquals(0, handler.getErrors().size());
    Assert.assertEquals(0, handler.getWarnings().size());
}
 
Example 3
Source File: TestSchemaValidation.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example 4
Source File: TestSchemaValidation.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Test
public void testWebapp_2_4() 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.4/WEB-INF/web.xml"));
    Assert.assertEquals("2.4", desc.getVersion());
    Assert.assertEquals(0, handler.getErrors().size());
    Assert.assertEquals(0, handler.getWarnings().size());
}
 
Example 5
Source File: TestSchemaValidation.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Test
public void testWebapp_2_3() 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.3/WEB-INF/web.xml"));
    Assert.assertEquals("2.3", desc.getVersion());
    Assert.assertEquals(XmlIdentifiers.WEB_23_PUBLIC, desc.getPublicId());
    Assert.assertEquals(0, handler.getErrors().size());
    Assert.assertEquals(0, handler.getWarnings().size());
}
 
Example 6
Source File: TestSchemaValidation.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example 7
Source File: TestWebXml.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
private void doTestValidateVersion(String version) throws IOException, SAXException {
    WebXml webxml = new WebXml();

    // Special cases
    if ("2.2".equals(version)) {
        webxml.setPublicId(XmlIdentifiers.WEB_22_PUBLIC);
    } else if ("2.3".equals(version)) {
        webxml.setPublicId(XmlIdentifiers.WEB_23_PUBLIC);
    } else {
        webxml.setVersion(version);
    }

    // Merged web.xml that is published as MERGED_WEB_XML context attribute
    // in the simplest case consists of webapp's web.xml file
    // plus the default conf/web.xml one.
    Set<WebXml> defaults = new HashSet<WebXml>();
    defaults.add(getDefaultWebXmlFragment());
    webxml.merge(defaults);

    Digester digester = DigesterFactory.newDigester(true, true, new WebRuleSet(), true);

    XmlErrorHandler handler = new XmlErrorHandler();
    digester.setErrorHandler(handler);

    InputSource is = new InputSource(new StringReader(webxml.toXml()));
    WebXml webxmlResult = new WebXml();
    digester.push(webxmlResult);
    digester.parse(is);

    Assert.assertEquals(0, handler.getErrors().size());
    Assert.assertEquals(0, handler.getWarnings().size());

    Assert.assertEquals(version, webxml.getVersion());
    Assert.assertEquals(version, webxmlResult.getVersion());
}
 
Example 8
Source File: TestSchemaValidation.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Test
public void testWebapp_3_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-3.0/WEB-INF/web.xml"));
    Assert.assertEquals("3.0", desc.getVersion());
    Assert.assertEquals(0, handler.getErrors().size());
    Assert.assertEquals(0, handler.getWarnings().size());
}
 
Example 9
Source File: TestSchemaValidation.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example 10
Source File: TestSchemaValidation.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Test
public void testWebapp_2_4() 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.4/WEB-INF/web.xml"));
    Assert.assertEquals("2.4", desc.getVersion());
    Assert.assertEquals(0, handler.getErrors().size());
    Assert.assertEquals(0, handler.getWarnings().size());
}
 
Example 11
Source File: TestWebXml.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
private void doTestValidateVersion(String version) throws IOException, SAXException {
    WebXml webxml = new WebXml();

    // Special cases
    if ("2.2".equals(version)) {
        webxml.setPublicId(XmlIdentifiers.WEB_22_PUBLIC);
    } else if ("2.3".equals(version)) {
        webxml.setPublicId(XmlIdentifiers.WEB_23_PUBLIC);
    } else {
        webxml.setVersion(version);
    }

    // Merged web.xml that is published as MERGED_WEB_XML context attribute
    // in the simplest case consists of webapp's web.xml file
    // plus the default conf/web.xml one.
    Set<WebXml> defaults = new HashSet<>();
    defaults.add(getDefaultWebXmlFragment());
    webxml.merge(defaults);

    Digester digester = DigesterFactory.newDigester(true, true, new WebRuleSet(), true);

    XmlErrorHandler handler = new XmlErrorHandler();
    digester.setErrorHandler(handler);

    InputSource is = new InputSource(new StringReader(webxml.toXml()));
    WebXml webxmlResult = new WebXml();
    digester.push(webxmlResult);
    digester.parse(is);

    Assert.assertEquals(0, handler.getErrors().size());
    Assert.assertEquals(0, handler.getWarnings().size());

    Assert.assertEquals(version, webxml.getVersion());
    Assert.assertEquals(version, webxmlResult.getVersion());
}
 
Example 12
Source File: TestSchemaValidation.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example 13
Source File: TestWebXml.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
private void doTestValidateVersion(String version) throws IOException, SAXException {
    WebXml webxml = new WebXml();

    // Special cases
    if ("2.2".equals(version)) {
        webxml.setPublicId(XmlIdentifiers.WEB_22_PUBLIC);
    } else if ("2.3".equals(version)) {
        webxml.setPublicId(XmlIdentifiers.WEB_23_PUBLIC);
    } else {
        webxml.setVersion(version);
    }

    // Merged web.xml that is published as MERGED_WEB_XML context attribute
    // in the simplest case consists of webapp's web.xml file
    // plus the default conf/web.xml one.
    Set<WebXml> defaults = new HashSet<WebXml>();
    defaults.add(getDefaultWebXmlFragment());
    webxml.merge(defaults);

    Digester digester = DigesterFactory.newDigester(true, true, new WebRuleSet(), true);

    XmlErrorHandler handler = new XmlErrorHandler();
    digester.setErrorHandler(handler);

    InputSource is = new InputSource(new StringReader(webxml.toXml()));
    WebXml webxmlResult = new WebXml();
    digester.push(webxmlResult);
    digester.parse(is);

    Assert.assertEquals(0, handler.getErrors().size());
    Assert.assertEquals(0, handler.getWarnings().size());

    Assert.assertEquals(version, webxml.getVersion());
    Assert.assertEquals(version, webxmlResult.getVersion());
}
 
Example 14
Source File: TestSchemaValidation.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@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());
}
 
Example 15
Source File: TestSchemaValidation.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testWebapp_3_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-3.0/WEB-INF/web.xml"));
    Assert.assertEquals("3.0", desc.getVersion());
    Assert.assertEquals(0, handler.getErrors().size());
    Assert.assertEquals(0, handler.getWarnings().size());
}
 
Example 16
Source File: TestSchemaValidation.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@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());
}
 
Example 17
Source File: TestSchemaValidation.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testWebapp_2_4() 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.4/WEB-INF/web.xml"));
    Assert.assertEquals("2.4", desc.getVersion());
    Assert.assertEquals(0, handler.getErrors().size());
    Assert.assertEquals(0, handler.getWarnings().size());
}
 
Example 18
Source File: TestSchemaValidation.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testWebapp_2_3() 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.3/WEB-INF/web.xml"));
    Assert.assertEquals("2.3", desc.getVersion());
    Assert.assertEquals(XmlIdentifiers.WEB_23_PUBLIC, desc.getPublicId());
    Assert.assertEquals(0, handler.getErrors().size());
    Assert.assertEquals(0, handler.getWarnings().size());
}
 
Example 19
Source File: TestSchemaValidation.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@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());
}
 
Example 20
Source File: TestSchemaValidation.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@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("3.1", desc.getVersion());
    Assert.assertEquals(0, handler.getErrors().size());
    Assert.assertEquals(0, handler.getWarnings().size());
}