Author: jboynes
Date: Fri Aug 16 05:55:40 2013
New Revision: 1514588

URL: http://svn.apache.org/r1514588
Log:
Finish converting TLD parsing to using Digester. 
TldParser now handles all TLD content required by Jasper rather than the 
minimum needed for listener scanning.
Added test TLD files outside the test webapps to test edge cases.

Added:
    tomcat/trunk/test/tld/
    tomcat/trunk/test/tld/listener.tld
      - copied unchanged from r1514130, 
tomcat/trunk/test/webapp-3.0/WEB-INF/listener.tld
    tomcat/trunk/test/tld/tags11.tld
      - copied unchanged from r1514130, 
tomcat/trunk/test/webapp-3.0/WEB-INF/tags11.tld
    tomcat/trunk/test/tld/tags12.tld
      - copied unchanged from r1514130, 
tomcat/trunk/test/webapp-3.0/WEB-INF/tags12.tld
    tomcat/trunk/test/tld/tags20.tld
      - copied unchanged from r1514130, 
tomcat/trunk/test/webapp-3.0/WEB-INF/tags20.tld
    tomcat/trunk/test/tld/tags21.tld
      - copied unchanged from r1514130, 
tomcat/trunk/test/webapp-3.0/WEB-INF/tags21.tld
    tomcat/trunk/test/tld/test.tld
      - copied, changed from r1514130, tomcat/trunk/test/webapp/WEB-INF/test.tld
Modified:
    tomcat/trunk/java/org/apache/tomcat/util/descriptor/tld/Tag.java
    tomcat/trunk/java/org/apache/tomcat/util/descriptor/tld/TagFile.java
    tomcat/trunk/java/org/apache/tomcat/util/descriptor/tld/TaglibXml.java
    tomcat/trunk/java/org/apache/tomcat/util/descriptor/tld/TldParser.java
    tomcat/trunk/java/org/apache/tomcat/util/descriptor/tld/TldRuleSet.java
    tomcat/trunk/java/org/apache/tomcat/util/descriptor/tld/Validator.java
    tomcat/trunk/test/org/apache/tomcat/util/descriptor/tld/TestTldParser.java

Modified: tomcat/trunk/java/org/apache/tomcat/util/descriptor/tld/Tag.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/descriptor/tld/Tag.java?rev=1514588&r1=1514587&r2=1514588&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/descriptor/tld/Tag.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/descriptor/tld/Tag.java Fri Aug 16 
05:55:40 2013
@@ -16,23 +16,31 @@
  */
 package org.apache.tomcat.util.descriptor.tld;
 
+import java.util.ArrayList;
 import java.util.List;
 
