You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Robert Petersen <ro...@orangefood.com> on 2001/05/31 00:42:24 UTC
[PATCH] RE: Packaged tag libraries
Ok well here is a patch to TldLocationsCache that should all Jasper to
correctly process packaged tab libraries. I tested on my system and it
works well. I changed processJars() to use the "getResourcePaths" method as
Remy suggested. I pulled "tldConfigJar()" as it did a bunch of stuff with
URL's that appeared to be overly complex. I put the logic from that method
right in the "processJars()" and accessed the jar files directly (i.e. w/out
a url or connection). I changed "parseTldForUri()" because it was looking
for a child <taglib> and then a <uri> it should have just looked for a <uri>
right off.
Lastly I'm not sure why the diff produced some 'goofy' stuff. If somebody
lets me know how to fix it I won't do it in the future.
Really lastly - this is my first attempt at sending in a patch to an open
source project so if somehow I've f'ed up the etiquette, then please be
gentle.
- Robert
4c4
< * Copyright (c) 1999 The Apache Software Foundation. All rights
---
> * Copyright (c) 1999 The Apache Software Foundation. All rights
12c12
< * notice, this list of conditions and the following disclaimer.
---
> * notice, this list of conditions and the following disclaimer.
20,21c20,21
< * any, must include the following acknowlegement:
< * "This product includes software developed by the
---
> * any, must include the following acknowlegement:
> * "This product includes software developed by the
28c28
< * from this software without prior written permission. For written
---
> * from this software without prior written permission. For written
54c54
< */
---
> */
63a64,65
> import java.util.Set;
> import java.util.Iterator;
82c84
< *
---
> *
121c123
<
---
>
188d189
<
190d190
<
200,212c200,221
< URL libURL = null;
< try {
< libURL = ctxt.getResource("/WEB-INF/lib");
< } catch (MalformedURLException e) {}
<
< if ((libURL != null) && "file".equals(libURL.getProtocol())) {
< File libFile = new File(libURL.getFile());
< if (libFile.exists() && libFile.canRead() &&
< libFile.isDirectory()) {
< String filenames[] = libFile.list();
< for (int i=0; i<filenames.length; i++) {
< if (!filenames[i].endsWith(".jar")) continue;
< tldConfigJar(ctxt, "/WEB-INF/lib/" + filenames[i]);
---
> try
> {
> Set libSet = ctxt.getResourcePaths("/WEB-INF/lib");
> Iterator it = libSet.iterator();
> while( it.hasNext() )
> {
> String resourcePath = (String) it.next();
> JarFile jarFile = new
JarFile(ctxt.getRealPath(resourcePath));
> Enumeration enumJarEntries = jarFile.entries();
> while( enumJarEntries.hasMoreElements() )
> {
> JarEntry jarEntry = (JarEntry)
enumJarEntries.nextElement();
> String name = jarEntry.getName();
> if (!name.startsWith("META-INF/")) continue;
> if (!name.endsWith(".tld")) continue;
> InputStream stream = jarFile.getInputStream(jarEntry);
> String uri = parseTldForUri(resourcePath, stream);
> if (uri != null)
> {
> mappings.put(uri,
> new String[]{resourcePath, name} );
> }
216c225,226
< }
---
> catch (MalformedURLException e) {}
> catch (IOException ioe) {}
218,272d227
< /**
< * Process a TLD in the JAR file at the specified resource path
< * (if there is one). Will update the URI mappings for all
< * the .tld files found in the META-INF directory tree, if
< * a <uri> element is defined in the TLD.
< *
< * @param resourcePath Context-relative resource path
< */
< private void tldConfigJar(ServletContext ctxt, String resourcePath)
< throws JasperException
< {
< JarFile jarFile = null;
< InputStream stream = null;
< try {
< URL url = ctxt.getResource(resourcePath);
< if (url == null) return;
< url = new URL("jar:" + url.toString() + "!/");
< JarURLConnection conn =
< (JarURLConnection) url.openConnection();
< jarFile = conn.getJarFile();
< Enumeration entries = jarFile.entries();
< while (entries.hasMoreElements()) {
< JarEntry entry = (JarEntry) entries.nextElement();
< String name = entry.getName();
< if (!name.startsWith("META-INF/")) continue;
< if (!name.endsWith(".tld")) continue;
< //p("tldConfigJar(" + resourcePath +
< // "): Processing entry '" + name + "'");
< stream = jarFile.getInputStream(entry);
< String uri = parseTldForUri(resourcePath, stream);
< //p("uri in TLD is: " + uri);
< if (uri != null) {
< mappings.put(uri,
< new String[]{resourcePath, name});
< //p("added mapping: " + uri +
< // " -> " + resourcePath + " " + name);
< }
< }
< // FIXME @@@
< // -- it seems that the JarURLConnection class caches JarFile
< // objects for particular URLs, and there is no way to get
< // it to release the cached entry, so
< // there's no way to redeploy from the same JAR file. Wierd.
< } catch (Exception ex) {
< if (stream != null) {
< try {
< stream.close();
< } catch (Throwable t) {}
< }
< if (jarFile != null) {
< try {
< jarFile.close();
< } catch (Throwable t) {}
< }
< }
275c230
< private String parseTldForUri(String resourcePath, InputStream in)
---
> private String parseTldForUri(String resourcePath, InputStream in)
282,298c237,241
< Iterator taglibs = tld.findChildren("taglib");
< int n = 0;
< while (taglibs.hasNext()) {
< n++;
< if (n > 1) {
< Constants.message("jsp.error.more.than.one.taglib",
< new Object[] {resourcePath},
< Logger.ERROR);
< return null;
< }
< TreeNode taglib = (TreeNode) taglibs.next();
< TreeNode uri = taglib.findChild("uri");
< if (uri != null) {
< String body = uri.getBody();
< if (body != null)
< return body;
< }
---
> TreeNode uri = tld.findChild("uri");
> if (uri != null) {
> String body = uri.getBody();
> if (body != null)
> return body;
308c251
< * Get the 'location' of the TLD associated with
---
> * Get the 'location' of the TLD associated with
310c253
< *
---
> *
317,318c260,261
< * A tag library is 'exposed' either explicitely in
< * web.xml or implicitely via the uri tag in the TLD
---
> * A tag library is 'exposed' either explicitely in
> * web.xml or implicitely via the uri tag in the TLD
321c264
< public String[] getLocation(String uri)
---
> public String[] getLocation(String uri)
330c273
< /**
---
> /**
-----Original Message-----
From: Remy Maucherat [mailto:remm@apache.org]
Sent: Tuesday, May 22, 2001 9:42 AM
To: tomcat-dev@jakarta.apache.org
Subject: Re: Packaged tag libraries
> Maybe I'm running a version that is too old (daily build from 5/12/2001)
but
> I cant find the method you sugest. What object is "getResourcePaths" on?
ServletContext.
Remy
RE: [PATCH] RE: Packaged tag libraries
Posted by Robert Petersen <ro...@orangefood.com>.
Thanks - good point about the null. So what's the deal with a
non-FilesystemBased context, i.e. what are they? In the original version of
the source only URL's with a protocol of "file" were processed. The prob
was that "file" resources are now being handed back with a protocol of
"jndi". So I guess the question is what should be supported? If only
"file" resources need to be supported then can we just "continue" out of the
loop if we get a null back, i.e. if the context is not FilesystemBased. Or
should all types of resources be supported? In which case I would think
that any URL's passed back in the call to getResource() should have a
service provider for their particular protocol, how to get a handle to
thoses service providers is another question. I'm happy to keep working on
this as I'd like to get it working.
Thanks,
Robert
-----Original Message-----
From: Remy Maucherat [mailto:remm@apache.org]
Sent: Wednesday, May 30, 2001 5:56 PM
To: tomcat-dev@jakarta.apache.org
Subject: Re: [PATCH] RE: Packaged tag libraries
> Ok well here is a patch to TldLocationsCache that should all Jasper to
> correctly process packaged tab libraries. I tested on my system and it
> works well. I changed processJars() to use the "getResourcePaths" method
as
> Remy suggested. I pulled "tldConfigJar()" as it did a bunch of stuff with
> URL's that appeared to be overly complex. I put the logic from that
method
> right in the "processJars()" and accessed the jar files directly (i.e.
w/out
> a url or connection). I changed "parseTldForUri()" because it was looking
> for a child <taglib> and then a <uri> it should have just looked for a
<uri>
> right off.
>
> Lastly I'm not sure why the diff produced some 'goofy' stuff. If somebody
> lets me know how to fix it I won't do it in the future.
>
> Really lastly - this is my first attempt at sending in a patch to an open
> source project so if somehow I've f'ed up the etiquette, then please be
> gentle.
Nice work, but you shouldn't use getRealPath() and access as a file, as
getRealPath() can return null.
Although it is indeed more complex, tldConfigJar() is the way to go, as it
should work in all cases.
Remy
Re: [PATCH] RE: Packaged tag libraries
Posted by Remy Maucherat <re...@apache.org>.
> Ok well here is a patch to TldLocationsCache that should all Jasper to
> correctly process packaged tab libraries. I tested on my system and it
> works well. I changed processJars() to use the "getResourcePaths" method
as
> Remy suggested. I pulled "tldConfigJar()" as it did a bunch of stuff with
> URL's that appeared to be overly complex. I put the logic from that
method
> right in the "processJars()" and accessed the jar files directly (i.e.
w/out
> a url or connection). I changed "parseTldForUri()" because it was looking
> for a child <taglib> and then a <uri> it should have just looked for a
<uri>
> right off.
>
> Lastly I'm not sure why the diff produced some 'goofy' stuff. If somebody
> lets me know how to fix it I won't do it in the future.
>
> Really lastly - this is my first attempt at sending in a patch to an open
> source project so if somehow I've f'ed up the etiquette, then please be
> gentle.
Nice work, but you shouldn't use getRealPath() and access as a file, as
getRealPath() can return null.
Although it is indeed more complex, tldConfigJar() is the way to go, as it
should work in all cases.
Remy