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()));
}
}
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);
}
}
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;
}
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()));
}
}
}
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;
}
Aggregations