kinman 2004/04/19 14:10:19
Modified: jasper2/src/share/org/apache/jasper/compiler Generator.java
JspUtil.java
Log:
- Fix 28380: Javac error with ':' and '.' in attribute names.
Revision Changes Path
1.232 +7 -29
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Generator.java
Index: Generator.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Generator.java,v
retrieving revision 1.231
retrieving revision 1.232
diff -u -r1.231 -r1.232
--- Generator.java 5 Apr 2004 16:07:41 -0000 1.231
+++ Generator.java 19 Apr 2004 21:10:19 -0000 1.232
@@ -254,18 +254,6 @@
boolean hasEmptyBody) {
String poolName = null;
- if (prefix.indexOf('-') >= 0)
- prefix = JspUtil.replace(prefix, '-', "$1");
- if (prefix.indexOf('.') >= 0)
- prefix = JspUtil.replace(prefix, '.', "$2");
-
- if (shortName.indexOf('-') >= 0)
- shortName = JspUtil.replace(shortName, '-', "$1");
- if (shortName.indexOf('.') >= 0)
- shortName = JspUtil.replace(shortName, '.', "$2");
- if (shortName.indexOf(':') >= 0)
- shortName = JspUtil.replace(shortName, ':', "$3");
-
poolName = "_jspx_tagPool_" + prefix + "_" + shortName;
if (attrs != null) {
String[] attrNames = new String[attrs.getLength()];
@@ -280,7 +268,7 @@
if (hasEmptyBody) {
poolName = poolName + "_nobody";
}
- return poolName;
+ return JspUtil.makeXmlJavaIdentifier(poolName);
}
}
@@ -2617,37 +2605,27 @@
/*
* Creates a tag variable name by concatenating the given prefix and
- * shortName and replacing '-' with "$1", '.' with "$2", and ':' with
- * "$3".
+ * shortName and endcoded to make the resultant string a valid Java
+ * Identifier.
*/
private String createTagVarName(
String fullName,
String prefix,
String shortName) {
- if (prefix.indexOf('-') >= 0)
- prefix = JspUtil.replace(prefix, '-', "$1");
- if (prefix.indexOf('.') >= 0)
- prefix = JspUtil.replace(prefix, '.', "$2");
-
- if (shortName.indexOf('-') >= 0)
- shortName = JspUtil.replace(shortName, '-', "$1");
- if (shortName.indexOf('.') >= 0)
- shortName = JspUtil.replace(shortName, '.', "$2");
- if (shortName.indexOf(':') >= 0)
- shortName = JspUtil.replace(shortName, ':', "$3");
+ String varName;
synchronized (tagVarNumbers) {
- String varName = prefix + "_" + shortName + "_";
+ varName = prefix + "_" + shortName + "_";
if (tagVarNumbers.get(fullName) != null) {
Integer i = (Integer)tagVarNumbers.get(fullName);
varName = varName + i.intValue();
tagVarNumbers.put(fullName, new Integer(i.intValue() + 1));
- return varName;
} else {
tagVarNumbers.put(fullName, new Integer(1));
- return varName + "0";
+ varName = varName + "0";
}
}
+ return JspUtil.makeXmlJavaIdentifier(varName);
}
private String evaluateAttribute(
1.48 +21 -0
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/JspUtil.java
Index: JspUtil.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/JspUtil.java,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -r1.47 -r1.48
--- JspUtil.java 17 Mar 2004 19:23:03 -0000 1.47
+++ JspUtil.java 19 Apr 2004 21:10:19 -0000 1.48
@@ -1003,6 +1003,27 @@
return false;
}
+ /**
+ * Converts the given Xml name to a legal Java identifier. This is
+ * slightly more efficient than makeJavaIdentifier in that we only need
+ * to worry about '.', '-', and ':' in the string. We also assume that
+ * the resultant string is further concatenated with some prefix string
+ * so that we don't have to worry about it being a Java key word.
+ *
+ * @param name Identifier to convert
+ *
+ * @return Legal Java identifier corresponding to the given identifier
+ */
+ public static final String makeXmlJavaIdentifier(String name) {
+ if (name.indexOf('-') >= 0)
+ name = replace(name, '-', "$1");
+ if (name.indexOf('.') >= 0)
+ name = replace(name, '.', "$2");
+ if (name.indexOf(':') >= 0)
+ name = replace(name, ':', "$3");
+ return name;
+ }
+
static InputStreamReader getReader(String fname, String encoding,
JarFile jarFile,
JspCompilationContext ctxt,
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]