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());
}
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());
}
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());
}
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");
}
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;
}
Aggregations