tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kin-Man Chung <Kin-Man.Ch...@Eng.Sun.COM>
Subject [PATCH] Jasper generates bad custom tag variable names
Date Thu, 06 Sep 2001 22:54:16 GMT
This patch fixes Bug 3019.

If a tag name includes a '-', the generated var name is not a legal Java
identifier name, causing javac compilation errors.  The bug is fixed by
substituting '-' with "$1".  Similarily, '.' is replaced by "$2",
and ':' by "$3".

runsocks cvs diff -u TagGeneratorBase.java
Index: TagGeneratorBase.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/T
agGeneratorBase.java,v
retrieving revision 1.2
diff -u -r1.2 TagGeneratorBase.java
--- TagGeneratorBase.java       2000/11/01 20:25:08     1.2
+++ TagGeneratorBase.java       2001/09/06 22:32:12
@@ -119,7 +119,42 @@
        return (TagVariableData) tagHandlerStack.peek();
     }
 
+    private String substitute(String name, char from, String to) {
+       StringBuffer s = new StringBuffer();
+       int begin = 0;
+       int last = name.length();
+       int end;
+       while (true) {
+           end = name.indexOf(from, begin);
+           if (end == -1)
+               end = last;
+           s.append(name.substring(begin, end));
+           if (end == last)
+               break;
+           s.append(to);
+           begin = end + 1;
+       }
+       return s.toString();
+    }
+           
+    /**
+     * Return a tag variable name from the given prefix and shortTagName.
+     * Not all NMTOKEN's are legal Java identifiers, since they may contain
+     * '-', '.', or ':'.  We use the following mapping: substitute "-" with
+     * "$1", "." with "$2", and ":" with "$3".
+     */
     protected String getTagVarName(String prefix, String shortTagName) {
+
+       if (shortTagName.indexOf('-') != -1) {
+           shortTagName = substitute(shortTagName, '-', "$1");
+       }
+       if (shortTagName.indexOf('.') != -1) {
+           shortTagName = substitute(shortTagName, '.', "$2");
+       }
+       if (shortTagName.indexOf(':') != -1) {
+           shortTagName = substitute(shortTagName, ':', "$3");
+       }
+
        // Fix: Can probably remove the synchronization now when no vars or 
method is static
        synchronized (tagVarNumbers) {
            String tag = prefix+":"+shortTagName;


Mime
View raw message