luehe 2002/12/11 14:34:06 Modified: jasper2/src/share/org/apache/jasper/runtime JspRuntimeLibrary.java jasper2/src/share/org/apache/jasper/compiler ErrorDispatcher.java Log: Leverage ErrorDispatcher in JspRuntimeLibrary Revision Changes Path 1.11 +42 -47 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/runtime/JspRuntimeLibrary.java Index: JspRuntimeLibrary.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/runtime/JspRuntimeLibrary.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- JspRuntimeLibrary.java 11 Dec 2002 19:40:45 -0000 1.10 +++ JspRuntimeLibrary.java 11 Dec 2002 22:34:06 -0000 1.11 @@ -81,7 +81,7 @@ import javax.servlet.jsp.tagext.BodyContent; import org.apache.jasper.JasperException; -import org.apache.jasper.Constants; +import org.apache.jasper.compiler.ErrorDispatcher; // for JSTL expression interpreter import javax.servlet.jsp.PageContext; @@ -100,6 +100,12 @@ */ public class JspRuntimeLibrary { + private static ErrorDispatcher err; + + static { + err = new ErrorDispatcher(); + } + protected static class PrivilegedIntrospectHelper implements PrivilegedExceptionAction { @@ -130,15 +136,15 @@ } public static Character getCharacter(String s) throws JasperException { - if (s.length() > 0) { - return new Character(s.charAt(0)); - } else { - throw new JasperException(Constants.getString("jsp.error.bad_string_Character")); + if (s.length() == 0) { + err.jspError("jsp.error.bad_string_Character"); } + return new Character(s.charAt(0)); } // __begin convertMethod - public static Object convert(String propertyName, String s, Class t, Class propertyEditorClass) + public static Object convert(String propertyName, String s, Class t, + Class propertyEditorClass) throws JasperException { try { @@ -248,10 +254,8 @@ if ( method != null ) { if (type.isArray()) { if (request == null) { - throw new JasperException(Constants.getString( - "jsp.error.beans.setproperty.noindexset", - new Object[] {})); - }; + err.jspError("jsp.error.beans.setproperty.noindexset"); + } Class t = type.getComponentType(); String[] values = request.getParameterValues(param); //XXX Please check. @@ -275,14 +279,11 @@ } if (!ignoreMethodNF && (method == null)) { if (type == null) { - throw new JasperException(Constants.getString( - "jsp.error.beans.noproperty", - new Object[] {prop, bean.getClass().getName()})); + err.jspError("jsp.error.beans.noproperty", + prop, bean.getClass().getName()); } else { - throw new JasperException(Constants.getString( - "jsp.error.beans.nomethod.setproperty", - new Object[] {prop, type.getName(), - bean.getClass().getName()})); + err.jspError("jsp.error.beans.nomethod.setproperty", + prop, type.getName(), bean.getClass().getName()); } } } @@ -336,16 +337,19 @@ * the request and the property is indexed. */ public static void createTypedArray(String propertyName, - Object bean, Method method, String []values, Class t, + Object bean, + Method method, + String[] values, + Class t, Class propertyEditorClass) - throws JasperException { + 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); + tmpval[i] = getValueFromBeanInfoPropertyEditor( + t, propertyName, values[i], propertyEditorClass); } method.invoke (bean, new Object[] {tmpval}); } else if (t.equals(Integer.class)) { @@ -508,9 +512,7 @@ public static Object handleGetProperty(Object o, String prop) throws JasperException { if (o == null) { - throw new JasperException(Constants.getString( - "jsp.error.beans.nullbean", - new Object[] {})); + err.jspError("jsp.error.beans.nullbean"); } Object value = null; try { @@ -692,23 +694,19 @@ } } else { // just in case introspection silently fails. - throw new JasperException(Constants.getString( - "jsp.error.beans.nobeaninfo", - new Object[] {beanClass.getName()})); + err.jspError("jsp.error.beans.nobeaninfo", + beanClass.getName()); } } catch (Exception ex) { throw new JasperException (ex); } if (method == null) { if (type == null) { - throw new JasperException(Constants.getString( - "jsp.error.beans.noproperty", - new Object[] {prop, beanClass.getName()})); + err.jspError("jsp.error.beans.noproperty", + prop, beanClass.getName()); } else { - throw new JasperException(Constants.getString( - "jsp.error.beans.nomethod.setproperty", - new Object[] {prop, type.getName(), - beanClass.getName()})); + err.jspError("jsp.error.beans.nomethod.setproperty", + prop, type.getName(), beanClass.getName()); } } return method; @@ -734,22 +732,19 @@ } } else { // just in case introspection silently fails. - throw new JasperException(Constants.getString( - "jsp.error.beans.nobeaninfo", - new Object[] {beanClass.getName()})); + err.jspError("jsp.error.beans.nobeaninfo", + beanClass.getName()); } } catch (Exception ex) { throw new JasperException (ex); } if (method == null) { if (type == null) { - throw new JasperException(Constants.getString( - "jsp.error.beans.noproperty", - new Object[] {prop, beanClass.getName()})); + err.jspError("jsp.error.beans.noproperty", + prop, beanClass.getName()); } else { - throw new JasperException(Constants.getString( - "jsp.error.beans.nomethod", - new Object[] {prop, beanClass.getName()})); + err.jspError("jsp.error.beans.nomethod", + prop, beanClass.getName()); } } 1.8 +21 -4 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/ErrorDispatcher.java Index: ErrorDispatcher.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/ErrorDispatcher.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- ErrorDispatcher.java 6 Nov 2002 20:14:19 -0000 1.7 +++ ErrorDispatcher.java 11 Dec 2002 22:34:06 -0000 1.8 @@ -91,7 +91,7 @@ /* * Constructor. */ - ErrorDispatcher() { + public ErrorDispatcher() { // XXX check web.xml for custom error handler errHandler = new DefaultErrorHandler(this); } @@ -197,6 +197,23 @@ public void jspError(String errCode, String arg1, String arg2) throws JasperException { dispatch(null, errCode, new Object[] {arg1, arg2}, null); + } + + /* + * Dispatches the given JSP parse error to the configured error handler. + * + * The given error code is localized. If it is not found in the + * resource bundle for localized error messages, it is used as the error + * message. + * + * @param errCode Error code + * @param arg1 First argument for parametric replacement + * @param arg2 Second argument for parametric replacement + * @param arg3 Third argument for parametric replacement + */ + public void jspError(String errCode, String arg1, String arg2, String arg3) + throws JasperException { + dispatch(null, errCode, new Object[] {arg1, arg2, arg3}, null); } /*
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>