View | Details | Raw Unified | Return to bug 46819
Collapse All | Expand All

(-)JspRuntimeLibrary.java (-45 / +45 lines)
Lines 121-134 Link Here
121
        if (s == null || s.length() == 0)
121
        if (s == null || s.length() == 0)
122
            return false;
122
            return false;
123
        else
123
        else
124
            return Boolean.valueOf(s).booleanValue();
124
            return Boolean.parseBoolean(s);
125
    }
125
    }
126
126
127
    public static byte coerceToByte(String s) {
127
    public static byte coerceToByte(String s) {
128
        if (s == null || s.length() == 0)
128
        if (s == null || s.length() == 0)
129
            return (byte) 0;
129
            return (byte) 0;
130
        else
130
        else
131
            return Byte.valueOf(s).byteValue();
131
            return Byte.parseByte(s);
132
    }
132
    }
133
133
134
    public static char coerceToChar(String s) {
134
    public static char coerceToChar(String s) {
Lines 144-178 Link Here
144
        if (s == null || s.length() == 0)
144
        if (s == null || s.length() == 0)
145
            return 0;
145
            return 0;
146
        else
146
        else
147
            return Double.valueOf(s).doubleValue();
147
            return Double.parseDouble(s);
148
    }
148
    }
149
149
150
    public static float coerceToFloat(String s) {
150
    public static float coerceToFloat(String s) {
151
        if (s == null || s.length() == 0)
151
        if (s == null || s.length() == 0)
152
            return 0;
152
            return 0;
153
        else
153
        else
154
            return Float.valueOf(s).floatValue();
154
            return Float.parseFloat(s);
155
    }
155
    }
156
156
157
    public static int coerceToInt(String s) {
157
    public static int coerceToInt(String s) {
158
        if (s == null || s.length() == 0)
158
        if (s == null || s.length() == 0)
159
            return 0;
159
            return 0;
160
        else
160
        else
161
            return Integer.valueOf(s).intValue();
161
            return Integer.parseInt(s);
162
    }
162
    }
163
163
164
    public static short coerceToShort(String s) {
164
    public static short coerceToShort(String s) {
165
        if (s == null || s.length() == 0)
165
        if (s == null || s.length() == 0)
166
            return (short) 0;
166
            return (short) 0;
167
        else
167
        else
168
            return Short.valueOf(s).shortValue();
168
            return Short.parseShort(s);
169
    }
169
    }
170
170
171
    public static long coerceToLong(String s) {
171
    public static long coerceToLong(String s) {
172
        if (s == null || s.length() == 0)
172
        if (s == null || s.length() == 0)
173
            return 0;
173
            return 0;
174
        else
174
        else
175
            return Long.valueOf(s).longValue();
175
            return Long.parseLong(s);
176
    }
176
    }
177
177
178
    public static Object coerce(String s, Class<?> target) {
178
    public static Object coerce(String s, Class<?> target) {
Lines 183-224 Link Here
183
            if (isNullOrEmpty) {
183
            if (isNullOrEmpty) {
184
                s = "false";
184
                s = "false";
185
            }
185
            }
186
            return new Boolean(s);
186
            return Boolean.valueOf(s);
187
        } else if (target == Byte.class) {
187
        } else if (target == Byte.class) {
188
            if (isNullOrEmpty)
188
            if (isNullOrEmpty)
189
                return new Byte((byte) 0);
189
                return Byte.valueOf((byte) 0);
190
            else
190
            else
191
                return new Byte(s);
191
                return Byte.valueOf(s);
192
        } else if (target == Character.class) {
192
        } else if (target == Character.class) {
193
            if (isNullOrEmpty)
193
            if (isNullOrEmpty)
194
                return new Character((char) 0);
194
                return Character.valueOf((char) 0);
195
            else 
195
            else 
196
                return new Character(s.charAt(0));
196
                return Character.valueOf(s.charAt(0));
197
        } else if (target == Double.class) {
197
        } else if (target == Double.class) {
198
            if (isNullOrEmpty)
198
            if (isNullOrEmpty)
199
                return new Double(0);
199
                return Double.valueOf(0);
200
            else
200
            else
201
                return new Double(s);
201
                return Double.valueOf(s);
202
        } else if (target == Float.class) {
202
        } else if (target == Float.class) {
203
            if (isNullOrEmpty)
203
            if (isNullOrEmpty)
204
                return new Float(0);
204
                return Float.valueOf(0);
205
            else
205
            else
206
                return new Float(s);
206
                return Float.valueOf(s);
207
        } else if (target == Integer.class) {
207
        } else if (target == Integer.class) {
208
            if (isNullOrEmpty)
208
            if (isNullOrEmpty)
209
                return new Integer(0);
209
                return Integer.valueOf(0);
210
            else
210
            else
211
                return new Integer(s);
211
                return Integer.valueOf(s);
212
        } else if (target == Short.class) {
212
        } else if (target == Short.class) {
213
            if (isNullOrEmpty)
213
            if (isNullOrEmpty)
214
                return new Short((short) 0);
214
                return Short.valueOf((short) 0);
215
            else
215
            else
216
                return new Short(s);
216
                return Short.valueOf(s);
217
        } else if (target == Long.class) {
217
        } else if (target == Long.class) {
218
            if (isNullOrEmpty)
218
            if (isNullOrEmpty)
219
                return new Long(0);
219
                return Long.valueOf(0L);
220
            else
220
            else
221
                return new Long(s);
221
                return Long.valueOf(s);
222
        } else {
222
        } else {
223
            return null;
223
            return null;
224
        }
224
        }
