use of org.apache.ofbiz.base.util.UtilXml.LocalResolver 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