{
String filePath = tldPath[0];
TldParser tldParser = new TldParser();
InputStream in = ctx.getResourceAsStream(filePath);
if(in == null) {
throw new TemplateModelException("Could not find webapp resource " + filePath);
}
String url = ctx.getResource(filePath).toExternalForm();
try {
String jarPath = tldPath[1];
if(jarPath != null) {
ZipInputStream zin = new ZipInputStream(in);
for(;;) {
ZipEntry ze = zin.getNextEntry();
if(ze == null) {
throw new TemplateModelException("Could not find JAR entry " + jarPath + " inside webapp resource " + filePath);
}
String zname = ze.getName();
if(zname.equals(jarPath)) {
parseXml(zin, "jar:" + url + "!" + zname, tldParser);
break;
}
}
}
else {
parseXml(in, url, tldParser);
}
}
finally {
in.close();
}
EventForwarding eventForwarding = EventForwarding.getInstance(ctx);
if(eventForwarding != null) {
eventForwarding.addListeners(tldParser.getListeners());
}
else if(tldParser.getListeners().size() > 0) {
throw new TemplateModelException(
"Event listeners specified in the TLD could not be " +
" registered since the web application doesn't have a" +
" listener of class " + EventForwarding.class.getName() +
". To remedy this, add this element to web.xml:\n" +
"| <listener>\n" +