Lines 244-264 Link Here
244
                    s = "true";
244
                    s = "true";
245
                else
245
                else
246
                    s = "false";
246
                    s = "false";
247
                return new Boolean(s);
247
                return Boolean.valueOf(s);
248
            } else if ( t.equals(Byte.class) || t.equals(Byte.TYPE) ) {
248
            } else if ( t.equals(Byte.class) || t.equals(Byte.TYPE) ) {
249
                return new Byte(s);
249
                return Byte.valueOf(s);
250
            } else if (t.equals(Character.class) || t.equals(Character.TYPE)) {
250
            } else if (t.equals(Character.class) || t.equals(Character.TYPE)) {
251
                return s.length() > 0 ? new Character(s.charAt(0)) : null;
251
                return s.length() > 0 ? new Character(s.charAt(0)) : null;
252
            } else if ( t.equals(Short.class) || t.equals(Short.TYPE) ) {
252
            } else if ( t.equals(Short.class) || t.equals(Short.TYPE) ) {
253
                return new Short(s);
253
                return Short.valueOf(s);
254
            } else if ( t.equals(Integer.class) || t.equals(Integer.TYPE) ) {
254
            } else if ( t.equals(Integer.class) || t.equals(Integer.TYPE) ) {
255
                return new Integer(s);
255
                return Integer.valueOf(s);
256
            } else if ( t.equals(Float.class) || t.equals(Float.TYPE) ) {
256
            } else if ( t.equals(Float.class) || t.equals(Float.TYPE) ) {
257
                return new Float(s);
257
                return Float.valueOf(s);
258
            } else if ( t.equals(Long.class) || t.equals(Long.TYPE) ) {
258
            } else if ( t.equals(Long.class) || t.equals(Long.TYPE) ) {
259
                return new Long(s);
259
                return Long.valueOf(s);
260
            } else if ( t.equals(Double.class) || t.equals(Double.TYPE) ) {
260
            } else if ( t.equals(Double.class) || t.equals(Double.TYPE) ) {
261
                return new Double(s);
261
                return Double.valueOf(s);
262
            } else if ( t.equals(String.class) ) {
262
            } else if ( t.equals(String.class) ) {
263
                return s;
263
                return s;
264
            } else if ( t.equals(java.io.File.class) ) {
264
            } else if ( t.equals(java.io.File.class) ) {
Lines 385-419 Link Here
385
    }
385
    }
386
386
387
    public static String toString(byte b) {
387
    public static String toString(byte b) {
388
        return new Byte(b).toString();
388
        return Byte.toString(b);
389
    }
389
    }
390
390
391
    public static String toString(boolean b) {
391
    public static String toString(boolean b) {
392
        return new Boolean(b).toString();
392
        return Boolean.toString(b);
393
    }
393
    }
394
394
395
    public static String toString(short s) {
395
    public static String toString(short s) {
396
        return new Short(s).toString();
396
        return Short.toString(s);
397
    }
397
    }
398
398
399
    public static String toString(int i) {
399
    public static String toString(int i) {
400
        return new Integer(i).toString();
400
        return Integer.toString(i);
401
    }
401
    }
402
402
403
    public static String toString(float f) {
403
    public static String toString(float f) {
404
        return new Float(f).toString();
404
        return Float.toString(f);
405
    }
405
    }
406
406
407
    public static String toString(long l) {
407
    public static String toString(long l) {
408
        return new Long(l).toString();
408
        return Long.toString(l);
409
    }
409
    }
410
410
411
    public static String toString(double d) {
411
    public static String toString(double d) {
412
        return new Double(d).toString();
412
        return Double.toString(d);
413
    }
413
    }
