tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Petr Jiricka <petr.jiri...@netbeans.com>
Subject [PATCH]: packaged tag libraries can not be specified in web.xml
Date Thu, 27 Jul 2000 17:55:56 GMT
Hello,

we found out that packaged tag libraries can not be specified in the taglib
entry in web.xml. I tried to jar up the example tag library from Tomcat and
modified the taglib entry in the examples web app:

    <taglib>
        <taglib-uri>
	   http://java.apache.org/tomcat/examples-taglib
        </taglib-uri>
        <taglib-location>
           WEB-INF/lib/example-taglib.jar
        </taglib-location>
    </taglib>

This does not work because of handling of jar files in TagLibraryInfoImpl.
If I am reading the specification correctly, this behavior is not consistent
with the spec.

Below is a patch (against 3.2 branch) which handles the above case
correctly. I don't know whether there are any other issues with this, so I
don't want to commit anything until we know this is safe.

Do you think this should be fixed and when ? (I would vote for 3.2, but I
know it's pushing it).

Petr

P:\Jakarta_32\jakarta-tomcat\src\share\org\apache\jasper\compiler>cvs
-d:pserver:anoncvs@localhost:/home/cvspublic diff -u TagLibraryInfoImpl.java
Index: TagLibraryInfoImpl.java
===================================================================
RCS file:
/home/cvspublic/jakarta-tomcat/src/share/org/apache/jasper/compiler/TagLibra
ryInfoImpl.java,v
retrieving revision 1.22
diff -u -r1.22 TagLibraryInfoImpl.java
--- TagLibraryInfoImpl.java     2000/06/27 20:59:40     1.22
+++ TagLibraryInfoImpl.java     2000/07/27 17:42:44
@@ -160,67 +160,68 @@
         boolean relativeURL = false;
        this.uri = uriIn;

-       if (!uriIn.endsWith("jar")) {
-           // Parse web.xml.
-           InputStream is = getResourceAsStream(WEBAPP_INF);
-
-           if (is != null) {
-                Document webtld =
-                   JspUtil.parseXMLDoc(is,
-                                       Constants.WEBAPP_DTD_RESOURCE,
-                                       Constants.WEBAPP_DTD_PUBLIC_ID);
-                NodeList nList =  webtld.getElementsByTagName("taglib");
-
-                if (nList.getLength() != 0) {
-                   for(int i = 0; i < nList.getLength(); i++) {
-                       String tagLoc = null;
-                       boolean match = false;
-                       Element e =  (Element) nList.item(i);
-
-                       // Assume only one entry for location and uri.
-                       NodeList uriList =
e.getElementsByTagName("taglib-uri");
-                       Element uriElem = (Element) uriList.item(0);
-                       Text t = (Text) uriElem.getFirstChild();
-
-                       if (t != null) {
-                           String tmpUri = t.getData();
-                           if (tmpUri != null) {
-                               tmpUri = tmpUri.trim();
-                               if (tmpUri.equals(uriIn)) {
-                                   match = true;
-                                   NodeList locList =
e.getElementsByTagName
-                                       ("taglib-location");
-                                   Element locElem = (Element)
locList.item(0);
-                                   Text tl = (Text)
locElem.getFirstChild();
-                                   if (tl != null) {
-                                       tagLoc = tl.getData();
-                                       if (tagLoc != null)
-                                           tagLoc = tagLoc.trim();
-                                   }
-                               }
-                           }
-                       }
-                       if (match == true && tagLoc != null) {
-                           this.uri = tagLoc;
-
-                           // If this is a relative path, then it has to be
-                           // relative to where web.xml is.
-
-                           // I'm taking the simple way out. Since web.xml
-                           // has to be directly under WEB-INF, I'm making
-                           // an absolute URI out of it by prepending
WEB-INF
-
-                           if (!uri.startsWith("/"))
-                               uri = "/WEB-INF/"+uri;
-                       }
-                   }
-               }
-           }
+        // Parse web.xml.
+        InputStream is = getResourceAsStream(WEBAPP_INF);
+
+        if (is != null) {
+            Document webtld =
+                JspUtil.parseXMLDoc(is,
+                                    Constants.WEBAPP_DTD_RESOURCE,
+                                    Constants.WEBAPP_DTD_PUBLIC_ID);
+            NodeList nList =  webtld.getElementsByTagName("taglib");
+
+            if (nList.getLength() != 0) {
+                for(int i = 0; i < nList.getLength(); i++) {
+                    String tagLoc = null;
+                    boolean match = false;
+                    Element e =  (Element) nList.item(i);
+
+                    // Assume only one entry for location and uri.
+                    NodeList uriList =
e.getElementsByTagName("taglib-uri");
+                    Element uriElem = (Element) uriList.item(0);
+                    Text t = (Text) uriElem.getFirstChild();
+
+                    if (t != null) {
+                        String tmpUri = t.getData();
+                        if (tmpUri != null) {
+                            tmpUri = tmpUri.trim();
+                            if (tmpUri.equals(uriIn)) {
+                                match = true;
+                                NodeList locList = e.getElementsByTagName
+                                    ("taglib-location");
+                                Element locElem = (Element)
locList.item(0);
+                                Text tl = (Text) locElem.getFirstChild();
+                                if (tl != null) {
+                                    tagLoc = tl.getData();
+                                    if (tagLoc != null)
+                                        tagLoc = tagLoc.trim();
+                                }
+                            }
+                        }
+                    }
+                    if (match == true && tagLoc != null) {
+                        this.uri = tagLoc;
+
+                        // If this is a relative path, then it has to be
+                        // relative to where web.xml is.
+
+                        // I'm taking the simple way out. Since web.xml
+                        // has to be directly under WEB-INF, I'm making
+                        // an absolute URI out of it by prepending WEB-INF
+
+                        if (!uri.startsWith("/") && isRelativeURI(uri))
+                            uri = "/WEB-INF/"+uri;
+                    }
+                }
+            }
+        }
+
+        // Try to resolve URI relative to the current JSP page
+        if (!uri.startsWith("/") && isRelativeURI(uri))
+            uri = ctxt.resolveRelativeUri(uri);

-           // Try to resolve URI relative to the current JSP page
-            if (!uri.startsWith("/"))
-               uri = ctxt.resolveRelativeUri(uri);

+        if (!uri.endsWith("jar")) {
            in = getResourceAsStream(uri);

            if (in == null)
@@ -231,14 +232,14 @@
        }

        // FIXME Take this stuff out when taglib changes are thoroughly
tested.
-       if (uriIn.endsWith("jar")) {
+       if (uri.endsWith("jar")) {

-           if (!uriIn.startsWith("/")) {
-               url = new URL(uriIn);
+           if (!isRelativeURI(uri)) {
+               url = new URL(uri);
                in = url.openStream();
            } else {
                relativeURL = true;
-               in = getResourceAsStream(uriIn);
+               in = getResourceAsStream(uri);
            }

            zin = new ZipInputStream(in);
@@ -326,6 +327,12 @@
                        }
                                                              ));
        } // Take this out (END of if(endsWith("jar")))
+    }
+
+    /** Returns true if the given URI is relative in this web application,
false if it is an internet URI.
+     */
+    private boolean isRelativeURI(String uri) {
+        return (uri.indexOf(':') == -1);
     }


Mime
View raw message