luehe       2002/12/12 15:31:52

  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 whose associated attributes are of primitive type
  
  Revision  Changes    Path
  1.12      +10 -3     
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.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- JspRuntimeLibrary.java    11 Dec 2002 22:34:06 -0000      1.11
  +++ JspRuntimeLibrary.java    12 Dec 2002 23:31:51 -0000      1.12
  @@ -142,6 +142,13 @@
        return new Character(s.charAt(0));
       }
   
  +    public static char getChar(String s) throws JasperException {
  +     if (s.length() == 0) {
  +         err.jspError("jsp.error.bad_string_Character");
  +     }
  +     return s.charAt(0);
  +    }
  +
      // __begin convertMethod
       public static Object convert(String propertyName, String s, Class t,
                                 Class propertyEditorClass) 
  
  
  
  1.141     +38 -16    
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.140
  retrieving revision 1.141
  diff -u -r1.140 -r1.141
  --- Generator.java    12 Dec 2002 03:30:58 -0000      1.140
  +++ Generator.java    12 Dec 2002 23:31:51 -0000      1.141
  @@ -2537,7 +2537,10 @@
            } else if (c == String.class) {
                return quoted;
            } else if (c == boolean.class) {
  -             return Boolean.valueOf(s).toString();
  +             if (isNamedAttribute)
  +                 return "Boolean.valueOf(" + s + ").booleanValue()";
  +             else
  +                 return Boolean.valueOf(s).toString();
            } else if (c == Boolean.class) {
                if (isNamedAttribute)
                    return "new Boolean(" + s + ")";
  @@ -2553,14 +2556,18 @@
                    // 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) {
  -                 char ch = s.charAt(0);
  -                 // this trick avoids escaping issues
  -                 return "((char) " + (int) ch + ")";
  +             if (isNamedAttribute) {
  +                 return "org.apache.jasper.runtime.JspRuntimeLibrary.getChar(" + s 
+ ")";
                } else {
  -                 throw new NumberFormatException(
  -                        err.getString("jsp.error.bad_string_char"));
  +                 // non-normative (normative method would fail to compile)
  +                 if (s.length() > 0) {
  +                     char ch = s.charAt(0);
  +                     // this trick avoids escaping issues
  +                     return "((char) " + (int) ch + ")";
  +                 } else {
  +                     throw new NumberFormatException(
  +                                err.getString("jsp.error.bad_string_char"));
  +                 }
                }
            } else if (c == Character.class) {
                if (isNamedAttribute) {
  @@ -2577,7 +2584,10 @@
                    }
                }
            } else if (c == double.class) {
  -             return Double.valueOf(s).toString();
  +             if (isNamedAttribute)
  +                 return "Double.valueOf(" + s + ").doubleValue()";
  +             else
  +                 return Double.valueOf(s).toString();
            } else if (c == Double.class) {
                if (isNamedAttribute)
                    return "new Double(" + s + ")";
  @@ -2585,7 +2595,10 @@
                    // Detect format error at translation time
                    return "new Double(" + Double.valueOf(s).toString() + ")";
            } else if (c == float.class) {
  -             return Float.valueOf(s).toString() + "f";
  +             if (isNamedAttribute)
  +                 return "Float.valueOf(" + s + ").floatValue()";
  +             else
  +                 return Float.valueOf(s).toString() + "f";
            } else if (c == Float.class) {
                if (isNamedAttribute)
                    return "new Float(" + s + ")";
  @@ -2593,7 +2606,10 @@
                    // Detect format error at translation time
                    return "new Float(" + Float.valueOf(s).toString() + "f)";
            } else if (c == int.class) {
  -             return Integer.valueOf(s).toString();
  +             if (isNamedAttribute)
  +                 return "Integer.valueOf(" + s + ").intValue()";
  +             else
  +                 return Integer.valueOf(s).toString();
            } else if (c == Integer.class) {
                if (isNamedAttribute)
                    return "new Integer(" + s + ")";
  @@ -2601,7 +2617,10 @@
                    // Detect format error at translation time
                    return "new Integer(" + Integer.valueOf(s).toString() + ")";
            } else if (c == short.class) {
  -             return "((short) " + Short.valueOf(s).toString() + ")";
  +             if (isNamedAttribute)
  +                 return "Short.valueOf(" + s + ").shortValue()";
  +             else
  +                 return "((short) " + Short.valueOf(s).toString() + ")";
            } else if (c == Short.class) {
                if (isNamedAttribute)
                    return "new Short(" + s + ")";
  @@ -2609,7 +2628,10 @@
                    // Detect format error at translation time
                    return "new Short(\"" + Short.valueOf(s).toString() + "\")";
            } else if (c == long.class) {
  -             return Long.valueOf(s).toString() + "l";
  +             if (isNamedAttribute)
  +                 return "Long.valueOf(" + s + ").longValue()";
  +             else
  +                 return Long.valueOf(s).toString() + "l";
            } else if (c == Long.class) {
                if (isNamedAttribute)
                    return "new Long(" + s + ")";
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to