414
414
415
    public static String toString(char c) {
415
    public static String toString(char c) {
416
        return new Character(c).toString();
416
        return Character.toString(c);
417
    }
417
    }
418
    // __end toStringMethod
418
    // __end toStringMethod
419
419
Lines 672-678 Link Here
672
    {
672
    {
673
        try {
673
        try {
674
            Method method = getWriteMethod(bean.getClass(), prop);
674
            Method method = getWriteMethod(bean.getClass(), prop);
675
            method.invoke(bean, new Object[] { new Integer(value) });
675
            method.invoke(bean, new Object[] { Integer.valueOf(value) });
676
        } catch (Exception ex) {
676
        } catch (Exception ex) {
677
            throw new JasperException(ex);
677
            throw new JasperException(ex);
678
        }        
678
        }        
Lines 684-690 Link Here
684
    {
684
    {
685
        try {
685
        try {
686
            Method method = getWriteMethod(bean.getClass(), prop);
686
            Method method = getWriteMethod(bean.getClass(), prop);
687
            method.invoke(bean, new Object[] { new Short(value) });
687
            method.invoke(bean, new Object[] { Short.valueOf(value) });
688
        } catch (Exception ex) {
688
        } catch (Exception ex) {
689
            throw new JasperException(ex);
689
            throw new JasperException(ex);
690
        }        
690
        }        
Lines 696-702 Link Here
696
    {
696
    {
697
        try {
697
        try {
698
            Method method = getWriteMethod(bean.getClass(), prop);
698
            Method method = getWriteMethod(bean.getClass(), prop);
699
            method.invoke(bean, new Object[] { new Long(value) });
699
            method.invoke(bean, new Object[] { Long.valueOf(value) });
700
        } catch (Exception ex) {
700
        } catch (Exception ex) {
701
            throw new JasperException(ex);
701
            throw new JasperException(ex);
702
        }        
702
        }        
Lines 708-714 Link Here
708
    {
708
    {
709
        try {
709
        try {
710
            Method method = getWriteMethod(bean.getClass(), prop);
710
            Method method = getWriteMethod(bean.getClass(), prop);
711
            method.invoke(bean, new Object[] { new Double(value) });
711
            method.invoke(bean, new Object[] { Double.valueOf(value) });
712
        } catch (Exception ex) {
712
        } catch (Exception ex) {
713
            throw new JasperException(ex);
713
            throw new JasperException(ex);
714
        }        
714
        }        
Lines 720-726 Link Here
720
    {
720
    {
721
        try {
721
        try {
722
            Method method = getWriteMethod(bean.getClass(), prop);
722
            Method method = getWriteMethod(bean.getClass(), prop);
723
            method.invoke(bean, new Object[] { new Float(value) });
723
            method.invoke(bean, new Object[] { Float.valueOf(value) });
724
        } catch (Exception ex) {
724
        } catch (Exception ex) {
725
            throw new JasperException(ex);
725
            throw new JasperException(ex);
726
        }        
726
        }        
Lines 732-738 Link Here
732
    {
732
    {
733
        try {
733
        try {
734
            Method method = getWriteMethod(bean.getClass(), prop);
734
            Method method = getWriteMethod(bean.getClass(), prop);
735
            method.invoke(bean, new Object[] { new Character(value) });
735
            method.invoke(bean, new Object[] { Character.valueOf(value) });
736
        } catch (Exception ex) {
736
        } catch (Exception ex) {
737
            throw new JasperException(ex);
737
            throw new JasperException(ex);
738
        }        
738
        }        
Lines 744-750 Link Here
744
    {
744
    {
745
        try {
745
        try {
746
            Method method = getWriteMethod(bean.getClass(), prop);
746
            Method method = getWriteMethod(bean.getClass(), prop);
747
            method.invoke(bean, new Object[] { new Byte(value) });
747
            method.invoke(bean, new Object[] { Byte.valueOf(value) });
748
        } catch (Exception ex) {
748
        } catch (Exception ex) {
749
            throw new JasperException(ex);
749
            throw new JasperException(ex);
750
        }        
750
        }        
Lines 756-762 Link Here
756
    {
756
    {
757
        try {
757
        try {
758
            Method method = getWriteMethod(bean.getClass(), prop);
758
            Method method = getWriteMethod(bean.getClass(), prop);
759
            method.invoke(bean, new Object[] { new Boolean(value) });
759
            method.invoke(bean, new Object[] { Boolean.valueOf(value) });
760
        } catch (Exception ex) {
760
        } catch (Exception ex) {
761
            throw new JasperException(ex);
761
            throw new JasperException(ex);
762
        }        
762
        }        

Return to bug 46819