Search in sources :

Example 1 with WebXml

use of org.apache.tomcat.util.descriptor.web.WebXml in project tomcat by apache.

the class TestSchemaValidation method testWebapp_3_0.

@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());
}
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 2 with WebXml

use of org.apache.tomcat.util.descriptor.web.WebXml 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 3 with WebXml

use of org.apache.tomcat.util.descriptor.web.WebXml 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 4 with WebXml

use of org.apache.tomcat.util.descriptor.web.WebXml in project ofbiz-framework by apache.

the class WebAppUtil method getWebSiteId.

/**
 * Returns the web site ID - as configured in the web application's <code>web.xml</code> file,
 * or <code>null</code> if no web site ID was found.
 *
 * @param webAppInfo
 * @throws IOException
 * @throws SAXException
 */
public static String getWebSiteId(WebappInfo webAppInfo) throws IOException, SAXException {
    Assert.notNull("webAppInfo", webAppInfo);
    WebXml webXml = getWebXml(webAppInfo);
    return webXml.getContextParams().get("webSiteId");
}
Also used : WebXml(org.apache.tomcat.util.descriptor.web.WebXml)

Example 5 with WebXml

use of org.apache.tomcat.util.descriptor.web.WebXml in project ofbiz-framework by apache.

the class WebAppUtil method parseWebXmlFile.

/**
 * Parses the specified <code>web.xml</code> file into a <code>WebXml</code> instance.
 *
 * @param webXmlFileLocation
 * @param validate
 * @throws IOException
 * @throws SAXException
 */
private static WebXml parseWebXmlFile(String webXmlFileLocation, boolean validate) throws IOException, SAXException {
    Assert.notEmpty("webXmlFileLocation", webXmlFileLocation);
    WebXml result = webXmlCache.get(webXmlFileLocation);
    if (result == null) {
        File file = new File(webXmlFileLocation);
        if (!file.exists()) {
            throw new IllegalArgumentException(webXmlFileLocation + " does not exist.");
        }
        boolean namespaceAware = true;
        InputStream is = new FileInputStream(file);
        result = new WebXml();
        LocalResolver lr = new LocalResolver(new DefaultHandler());
        ErrorHandler handler = new LocalErrorHandler(webXmlFileLocation, lr);
        Digester digester = DigesterFactory.newDigester(validate, namespaceAware, new WebRuleSet(), false);
        digester.getParser();
        digester.push(result);
        digester.setErrorHandler(handler);
        try {
            digester.parse(new InputSource(is));
        } finally {
            digester.reset();
            if (is != null) {
                try {
                    is.close();
                } catch (Throwable t) {
                    Debug.logError(t, "Exception thrown while parsing " + webXmlFileLocation + ": ", module);
                }
            }
        }
        result = webXmlCache.putIfAbsentAndGet(webXmlFileLocation, result);
    }
    return result;
}
Also used : ErrorHandler(org.xml.sax.ErrorHandler) LocalErrorHandler(org.apache.ofbiz.base.util.UtilXml.LocalErrorHandler) InputSource(org.xml.sax.InputSource) LocalResolver(org.apache.ofbiz.base.util.UtilXml.LocalResolver) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileInputStream(java.io.FileInputStream) DefaultHandler(org.xml.sax.helpers.DefaultHandler) WebXml(org.apache.tomcat.util.descriptor.web.WebXml) LocalErrorHandler(org.apache.ofbiz.base.util.UtilXml.LocalErrorHandler) Digester(org.apache.tomcat.util.digester.Digester) File(java.io.File) WebRuleSet(org.apache.tomcat.util.descriptor.web.WebRuleSet)

Aggregations

WebXml (org.apache.tomcat.util.descriptor.web.WebXml)42 File (java.io.File)31 Test (org.junit.Test)28 WebRuleSet (org.apache.tomcat.util.descriptor.web.WebRuleSet)21 Digester (org.apache.tomcat.util.digester.Digester)21 XmlErrorHandler (org.apache.tomcat.util.descriptor.XmlErrorHandler)20 HashMap (java.util.HashMap)10 JavaClassCacheEntry (org.apache.catalina.startup.ContextConfig.JavaClassCacheEntry)9 ServletDef (org.apache.tomcat.util.descriptor.web.ServletDef)7 URL (java.net.URL)6 InputSource (org.xml.sax.InputSource)6 IOException (java.io.IOException)5 HashSet (java.util.HashSet)4 LinkedHashSet (java.util.LinkedHashSet)4 URISyntaxException (java.net.URISyntaxException)3 FilterDef (org.apache.tomcat.util.descriptor.web.FilterDef)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 StandardContext (org.apache.catalina.core.StandardContext)2 JasperException (org.apache.jasper.JasperException)2