use of org.apache.jasper.JasperException in project tomcat70 by apache.
the class SmapUtil method generateSmap.
// *********************************************************************
// Public entry points
/**
* Generates an appropriate SMAP representing the current compilation
* context. (JSR-045.)
*
* @param ctxt Current compilation context
* @param pageNodes The current JSP page
* @return a SMAP for the page
*/
public static String[] generateSmap(JspCompilationContext ctxt, Node.Nodes pageNodes) throws IOException {
// Scan the nodes for presence of Jasper generated inner classes
PreScanVisitor psVisitor = new PreScanVisitor();
try {
pageNodes.visit(psVisitor);
} catch (JasperException ex) {
}
HashMap<String, SmapStratum> map = psVisitor.getMap();
// set up our SMAP generator
SmapGenerator g = new SmapGenerator();
/**
* Disable reading of input SMAP because:
* 1. There is a bug here: getRealPath() is null if .jsp is in a jar
* Bugzilla 14660.
* 2. Mappings from other sources into .jsp files are not supported.
* TODO: fix 1. if 2. is not true.
* // determine if we have an input SMAP
* String smapPath = inputSmapPath(ctxt.getRealPath(ctxt.getJspFile()));
* File inputSmap = new File(smapPath);
* if (inputSmap.exists()) {
* byte[] embeddedSmap = null;
* byte[] subSmap = SDEInstaller.readWhole(inputSmap);
* String subSmapString = new String(subSmap, SMAP_ENCODING);
* g.addSmap(subSmapString, "JSP");
* }
*/
// now, assemble info about our own stratum (JSP) using JspLineMap
SmapStratum s = new SmapStratum("JSP");
g.setOutputFileName(unqualify(ctxt.getServletJavaFileName()));
// Map out Node.Nodes
evaluateNodes(pageNodes, s, map, ctxt.getOptions().getMappedFile());
s.optimizeLineSection();
g.addStratum(s, true);
if (ctxt.getOptions().isSmapDumped()) {
File outSmap = new File(ctxt.getClassFileName() + ".smap");
PrintWriter so = new PrintWriter(new OutputStreamWriter(new FileOutputStream(outSmap), SMAP_ENCODING));
so.print(g.getString());
so.close();
}
String classFileName = ctxt.getClassFileName();
int innerClassCount = map.size();
String[] smapInfo = new String[2 + innerClassCount * 2];
smapInfo[0] = classFileName;
smapInfo[1] = g.getString();
int count = 2;
Iterator<Map.Entry<String, SmapStratum>> iter = map.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry<String, SmapStratum> entry = iter.next();
String innerClass = entry.getKey();
s = entry.getValue();
s.optimizeLineSection();
g = new SmapGenerator();
g.setOutputFileName(unqualify(ctxt.getServletJavaFileName()));
g.addStratum(s, true);
String innerClassFileName = classFileName.substring(0, classFileName.indexOf(".class")) + '$' + innerClass + ".class";
if (ctxt.getOptions().isSmapDumped()) {
File outSmap = new File(innerClassFileName + ".smap");
PrintWriter so = new PrintWriter(new OutputStreamWriter(new FileOutputStream(outSmap), SMAP_ENCODING));
so.print(g.getString());
so.close();
}
smapInfo[count] = innerClassFileName;
smapInfo[count + 1] = g.getString();
count += 2;
}
return smapInfo;
}
use of org.apache.jasper.JasperException in project tomcat70 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 tomcat70 by apache.
the class JspRuntimeLibrary method handleSetProperty.
public static void handleSetProperty(Object bean, String prop, char value) throws JasperException {
try {
Method method = getWriteMethod(bean.getClass(), prop);
method.invoke(bean, new Object[] { Character.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 tomcat70 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) {
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 tomcat70 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;
}
Aggregations