luehe 2002/12/11 11:40:46
Modified: jasper2/src/share/org/apache/jasper/runtime
JspRuntimeLibrary.java
jasper2/src/share/org/apache/jasper/compiler Generator.java
Log:
Added support for named attributes that do not evaluate to String
Revision Changes Path
1.10 +12 -4
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/runtime/JspRuntimeLibrary.java
Index: JspRuntimeLibrary.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/runtime/JspRuntimeLibrary.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- JspRuntimeLibrary.java 27 Nov 2002 02:54:46 -0000 1.9
+++ JspRuntimeLibrary.java 11 Dec 2002 19:40:45 -0000 1.10
@@ -128,7 +128,15 @@
return null;
}
}
-
+
+ public static Character getCharacter(String s) throws JasperException {
+ if (s.length() > 0) {
+ return new Character(s.charAt(0));
+ } else {
+ throw new
JasperException(Constants.getString("jsp.error.bad_string_Character"));
+ }
+ }
+
// __begin convertMethod
public static Object convert(String propertyName, String s, Class t, Class
propertyEditorClass)
throws JasperException
1.139 +54 -21
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.138
retrieving revision 1.139
diff -u -r1.138 -r1.139
--- Generator.java 5 Dec 2002 23:56:39 -0000 1.138
+++ Generator.java 11 Dec 2002 19:40:45 -0000 1.139
@@ -2419,7 +2419,7 @@
attrValue = convertString(
c[0], attrValue, attrName,
handlerInfo.getPropertyEditorClass(attrName),
- false);
+ true);
}
} else if (attr.isELInterpreterInput()) {
// run attrValue through the expression interpreter
@@ -2429,7 +2429,7 @@
attrValue = convertString(
c[0], attrValue, attrName,
handlerInfo.getPropertyEditorClass(attrName),
- true);
+ false);
}
return attrValue;
}
@@ -2519,11 +2519,12 @@
}
private String convertString(Class c, String s, String attrName,
- Class propEditorClass, boolean quote)
+ Class propEditorClass,
+ boolean isNamedAttribute)
throws JasperException {
String quoted = s;
- if (quote) {
+ if (!isNamedAttribute) {
quoted = quote(s);
}
@@ -2538,11 +2539,19 @@
} else if (c == boolean.class) {
return Boolean.valueOf(s).toString();
} else if (c == Boolean.class) {
- return "new Boolean(" + Boolean.valueOf(s).toString() + ")";
+ if (isNamedAttribute)
+ return "new Boolean(" + s + ")";
+ else
+ // Detect format error at translation time
+ return "new Boolean(" + Boolean.valueOf(s).toString() + ")";
} else if (c == byte.class) {
return "((byte)" + Byte.valueOf(s).toString() + ")";
} else if (c == Byte.class) {
- return "new Byte((byte)" + Byte.valueOf(s).toString() + ")";
+ if (isNamedAttribute)
+ return "new Byte(" + s + ")";
+ else
+ // Detect format error at translation time
+ return "new Byte((byte)" + Byte.valueOf(s).toString() + ")";
} else if (c == char.class) {
// non-normative (normative method would fail to compile)
if (s.length() > 0) {
@@ -2554,35 +2563,59 @@
err.getString("jsp.error.bad_string_char"));
}
} else if (c == Character.class) {
- // non-normative (normative method would fail to compile)
- if (s.length() > 0) {
- char ch = s.charAt(0);
- // this trick avoids escaping issues
- return "new Character((char) " + (int) ch + ")";
+ if (isNamedAttribute) {
+ return "org.apache.jasper.runtime.JspRuntimeLibrary.getCharacter("
+ s + ")";
} else {
- throw new NumberFormatException(
- err.getString("jsp.error.bad_string_Character"));
+ // non-normative (normative method would fail to compile)
+ if (s.length() > 0) {
+ char ch = s.charAt(0);
+ // this trick avoids escaping issues
+ return "new Character((char) " + (int) ch + ")";
+ } else {
+ throw new NumberFormatException(
+ err.getString("jsp.error.bad_string_Character"));
+ }
}
} else if (c == double.class) {
return Double.valueOf(s).toString();
} else if (c == Double.class) {
- return "new Double(" + Double.valueOf(s).toString() + ")";
+ if (isNamedAttribute)
+ return "new Double(" + s + ")";
+ else
+ // Detect format error at translation time
+ return "new Double(" + Double.valueOf(s).toString() + ")";
} else if (c == float.class) {
return Float.valueOf(s).toString() + "f";
} else if (c == Float.class) {
- return "new Float(" + Float.valueOf(s).toString() + "f)";
+ if (isNamedAttribute)
+ return "new Float(" + s + ")";
+ else
+ // Detect format error at translation time
+ return "new Float(" + Float.valueOf(s).toString() + "f)";
} else if (c == int.class) {
return Integer.valueOf(s).toString();
} else if (c == Integer.class) {
- return "new Integer(" + Integer.valueOf(s).toString() + ")";
+ if (isNamedAttribute)
+ return "new Integer(" + s + ")";
+ else
+ // Detect format error at translation time
+ return "new Integer(" + Integer.valueOf(s).toString() + ")";
} else if (c == short.class) {
return "((short) " + Short.valueOf(s).toString() + ")";
} else if (c == Short.class) {
- return "new Short(" + Short.valueOf(s).toString() + ")";
+ if (isNamedAttribute)
+ return "new Short(" + s + ")";
+ else
+ // Detect format error at translation time
+ return "new Short(\"" + Short.valueOf(s).toString() + "\")";
} else if (c == long.class) {
return Long.valueOf(s).toString() + "l";
} else if (c == Long.class) {
- return "new Long(" + Long.valueOf(s).toString() + "l)";
+ if (isNamedAttribute)
+ return "new Long(" + s + ")";
+ else
+ // Detect format error at translation time
+ return "new Long(" + Long.valueOf(s).toString() + "l)";
} else if (c == Object.class) {
return "new String(" + quoted + ")";
} else {
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>