{
final TldParser tldParser = new TldParser();
final String filePath = tldPath.filePath;
final InputStream in = ctx.getResourceAsStream(filePath);
if(in == null) {
throw new TemplateModelException("Could not find webapp resource " +
filePath + " for URI " + uri);
}
final String fileUrl = ctx.getResource(filePath).toExternalForm();
try {
final String jarItemPath = tldPath.jarItemPath;
if(jarItemPath != null) {
final ZipInputStream zin = new ZipInputStream(in);
for(;;) {
final ZipEntry ze = zin.getNextEntry();
if(ze == null) {
throw new TemplateModelException(
"Could not find JAR entry " + jarItemPath +
" inside webapp resource " + filePath +
" for URI " + uri);
}
final String zname = ze.getName();
if(zname.equals(jarItemPath)) {
parseXml(zin, "jar:" + fileUrl + "!" + zname, tldParser);
break;
}
}
}
else {
parseXml(in, fileUrl, 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" +