Search in sources :

Example 31 with JasperException

use of org.apache.sling.scripting.jsp.jasper.JasperException in project sling by apache.

the class JspRuntimeLibrary method handleSetProperty.

public static void handleSetProperty(Object bean, String prop, 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);
    }
}
Also used : JasperException(org.apache.sling.scripting.jsp.jasper.JasperException) Method(java.lang.reflect.Method) PrivilegedActionException(java.security.PrivilegedActionException) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) JasperException(org.apache.sling.scripting.jsp.jasper.JasperException)

Example 32 with JasperException

use of org.apache.sling.scripting.jsp.jasper.JasperException in project sling by apache.

the class JspRuntimeLibrary method handleSetProperty.

public static void handleSetProperty(Object bean, String prop, 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);
    }
}
Also used : JasperException(org.apache.sling.scripting.jsp.jasper.JasperException) Method(java.lang.reflect.Method) PrivilegedActionException(java.security.PrivilegedActionException) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) JasperException(org.apache.sling.scripting.jsp.jasper.JasperException)

Example 33 with JasperException

use of org.apache.sling.scripting.jsp.jasper.JasperException in project sling by apache.

the class JspRuntimeLibrary method handleSetProperty.

public static void handleSetProperty(Object bean, String prop, 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);
    }
}
Also used : JasperException(org.apache.sling.scripting.jsp.jasper.JasperException) Method(java.lang.reflect.Method) PrivilegedActionException(java.security.PrivilegedActionException) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) JasperException(org.apache.sling.scripting.jsp.jasper.JasperException)

Example 34 with JasperException

use of org.apache.sling.scripting.jsp.jasper.JasperException in project sling by apache.

the class JspRuntimeLibrary method internalIntrospecthelper.

private static void internalIntrospecthelper(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) {
            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 {
                    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);
    }
    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) PrivilegedActionException(java.security.PrivilegedActionException) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) JasperException(org.apache.sling.scripting.jsp.jasper.JasperException) JasperException(org.apache.sling.scripting.jsp.jasper.JasperException)

Example 35 with JasperException

use of org.apache.sling.scripting.jsp.jasper.JasperException in project sling by apache.

the class JspRuntimeLibrary method handleSetProperty.

public static void handleSetProperty(Object bean, String prop, 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);
    }
}
Also used : JasperException(org.apache.sling.scripting.jsp.jasper.JasperException) Method(java.lang.reflect.Method) PrivilegedActionException(java.security.PrivilegedActionException) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) JasperException(org.apache.sling.scripting.jsp.jasper.JasperException)

Aggregations

JasperException (org.apache.sling.scripting.jsp.jasper.JasperException)42 IOException (java.io.IOException)31 ServletException (javax.servlet.ServletException)19 PrivilegedActionException (java.security.PrivilegedActionException)17 Method (java.lang.reflect.Method)14 FileNotFoundException (java.io.FileNotFoundException)9 MalformedURLException (java.net.MalformedURLException)6 Iterator (java.util.Iterator)6 InputStream (java.io.InputStream)5 JarFile (java.util.jar.JarFile)5 TagInfo (javax.servlet.jsp.tagext.TagInfo)4 TreeNode (org.apache.sling.scripting.jsp.jasper.xmlparser.TreeNode)4 DependencyResolutionRequiredException (org.apache.maven.artifact.DependencyResolutionRequiredException)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 SAXException (org.xml.sax.SAXException)3 File (java.io.File)2 InputStreamReader (java.io.InputStreamReader)2 URL (java.net.URL)2 Enumeration (java.util.Enumeration)2 HashMap (java.util.HashMap)2