Search in sources :

Example 16 with JasperException

use of org.apache.sling.scripting.jsp.jasper.JasperException in project sling 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.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 17 with JasperException

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

the class JspRuntimeLibrary method getReadMethod.

public static Method getReadMethod(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].getReadMethod();
                    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", prop, beanClass.getName()));
        }
    }
    return method;
}
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 18 with JasperException

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

the class JspRuntimeLibrary method handleSetPropertyExpression.

// __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);
	}
    }
**/
public static void handleSetPropertyExpression(Object bean, 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) });
    } 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 19 with JasperException

use of org.apache.sling.scripting.jsp.jasper.JasperException in project sling 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) {
        throw new JasperException(ex);
    }
    return value;
}
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 20 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, 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);
    }
}
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