Search in sources :

Example 1 with LocalResolver

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;
}
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

File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 LocalErrorHandler (org.apache.ofbiz.base.util.UtilXml.LocalErrorHandler)1 LocalResolver (org.apache.ofbiz.base.util.UtilXml.LocalResolver)1 WebRuleSet (org.apache.tomcat.util.descriptor.web.WebRuleSet)1 WebXml (org.apache.tomcat.util.descriptor.web.WebXml)1 Digester (org.apache.tomcat.util.digester.Digester)1 ErrorHandler (org.xml.sax.ErrorHandler)1 InputSource (org.xml.sax.InputSource)1 DefaultHandler (org.xml.sax.helpers.DefaultHandler)1