Search in sources :

Example 1 with TldTaglib

use of org.apache.openejb.jee.TldTaglib in project tomee by apache.

the class DeploymentLoader method addTagLibraries.

private void addTagLibraries(final WebModule webModule) throws OpenEJBException {
    final Set<URL> tldLocations = new HashSet<>();
    // web.xml contains tag lib locations in nested jsp config elements
    final File warFile = new File(webModule.getJarLocation());
    final WebApp webApp = webModule.getWebApp();
    if (webApp != null) {
        for (final JspConfig jspConfig : webApp.getJspConfig()) {
            for (final Taglib taglib : jspConfig.getTaglib()) {
                String location = taglib.getTaglibLocation();
                if (!location.startsWith("/")) {
                    // this reproduces a tomcat bug
                    location = "/WEB-INF/" + location;
                }
                try {
                    final File file = new File(warFile, location).getCanonicalFile().getAbsoluteFile();
                    tldLocations.addAll(TldScanner.scanForTagLibs(file));
                } catch (final IOException e) {
                    LOGGER.warning("JSP tag library location bad: " + location, e);
                }
            }
        }
    }
    // WEB-INF/**/*.tld except in WEB-INF/classes and WEB-INF/lib
    Set<URL> urls = TldScanner.scanWarForTagLibs(warFile);
    tldLocations.addAll(urls);
    // Search all libs
    final ClassLoader parentClassLoader = webModule.getClassLoader().getParent();
    urls = TldScanner.scan(parentClassLoader);
    tldLocations.addAll(urls);
    // load the tld files
    for (final URL location : tldLocations) {
        final TldTaglib taglib = ReadDescriptors.readTldTaglib(location);
        if (taglib != null && taglib != ReadDescriptors.SKIP_TAGLIB) {
            webModule.getTaglibs().add(taglib);
            if ("file".equals(location.getProtocol())) {
                webModule.getWatchedResources().add(URLs.toFilePath(location));
            }
        }
    }
    // no more need + this classloader is a temp one in Servlet container so avoid mem leaks
    TldScanner.quickClean(parentClassLoader);
}
Also used : JspConfig(org.apache.openejb.jee.JspConfig) TldTaglib(org.apache.openejb.jee.TldTaglib) Taglib(org.apache.openejb.jee.Taglib) TldTaglib(org.apache.openejb.jee.TldTaglib) URLClassLoader(java.net.URLClassLoader) EmptyResourcesClassLoader(org.apache.openejb.core.EmptyResourcesClassLoader) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) File(java.io.File) URL(java.net.URL) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) WebApp(org.apache.openejb.jee.WebApp)

Example 2 with TldTaglib

use of org.apache.openejb.jee.TldTaglib in project tomee by apache.

the class ReadDescriptors method readTldTaglib.

public static TldTaglib readTldTaglib(final URL url) throws OpenEJBException {
    // TOMEE-164 Optimization on reading built-in tld files
    if (url.getPath().contains("jstl-1.2.jar") || ((url.getPath().contains("taglibs-standard-") || url.getPath().contains("taglibs-shade-") && url.getPath().contains(".jar!")))) {
        return SKIP_TAGLIB;
    }
    if (url.getPath().contains("myfaces-impl")) {
        // we should return SKIP_TAGLIB too
        final TldTaglib taglib = new TldTaglib();
        final Listener listener = new Listener();
        listener.setListenerClass("org.apache.myfaces.webapp.StartupServletContextListener");
        taglib.getListener().add(listener);
        return taglib;
    }
    try {
        return TldTaglibXml.unmarshal(url);
    } catch (final SAXException e) {
        final String message = "Cannot parse the JSP tag library definition file: " + url.toExternalForm();
        logger.warning(message);
        logger.debug(message, e);
    } catch (final JAXBException e) {
        final String message = "Cannot unmarshall the JSP tag library definition file: " + url.toExternalForm();
        logger.warning(message);
        logger.debug(message, e);
    } catch (final IOException e) {
        final String message = "Cannot read the JSP tag library definition file: " + url.toExternalForm();
        logger.warning(message);
        logger.debug(message, e);
    } catch (final Exception e) {
        final String message = "Encountered unknown error parsing the JSP tag library definition file: " + url.toExternalForm();
        logger.warning(message);
        logger.debug(message, e);
    }
    return SKIP_TAGLIB;
}
Also used : Listener(org.apache.openejb.jee.Listener) TldTaglib(org.apache.openejb.jee.TldTaglib) JAXBException(javax.xml.bind.JAXBException) IOException(java.io.IOException) OpenEJBException(org.apache.openejb.OpenEJBException) JAXBException(javax.xml.bind.JAXBException) SAXException(org.xml.sax.SAXException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Aggregations

IOException (java.io.IOException)2 TldTaglib (org.apache.openejb.jee.TldTaglib)2 File (java.io.File)1 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 JarFile (java.util.jar.JarFile)1 JAXBException (javax.xml.bind.JAXBException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 OpenEJBException (org.apache.openejb.OpenEJBException)1 EmptyResourcesClassLoader (org.apache.openejb.core.EmptyResourcesClassLoader)1 JspConfig (org.apache.openejb.jee.JspConfig)1 Listener (org.apache.openejb.jee.Listener)1 Taglib (org.apache.openejb.jee.Taglib)1 WebApp (org.apache.openejb.jee.WebApp)1 SAXException (org.xml.sax.SAXException)1