+import javax.servlet.jsp.tagext.TagAttributeInfo;
+import javax.servlet.jsp.tagext.TagInfo;
+import javax.servlet.jsp.tagext.TagVariableInfo;
+
 /**
- *
+ * Model of a tag define in a tag library descriptor.
+ * This represents the information as parsed from the XML but differs from
+ * TagInfo in that is does not provide a link back to the tag library that
+ * defined it.
  */
 public class Tag {
     private String name;
     private String tagClass;
     private String teiClass;
-    private String bodyContent;
+    private String bodyContent = TagInfo.BODY_CONTENT_JSP;
     private String displayName;
     private String smallIcon;
     private String largeIcon;
     private String info;
     private boolean dynamicAttributes;
-    private List<Variable> variables;
-    private List<Attribute> attributes;
+    private List<TagAttributeInfo> attributes;
+    private List<TagVariableInfo> variables;
 
     public String getName() {
         return name;
@@ -106,144 +114,17 @@ public class Tag {
         this.dynamicAttributes = dynamicAttributes;
     }
 
-    public static class Variable {
-        private String nameGiven;
-        private String nameFromAttribute;
-        private String className;
-        private boolean declare;
-        private int scope;
-
-        public String getNameGiven() {
-            return nameGiven;
-        }
-
-        public void setNameGiven(String nameGiven) {
-            this.nameGiven = nameGiven;
-        }
-
-        public String getNameFromAttribute() {
-            return nameFromAttribute;
-        }
-
-        public void setNameFromAttribute(String nameFromAttribute) {
-            this.nameFromAttribute = nameFromAttribute;
-        }
-
-        public String getClassName() {
-            return className;
-        }
-
-        public void setClassName(String className) {
-            this.className = className;
-        }
-
-        public boolean isDeclare() {
-            return declare;
-        }
-
-        public void setDeclare(boolean declare) {
-            this.declare = declare;
-        }
-
-        public int getScope() {
-            return scope;
-        }
-
-        public void setScope(int scope) {
-            this.scope = scope;
+    public List<TagAttributeInfo> getAttributes() {
+        if (attributes == null) {
+            attributes = new ArrayList<>();
         }
+        return attributes;
     }
 
-    public static class Attribute {
-        private String name;
-        private boolean required;
-        private String type;
-        private boolean requestTime;
-        private boolean fragment;
-        private String description;
-        private boolean deferredValue;
-        private boolean deferredMethod;
-        private String expectedTypeName;
-        private String methodSignature;
-
-        public String getName() {
-            return name;
-        }
-
-        public void setName(String name) {
-            this.name = name;
-        }
-
-        public boolean isRequired() {
-            return required;
-        }
-
-        public void setRequired(boolean required) {
-            this.required = required;
-        }
-
-        public String getType() {
-            return type;
-        }
-
-        public void setType(String type) {
-            this.type = type;
-        }
-
-        public boolean isRequestTime() {
-            return requestTime;
-        }
-
-        public void setRequestTime(boolean requestTime) {
-            this.requestTime = requestTime;
-        }
-
-        public boolean isFragment() {
-            return fragment;
-        }
-
-        public void setFragment(boolean fragment) {
-            this.fragment = fragment;
-        }
-
-        public String getDescription() {
-            return description;
-        }
-
-        public void setDescription(String description) {
-            this.description = description;
-        }
-
-        public boolean isDeferredValue() {
-            return deferredValue;
-        }
-
-        public void setDeferredValue(boolean deferredValue) {
-            this.deferredValue = deferredValue;
-        }
-
-        public boolean isDeferredMethod() {
-            return deferredMethod;
-        }
-
-        public void setDeferredMethod(boolean deferredMethod) {
-            this.deferredMethod = deferredMethod;
-        }
-
-        public String getExpectedTypeName() {
-            return expectedTypeName;
-        }
-
-        public void setExpectedTypeName(String expectedTypeName) {
-            this.expectedTypeName = expectedTypeName;
-        }
-
-        public String getMethodSignature() {
-            return methodSignature;
-        }
-
-        public void setMethodSignature(String methodSignature) {
-            this.methodSignature = methodSignature;
+    public List<TagVariableInfo> getVariables() {
+        if (variables == null) {
+            variables = new ArrayList<>();
         }
+        return variables;
     }
 }

Modified: tomcat/trunk/java/org/apache/tomcat/util/descriptor/tld/TagFile.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/descriptor/tld/TagFile.java?rev=1514588&r1=1514587&r2=1514588&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/descriptor/tld/TagFile.java 
(original)
+++ tomcat/trunk/java/org/apache/tomcat/util/descriptor/tld/TagFile.java Fri 
Aug 16 05:55:40 2013
@@ -17,7 +17,9 @@
 package org.apache.tomcat.util.descriptor.tld;
 
 /**
- *
+ * Bare-bone model of a tag file loaded from a TLD.
+ * This does not contain the tag-specific attributes that requiring parsing
+ * the actual tag file to derive.
  */
 public class TagFile {
     private String name;

Modified: tomcat/trunk/java/org/apache/tomcat/util/descriptor/tld/TaglibXml.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/descriptor/tld/TaglibXml.java?rev=1514588&r1=1514587&r2=1514588&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/descriptor/tld/TaglibXml.java 
(original)
+++ tomcat/trunk/java/org/apache/tomcat/util/descriptor/tld/TaglibXml.java Fri 
Aug 16 05:55:40 2013
@@ -38,6 +38,7 @@ public class TaglibXml {
     private String info;
     private Validator validator;
     private List<Tag> tags;
+    private List<TagFile> tagFiles;
     private List<String> listeners;
     private List<FunctionInfo> functions;
 
@@ -100,6 +101,17 @@ public class TaglibXml {
         return tags;
     }
 
+    public void addTagFile(TagFile tag) {
+        if (tagFiles == null) {
+            tagFiles = new ArrayList<>();
+        }
+        tagFiles.add(tag);
+    }
+
+    public List<TagFile> getTagFiles() {
+        return tagFiles;
+    }
+
     public void addListener(String listener) {
         if (listeners == null) {
             listeners = new ArrayList<>();
@@ -111,11 +123,11 @@ public class TaglibXml {
         return listeners;
     }
 
-    public void addFunction(FunctionInfo functionInfo) {
+    public void addFunction(String name, String klass, String signature) {
         if (functions == null) {
             functions = new ArrayList<>();
         }
-        functions.add(functionInfo);
+        functions.add(new FunctionInfo(name, klass, signature));
     }
 
     public List<FunctionInfo> getFunctions() {

Modified: tomcat/trunk/java/org/apache/tomcat/util/descriptor/tld/TldParser.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/descriptor/tld/TldParser.java?rev=1514588&r1=1514587&r2=1514588&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/descriptor/tld/TldParser.java 
(original)
+++ tomcat/trunk/java/org/apache/tomcat/util/descriptor/tld/TldParser.java Fri 
Aug 16 05:55:40 2013
@@ -52,6 +52,10 @@ public class TldParser {
             digester.parse(source);
             if (!handler.getWarnings().isEmpty() || 
!handler.getErrors().isEmpty()) {
                 handler.logFindings(LOG, source.getSystemId());
+                if (!handler.getErrors().isEmpty()) {
+                    // throw the first to indicate there was a error during 
processing
+                    throw handler.getErrors().iterator().next();
+                }
             }
             return taglibXml;
         } finally {

Modified: 
tomcat/trunk/java/org/apache/tomcat/util/descriptor/tld/TldRuleSet.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/descriptor/tld/TldRuleSet.java?rev=1514588&r1=1514587&r2=1514588&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/descriptor/tld/TldRuleSet.java 
(original)
+++ tomcat/trunk/java/org/apache/tomcat/util/descriptor/tld/TldRuleSet.java Fri 
Aug 16 05:55:40 2013
@@ -16,6 +16,12 @@
  */
 package org.apache.tomcat.util.descriptor.tld;
 
+import java.lang.reflect.Method;
+
+import javax.servlet.jsp.tagext.TagAttributeInfo;
+import javax.servlet.jsp.tagext.TagVariableInfo;
+import javax.servlet.jsp.tagext.VariableInfo;
+
 import org.apache.tomcat.util.digester.Digester;
 import org.apache.tomcat.util.digester.Rule;
 import org.apache.tomcat.util.digester.RuleSetBase;
@@ -26,7 +32,10 @@ import org.xml.sax.Attributes;
  */
 public class TldRuleSet extends RuleSetBase {
     private static final String PREFIX = "taglib";
+    private static final String VALIDATOR_PREFIX = PREFIX + "/validator";
     private static final String TAG_PREFIX = PREFIX + "/tag";
+    private static final String TAGFILE_PREFIX = PREFIX + "/tag-file";
+    private static final String FUNCTION_PREFIX = PREFIX + "/function";
 
     @Override
     public void addRuleInstances(Digester digester) {
@@ -52,8 +61,18 @@ public class TldRuleSet extends RuleSetB
         digester.addCallMethod(PREFIX + "/description", "setInfo", 0);
         digester.addCallMethod(PREFIX + "/listener/listener-class", 
"addListener", 0);
 
+        // validator
+        digester.addObjectCreate(VALIDATOR_PREFIX, Validator.class.getName());
+        digester.addCallMethod(VALIDATOR_PREFIX + "/validator-class", 
"setValidatorClass", 0);
+        digester.addCallMethod(VALIDATOR_PREFIX + "/init-param", 
"addInitParam", 2);
+        digester.addCallParam(VALIDATOR_PREFIX + "/init-param/param-name", 0);
+        digester.addCallParam(VALIDATOR_PREFIX + "/init-param/param-value", 1);
+        digester.addSetNext(VALIDATOR_PREFIX, "setValidator", 
Validator.class.getName());
+
+
         // tag
         digester.addObjectCreate(TAG_PREFIX, Tag.class.getName());
+        addDescriptionGroup(digester, TAG_PREFIX);
         digester.addCallMethod(TAG_PREFIX + "/name", "setName", 0);
         digester.addCallMethod(TAG_PREFIX + "/tagclass", "setTagClass", 0);
         digester.addCallMethod(TAG_PREFIX + "/tag-class", "setTagClass", 0);
@@ -61,6 +80,280 @@ public class TldRuleSet extends RuleSetB
         digester.addCallMethod(TAG_PREFIX + "/tei-class", "setTeiClass", 0);
         digester.addCallMethod(TAG_PREFIX + "/bodycontent", "setBodyContent", 
0);
         digester.addCallMethod(TAG_PREFIX + "/body-content", "setBodyContent", 
0);
+
+        digester.addRule(TAG_PREFIX + "/variable", new ScriptVariableRule());
+        digester.addCallMethod(TAG_PREFIX + "/variable/name-given", 
"setNameGiven", 0);
+        digester.addCallMethod(TAG_PREFIX + "/variable/name-from-attribute",
+                "setNameFromAttribute", 0);
+        digester.addCallMethod(TAG_PREFIX + "/variable/variable-class", 
"setClassName", 0);
+        digester.addRule(TAG_PREFIX + "/variable/declare",
+                new GenericBooleanRule(Variable.class, "setDeclare"));
+        digester.addCallMethod(TAG_PREFIX + "/variable/scope", "setScope", 0);
+
+        digester.addRule(TAG_PREFIX + "/attribute", new TagAttributeRule());
+        digester.addCallMethod(TAG_PREFIX + "/attribute/description", 
"setDescription", 0);
+        digester.addCallMethod(TAG_PREFIX + "/attribute/name", "setName", 0);
+        digester.addRule(TAG_PREFIX + "/attribute/required",
+                new GenericBooleanRule(Attribute.class, "setRequired"));
+        digester.addRule(TAG_PREFIX + "/attribute/rtexprvalue",
+                new GenericBooleanRule(Attribute.class, "setRequestTime"));
+        digester.addCallMethod(TAG_PREFIX + "/attribute/type", "setType", 0);
+        digester.addCallMethod(TAG_PREFIX + "/attribute/deferred-value", 
"setDeferredValue");
+        digester.addCallMethod(TAG_PREFIX + "/attribute/deferred-value/type",
+                "setExpectedTypeName", 0);
+        digester.addCallMethod(TAG_PREFIX + "/attribute/deferred-method", 
"setDeferredMethod");
+        digester.addCallMethod(TAG_PREFIX + 
"/attribute/deferred-method/method-signature",
+                "setMethodSignature", 0);
+        digester.addRule(TAG_PREFIX + "/attribute/fragment",
+                new GenericBooleanRule(Attribute.class, "setFragment"));
+
+        digester.addRule(TAG_PREFIX + "/dynamic-attributes",
+                new GenericBooleanRule(Tag.class, "setDynamicAttributes"));
         digester.addSetNext(TAG_PREFIX, "addTag", Tag.class.getName());
+
+        // tag-file
+        digester.addObjectCreate(TAGFILE_PREFIX, TagFile.class.getName());
+        addDescriptionGroup(digester, TAGFILE_PREFIX);
+        digester.addCallMethod(TAGFILE_PREFIX + "/name", "setName", 0);
+        digester.addCallMethod(TAGFILE_PREFIX + "/path", "setPath", 0);
+        digester.addSetNext(TAGFILE_PREFIX, "addTagFile", 
TagFile.class.getName());
+
+        // function
+        digester.addCallMethod(FUNCTION_PREFIX, "addFunction", 3);
+        digester.addCallParam(FUNCTION_PREFIX + "/name", 0);
+        digester.addCallParam(FUNCTION_PREFIX + "/function-class", 1);
+        digester.addCallParam(FUNCTION_PREFIX + "/function-signature", 2);
+    }
+
+    private void addDescriptionGroup(Digester digester, String prefix) {
+        digester.addCallMethod(prefix + "/info", "setInfo", 0);
+        digester.addCallMethod(prefix + "small-icon", "setSmallIcon", 0);
+        digester.addCallMethod(prefix + "large-icon", "setLargeIcon", 0);
+
+        digester.addCallMethod(prefix + "/description", "setInfo", 0);
+        digester.addCallMethod(prefix + "/display-name", "setDisplayName", 0);
+        digester.addCallMethod(prefix + "/icon/small-icon", "setSmallIcon", 0);
+        digester.addCallMethod(prefix + "/icon/large-icon", "setLargeIcon", 0);
+    }
+
+    private static class TagAttributeRule extends Rule {
+        @Override
+        public void begin(String namespace, String name, Attributes 
attributes) throws Exception {
+            TaglibXml taglibXml = (TaglibXml) 
digester.peek(digester.getCount() - 1);
+            digester.push(new 
Attribute("1.2".equals(taglibXml.getJspVersion())));
+        }
+
+        @Override
+        public void end(String namespace, String name) throws Exception {
+            Attribute attribute = (Attribute) digester.pop();
+            Tag tag = (Tag) digester.peek();
+            tag.getAttributes().add(attribute.toTagAttributeInfo());
+        }
+    }
+
+    public static class Attribute {
+        private final boolean allowShortNames;
+        private String name;
+        private boolean required;
+        private String type;
+        private boolean requestTime;
+        private boolean fragment;
+        private String description;
+        private boolean deferredValue;
+        private boolean deferredMethod;
+        private String expectedTypeName;
+        private String methodSignature;
+
+        private Attribute(boolean allowShortNames) {
+            this.allowShortNames = allowShortNames;
+        }
+
+        public void setName(String name) {
+            this.name = name;
+        }
+
+        public void setRequired(boolean required) {
+            this.required = required;
+        }
+
+        public void setType(String type) {
+            if (allowShortNames) {
+                switch (type) {
+                    case "Boolean":
+                        this.type = "java.lang.Boolean";
+                        break;
+                    case "Character":
+                        this.type = "java.lang.Character";
+                        break;
+                    case "Byte":
+                        this.type = "java.lang.Byte";
+                        break;
+                    case "Short":
+                        this.type = "java.lang.Short";
+                        break;
+                    case "Integer":
+                        this.type = "java.lang.Integer";
+                        break;
+                    case "Long":
+                        this.type = "java.lang.Long";
+                        break;
+                    case "Float":
+                        this.type = "java.lang.Float";
+                        break;
+                    case "Double":
+                        this.type = "java.lang.Double";
+                        break;
+                    case "String":
+                        this.type = "java.lang.String";
+                        break;
+                    case "Object":
+                        this.type = "java.lang.Object";
+                        break;
+                    default:
+                        this.type = type;
+                        break;
+                }
+            } else {
+                this.type = type;
+            }
+        }
+
+        public void setRequestTime(boolean requestTime) {
+            this.requestTime = requestTime;
+        }
+
+        public void setFragment(boolean fragment) {
+            this.fragment = fragment;
+        }
+
+        public void setDescription(String description) {
+            this.description = description;
+        }
+
+        public void setDeferredValue() {
+            this.deferredValue = true;
+        }
+
+        public void setDeferredMethod() {
+            this.deferredMethod = true;
+        }
+
+        public void setExpectedTypeName(String expectedTypeName) {
+            this.expectedTypeName = expectedTypeName;
+        }
+
+        public void setMethodSignature(String methodSignature) {
+            this.methodSignature = methodSignature;
+        }
+
+        public TagAttributeInfo toTagAttributeInfo() {
+            if (fragment) {
+                // JSP8.5.2: for a fragment type is fixed and rexprvalue is 
true
+                type = "javax.servlet.jsp.tagext.JspFragment";
+                requestTime = true;
+            } else if (deferredValue) {
+                type = "javax.el.ValueExpression";
+                if (expectedTypeName == null) {
+                    expectedTypeName = "java.lang.Object";
+                }
+            } else if (deferredMethod) {
+                type = "javax.el.MethodExpression";
+                if (methodSignature == null) {
+                    methodSignature = "java.lang.Object method()";
+                }
+            }
+
+            // According to JSP spec, for static values (those determined at
+            // translation time) the type is fixed at java.lang.String.
+            if (!requestTime && type == null) {
+                type = "java.lang.String";
+            }
+
+            return new TagAttributeInfo(
+                    name,
+                    required,
+                    type,
+                    requestTime,
+                    fragment,
+                    description,
+                    deferredValue,
+                    deferredMethod,
+                    expectedTypeName,
+                    methodSignature);
+        }
+    }
+
+    private static class ScriptVariableRule extends Rule {
+        @Override
+        public void begin(String namespace, String name, Attributes 
attributes) throws Exception {
+            digester.push(new Variable());
+        }
+
+        @Override
+        public void end(String namespace, String name) throws Exception {
+            Variable variable = (Variable) digester.pop();
+            Tag tag = (Tag) digester.peek();
+            tag.getVariables().add(variable.toTagVariableInfo());
+        }
+    }
+
+    public static class Variable {
+        private String nameGiven;
+        private String nameFromAttribute;
+        private String className = "java.lang.String";
+        private boolean declare;
+        private int scope = VariableInfo.NESTED;
+
+        public void setNameGiven(String nameGiven) {
+            this.nameGiven = nameGiven;
+        }
+
+        public void setNameFromAttribute(String nameFromAttribute) {
+            this.nameFromAttribute = nameFromAttribute;
+        }
+
+        public void setClassName(String className) {
+            this.className = className;
+        }
+
+        public void setDeclare(boolean declare) {
+            this.declare = declare;
+        }
+
+        public void setScope(String scopeName) {
+            switch (scopeName) {
+                case "NESTED":
+                    scope = VariableInfo.NESTED;
+                    break;
+                case "AT_BEGIN":
+                    scope = VariableInfo.AT_BEGIN;
+                    break;
+                case "AT_END":
+                    scope = VariableInfo.AT_END;
+                    break;
+            }
+        }
+
+        public TagVariableInfo toTagVariableInfo() {
+            return new TagVariableInfo(nameGiven, nameFromAttribute, 
className, declare, scope);
+        }
+    }
+
+    private static class GenericBooleanRule extends Rule {
+        private final Method setter;
+
+        private GenericBooleanRule(Class<?> type, String setterName) {
+            try {
+                this.setter = type.getMethod(setterName, Boolean.TYPE);
+            } catch (NoSuchMethodException e) {
+                throw new IllegalArgumentException(e);
+            }
+        }
+
+        @Override
+        public void body(String namespace, String name, String text) throws 
Exception {
+            boolean value = "true".equalsIgnoreCase(text) || 
"yes".equalsIgnoreCase(text);
+            setter.invoke(digester.peek(), value);
+        }
     }
 }

Modified: tomcat/trunk/java/org/apache/tomcat/util/descriptor/tld/Validator.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/descriptor/tld/Validator.java?rev=1514588&r1=1514587&r2=1514588&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/descriptor/tld/Validator.java 
(original)
+++ tomcat/trunk/java/org/apache/tomcat/util/descriptor/tld/Validator.java Fri 
Aug 16 05:55:40 2013
@@ -23,15 +23,15 @@ import java.util.Map;
  * Model of a Tag Library Validator from the XML descriptor.
  */
 public class Validator {
-    private String validationClass;
+    private String validatorClass;
     private Map<String, String> initParams;
 
-    public String getValidationClass() {
-        return validationClass;
+    public String getValidatorClass() {
+        return validatorClass;
     }
 
-    public void setValidationClass(String validationClass) {
-        this.validationClass = validationClass;
+    public void setValidatorClass(String validatorClass) {
+        this.validatorClass = validatorClass;
     }
 
     public void addInitParam(String name, String value) {

Modified: 
tomcat/trunk/test/org/apache/tomcat/util/descriptor/tld/TestTldParser.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/util/descriptor/tld/TestTldParser.java?rev=1514588&r1=1514587&r2=1514588&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/tomcat/util/descriptor/tld/TestTldParser.java 
(original)
+++ tomcat/trunk/test/org/apache/tomcat/util/descriptor/tld/TestTldParser.java 
Fri Aug 16 05:55:40 2013
@@ -20,6 +20,11 @@ import java.io.File;
 import java.io.IOException;
 import java.util.List;
 
+import javax.servlet.jsp.tagext.FunctionInfo;
+import javax.servlet.jsp.tagext.TagAttributeInfo;
+import javax.servlet.jsp.tagext.TagVariableInfo;
+import javax.servlet.jsp.tagext.VariableInfo;
+
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -35,8 +40,76 @@ public class TestTldParser {
     }
 
     @Test
+    public void testTld() throws Exception {
+        TaglibXml xml = parse("test/tld/test.tld");
+        Assert.assertEquals("1.0", xml.getTlibVersion());
+        Assert.assertEquals("2.1", xml.getJspVersion());
+        Assert.assertEquals("test", xml.getShortName());
+        Assert.assertEquals("http://tomcat.apache.org/TldTests";, xml.getUri());
+        Assert.assertEquals(1, xml.getFunctions().size());
+
+        Validator validator = xml.getValidator();
+        Assert.assertEquals("com.example.Validator", 
validator.getValidatorClass());
+        Assert.assertEquals(1, validator.getInitParams().size());
+        Assert.assertEquals("value", validator.getInitParams().get("name"));
+
+        Assert.assertEquals(1, xml.getTags().size());
+        Tag tag = xml.getTags().get(0);
+        Assert.assertEquals("org.apache.jasper.compiler.TestValidator$Echo", 
tag.getTagClass());
+        Assert.assertEquals("empty", tag.getBodyContent());
+        Assert.assertTrue(tag.hasDynamicAttributes());
+
+        Assert.assertEquals(1, tag.getVariables().size());
+        TagVariableInfo variableInfo = tag.getVariables().get(0);
+        Assert.assertEquals("var", variableInfo.getNameGiven());
+        Assert.assertEquals("java.lang.Object", variableInfo.getClassName());
+        Assert.assertTrue(variableInfo.getDeclare());
+        Assert.assertEquals(VariableInfo.AT_END, variableInfo.getScope());
+
+        Assert.assertEquals(4, tag.getAttributes().size());
+        TagAttributeInfo attributeInfo = tag.getAttributes().get(0);
+        Assert.assertEquals("Echo Tag", tag.getInfo());
+        Assert.assertEquals("Echo", tag.getDisplayName());
+        Assert.assertEquals("small", tag.getSmallIcon());
+        Assert.assertEquals("large", tag.getLargeIcon());
+        Assert.assertEquals("echo", attributeInfo.getName());
+        Assert.assertTrue(attributeInfo.isRequired());
+        Assert.assertTrue(attributeInfo.canBeRequestTime());
+
+        attributeInfo = tag.getAttributes().get(1);
+        Assert.assertEquals("fragment", attributeInfo.getName());
+        Assert.assertTrue(attributeInfo.isFragment());
+        Assert.assertTrue(attributeInfo.canBeRequestTime());
+        Assert.assertEquals("javax.servlet.jsp.tagext.JspFragment", 
attributeInfo.getTypeName());
+
+        attributeInfo = tag.getAttributes().get(2);
+        Assert.assertEquals("deferredValue", attributeInfo.getName());
+        Assert.assertEquals("javax.el.ValueExpression", 
attributeInfo.getTypeName());
+        Assert.assertEquals("java.util.Date", 
attributeInfo.getExpectedTypeName());
+
+        attributeInfo = tag.getAttributes().get(3);
+        Assert.assertEquals("deferredMethod", attributeInfo.getName());
+        Assert.assertEquals("javax.el.MethodExpression", 
attributeInfo.getTypeName());
+        Assert.assertEquals("java.util.Date getDate()", 
attributeInfo.getMethodSignature());
+
+        Assert.assertEquals(1, xml.getTagFiles().size());
+        TagFile tagFile = xml.getTagFiles().get(0);
+        Assert.assertEquals("Echo", tag.getDisplayName());
+        Assert.assertEquals("small", tag.getSmallIcon());
+        Assert.assertEquals("large", tag.getLargeIcon());
+        Assert.assertEquals("Echo2", tagFile.getName());
+        Assert.assertEquals("/echo.tag", tagFile.getPath());
+
+        Assert.assertEquals(1, xml.getFunctions().size());
+        FunctionInfo fn = xml.getFunctions().get(0);
+        Assert.assertEquals("trim", fn.getName());
+        Assert.assertEquals("org.apache.el.TesterFunctions", 
fn.getFunctionClass());
+        Assert.assertEquals("java.lang.String trim(java.lang.String)", 
fn.getFunctionSignature());
+    }
+
+    @Test
     public void testParseTld21() throws Exception {
-        TaglibXml xml = parse("test/webapp-3.1/WEB-INF/tags21.tld");
+        TaglibXml xml = parse("test/tld/tags21.tld");
         Assert.assertEquals("1.0", xml.getTlibVersion());
         Assert.assertEquals("2.1", xml.getJspVersion());
         Assert.assertEquals("Tags21", xml.getShortName());
@@ -46,7 +119,7 @@ public class TestTldParser {
 
     @Test
     public void testParseTld20() throws Exception {
-        TaglibXml xml = parse("test/webapp-3.1/WEB-INF/tags20.tld");
+        TaglibXml xml = parse("test/tld/tags20.tld");
         Assert.assertEquals("1.0", xml.getTlibVersion());
         Assert.assertEquals("2.0", xml.getJspVersion());
         Assert.assertEquals("Tags20", xml.getShortName());
@@ -56,7 +129,7 @@ public class TestTldParser {
 
     @Test
     public void testParseTld12() throws Exception {
-        TaglibXml xml = parse("test/webapp-3.1/WEB-INF/tags12.tld");
+        TaglibXml xml = parse("test/tld/tags12.tld");
         Assert.assertEquals("1.0", xml.getTlibVersion());
         Assert.assertEquals("1.2", xml.getJspVersion());
         Assert.assertEquals("Tags12", xml.getShortName());
@@ -66,7 +139,7 @@ public class TestTldParser {
 
     @Test
     public void testParseTld11() throws Exception {
-        TaglibXml xml = parse("test/webapp-3.1/WEB-INF/tags11.tld");
+        TaglibXml xml = parse("test/tld/tags11.tld");
         Assert.assertEquals("1.0", xml.getTlibVersion());
         Assert.assertEquals("1.1", xml.getJspVersion());
         Assert.assertEquals("Tags11", xml.getShortName());
@@ -78,14 +151,13 @@ public class TestTldParser {
         Assert.assertEquals(1, tags.size());
         Tag tag = tags.get(0);
         Assert.assertEquals("Echo", tag.getName());
-        Assert.assertEquals("org.apache.jasper.compiler.TestValidator$Echo",
-                tag.getTagClass());
+        Assert.assertEquals("org.apache.jasper.compiler.TestValidator$Echo", 
tag.getTagClass());
         Assert.assertEquals("empty", tag.getBodyContent());
     }
 
     @Test
     public void testListener() throws Exception {
-        TaglibXml xml = parse("test/webapp-3.0/WEB-INF/listener.tld");
+        TaglibXml xml = parse("test/tld/listener.tld");
         Assert.assertEquals("1.0", xml.getTlibVersion());
         List<String> listeners = xml.getListeners();
         Assert.assertEquals(1, listeners.size());

Copied: tomcat/trunk/test/tld/test.tld (from r1514130, 
tomcat/trunk/test/webapp/WEB-INF/test.tld)
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/tld/test.tld?p2=tomcat/trunk/test/tld/test.tld&p1=tomcat/trunk/test/webapp/WEB-INF/test.tld&r1=1514130&r2=1514588&rev=1514588&view=diff
==============================================================================
--- tomcat/trunk/test/webapp/WEB-INF/test.tld (original)
+++ tomcat/trunk/test/tld/test.tld Fri Aug 16 05:55:40 2013
@@ -21,8 +21,67 @@
       http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd";
       version="2.1">
   <tlib-version>1.0</tlib-version>
-  <short-name>TesterFunctions</short-name>
-  <uri>http://tomcat.apache.org/testerFunctions</uri>
+  <short-name>test</short-name>
+  <uri>http://tomcat.apache.org/TldTests</uri>
+
+  <validator>
+    <validator-class>com.example.Validator</validator-class>
+    <init-param>
+      <param-name>name</param-name>
+      <param-value>value</param-value>
+    </init-param>
+  </validator>
+
+  <tag>
+    <description>Echo Tag</description>
+    <display-name>Echo</display-name>
+    <icon>
+      <small-icon>small</small-icon>
+      <large-icon>large</large-icon>
+    </icon>
+    <name>Echo</name>
+    <tag-class>org.apache.jasper.compiler.TestValidator$Echo</tag-class>
+    <body-content>empty</body-content>
+    <variable>
+      <name-given>var</name-given>
+      <variable-class>java.lang.Object</variable-class>
+      <declare>yes</declare>
+      <scope>AT_END</scope>
+    </variable>
+    <attribute>
+      <name>echo</name>
+      <required>yes</required>
+      <rtexprvalue>true</rtexprvalue>
+    </attribute>
+    <attribute>
+      <name>fragment</name>
+      <fragment>yes</fragment>
+    </attribute>
+    <attribute>
+      <name>deferredValue</name>
+      <deferred-value>
+        <type>java.util.Date</type>
+      </deferred-value>
+    </attribute>
+    <attribute>
+      <name>deferredMethod</name>
+      <deferred-method>
+        <method-signature>java.util.Date getDate()</method-signature>
+      </deferred-method>
+    </attribute>
+    <dynamic-attributes>true</dynamic-attributes>
+  </tag>
+
+  <tag-file>
+    <description>Echo Tag</description>
+    <display-name>Echo</display-name>
+    <icon>
+      <small-icon>small</small-icon>
+      <large-icon>large</large-icon>
+    </icon>
+    <name>Echo2</name>
+    <path>/echo.tag</path>
+  </tag-file>
 
   <function>
     <name>trim</name>



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to