Search in sources :

Example 11 with JasperException

use of org.apache.jasper.JasperException in project tomcat by apache.

the class JspRuntimeLibrary method getValueFromBeanInfoPropertyEditor.

//*********************************************************************
// 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()));
    }
}
Also used : JasperException(org.apache.jasper.JasperException) PropertyEditor(java.beans.PropertyEditor) ServletException(javax.servlet.ServletException) JspException(javax.servlet.jsp.JspException) IOException(java.io.IOException) JasperException(org.apache.jasper.JasperException)

Example 12 with JasperException

use of org.apache.jasper.JasperException in project tomcat by apache.

the class JspRuntimeLibrary method handleSetProperty.

public static void handleSetProperty(Object bean, String prop, boolean value) throws JasperException {
    try {
        Method method = getWriteMethod(bean.getClass(), prop);
        method.invoke(bean, new Object[] { Boolean.valueOf(value) });
    } catch (Exception ex) {
        Throwable thr = ExceptionUtils.unwrapInvocationTargetException(ex);
        ExceptionUtils.handleThrowable(thr);
        throw new JasperException(ex);
    }
}
Also used : JasperException(org.apache.jasper.JasperException) Method(java.lang.reflect.Method) ServletException(javax.servlet.ServletException) JspException(javax.servlet.jsp.JspException) IOException(java.io.IOException) JasperException(org.apache.jasper.JasperException)

Example 13 with JasperException

use of org.apache.jasper.JasperException in project tomcat by apache.

the class JspRuntimeLibrary method handleGetProperty.

// __begin lookupReadMethodMethod
public static Object handleGetProperty(Object o, String prop) throws JasperException {
    if (o == null) {
        throw new JasperException(Localizer.getMessage("jsp.error.beans.nullbean"));
    }
    Object value = null;
    try {
        Method method = getReadMethod(o.getClass(), prop);
        value = method.invoke(o, (Object[]) null);
    } catch (Exception ex) {
        Throwable thr = ExceptionUtils.unwrapInvocationTargetException(ex);
        ExceptionUtils.handleThrowable(thr);
        throw new JasperException(ex);
    }
    return value;
}
Also used : JasperException(org.apache.jasper.JasperException) Method(java.lang.reflect.Method) ServletException(javax.servlet.ServletException) JspException(javax.servlet.jsp.JspException) IOException(java.io.IOException) JasperException(org.apache.jasper.JasperException)

Example 14 with JasperException

use of org.apache.jasper.JasperException in project tomcat by apache.

the class JspRuntimeLibrary method introspecthelper.

// __end introspectMethod
// __begin introspecthelperMethod
public static void introspecthelper(Object bean, String prop, 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 && type != null) {
            if (type.isArray()) {
                if (request == null) {
                    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 {
                    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) {
        Throwable thr = ExceptionUtils.unwrapInvocationTargetException(ex);
        ExceptionUtils.handleThrowable(thr);
        throw new JasperException(ex);
    }
    if (!ignoreMethodNF && (method == null)) {
        if (type == null) {
            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()));
        }
    }
}
Also used : Method(java.lang.reflect.Method) ServletException(javax.servlet.ServletException) JspException(javax.servlet.jsp.JspException) IOException(java.io.IOException) JasperException(org.apache.jasper.JasperException) JasperException(org.apache.jasper.JasperException)

Example 15 with JasperException

use of org.apache.jasper.JasperException in project tomcat by apache.

the class JspRuntimeLibrary method getWriteMethod.

public static Method getWriteMethod(Class<?> beanClass, String prop) 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 {
            // just in case introspection silently fails.
            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()));
        } else {
            throw new JasperException(Localizer.getMessage("jsp.error.beans.nomethod.setproperty", prop, type.getName(), beanClass.getName()));
        }
    }
    return method;
}
Also used : JasperException(org.apache.jasper.JasperException) Method(java.lang.reflect.Method) ServletException(javax.servlet.ServletException) JspException(javax.servlet.jsp.JspException) IOException(java.io.IOException) JasperException(org.apache.jasper.JasperException)

Aggregations

JasperException (org.apache.jasper.JasperException)35 IOException (java.io.IOException)29 ServletException (javax.servlet.ServletException)20 JspException (javax.servlet.jsp.JspException)17 Method (java.lang.reflect.Method)14 FileNotFoundException (java.io.FileNotFoundException)7 HashMap (java.util.HashMap)3 UnavailableException (javax.servlet.UnavailableException)3 TagInfo (javax.servlet.jsp.tagext.TagInfo)3 SAXException (org.xml.sax.SAXException)3 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 InputStream (java.io.InputStream)2 URISyntaxException (java.net.URISyntaxException)2 URL (java.net.URL)2 Map (java.util.Map)2 Servlet (javax.servlet.Servlet)2 TagFileInfo (javax.servlet.jsp.tagext.TagFileInfo)2 PropertyEditor (java.beans.PropertyEditor)1 BufferedOutputStream (java.io.BufferedOutputStream)1