Search in sources :

Example 56 with JasperException

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;
}
Also used : JasperException(org.apache.jasper.JasperException) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) PrintWriter(java.io.PrintWriter)

Example 57 with JasperException

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()));
    }
}
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 58 with JasperException

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);
    }
}
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 59 with JasperException

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()));
        }
    }
}
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 60 with JasperException

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;
}
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)80 IOException (java.io.IOException)61 Method (java.lang.reflect.Method)28 ServletException (javax.servlet.ServletException)21 FileNotFoundException (java.io.FileNotFoundException)19 ServletException (jakarta.servlet.ServletException)18 JspException (javax.servlet.jsp.JspException)18 JspException (jakarta.servlet.jsp.JspException)15 File (java.io.File)8 SAXException (org.xml.sax.SAXException)7 HashMap (java.util.HashMap)6 FileOutputStream (java.io.FileOutputStream)5 InputStream (java.io.InputStream)5 InputStreamReader (java.io.InputStreamReader)4 URL (java.net.URL)4 ArrayList (java.util.ArrayList)4 TreeNode (org.apache.jasper.xmlparser.TreeNode)4 TagInfo (jakarta.servlet.jsp.tagext.TagInfo)3 BufferedOutputStream (java.io.BufferedOutputStream)3 BufferedReader (java.io.BufferedReader)3