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