Correct location of taglib element varies with spec version. WebRuleSet was using...
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Fri, 10 Jul 2009 15:53:59 +0000 (15:53 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Fri, 10 Jul 2009 15:53:59 +0000 (15:53 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@792996 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/startup/WebRuleSet.java

index 951b79a..9bc7d55 100644 (file)
@@ -301,11 +301,20 @@ public class WebRuleSet extends RuleSetBase {
                                new Class[] { Integer.TYPE });
         digester.addCallParam(prefix + "web-app/session-config/session-timeout", 0);
 
+        // Taglibs pre Servlet 2.4
+        digester.addRule(prefix + "web-app/taglib", new TaglibLocationRule(false));
         digester.addCallMethod(prefix + "web-app/taglib",
                                "addTaglib", 2);
         digester.addCallParam(prefix + "web-app/taglib/taglib-location", 1);
         digester.addCallParam(prefix + "web-app/taglib/taglib-uri", 0);
 
+        // Taglibs Servlet 2.4 onwards
+        digester.addRule(prefix + "web-app/jsp-config/taglib", new TaglibLocationRule(true));
+        digester.addCallMethod(prefix + "web-app/jsp-config/taglib",
+                "addTaglib", 2);
+        digester.addCallParam(prefix + "web-app/jsp-config/taglib/taglib-location", 1);
+        digester.addCallParam(prefix + "web-app/jsp-config/taglib/taglib-uri", 0);
+
         digester.addCallMethod(prefix + "web-app/welcome-file-list/welcome-file",
                                "addWelcomeFile", 0);
 
@@ -925,5 +934,32 @@ final class ServiceQnameRule extends Rule {
         contextService.setServiceqnameLocalpart(localpart);
         contextService.setServiceqnameNamespaceURI(namespaceuri);
     }
+    
 }
 
+/**
+ * A rule that checks if the taglib element is in the right place. 
+ */
+final class TaglibLocationRule extends Rule {
+
+    final boolean isServlet24OrLater;
+    
+    public TaglibLocationRule(boolean isServlet24OrLater) {
+        this.isServlet24OrLater = isServlet24OrLater;
+    }
+    
+    @Override
+    public void begin(String namespace, String name, Attributes attributes)
+            throws Exception {
+        Context context = (Context) digester.peek(digester.getCount() - 1);
+        // If we have a public ID, this is not a 2.4 or later webapp
+        boolean havePublicId = (context.getPublicId() != null);
+        // havePublicId and isServlet24OrLater should be mutually exclusive
+        if (havePublicId == isServlet24OrLater) {
+            throw new IllegalArgumentException(
+                    "taglib definition not consistent with specification version");
+        }
+    }
+
+    
+}
\ No newline at end of file