From 3ce04ef0829fb8c48c55c5f496b323205d727599 Mon Sep 17 00:00:00 2001 From: markt Date: Wed, 26 Nov 2008 21:41:03 +0000 Subject: [PATCH] Tabs -> 8 spaces git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@720991 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/jasper/runtime/JspRuntimeLibrary.java | 964 ++++++++++----------- 1 file changed, 482 insertions(+), 482 deletions(-) diff --git a/java/org/apache/jasper/runtime/JspRuntimeLibrary.java b/java/org/apache/jasper/runtime/JspRuntimeLibrary.java index 02d21ddf8..e5644f3c0 100644 --- a/java/org/apache/jasper/runtime/JspRuntimeLibrary.java +++ b/java/org/apache/jasper/runtime/JspRuntimeLibrary.java @@ -56,34 +56,34 @@ import org.apache.jasper.compiler.Localizer; public class JspRuntimeLibrary { private static final String SERVLET_EXCEPTION - = "javax.servlet.error.exception"; + = "javax.servlet.error.exception"; private static final String JSP_EXCEPTION - = "javax.servlet.jsp.jspException"; + = "javax.servlet.jsp.jspException"; protected static class PrivilegedIntrospectHelper - implements PrivilegedExceptionAction { + implements PrivilegedExceptionAction { - private Object bean; - private String prop; - private String value; - private ServletRequest request; - private String param; - private boolean ignoreMethodNF; + private Object bean; + private String prop; + private String value; + private ServletRequest request; + private String param; + private boolean ignoreMethodNF; PrivilegedIntrospectHelper(Object bean, String prop, String value, ServletRequest request, String param, boolean ignoreMethodNF) { - this.bean = bean; - this.prop = prop; - this.value = value; + this.bean = bean; + this.prop = prop; + this.value = value; this.request = request; - this.param = param; - this.ignoreMethodNF = ignoreMethodNF; + this.param = param; + this.ignoreMethodNF = ignoreMethodNF; } public Object run() throws JasperException { - internalIntrospecthelper( + internalIntrospecthelper( bean,prop,value,request,param,ignoreMethodNF); return null; } @@ -99,134 +99,134 @@ public class JspRuntimeLibrary { * variable is initialized. */ public static Throwable getThrowable(ServletRequest request) { - Throwable error = (Throwable) request.getAttribute(SERVLET_EXCEPTION); - if (error == null) { - error = (Throwable) request.getAttribute(JSP_EXCEPTION); - if (error != null) { - /* - * The only place that sets JSP_EXCEPTION is - * PageContextImpl.handlePageException(). It really should set - * SERVLET_EXCEPTION, but that would interfere with the - * ErrorReportValve. Therefore, if JSP_EXCEPTION is set, we - * need to set SERVLET_EXCEPTION. - */ - request.setAttribute(SERVLET_EXCEPTION, error); - } - } - - return error; + Throwable error = (Throwable) request.getAttribute(SERVLET_EXCEPTION); + if (error == null) { + error = (Throwable) request.getAttribute(JSP_EXCEPTION); + if (error != null) { + /* + * The only place that sets JSP_EXCEPTION is + * PageContextImpl.handlePageException(). It really should set + * SERVLET_EXCEPTION, but that would interfere with the + * ErrorReportValve. Therefore, if JSP_EXCEPTION is set, we + * need to set SERVLET_EXCEPTION. + */ + request.setAttribute(SERVLET_EXCEPTION, error); + } + } + + return error; } public static boolean coerceToBoolean(String s) { - if (s == null || s.length() == 0) - return false; - else - return Boolean.valueOf(s).booleanValue(); + if (s == null || s.length() == 0) + return false; + else + return Boolean.valueOf(s).booleanValue(); } public static byte coerceToByte(String s) { - if (s == null || s.length() == 0) - return (byte) 0; - else - return Byte.valueOf(s).byteValue(); + if (s == null || s.length() == 0) + return (byte) 0; + else + return Byte.valueOf(s).byteValue(); } public static char coerceToChar(String s) { - if (s == null || s.length() == 0) { - return (char) 0; - } else { - // this trick avoids escaping issues - return (char)(int) s.charAt(0); - } + if (s == null || s.length() == 0) { + return (char) 0; + } else { + // this trick avoids escaping issues + return (char)(int) s.charAt(0); + } } public static double coerceToDouble(String s) { - if (s == null || s.length() == 0) - return (double) 0; - else - return Double.valueOf(s).doubleValue(); + if (s == null || s.length() == 0) + return (double) 0; + else + return Double.valueOf(s).doubleValue(); } public static float coerceToFloat(String s) { - if (s == null || s.length() == 0) - return (float) 0; - else - return Float.valueOf(s).floatValue(); + if (s == null || s.length() == 0) + return (float) 0; + else + return Float.valueOf(s).floatValue(); } public static int coerceToInt(String s) { - if (s == null || s.length() == 0) - return 0; - else - return Integer.valueOf(s).intValue(); + if (s == null || s.length() == 0) + return 0; + else + return Integer.valueOf(s).intValue(); } public static short coerceToShort(String s) { - if (s == null || s.length() == 0) - return (short) 0; - else - return Short.valueOf(s).shortValue(); + if (s == null || s.length() == 0) + return (short) 0; + else + return Short.valueOf(s).shortValue(); } public static long coerceToLong(String s) { - if (s == null || s.length() == 0) - return (long) 0; - else - return Long.valueOf(s).longValue(); + if (s == null || s.length() == 0) + return (long) 0; + else + return Long.valueOf(s).longValue(); } public static Object coerce(String s, Class target) { - boolean isNullOrEmpty = (s == null || s.length() == 0); - - if (target == Boolean.class) { - if (isNullOrEmpty) { - s = "false"; - } - return new Boolean(s); - } else if (target == Byte.class) { - if (isNullOrEmpty) - return new Byte((byte) 0); - else - return new Byte(s); - } else if (target == Character.class) { - if (isNullOrEmpty) - return new Character((char) 0); - else - return new Character(s.charAt(0)); - } else if (target == Double.class) { - if (isNullOrEmpty) - return new Double(0); - else - return new Double(s); - } else if (target == Float.class) { - if (isNullOrEmpty) - return new Float(0); - else - return new Float(s); - } else if (target == Integer.class) { - if (isNullOrEmpty) - return new Integer(0); - else - return new Integer(s); - } else if (target == Short.class) { - if (isNullOrEmpty) - return new Short((short) 0); - else - return new Short(s); - } else if (target == Long.class) { - if (isNullOrEmpty) - return new Long(0); - else - return new Long(s); - } else { - return null; - } + boolean isNullOrEmpty = (s == null || s.length() == 0); + + if (target == Boolean.class) { + if (isNullOrEmpty) { + s = "false"; + } + return new Boolean(s); + } else if (target == Byte.class) { + if (isNullOrEmpty) + return new Byte((byte) 0); + else + return new Byte(s); + } else if (target == Character.class) { + if (isNullOrEmpty) + return new Character((char) 0); + else + return new Character(s.charAt(0)); + } else if (target == Double.class) { + if (isNullOrEmpty) + return new Double(0); + else + return new Double(s); + } else if (target == Float.class) { + if (isNullOrEmpty) + return new Float(0); + else + return new Float(s); + } else if (target == Integer.class) { + if (isNullOrEmpty) + return new Integer(0); + else + return new Integer(s); + } else if (target == Short.class) { + if (isNullOrEmpty) + return new Short((short) 0); + else + return new Short(s); + } else if (target == Long.class) { + if (isNullOrEmpty) + return new Long(0); + else + return new Long(s); + } else { + return null; + } } // __begin convertMethod public static Object convert(String propertyName, String s, Class t, - Class propertyEditorClass) + Class propertyEditorClass) throws JasperException { try { @@ -236,10 +236,10 @@ public class JspRuntimeLibrary { else return null; } - if (propertyEditorClass != null) { - return getValueFromBeanInfoPropertyEditor( - t, propertyName, s, propertyEditorClass); - } else if ( t.equals(Boolean.class) || t.equals(Boolean.TYPE) ) { + if (propertyEditorClass != null) { + return getValueFromBeanInfoPropertyEditor( + t, propertyName, s, propertyEditorClass); + } else if ( t.equals(Boolean.class) || t.equals(Boolean.TYPE) ) { if (s.equalsIgnoreCase("on") || s.equalsIgnoreCase("true")) s = "true"; else @@ -265,8 +265,8 @@ public class JspRuntimeLibrary { return new java.io.File(s); } else if (t.getName().equals("java.lang.Object")) { return new Object[] {s}; - } else { - return getValueFromPropertyEditorManager( + } else { + return getValueFromPropertyEditorManager( t, propertyName, s); } } catch (Exception ex) { @@ -279,12 +279,12 @@ public class JspRuntimeLibrary { public static void introspect(Object bean, ServletRequest request) throws JasperException { - Enumeration e = request.getParameterNames(); - while ( e.hasMoreElements() ) { - String name = (String) e.nextElement(); - String value = request.getParameter(name); - introspecthelper(bean, name, value, request, name, true); - } + Enumeration e = request.getParameterNames(); + while ( e.hasMoreElements() ) { + String name = (String) e.nextElement(); + String value = request.getParameter(name); + introspecthelper(bean, name, value, request, name, true); + } } // __end introspectMethod @@ -297,8 +297,8 @@ public class JspRuntimeLibrary { if( Constants.IS_SECURITY_ENABLED ) { try { PrivilegedIntrospectHelper dp = - new PrivilegedIntrospectHelper( - bean,prop,value,request,param,ignoreMethodNF); + new PrivilegedIntrospectHelper( + bean,prop,value,request,param,ignoreMethodNF); AccessController.doPrivileged(dp); } catch( PrivilegedActionException pe) { Exception e = pe.getException(); @@ -306,72 +306,72 @@ public class JspRuntimeLibrary { } } else { internalIntrospecthelper( - bean,prop,value,request,param,ignoreMethodNF); + bean,prop,value,request,param,ignoreMethodNF); } } private static void internalIntrospecthelper(Object bean, String prop, - String value, ServletRequest request, - String param, boolean ignoreMethodNF) - throws JasperException + String value, ServletRequest request, + String param, boolean ignoreMethodNF) + throws JasperException { Method method = null; Class type = null; Class propertyEditorClass = null; - try { - java.beans.BeanInfo info - = java.beans.Introspector.getBeanInfo(bean.getClass()); - if ( info != null ) { - java.beans.PropertyDescriptor pd[] - = info.getPropertyDescriptors(); - for (int i = 0 ; i < pd.length ; i++) { - if ( pd[i].getName().equals(prop) ) { - method = pd[i].getWriteMethod(); - type = pd[i].getPropertyType(); - propertyEditorClass = pd[i].getPropertyEditorClass(); - break; - } - } - } - if ( method != null ) { - if (type.isArray()) { + try { + java.beans.BeanInfo info + = java.beans.Introspector.getBeanInfo(bean.getClass()); + if ( info != null ) { + java.beans.PropertyDescriptor pd[] + = info.getPropertyDescriptors(); + for (int i = 0 ; i < pd.length ; i++) { + if ( pd[i].getName().equals(prop) ) { + method = pd[i].getWriteMethod(); + type = pd[i].getPropertyType(); + propertyEditorClass = pd[i].getPropertyEditorClass(); + break; + } + } + } + if ( method != null ) { + if (type.isArray()) { if (request == null) { - throw new JasperException( - Localizer.getMessage("jsp.error.beans.setproperty.noindexset")); + throw new JasperException( + Localizer.getMessage("jsp.error.beans.setproperty.noindexset")); + } + Class t = type.getComponentType(); + String[] values = request.getParameterValues(param); + //XXX Please check. + if(values == null) return; + if(t.equals(String.class)) { + method.invoke(bean, new Object[] { values }); + } else { + Object tmpval = null; + createTypedArray (prop, bean, method, values, t, + propertyEditorClass); } - Class t = type.getComponentType(); - String[] values = request.getParameterValues(param); - //XXX Please check. - if(values == null) return; - if(t.equals(String.class)) { - method.invoke(bean, new Object[] { values }); - } else { - Object tmpval = null; - createTypedArray (prop, bean, method, values, t, - propertyEditorClass); - } - } else { - if(value == null || (param != null && value.equals(""))) return; - Object oval = convert(prop, value, type, propertyEditorClass); - if ( oval != null ) - method.invoke(bean, new Object[] { oval }); - } - } - } catch (Exception ex) { - throw new JasperException(ex); - } + } else { + if(value == null || (param != null && value.equals(""))) return; + Object oval = convert(prop, value, type, propertyEditorClass); + if ( oval != null ) + method.invoke(bean, new Object[] { oval }); + } + } + } catch (Exception ex) { + throw new JasperException(ex); + } if (!ignoreMethodNF && (method == null)) { if (type == null) { - throw new JasperException( + throw new JasperException( Localizer.getMessage("jsp.error.beans.noproperty", - prop, - bean.getClass().getName())); + prop, + bean.getClass().getName())); } else { - throw new JasperException( - Localizer.getMessage("jsp.error.beans.nomethod.setproperty", - prop, - type.getName(), - bean.getClass().getName())); + throw new JasperException( + Localizer.getMessage("jsp.error.beans.nomethod.setproperty", + prop, + type.getName(), + bean.getClass().getName())); } } } @@ -425,113 +425,113 @@ public class JspRuntimeLibrary { * the request and the property is indexed. */ public static void createTypedArray(String propertyName, - Object bean, - Method method, - String[] values, - Class t, - Class propertyEditorClass) - throws JasperException { - - try { - if (propertyEditorClass != null) { - Object[] tmpval = new Integer[values.length]; - for (int i=0; i>4) & 0xf, 16)); - out.append(Character.forDigit(ba[j] & 0xf, 16)); - } - buf.reset(); - } - } - return out.toString(); + if (s == null) { + return "null"; + } + + if (enc == null) { + enc = "ISO-8859-1"; // The default request encoding + } + + StringBuffer out = new StringBuffer(s.length()); + ByteArrayOutputStream buf = new ByteArrayOutputStream(); + OutputStreamWriter writer = null; + try { + writer = new OutputStreamWriter(buf, enc); + } catch (java.io.UnsupportedEncodingException ex) { + // Use the default encoding? + writer = new OutputStreamWriter(buf); + } + + for (int i = 0; i < s.length(); i++) { + int c = s.charAt(i); + if (c == ' ') { + out.append('+'); + } else if (isSafeChar(c)) { + out.append((char)c); + } else { + // convert to external encoding before hex conversion + try { + writer.write(c); + writer.flush(); + } catch(IOException e) { + buf.reset(); + continue; + } + byte[] ba = buf.toByteArray(); + for (int j = 0; j < ba.length; j++) { + out.append('%'); + // Converting each byte in the buffer + out.append(Character.forDigit((ba[j]>>4) & 0xf, 16)); + out.append(Character.forDigit(ba[j] & 0xf, 16)); + } + buf.reset(); + } + } + return out.toString(); } private static boolean isSafeChar(int c) { - if (c >= 'a' && c <= 'z') { - return true; - } - if (c >= 'A' && c <= 'Z') { - return true; - } - if (c >= '0' && c <= '9') { - return true; - } - if (c == '-' || c == '_' || c == '.' || c == '!' || - c == '~' || c == '*' || c == '\'' || c == '(' || c == ')') { - return true; - } - return false; + if (c >= 'a' && c <= 'z') { + return true; + } + if (c >= 'A' && c <= 'Z') { + return true; + } + if (c >= '0' && c <= '9') { + return true; + } + if (c == '-' || c == '_' || c == '.' || c == '!' || + c == '~' || c == '*' || c == '\'' || c == '(' || c == ')') { + return true; + } + return false; } } -- 2.11.0