Search in sources :

Example 1 with WebRuleSet

use of org.apache.catalina.startup.WebRuleSet in project tomcat70 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.catalina.deploy.WebXml) Digester(org.apache.tomcat.util.digester.Digester) XmlErrorHandler(org.apache.tomcat.util.descriptor.XmlErrorHandler) WebRuleSet(org.apache.catalina.startup.WebRuleSet) File(java.io.File) Test(org.junit.Test)

Example 2 with WebRuleSet

use of org.apache.catalina.startup.WebRuleSet in project tomcat70 by apache.

the class TestSchemaValidation method testWebapp_2_3.

@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());
}
Also used : WebXml(org.apache.catalina.deploy.WebXml) Digester(org.apache.tomcat.util.digester.Digester) XmlErrorHandler(org.apache.tomcat.util.descriptor.XmlErrorHandler) WebRuleSet(org.apache.catalina.startup.WebRuleSet) File(java.io.File) Test(org.junit.Test)

Example 3 with WebRuleSet

use of org.apache.catalina.startup.WebRuleSet in project tomcat70 by apache.

the class TestWebXml method doTestValidateVersion.

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());
}
Also used : InputSource(org.xml.sax.InputSource) Digester(org.apache.tomcat.util.digester.Digester) StringReader(java.io.StringReader) XmlErrorHandler(org.apache.tomcat.util.descriptor.XmlErrorHandler) WebRuleSet(org.apache.catalina.startup.WebRuleSet) HashSet(java.util.HashSet)

Example 4 with WebRuleSet

use of org.apache.catalina.startup.WebRuleSet in project tomcat70 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.catalina.deploy.WebXml) Digester(org.apache.tomcat.util.digester.Digester) XmlErrorHandler(org.apache.tomcat.util.descriptor.XmlErrorHandler) WebRuleSet(org.apache.catalina.startup.WebRuleSet) File(java.io.File) Test(org.junit.Test)

Example 5 with WebRuleSet

use of org.apache.catalina.startup.WebRuleSet in project tomcat70 by apache.

the class TestSchemaValidation method testWebapp_2_4.

@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());
}
Also used : WebXml(org.apache.catalina.deploy.WebXml) Digester(org.apache.tomcat.util.digester.Digester) XmlErrorHandler(org.apache.tomcat.util.descriptor.XmlErrorHandler) WebRuleSet(org.apache.catalina.startup.WebRuleSet) File(java.io.File) Test(org.junit.Test)

Aggregations

WebRuleSet (org.apache.catalina.startup.WebRuleSet)7 XmlErrorHandler (org.apache.tomcat.util.descriptor.XmlErrorHandler)7 Digester (org.apache.tomcat.util.digester.Digester)7 File (java.io.File)6 WebXml (org.apache.catalina.deploy.WebXml)5 Test (org.junit.Test)5 InputSource (org.xml.sax.InputSource)2 StringReader (java.io.StringReader)1 HashSet (java.util.HashSet)1