String location = (String)iter.next();
if (location!=null && location.toLowerCase().endsWith(".tld"))
{
if (!location.startsWith("/"))
location="/WEB-INF/"+location;
Resource l=_context.getBaseResource().addPath(location);
tlds.add(l);
}
}
}
// Look for any tlds in WEB-INF directly.
Resource web_inf = _context.getWebInf();
if (web_inf!=null)
{
String[] contents = web_inf.list();
for (int i=0;contents!=null && i<contents.length;i++)
{
if (contents[i]!=null && contents[i].toLowerCase().endsWith(".tld"))
{
Resource l=_context.getWebInf().addPath(contents[i]);
tlds.add(l);
}
}
}
// Get the pattern for noTLDJars
String no_TLD_attr = _context.getInitParameter("org.mortbay.jetty.webapp.NoTLDJarPattern");
Pattern no_TLD_pattern = no_TLD_attr==null?null:Pattern.compile(no_TLD_attr);
// Look for tlds in any jars
ClassLoader loader = Thread.currentThread().getContextClassLoader();
boolean parent=false;
while (loader!=null)
{
if (loader instanceof URLClassLoader)
{
URL[] urls = ((URLClassLoader)loader).getURLs();
if (urls!=null)
{
for (int i=0;i<urls.length;i++)
{
if (urls[i].toString().toLowerCase().endsWith(".jar"))
{
String jar = urls[i].toString();
int slash=jar.lastIndexOf('/');
jar=jar.substring(slash+1);
if (parent && (
(!_context.isParentLoaderPriority() && jars.contains(jar)) ||
(no_TLD_pattern!=null && no_TLD_pattern.matcher(jar).matches())))
continue;
jars.add(jar);
Log.debug("TLD search of {}",urls[i]);
File file=Resource.newResource(urls[i]).getFile();
if (file==null || !file.exists() || !file.canRead())
continue;
JarFile jarfile = null;
try
{
jarfile = new JarFile(file);
Enumeration e = jarfile.entries();
while (e.hasMoreElements())
{
ZipEntry entry = (ZipEntry)e.nextElement();
String name = entry.getName();
if (name.startsWith("META-INF/") && name.toLowerCase().endsWith(".tld"))
{
Resource tld=Resource.newResource("jar:"+urls[i]+"!/"+name);
tlds.add(tld);
Log.debug("TLD found {}",tld);
}
}
}
catch (Exception e)
{
Log.warn("Failed to read file: " + file, e);
}
finally
{
if (jarfile != null)
{
jarfile.close();
}
}
}
}
}
}
loader=loader.getParent();
parent=true;
}
// Create a TLD parser
XmlParser parser = new XmlParser(false);
parser.redirectEntity("web-jsptaglib_1_1.dtd",Loader.getResource(TagLibConfiguration.class,"javax/servlet/jsp/resources/web-jsptaglibrary_1_1.dtd", false));
parser.redirectEntity("web-jsptaglib_1_2.dtd",Loader.getResource(TagLibConfiguration.class,"javax/servlet/jsp/resources/web-jsptaglibrary_1_2.dtd", false));
parser.redirectEntity("web-jsptaglib_2_0.xsd",Loader.getResource(TagLibConfiguration.class,"javax/servlet/jsp/resources/web-jsptaglibrary_2_0.xsd", false));
parser.redirectEntity("web-jsptaglibrary_1_1.dtd",Loader.getResource(TagLibConfiguration.class,"javax/servlet/jsp/resources/web-jsptaglibrary_1_1.dtd", false));
parser.redirectEntity("web-jsptaglibrary_1_2.dtd",Loader.getResource(TagLibConfiguration.class,"javax/servlet/jsp/resources/web-jsptaglibrary_1_2.dtd", false));
parser.redirectEntity("web-jsptaglibrary_2_0.xsd",Loader.getResource(TagLibConfiguration.class,"javax/servlet/jsp/resources/web-jsptaglibrary_2_0.xsd", false));
parser.setXpath("/taglib/listener/listener-class");
// Parse all the discovered TLDs
Iterator iter = tlds.iterator();
while (iter.hasNext())
{
try
{
Resource tld = (Resource)iter.next();
if (Log.isDebugEnabled()) Log.debug("TLD="+tld);
XmlParser.Node root;
try
{
//xerces on apple appears to sometimes close the zip file instead
//of the inputstream, so try opening the input stream, but if
//that doesn't work, fallback to opening a new url
root = parser.parse(tld.getInputStream());
}
catch (Exception e)
{
root = parser.parse(tld.getURL().toString());
}
if (root==null)
{
Log.warn("No TLD root in {}",tld);