http://git-wip-us.apache.org/repos/asf/struts/blob/775c82a7/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/runtime/JspRuntimeLibrary.java ---------------------------------------------------------------------- diff --git a/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/runtime/JspRuntimeLibrary.java b/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/runtime/JspRuntimeLibrary.java index dc0d520..5108a32 100644 --- a/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/runtime/JspRuntimeLibrary.java +++ b/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/runtime/JspRuntimeLibrary.java @@ -17,6 +17,18 @@ package org.apache.struts2.jasper.runtime; +import org.apache.struts2.jasper.Constants; +import org.apache.struts2.jasper.JasperException; +import org.apache.struts2.jasper.compiler.Localizer; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.jsp.JspWriter; +import javax.servlet.jsp.PageContext; +import javax.servlet.jsp.tagext.BodyContent; import java.beans.PropertyEditor; import java.beans.PropertyEditorManager; import java.io.ByteArrayOutputStream; @@ -28,207 +40,197 @@ import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; import java.util.Enumeration; -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.jsp.JspWriter; -import javax.servlet.jsp.PageContext; -import javax.servlet.jsp.tagext.BodyContent; - -import org.apache.struts2.jasper.Constants; -import org.apache.struts2.jasper.JasperException; -import org.apache.struts2.jasper.compiler.Localizer; - /** + * <p> * Bunch of util methods that are used by code generated for useBean, - * getProperty and setProperty. + * getProperty and setProperty. + * </p> * + * <p> * The __begin, __end stuff is there so that the JSP engine can * actually parse this file and inline them if people don't want * runtime dependencies on this class. However, I'm not sure if that * works so well right now. It got forgotten at some point. -akv + * </p> * * @author Mandar Raje * @author Shawn Bayern */ 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; + String param, boolean ignoreMethodNF) { + 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( - bean,prop,value,request,param,ignoreMethodNF); + internalIntrospecthelper( + bean, prop, value, request, param, ignoreMethodNF); return null; } } /** - * Returns the value of the javax.servlet.error.exception request - * attribute value, if present, otherwise the value of the - * javax.servlet.jsp.jspException request attribute value. - * * This method is called at the beginning of the generated servlet code * for a JSP error page, when the "exception" implicit scripting language * variable is initialized. + * + * @param request servlet request + * @return the value of the javax.servlet.error.exception request + * attribute value, if present, otherwise the value of the + * javax.servlet.jsp.jspException request attribute value. */ 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) { - /* + 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); - } - } + request.setAttribute(SERVLET_EXCEPTION, error); + } + } - return 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 + // __begin convertMethod public static Object convert(String propertyName, String s, Class t, - Class propertyEditorClass) - throws JasperException - { + Class propertyEditorClass) + throws JasperException { try { if (s == null) { if (t.equals(Boolean.class) || t.equals(Boolean.TYPE)) @@ -236,38 +238,38 @@ 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 s = "false"; return new Boolean(s); - } else if ( t.equals(Byte.class) || t.equals(Byte.TYPE) ) { + } else if (t.equals(Byte.class) || t.equals(Byte.TYPE)) { return new Byte(s); } else if (t.equals(Character.class) || t.equals(Character.TYPE)) { return s.length() > 0 ? new Character(s.charAt(0)) : null; - } else if ( t.equals(Short.class) || t.equals(Short.TYPE) ) { + } else if (t.equals(Short.class) || t.equals(Short.TYPE)) { return new Short(s); - } else if ( t.equals(Integer.class) || t.equals(Integer.TYPE) ) { + } else if (t.equals(Integer.class) || t.equals(Integer.TYPE)) { return new Integer(s); - } else if ( t.equals(Float.class) || t.equals(Float.TYPE) ) { + } else if (t.equals(Float.class) || t.equals(Float.TYPE)) { return new Float(s); - } else if ( t.equals(Long.class) || t.equals(Long.TYPE) ) { + } else if (t.equals(Long.class) || t.equals(Long.TYPE)) { return new Long(s); - } else if ( t.equals(Double.class) || t.equals(Double.TYPE) ) { + } else if (t.equals(Double.class) || t.equals(Double.TYPE)) { return new Double(s); - } else if ( t.equals(String.class) ) { + } else if (t.equals(String.class)) { return s; - } else if ( t.equals(java.io.File.class) ) { + } else if (t.equals(java.io.File.class)) { return new java.io.File(s); } else if (t.getName().equals("java.lang.Object")) { - return new Object[] {s}; - } else { - return getValueFromPropertyEditorManager( - t, propertyName, s); + return new Object[]{s}; + } else { + return getValueFromPropertyEditorManager( + t, propertyName, s); } } catch (Exception ex) { throw new JasperException(ex); @@ -277,106 +279,103 @@ public class JspRuntimeLibrary { // __begin introspectMethod 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); - } + 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); + } } // __end introspectMethod - + // __begin introspecthelperMethod public static void introspecthelper(Object bean, String prop, String value, ServletRequest request, String param, boolean ignoreMethodNF) - throws JasperException - { - if( Constants.IS_SECURITY_ENABLED ) { + throws JasperException { + 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) { + } catch (PrivilegedActionException pe) { Exception e = pe.getException(); - throw (JasperException)e; + throw (JasperException) e; } } 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( - Localizer.getMessage("jsp.error.beans.noproperty", - prop, - bean.getClass().getName())); + throw new JasperException( + Localizer.getMessage("jsp.error.beans.noproperty", + 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())); } } } // __end introspecthelperMethod - + //------------------------------------------------------------------- // functions to convert builtin Java data types to string. //------------------------------------------------------------------- @@ -423,233 +422,256 @@ public class JspRuntimeLibrary { * Create a typed array. * This is a special case where params are passed through * the request and the property is indexed. + * + * @param propertyName name of property + * @param bean bean + * @param method method + * @param values values as string array + * @param t class type + * @param propertyEditorClass property editor class + * + * @throws JasperException in case of Jasper errors */ 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<values.length; i++) { - tmpval[i] = getValueFromBeanInfoPropertyEditor( + 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 < values.length; i++) { + tmpval[i] = getValueFromBeanInfoPropertyEditor( t, propertyName, values[i], propertyEditorClass); - } - method.invoke (bean, new Object[] {tmpval}); - } else if (t.equals(Integer.class)) { - Integer []tmpval = new Integer[values.length]; - for (int i = 0 ; i < values.length; i++) - tmpval[i] = new Integer (values[i]); - method.invoke (bean, new Object[] {tmpval}); - } else if (t.equals(Byte.class)) { - Byte[] tmpval = new Byte[values.length]; - for (int i = 0 ; i < values.length; i++) - tmpval[i] = new Byte (values[i]); - method.invoke (bean, new Object[] {tmpval}); - } else if (t.equals(Boolean.class)) { - Boolean[] tmpval = new Boolean[values.length]; - for (int i = 0 ; i < values.length; i++) - tmpval[i] = new Boolean (values[i]); - method.invoke (bean, new Object[] {tmpval}); - } else if (t.equals(Short.class)) { - Short[] tmpval = new Short[values.length]; - for (int i = 0 ; i < values.length; i++) - tmpval[i] = new Short (values[i]); - method.invoke (bean, new Object[] {tmpval}); - } else if (t.equals(Long.class)) { - Long[] tmpval = new Long[values.length]; - for (int i = 0 ; i < values.length; i++) - tmpval[i] = new Long (values[i]); - method.invoke (bean, new Object[] {tmpval}); - } else if (t.equals(Double.class)) { - Double[] tmpval = new Double[values.length]; - for (int i = 0 ; i < values.length; i++) - tmpval[i] = new Double (values[i]); - method.invoke (bean, new Object[] {tmpval}); - } else if (t.equals(Float.class)) { - Float[] tmpval = new Float[values.length]; - for (int i = 0 ; i < values.length; i++) - tmpval[i] = new Float (values[i]); - method.invoke (bean, new Object[] {tmpval}); - } else if (t.equals(Character.class)) { - Character[] tmpval = new Character[values.length]; - for (int i = 0 ; i < values.length; i++) - tmpval[i] = new Character(values[i].charAt(0)); - method.invoke (bean, new Object[] {tmpval}); - } else if (t.equals(int.class)) { - int []tmpval = new int[values.length]; - for (int i = 0 ; i < values.length; i++) - tmpval[i] = Integer.parseInt (values[i]); - method.invoke (bean, new Object[] {tmpval}); - } else if (t.equals(byte.class)) { - byte[] tmpval = new byte[values.length]; - for (int i = 0 ; i < values.length; i++) - tmpval[i] = Byte.parseByte (values[i]); - method.invoke (bean, new Object[] {tmpval}); - } else if (t.equals(boolean.class)) { - boolean[] tmpval = new boolean[values.length]; - for (int i = 0 ; i < values.length; i++) - tmpval[i] = (Boolean.valueOf(values[i])).booleanValue(); - method.invoke (bean, new Object[] {tmpval}); - } else if (t.equals(short.class)) { - short[] tmpval = new short[values.length]; - for (int i = 0 ; i < values.length; i++) - tmpval[i] = Short.parseShort (values[i]); - method.invoke (bean, new Object[] {tmpval}); - } else if (t.equals(long.class)) { - long[] tmpval = new long[values.length]; - for (int i = 0 ; i < values.length; i++) - tmpval[i] = Long.parseLong (values[i]); - method.invoke (bean, new Object[] {tmpval}); - } else if (t.equals(double.class)) { - double[] tmpval = new double[values.length]; - for (int i = 0 ; i < values.length; i++) - tmpval[i] = Double.valueOf(values[i]).doubleValue(); - method.invoke (bean, new Object[] {tmpval}); - } else if (t.equals(float.class)) { - float[] tmpval = new float[values.length]; - for (int i = 0 ; i < values.length; i++) - tmpval[i] = Float.valueOf(values[i]).floatValue(); - method.invoke (bean, new Object[] {tmpval}); - } else if (t.equals(char.class)) { - char[] tmpval = new char[values.length]; - for (int i = 0 ; i < values.length; i++) - tmpval[i] = values[i].charAt(0); - method.invoke (bean, new Object[] {tmpval}); - } else { - Object[] tmpval = new Integer[values.length]; - for (int i=0; i<values.length; i++) { - tmpval[i] = - getValueFromPropertyEditorManager( - t, propertyName, values[i]); - } - method.invoke (bean, new Object[] {tmpval}); - } - } catch (Exception ex) { - throw new JasperException ("error in invoking method", ex); - } + } + method.invoke(bean, new Object[]{tmpval}); + } else if (t.equals(Integer.class)) { + Integer[] tmpval = new Integer[values.length]; + for (int i = 0; i < values.length; i++) + tmpval[i] = new Integer(values[i]); + method.invoke(bean, new Object[]{tmpval}); + } else if (t.equals(Byte.class)) { + Byte[] tmpval = new Byte[values.length]; + for (int i = 0; i < values.length; i++) + tmpval[i] = new Byte(values[i]); + method.invoke(bean, new Object[]{tmpval}); + } else if (t.equals(Boolean.class)) { + Boolean[] tmpval = new Boolean[values.length]; + for (int i = 0; i < values.length; i++) + tmpval[i] = new Boolean(values[i]); + method.invoke(bean, new Object[]{tmpval}); + } else if (t.equals(Short.class)) { + Short[] tmpval = new Short[values.length]; + for (int i = 0; i < values.length; i++) + tmpval[i] = new Short(values[i]); + method.invoke(bean, new Object[]{tmpval}); + } else if (t.equals(Long.class)) { + Long[] tmpval = new Long[values.length]; + for (int i = 0; i < values.length; i++) + tmpval[i] = new Long(values[i]); + method.invoke(bean, new Object[]{tmpval}); + } else if (t.equals(Double.class)) { + Double[] tmpval = new Double[values.length]; + for (int i = 0; i < values.length; i++) + tmpval[i] = new Double(values[i]); + method.invoke(bean, new Object[]{tmpval}); + } else if (t.equals(Float.class)) { + Float[] tmpval = new Float[values.length]; + for (int i = 0; i < values.length; i++) + tmpval[i] = new Float(values[i]); + method.invoke(bean, new Object[]{tmpval}); + } else if (t.equals(Character.class)) { + Character[] tmpval = new Character[values.length]; + for (int i = 0; i < values.length; i++) + tmpval[i] = new Character(values[i].charAt(0)); + method.invoke(bean, new Object[]{tmpval}); + } else if (t.equals(int.class)) { + int[] tmpval = new int[values.length]; + for (int i = 0; i < values.length; i++) + tmpval[i] = Integer.parseInt(values[i]); + method.invoke(bean, new Object[]{tmpval}); + } else if (t.equals(byte.class)) { + byte[] tmpval = new byte[values.length]; + for (int i = 0; i < values.length; i++) + tmpval[i] = Byte.parseByte(values[i]); + method.invoke(bean, new Object[]{tmpval}); + } else if (t.equals(boolean.class)) { + boolean[] tmpval = new boolean[values.length]; + for (int i = 0; i < values.length; i++) + tmpval[i] = (Boolean.valueOf(values[i])).booleanValue(); + method.invoke(bean, new Object[]{tmpval}); + } else if (t.equals(short.class)) { + short[] tmpval = new short[values.length]; + for (int i = 0; i < values.length; i++) + tmpval[i] = Short.parseShort(values[i]); + method.invoke(bean, new Object[]{tmpval}); + } else if (t.equals(long.class)) { + long[] tmpval = new long[values.length]; + for (int i = 0; i < values.length; i++) + tmpval[i] = Long.parseLong(values[i]); + method.invoke(bean, new Object[]{tmpval}); + } else if (t.equals(double.class)) { + double[] tmpval = new double[values.length]; + for (int i = 0; i < values.length; i++) + tmpval[i] = Double.valueOf(values[i]).doubleValue(); + method.invoke(bean, new Object[]{tmpval}); + } else if (t.equals(float.class)) { + float[] tmpval = new float[values.length]; + for (int i = 0; i < values.length; i++) + tmpval[i] = Float.valueOf(values[i]).floatValue(); + method.invoke(bean, new Object[]{tmpval}); + } else if (t.equals(char.class)) { + char[] tmpval = new char[values.length]; + for (int i = 0; i < values.length; i++) + tmpval[i] = values[i].charAt(0); + method.invoke(bean, new Object[]{tmpval}); + } else { + Object[] tmpval = new Integer[values.length]; + for (int i = 0; i < values.length; i++) { + tmpval[i] = + getValueFromPropertyEditorManager( + t, propertyName, values[i]); + } + method.invoke(bean, new Object[]{tmpval}); + } + } catch (Exception ex) { + throw new JasperException("error in invoking method", ex); + } } /** * Escape special shell characters. + * * @param unescString The string to shell-escape * @return The escaped shell string. */ public static String escapeQueryString(String unescString) { - if ( unescString == null ) - return null; - - String escString = ""; - String shellSpChars = "&;`'\"|*?~<>^()[]{}$\\\n"; - - for(int index=0; index<unescString.length(); index++) { - char nextChar = unescString.charAt(index); - - if( shellSpChars.indexOf(nextChar) != -1 ) - escString += "\\"; - - escString += nextChar; - } - return escString; + if (unescString == null) + return null; + + String escString = ""; + String shellSpChars = "&;`'\"|*?~<>^()[]{}$\\\n"; + + for (int index = 0; index < unescString.length(); index++) { + char nextChar = unescString.charAt(index); + + if (shellSpChars.indexOf(nextChar) != -1) + escString += "\\"; + + escString += nextChar; + } + return escString; } /** * Decode an URL formatted string. + * * @param encoded The string to decode. * @return The decoded string. */ public static String decode(String encoded) { // speedily leave if we're not needed - if (encoded == null) return null; + if (encoded == null) return null; if (encoded.indexOf('%') == -1 && encoded.indexOf('+') == -1) - return encoded; + return encoded; - //allocate the buffer - use byte[] to avoid calls to new. + //allocate the buffer - use byte[] to avoid calls to new. byte holdbuffer[] = new byte[encoded.length()]; char holdchar; int bufcount = 0; for (int count = 0; count < encoded.length(); count++) { - char cur = encoded.charAt(count); + char cur = encoded.charAt(count); if (cur == '%') { - holdbuffer[bufcount++] = - (byte)Integer.parseInt(encoded.substring(count+1,count+3),16); + holdbuffer[bufcount++] = + (byte) Integer.parseInt(encoded.substring(count + 1, count + 3), 16); if (count + 2 >= encoded.length()) count = encoded.length(); else count += 2; } else if (cur == '+') { - holdbuffer[bufcount++] = (byte) ' '; - } else { - holdbuffer[bufcount++] = (byte) cur; + holdbuffer[bufcount++] = (byte) ' '; + } else { + holdbuffer[bufcount++] = (byte) cur; } } - // REVISIT -- remedy for Deprecated warning. - //return new String(holdbuffer,0,0,bufcount); - return new String(holdbuffer,0,bufcount); + // REVISIT -- remedy for Deprecated warning. + //return new String(holdbuffer,0,0,bufcount); + return new String(holdbuffer, 0, bufcount); } // __begin lookupReadMethodMethod public static Object handleGetProperty(Object o, String prop) - throws JasperException { + throws JasperException { if (o == null) { - throw new JasperException( - Localizer.getMessage("jsp.error.beans.nullbean")); + throw new JasperException( + Localizer.getMessage("jsp.error.beans.nullbean")); } - Object value = null; + Object value = null; try { Method method = getReadMethod(o.getClass(), prop); - value = method.invoke(o, (Object[]) null); + value = method.invoke(o, (Object[]) null); } catch (Exception ex) { - throw new JasperException (ex); + throw new JasperException(ex); } return value; } // __end lookupReadMethodMethod // handles <jsp:setProperty> with EL expression for 'value' attribute -/** Use proprietaryEvaluate - public static void handleSetPropertyExpression(Object bean, - String prop, String expression, PageContext pageContext, - VariableResolver variableResolver, FunctionMapper functionMapper ) - throws JasperException - { - try { - Method method = getWriteMethod(bean.getClass(), prop); - method.invoke(bean, new Object[] { - pageContext.getExpressionEvaluator().evaluate( - expression, - method.getParameterTypes()[0], - variableResolver, - functionMapper, - null ) - }); - } catch (Exception ex) { - throw new JasperException(ex); - } - } -**/ + + /** + * Use proprietaryEvaluate + * + * <pre> + * public static void handleSetPropertyExpression(Object bean, + * String prop, String expression, PageContext pageContext, + * VariableResolver variableResolver, FunctionMapper functionMapper ) + * throws JasperException + * { + * try { + * Method method = getWriteMethod(bean.getClass(), prop); + * method.invoke(bean, new Object[] { + * pageContext.getExpressionEvaluator().evaluate( + * expression, + * method.getParameterTypes()[0], + * variableResolver, + * functionMapper, + * null ) + * }); + * } catch (Exception ex) { + * throw new JasperException(ex); + * } + * } + * </pre> + * + * @param bean bean + * @param prop property + * @param expression expression + * @param pageContext page context + * @param functionMapper function mapper + * + * @throws JasperException in case of Jasper errors + */ public static void handleSetPropertyExpression(Object bean, - String prop, String expression, PageContext pageContext, - ProtectedFunctionMapper functionMapper ) - throws JasperException - { + String prop, String expression, PageContext pageContext, + ProtectedFunctionMapper functionMapper) + throws JasperException { try { Method method = getWriteMethod(bean.getClass(), prop); - method.invoke(bean, new Object[] { - PageContextImpl.proprietaryEvaluate( - expression, - method.getParameterTypes()[0], - pageContext, - functionMapper, - false ) + method.invoke(bean, new Object[]{ + PageContextImpl.proprietaryEvaluate( + expression, + method.getParameterTypes()[0], + pageContext, + functionMapper, + false) }); } catch (Exception ex) { throw new JasperException(ex); @@ -657,238 +679,227 @@ public class JspRuntimeLibrary { } public static void handleSetProperty(Object bean, String prop, - Object value) - throws JasperException - { - try { + Object value) + throws JasperException { + try { Method method = getWriteMethod(bean.getClass(), prop); - method.invoke(bean, new Object[] { value }); - } catch (Exception ex) { - throw new JasperException(ex); - } + method.invoke(bean, new Object[]{value}); + } catch (Exception ex) { + throw new JasperException(ex); + } } - + public static void handleSetProperty(Object bean, String prop, - int value) - throws JasperException - { - try { + int value) + throws JasperException { + try { Method method = getWriteMethod(bean.getClass(), prop); - method.invoke(bean, new Object[] { new Integer(value) }); - } catch (Exception ex) { - throw new JasperException(ex); - } + method.invoke(bean, new Object[]{new Integer(value)}); + } catch (Exception ex) { + throw new JasperException(ex); + } } - + public static void handleSetProperty(Object bean, String prop, - short value) - throws JasperException - { - try { + short value) + throws JasperException { + try { Method method = getWriteMethod(bean.getClass(), prop); - method.invoke(bean, new Object[] { new Short(value) }); - } catch (Exception ex) { - throw new JasperException(ex); - } + method.invoke(bean, new Object[]{new Short(value)}); + } catch (Exception ex) { + throw new JasperException(ex); + } } - + public static void handleSetProperty(Object bean, String prop, - long value) - throws JasperException - { - try { + long value) + throws JasperException { + try { Method method = getWriteMethod(bean.getClass(), prop); - method.invoke(bean, new Object[] { new Long(value) }); - } catch (Exception ex) { - throw new JasperException(ex); - } - } - + method.invoke(bean, new Object[]{new Long(value)}); + } catch (Exception ex) { + throw new JasperException(ex); + } + } + public static void handleSetProperty(Object bean, String prop, - double value) - throws JasperException - { - try { + double value) + throws JasperException { + try { Method method = getWriteMethod(bean.getClass(), prop); - method.invoke(bean, new Object[] { new Double(value) }); - } catch (Exception ex) { - throw new JasperException(ex); - } + method.invoke(bean, new Object[]{new Double(value)}); + } catch (Exception ex) { + throw new JasperException(ex); + } } - + public static void handleSetProperty(Object bean, String prop, - float value) - throws JasperException - { - try { + float value) + throws JasperException { + try { Method method = getWriteMethod(bean.getClass(), prop); - method.invoke(bean, new Object[] { new Float(value) }); - } catch (Exception ex) { - throw new JasperException(ex); - } + method.invoke(bean, new Object[]{new Float(value)}); + } catch (Exception ex) { + throw new JasperException(ex); + } } - + public static void handleSetProperty(Object bean, String prop, - char value) - throws JasperException - { - try { + char value) + throws JasperException { + try { Method method = getWriteMethod(bean.getClass(), prop); - method.invoke(bean, new Object[] { new Character(value) }); - } catch (Exception ex) { - throw new JasperException(ex); - } + method.invoke(bean, new Object[]{new Character(value)}); + } catch (Exception ex) { + throw new JasperException(ex); + } } public static void handleSetProperty(Object bean, String prop, - byte value) - throws JasperException - { - try { + byte value) + throws JasperException { + try { Method method = getWriteMethod(bean.getClass(), prop); - method.invoke(bean, new Object[] { new Byte(value) }); - } catch (Exception ex) { - throw new JasperException(ex); - } + method.invoke(bean, new Object[]{new Byte(value)}); + } catch (Exception ex) { + throw new JasperException(ex); + } } - + public static void handleSetProperty(Object bean, String prop, - boolean value) - throws JasperException - { - try { + boolean value) + throws JasperException { + try { Method method = getWriteMethod(bean.getClass(), prop); - method.invoke(bean, new Object[] { new Boolean(value) }); - } catch (Exception ex) { - throw new JasperException(ex); - } + method.invoke(bean, new Object[]{new Boolean(value)}); + } catch (Exception ex) { + throw new JasperException(ex); + } } - + public static Method getWriteMethod(Class beanClass, String prop) - throws JasperException { - Method method = null; + throws JasperException { + Method method = null; Class type = null; - try { - java.beans.BeanInfo info - = java.beans.Introspector.getBeanInfo(beanClass); - 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(); - break; - } - } - } else { + try { + java.beans.BeanInfo info + = java.beans.Introspector.getBeanInfo(beanClass); + 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(); + break; + } + } + } else { // just in case introspection silently fails. throw new JasperException( - Localizer.getMessage("jsp.error.beans.nobeaninfo", - beanClass.getName())); + Localizer.getMessage("jsp.error.beans.nobeaninfo", + beanClass.getName())); } } catch (Exception ex) { - throw new JasperException (ex); + throw new JasperException(ex); } if (method == null) { if (type == null) { - throw new JasperException( + throw new JasperException( Localizer.getMessage("jsp.error.beans.noproperty", - prop, - beanClass.getName())); + prop, + beanClass.getName())); } else { - throw new JasperException( - Localizer.getMessage("jsp.error.beans.nomethod.setproperty", - prop, - type.getName(), - beanClass.getName())); + throw new JasperException( + Localizer.getMessage("jsp.error.beans.nomethod.setproperty", + prop, + type.getName(), + beanClass.getName())); } } return method; } public static Method getReadMethod(Class beanClass, String prop) - throws JasperException { + throws JasperException { - Method method = null; + Method method = null; Class type = null; try { java.beans.BeanInfo info - = java.beans.Introspector.getBeanInfo(beanClass); - if ( info != null ) { + = java.beans.Introspector.getBeanInfo(beanClass); + if (info != null) { java.beans.PropertyDescriptor pd[] - = info.getPropertyDescriptors(); - for (int i = 0 ; i < pd.length ; i++) { - if ( pd[i].getName().equals(prop) ) { + = info.getPropertyDescriptors(); + for (int i = 0; i < pd.length; i++) { + if (pd[i].getName().equals(prop)) { method = pd[i].getReadMethod(); - type = pd[i].getPropertyType(); + type = pd[i].getPropertyType(); break; } } - } else { + } else { // just in case introspection silently fails. - throw new JasperException( - Localizer.getMessage("jsp.error.beans.nobeaninfo", - beanClass.getName())); - } - } catch (Exception ex) { - throw new JasperException (ex); - } + throw new JasperException( + Localizer.getMessage("jsp.error.beans.nobeaninfo", + beanClass.getName())); + } + } catch (Exception ex) { + throw new JasperException(ex); + } if (method == null) { if (type == null) { - throw new JasperException( - Localizer.getMessage("jsp.error.beans.noproperty", prop, - beanClass.getName())); + throw new JasperException( + Localizer.getMessage("jsp.error.beans.noproperty", prop, + beanClass.getName())); } else { - throw new JasperException( - Localizer.getMessage("jsp.error.beans.nomethod", prop, - beanClass.getName())); + throw new JasperException( + Localizer.getMessage("jsp.error.beans.nomethod", prop, + beanClass.getName())); } } - return method; + return method; } //********************************************************************* // PropertyEditor Support public static Object getValueFromBeanInfoPropertyEditor( - Class attrClass, String attrName, String attrValue, - Class propertyEditorClass) - throws JasperException - { - try { - PropertyEditor pe = (PropertyEditor)propertyEditorClass.newInstance(); - pe.setAsText(attrValue); - return pe.getValue(); - } catch (Exception ex) { - throw new JasperException( - Localizer.getMessage("jsp.error.beans.property.conversion", - attrValue, attrClass.getName(), attrName, - ex.getMessage())); - } + Class attrClass, String attrName, String attrValue, + Class propertyEditorClass) + throws JasperException { + try { + PropertyEditor pe = (PropertyEditor) propertyEditorClass.newInstance(); + pe.setAsText(attrValue); + return pe.getValue(); + } catch (Exception ex) { + throw new JasperException( + Localizer.getMessage("jsp.error.beans.property.conversion", + attrValue, attrClass.getName(), attrName, + ex.getMessage())); + } } public static Object getValueFromPropertyEditorManager( - Class attrClass, String attrName, String attrValue) - throws JasperException - { - try { - PropertyEditor propEditor = - PropertyEditorManager.findEditor(attrClass); - if (propEditor != null) { - propEditor.setAsText(attrValue); - return propEditor.getValue(); - } else { - throw new IllegalArgumentException( - Localizer.getMessage("jsp.error.beans.propertyeditor.notregistered")); - } - } catch (IllegalArgumentException ex) { - throw new JasperException( - Localizer.getMessage("jsp.error.beans.property.conversion", - attrValue, attrClass.getName(), attrName, - ex.getMessage())); - } + Class attrClass, String attrName, String attrValue) + throws JasperException { + try { + PropertyEditor propEditor = + PropertyEditorManager.findEditor(attrClass); + if (propEditor != null) { + propEditor.setAsText(attrValue); + return propEditor.getValue(); + } else { + throw new IllegalArgumentException( + Localizer.getMessage("jsp.error.beans.propertyeditor.notregistered")); + } + } catch (IllegalArgumentException ex) { + throw new JasperException( + Localizer.getMessage("jsp.error.beans.property.conversion", + attrValue, attrClass.getName(), attrName, + ex.getMessage())); + } } @@ -901,8 +912,9 @@ public class JspRuntimeLibrary { * Convert a possibly relative resource path into a context-relative * resource path that starts with a '/'. * - * @param request The servlet request we are processing + * @param request The servlet request we are processing * @param relativePath The possibly relative resource path + * @return context-relative resource path */ public static String getContextRelativePath(ServletRequest request, String relativePath) { @@ -935,21 +947,20 @@ public class JspRuntimeLibrary { * Perform a RequestDispatcher.include() operation, with optional flushing * of the response beforehand. * - * @param request The servlet request we are processing - * @param response The servlet response we are processing + * @param request The servlet request we are processing + * @param response The servlet response we are processing * @param relativePath The relative path of the resource to be included - * @param out The Writer to whom we are currently writing - * @param flush Should we flush before the include is processed? - * - * @exception IOException if thrown by the included servlet - * @exception ServletException if thrown by the included servlet + * @param out The Writer to whom we are currently writing + * @param flush Should we flush before the include is processed? + * @throws IOException if thrown by the included servlet + * @throws ServletException if thrown by the included servlet */ public static void include(ServletRequest request, ServletResponse response, String relativePath, JspWriter out, boolean flush) - throws IOException, ServletException { + throws IOException, ServletException { if (flush && !(out instanceof BodyContent)) out.flush(); @@ -965,7 +976,7 @@ public class JspRuntimeLibrary { RequestDispatcher rd = request.getRequestDispatcher(resourcePath); rd.include(request, - new ServletResponseWrapperInclude(response, out)); + new ServletResponseWrapperInclude(response, out)); } @@ -974,73 +985,74 @@ public class JspRuntimeLibrary { * This performs the same function as java.next.URLEncode.encode * in J2SDK1.4, and should be removed if the only platform supported * is 1.4 or higher. - * @param s The String to be URL encoded. - * @param enc The character encoding + * + * @param s The String to be URL encoded. + * @param enc The character encoding * @return The URL encoded String */ public static String URLEncode(String s, String enc) { - 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(); + 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; } }
http://git-wip-us.apache.org/repos/asf/struts/blob/775c82a7/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/runtime/JspSourceDependent.java ---------------------------------------------------------------------- diff --git a/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/runtime/JspSourceDependent.java b/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/runtime/JspSourceDependent.java index ae273a0..ed9abfc 100644 --- a/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/runtime/JspSourceDependent.java +++ b/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/runtime/JspSourceDependent.java @@ -29,7 +29,7 @@ package org.apache.struts2.jasper.runtime; public interface JspSourceDependent { /** - * Returns a list of files names that the current page has a source + * @return a list of files names that the current page has a source * dependency on. */ // FIXME: Type used is Object due to very weird behavior http://git-wip-us.apache.org/repos/asf/struts/blob/775c82a7/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/runtime/JspWriterImpl.java ---------------------------------------------------------------------- diff --git a/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/runtime/JspWriterImpl.java b/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/runtime/JspWriterImpl.java index f1bb279..143ed2f 100644 --- a/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/runtime/JspWriterImpl.java +++ b/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/runtime/JspWriterImpl.java @@ -71,8 +71,9 @@ public class JspWriterImpl extends JspWriter { * * @param response A Servlet Response * @param sz Output-buffer size, a positive integer + * @param autoFlush enable auto flush * - * @exception IllegalArgumentException If sz is <= 0 + * @exception IllegalArgumentException If sz is <= 0 */ public JspWriterImpl(ServletResponse response, int sz, boolean autoFlush) { @@ -107,6 +108,8 @@ public class JspWriterImpl extends JspWriter { * Flush the output buffer to the underlying character stream, without * flushing the stream itself. This method is non-private only so that it * may be invoked by PrintStream. + * + * @throws IOException in case of IO errors */ protected final void flushBuffer() throws IOException { if (bufferSize == 0) @@ -168,6 +171,7 @@ public class JspWriterImpl extends JspWriter { /** * Flush the stream. * + * @throws IOException in case of IO errors */ public void flush() throws IOException { flushBuffer(); @@ -179,6 +183,7 @@ public class JspWriterImpl extends JspWriter { /** * Close the stream. * + * @throws IOException in case of IO errors */ public void close() throws IOException { if (response == null || closed) @@ -198,7 +203,10 @@ public class JspWriterImpl extends JspWriter { return bufferSize - nextChar; } - /** check to make sure that the stream has not been closed */ + /** check to make sure that the stream has not been closed + * + * @throws IOException in case of IO errors + */ private void ensureOpen() throws IOException { if (response == null || closed) throw new IOException("Stream closed"); @@ -207,6 +215,7 @@ public class JspWriterImpl extends JspWriter { /** * Write a single character. + * @throws IOException in case of IO errors */ public void write(int c) throws IOException { ensureOpen(); @@ -246,6 +255,8 @@ public class JspWriterImpl extends JspWriter { * @param cbuf A character array * @param off Offset from which to start reading characters * @param len Number of characters to write + * + * @throws IOException in case of IO errors */ public void write(char cbuf[], int off, int len) throws IOException @@ -296,6 +307,7 @@ public class JspWriterImpl extends JspWriter { /** * Write an array of characters. This method cannot be inherited from the * Writer class because it must suppress I/O exceptions. + * @throws IOException in case of IO errors */ public void write(char buf[]) throws IOException { write(buf, 0, buf.length); @@ -307,6 +319,8 @@ public class JspWriterImpl extends JspWriter { * @param s String to be written * @param off Offset from which to start reading characters * @param len Number of characters to be written + * + * @throws IOException in case of IO errors */ public void write(String s, int off, int len) throws IOException { ensureOpen(); @@ -332,6 +346,8 @@ public class JspWriterImpl extends JspWriter { /** * Write a string. This method cannot be inherited from the Writer class * because it must suppress I/O exceptions. + * + * @throws IOException in case of IO errors */ public void write(String s) throws IOException { // Simple fix for Bugzilla 35410 @@ -351,7 +367,7 @@ public class JspWriterImpl extends JspWriter { * system property <tt>line.separator</tt>, and is not necessarily a single * newline ('\n') character. * - * @exception IOException If an I/O error occurs + * @throws IOException in case of IO errors */ public void newLine() throws IOException { @@ -369,6 +385,8 @@ public class JspWriterImpl extends JspWriter { * #write(int)}</code> method. * * @param b The <code>boolean</code> to be printed + * + * @throws IOException in case of IO errors */ public void print(boolean b) throws IOException { write(b ? "true" : "false"); @@ -381,6 +399,8 @@ public class JspWriterImpl extends JspWriter { * #write(int)}</code> method. * * @param c The <code>char</code> to be printed + * + * @throws IOException in case of IO errors */ public void print(char c) throws IOException { write(String.valueOf(c)); @@ -394,6 +414,8 @@ public class JspWriterImpl extends JspWriter { * method. * * @param i The <code>int</code> to be printed + * + * @throws IOException in case of IO errors */ public void print(int i) throws IOException { write(String.valueOf(i)); @@ -407,6 +429,8 @@ public class JspWriterImpl extends JspWriter { * method. * * @param l The <code>long</code> to be printed + * + * @throws IOException in case of IO errors */ public void print(long l) throws IOException { write(String.valueOf(l)); @@ -420,6 +444,8 @@ public class JspWriterImpl extends JspWriter { * method. * * @param f The <code>float</code> to be printed + * + * @throws IOException in case of IO errors */ public void print(float f) throws IOException { write(String.valueOf(f)); @@ -433,6 +459,8 @@ public class JspWriterImpl extends JspWriter { * #write(int)}</code> method. * * @param d The <code>double</code> to be printed + * + * @throws IOException in case of IO errors */ public void print(double d) throws IOException { write(String.valueOf(d)); @@ -447,6 +475,7 @@ public class JspWriterImpl extends JspWriter { * @param s The array of chars to be printed * * @throws NullPointerException If <code>s</code> is <code>null</code> + * @throws IOException in case of IO errors */ public void print(char s[]) throws IOException { write(s); @@ -460,6 +489,8 @@ public class JspWriterImpl extends JspWriter { * <code>{@link #write(int)}</code> method. * * @param s The <code>String</code> to be printed + * + * @throws IOException in case of IO errors */ public void print(String s) throws IOException { if (s == null) { @@ -476,6 +507,8 @@ public class JspWriterImpl extends JspWriter { * method. * * @param obj The <code>Object</code> to be printed + * + * @throws IOException in case of IO errors */ public void print(Object obj) throws IOException { write(String.valueOf(obj)); @@ -491,7 +524,9 @@ public class JspWriterImpl extends JspWriter { * * Need to change this from PrintWriter because the default * println() writes to the sink directly instead of through the - * write method... + * write method... + * + * @throws IOException in case of IO errors */ public void println() throws IOException { newLine(); @@ -501,6 +536,10 @@ public class JspWriterImpl extends JspWriter { * Print a boolean value and then terminate the line. This method behaves * as though it invokes <code>{@link #print(boolean)}</code> and then * <code>{@link #println()}</code>. + * + * @param x The <code>boolean</code> to be printed + * + * @throws IOException in case of IO errors */ public void println(boolean x) throws IOException { print(x); @@ -511,6 +550,10 @@ public class JspWriterImpl extends JspWriter { * Print a character and then terminate the line. This method behaves as * though it invokes <code>{@link #print(char)}</code> and then <code>{@link * #println()}</code>. + * + * @param x The <code>char</code> to be printed + * + * @throws IOException in case of IO errors */ public void println(char x) throws IOException { print(x); @@ -521,6 +564,10 @@ public class JspWriterImpl extends JspWriter { * Print an integer and then terminate the line. This method behaves as * though it invokes <code>{@link #print(int)}</code> and then <code>{@link * #println()}</code>. + * + * @param x The <code>int</code> to be printed + * + * @throws IOException in case of IO errors */ public void println(int x) throws IOException { print(x); @@ -531,6 +578,10 @@ public class JspWriterImpl extends JspWriter { * Print a long integer and then terminate the line. This method behaves * as though it invokes <code>{@link #print(long)}</code> and then * <code>{@link #println()}</code>. + * + * @param x The <code>long</code> to be printed + * + * @throws IOException in case of IO errors */ public void println(long x) throws IOException { print(x); @@ -541,6 +592,10 @@ public class JspWriterImpl extends JspWriter { * Print a floating-point number and then terminate the line. This method * behaves as though it invokes <code>{@link #print(float)}</code> and then * <code>{@link #println()}</code>. + * + * @param x The <code>float</code> to be printed + * + * @throws IOException in case of IO errors */ public void println(float x) throws IOException { print(x); @@ -551,6 +606,10 @@ public class JspWriterImpl extends JspWriter { * Print a double-precision floating-point number and then terminate the * line. This method behaves as though it invokes <code>{@link * #print(double)}</code> and then <code>{@link #println()}</code>. + * + * @param x The <code>double</code> to be printed + * + * @throws IOException in case of IO errors */ public void println(double x) throws IOException { print(x); @@ -561,6 +620,10 @@ public class JspWriterImpl extends JspWriter { * Print an array of characters and then terminate the line. This method * behaves as though it invokes <code>{@link #print(char[])}</code> and then * <code>{@link #println()}</code>. + * + * @param x The <code>char[]</code> to be printed + * + * @throws IOException in case of IO errors */ public void println(char x[]) throws IOException { print(x); @@ -571,6 +634,10 @@ public class JspWriterImpl extends JspWriter { * Print a String and then terminate the line. This method behaves as * though it invokes <code>{@link #print(String)}</code> and then * <code>{@link #println()}</code>. + * + * @param x The <code>String</code> to be printed + * + * @throws IOException in case of IO errors */ public void println(String x) throws IOException { print(x); @@ -581,6 +648,10 @@ public class JspWriterImpl extends JspWriter { * Print an Object and then terminate the line. This method behaves as * though it invokes <code>{@link #print(Object)}</code> and then * <code>{@link #println()}</code>. + * + * @param x The <code>Object</code> to be printed + * + * @throws IOException in case of IO errors */ public void println(Object x) throws IOException { print(x); http://git-wip-us.apache.org/repos/asf/struts/blob/775c82a7/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/runtime/PageContextImpl.java ---------------------------------------------------------------------- diff --git a/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/runtime/PageContextImpl.java b/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/runtime/PageContextImpl.java index 4fbccad..0d4d4f0 100644 --- a/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/runtime/PageContextImpl.java +++ b/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/runtime/PageContextImpl.java @@ -900,7 +900,12 @@ public class PageContextImpl extends PageContext { * The page context * @param functionMap * Maps prefix and name to Method + * @param escape + * enable escaping + * * @return The result of the evaluation + * + * @throws ELException in case of errors */ public static Object proprietaryEvaluate(final String expression, final Class expectedType, final PageContext pageContext, http://git-wip-us.apache.org/repos/asf/struts/blob/775c82a7/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/runtime/ProtectedFunctionMapper.java ---------------------------------------------------------------------- diff --git a/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/runtime/ProtectedFunctionMapper.java b/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/runtime/ProtectedFunctionMapper.java index e585444..14539c1 100644 --- a/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/runtime/ProtectedFunctionMapper.java +++ b/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/runtime/ProtectedFunctionMapper.java @@ -135,6 +135,9 @@ public final class ProtectedFunctionMapper extends javax.el.FunctionMapper * The name of the Java method * @param args * The arguments of the Java method + * + * @return function mapper + * * @throws RuntimeException * if no method with the given signature could be found. */ http://git-wip-us.apache.org/repos/asf/struts/blob/775c82a7/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/security/SecurityUtil.java ---------------------------------------------------------------------- diff --git a/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/security/SecurityUtil.java b/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/security/SecurityUtil.java index 6ecdb3d..25b06c4 100644 --- a/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/security/SecurityUtil.java +++ b/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/security/SecurityUtil.java @@ -30,7 +30,7 @@ public final class SecurityUtil{ System.getProperty("package.definition") == null ? false : true; /** - * Return the <code>SecurityManager</code> only if Security is enabled AND + * @return the <code>SecurityManager</code> only if Security is enabled AND * package protection mechanism is enabled. */ public static boolean isPackageProtectionEnabled(){ @@ -47,6 +47,7 @@ public final class SecurityUtil{ * codes in the request URL that is often reported in error messages. * * @param message The message string to be filtered + * @return filtered message */ public static String filter(String message) { http://git-wip-us.apache.org/repos/asf/struts/blob/775c82a7/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/servlet/JspCServletContext.java ---------------------------------------------------------------------- diff --git a/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/servlet/JspCServletContext.java b/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/servlet/JspCServletContext.java index 60646ba..219c759 100644 --- a/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/servlet/JspCServletContext.java +++ b/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/servlet/JspCServletContext.java @@ -78,7 +78,7 @@ public class JspCServletContext implements ServletContext { * Create a new instance of this ServletContext implementation. * * @param aLogWriter PrintWriter which is used for <code>log()</code> calls - * @param aResourceBaseURL Resource base URL + * @param classLoaderInterface classloader interface */ public JspCServletContext(PrintWriter aLogWriter, ClassLoaderInterface classLoaderInterface) { @@ -92,7 +92,7 @@ public class JspCServletContext implements ServletContext { /** - * Return the specified context attribute, if any. + * @return the specified context attribute, if any. * * @param name Name of the requested attribute */ @@ -104,7 +104,7 @@ public class JspCServletContext implements ServletContext { /** - * Return an enumeration of context attribute names. + * @return an enumeration of context attribute names. */ public Enumeration getAttributeNames() { @@ -114,7 +114,7 @@ public class JspCServletContext implements ServletContext { /** - * Return the servlet context for the specified path. + * @return the servlet context for the specified path. * * @param uripath Server-relative path starting with '/' */ @@ -126,7 +126,7 @@ public class JspCServletContext implements ServletContext { /** - * Return the context path. + * @return the context path. */ public String getContextPath() { @@ -136,7 +136,7 @@ public class JspCServletContext implements ServletContext { /** - * Return the specified context initialization parameter. + * @return the specified context initialization parameter. * * @param name Name of the requested parameter */ @@ -148,7 +148,7 @@ public class JspCServletContext implements ServletContext { /** - * Return an enumeration of the names of context initialization + * @return an enumeration of the names of context initialization * parameters. */ public Enumeration getInitParameterNames() { @@ -159,7 +159,7 @@ public class JspCServletContext implements ServletContext { /** - * Return the Servlet API major version number. + * @return the Servlet API major version number. */ public int getMajorVersion() { @@ -169,7 +169,7 @@ public class JspCServletContext implements ServletContext { /** - * Return the MIME type for the specified filename. + * @return the MIME type for the specified filename. * * @param file Filename whose MIME type is requested */ @@ -181,7 +181,7 @@ public class JspCServletContext implements ServletContext { /** - * Return the Servlet API minor version number. + * @return the Servlet API minor version number. */ public int getMinorVersion() { @@ -191,7 +191,7 @@ public class JspCServletContext implements ServletContext { /** - * Return a request dispatcher for the specified servlet name. + * @return a request dispatcher for the specified servlet name. * * @param name Name of the requested servlet */ @@ -203,7 +203,7 @@ public class JspCServletContext implements ServletContext { /** - * Return the real path for the specified context-relative + * @return the real path for the specified context-relative * virtual path. * * @param path The context-relative virtual path to resolve @@ -219,7 +219,7 @@ public class JspCServletContext implements ServletContext { /** - * Return a request dispatcher for the specified context-relative path. + * @return a request dispatcher for the specified context-relative path. * * @param path Context-relative path for which to acquire a dispatcher */ @@ -231,7 +231,7 @@ public class JspCServletContext implements ServletContext { /** - * Return a URL object of a resource that is mapped to the + * @return a URL object of a resource that is mapped to the * specified context-relative path. * * @param path Context-relative path of the desired resource @@ -253,7 +253,7 @@ public class JspCServletContext implements ServletContext { /** - * Return an InputStream allowing access to the resource at the + * @return an InputStream allowing access to the resource at the * specified context-relative path. * * @param path Context-relative path of the desired resource @@ -268,7 +268,7 @@ public class JspCServletContext implements ServletContext { /** - * Return the set of resource paths for the "directory" at the + * @return the set of resource paths for the "directory" at the * specified context path. * * @param path Context-relative base path @@ -298,7 +298,7 @@ public class JspCServletContext implements ServletContext { /** - * Return descriptive information about this server. + * @return descriptive information about this server. */ public String getServerInfo() { @@ -308,7 +308,7 @@ public class JspCServletContext implements ServletContext { /** - * Return a null reference for the specified servlet name. + * @return a null reference for the specified servlet name. * * @param name Name of the requested servlet * @@ -322,7 +322,7 @@ public class JspCServletContext implements ServletContext { /** - * Return the name of this servlet context. + * @return the name of this servlet context. */ public String getServletContextName() { @@ -332,7 +332,7 @@ public class JspCServletContext implements ServletContext { /** - * Return an empty enumeration of servlet names. + * @return an empty enumeration of servlet names. * * @deprecated This method has been deprecated with no replacement */ @@ -344,7 +344,7 @@ public class JspCServletContext implements ServletContext { /** - * Return an empty enumeration of servlets. + * @return an empty enumeration of servlets. * * @deprecated This method has been deprecated with no replacement */ http://git-wip-us.apache.org/repos/asf/struts/blob/775c82a7/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/tagplugins/jstl/Util.java ---------------------------------------------------------------------- diff --git a/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/tagplugins/jstl/Util.java b/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/tagplugins/jstl/Util.java index 869e359..ec4503f 100644 --- a/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/tagplugins/jstl/Util.java +++ b/plugins/embeddedjsp/src/main/java/org/apache/struts2/jasper/tagplugins/jstl/Util.java @@ -88,7 +88,9 @@ public class Util { } /** - * Returns <tt>true</tt> if our current URL is absolute, + * @param url the URL + * + * @return <tt>true</tt> if our current URL is absolute, * <tt>false</tt> otherwise. * taken from org.apache.taglibs.standard.tag.common.core.ImportSupport */ @@ -112,7 +114,11 @@ public class Util { } /** - * Get the value associated with a content-type attribute. + * + * @param input input string + * @param name name of attribute + * + * @return the value associated with a content-type attribute. * Syntax defined in RFC 2045, section 5.1. * taken from org.apache.taglibs.standard.tag.common.core.Util */ @@ -148,6 +154,9 @@ public class Util { * and either EOS or a subsequent ';' (exclusive). * * taken from org.apache.taglibs.standard.tag.common.core.ImportSupport + * + * @param url the URL + * @return servlet session ID from URL */ public static String stripSession(String url) { StringBuffer u = new StringBuffer(url); @@ -165,18 +174,25 @@ public class Util { /** + * <p> * Performs the following substring replacements * (to facilitate output to XML/HTML pages): + * </p> * - * & -> & - * < -> < - * > -> > - * " -> " - * ' -> ' + * <pre> + * & -> &amp; + * < -> &lt; + * > -> &gt; + * " -> &#034; + * ' -> &#039; + * </pre> * * See also OutSupport.writeEscapedXml(). * * taken from org.apache.taglibs.standard.tag.common.core.Util + * + * @param buffer string + * @return escaped string */ public static String escapeXml(String buffer) { int start = 0; @@ -214,8 +230,16 @@ public class Util { return escapedBuffer.toString(); } - /** Utility methods + /** + * Utility methods * taken from org.apache.taglibs.standard.tag.common.core.UrlSupport + * + * @param url URL + * @param context context + * @param pageContext page context + * + * @return the URL + * @throws JspException in case of errors */ public static String resolveUrl( String url, String context, PageContext pageContext) @@ -271,27 +295,35 @@ public class Util { } public PrintWriter getWriter() { - if (isStreamUsed) - throw new IllegalStateException("Unexpected internal error during <import>: " + - "Target servlet called getWriter(), then getOutputStream()"); + if (isStreamUsed) { + throw new IllegalStateException("Unexpected internal error during <import>: Target servlet called getWriter(), then getOutputStream()"); + } isWriterUsed = true; return new PrintWriter(sw); } public ServletOutputStream getOutputStream() { - if (isWriterUsed) - throw new IllegalStateException("Unexpected internal error during <import>: " + - "Target servlet called getOutputStream(), then getWriter()"); + if (isWriterUsed) { + throw new IllegalStateException("Unexpected internal error during <import>: Target servlet called getOutputStream(), then getWriter()"); + } isStreamUsed = true; return sos; } - /** Has no effect. */ + /** + * Has no effect. + * + * @param x content type + */ public void setContentType(String x) { // ignore } - /** Has no effect. */ + /** + * Has no effect. + * + * @param x locale + */ public void setLocale(Locale x) { // ignore }