Search in sources :

Example 76 with JasperException

use of org.apache.jasper.JasperException in project tomcat 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[] { Float.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) IOException(java.io.IOException) ServletException(jakarta.servlet.ServletException) JspException(jakarta.servlet.jsp.JspException) JasperException(org.apache.jasper.JasperException)

Example 77 with JasperException

use of org.apache.jasper.JasperException in project tomcat 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
 * @throws IOException Error writing SMAP
 */
public static Map<String, SmapStratum> generateSmap(JspCompilationContext ctxt, Node.Nodes pageNodes) throws IOException {
    Map<String, SmapStratum> smapInfo = new HashMap<>();
    // 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();
    // Assemble info about our own stratum (JSP) using JspLineMap
    SmapStratum s = new SmapStratum();
    // Map out Node.Nodes
    evaluateNodes(pageNodes, s, map, ctxt.getOptions().getMappedFile());
    s.optimizeLineSection();
    s.setOutputFileName(unqualify(ctxt.getServletJavaFileName()));
    String classFileName = ctxt.getClassFileName();
    s.setClassFileName(classFileName);
    smapInfo.put(ctxt.getFQCN(), s);
    if (ctxt.getOptions().isSmapDumped()) {
        File outSmap = new File(classFileName + ".smap");
        PrintWriter so = new PrintWriter(new OutputStreamWriter(new FileOutputStream(outSmap), SMAP_ENCODING));
        so.print(s.getSmapString());
        so.close();
    }
    for (Map.Entry<String, SmapStratum> entry : map.entrySet()) {
        String innerClass = entry.getKey();
        s = entry.getValue();
        s.optimizeLineSection();
        s.setOutputFileName(unqualify(ctxt.getServletJavaFileName()));
        String innerClassFileName = classFileName.substring(0, classFileName.indexOf(".class")) + '$' + innerClass + ".class";
        s.setClassFileName(innerClassFileName);
        smapInfo.put(ctxt.getFQCN() + "." + innerClass, s);
        if (ctxt.getOptions().isSmapDumped()) {
            File outSmap = new File(innerClassFileName + ".smap");
            PrintWriter so = new PrintWriter(new OutputStreamWriter(new FileOutputStream(outSmap), SMAP_ENCODING));
            so.print(s.getSmapString());
            so.close();
        }
    }
    return smapInfo;
}
Also used : HashMap(java.util.HashMap) 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 78 with JasperException

use of org.apache.jasper.JasperException in project tomcat by apache.

the class TldCache method getTaglibXml.

public TaglibXml getTaglibXml(TldResourcePath tldResourcePath) throws JasperException {
    TaglibXmlCacheEntry cacheEntry = tldResourcePathTaglibXmlMap.get(tldResourcePath);
    if (cacheEntry == null) {
        return null;
    }
    long[] lastModified = getLastModified(tldResourcePath);
    if (lastModified[0] != cacheEntry.getWebAppPathLastModified() || lastModified[1] != cacheEntry.getEntryLastModified()) {
        synchronized (cacheEntry) {
            if (lastModified[0] != cacheEntry.getWebAppPathLastModified() || lastModified[1] != cacheEntry.getEntryLastModified()) {
                // Re-parse TLD
                TaglibXml updatedTaglibXml;
                try {
                    updatedTaglibXml = tldParser.parse(tldResourcePath);
                } catch (IOException | SAXException e) {
                    throw new JasperException(e);
                }
                cacheEntry.setTaglibXml(updatedTaglibXml);
                cacheEntry.setWebAppPathLastModified(lastModified[0]);
                cacheEntry.setEntryLastModified(lastModified[1]);
            }
        }
    }
    return cacheEntry.getTaglibXml();
}
Also used : TaglibXml(org.apache.tomcat.util.descriptor.tld.TaglibXml) JasperException(org.apache.jasper.JasperException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Example 79 with JasperException

use of org.apache.jasper.JasperException in project tomcat by apache.

the class TagLibraryInfoImpl method createValidator.

private TagLibraryValidator createValidator(ValidatorXml validatorXml) throws JasperException {
    if (validatorXml == null) {
        return null;
    }
    String validatorClass = validatorXml.getValidatorClass();
    if (validatorClass == null || validatorClass.isEmpty()) {
        return null;
    }
    Map<String, Object> initParams = new Hashtable<>(validatorXml.getInitParams());
    try {
        Class<?> tlvClass = ctxt.getClassLoader().loadClass(validatorClass);
        TagLibraryValidator tlv = (TagLibraryValidator) tlvClass.getConstructor().newInstance();
        tlv.setInitParameters(initParams);
        return tlv;
    } catch (Exception e) {
        err.jspError(e, "jsp.error.tlvclass.instantiation", validatorClass);
        return null;
    }
}
Also used : Hashtable(java.util.Hashtable) TagLibraryValidator(jakarta.servlet.jsp.tagext.TagLibraryValidator) URISyntaxException(java.net.URISyntaxException) JasperException(org.apache.jasper.JasperException) IOException(java.io.IOException)

Example 80 with JasperException

use of org.apache.jasper.JasperException in project tomcat by apache.

the class TagLibraryInfoImpl method createTagInfo.

private TagInfo createTagInfo(TagXml tagXml) throws JasperException {
    String teiClassName = tagXml.getTeiClass();
    TagExtraInfo tei = null;
    if (teiClassName != null && !teiClassName.isEmpty()) {
        try {
            Class<?> teiClass = ctxt.getClassLoader().loadClass(teiClassName);
            tei = (TagExtraInfo) teiClass.getConstructor().newInstance();
        } catch (Exception e) {
            err.jspError(e, "jsp.error.teiclass.instantiation", teiClassName);
        }
    }
    List<TagAttributeInfo> attributeInfos = tagXml.getAttributes();
    List<TagVariableInfo> variableInfos = tagXml.getVariables();
    return new TagInfo(tagXml.getName(), tagXml.getTagClass(), tagXml.getBodyContent(), tagXml.getInfo(), this, tei, attributeInfos.toArray(new TagAttributeInfo[0]), tagXml.getDisplayName(), tagXml.getSmallIcon(), tagXml.getLargeIcon(), variableInfos.toArray(new TagVariableInfo[0]), tagXml.hasDynamicAttributes());
}
Also used : TagExtraInfo(jakarta.servlet.jsp.tagext.TagExtraInfo) TagAttributeInfo(jakarta.servlet.jsp.tagext.TagAttributeInfo) TagInfo(jakarta.servlet.jsp.tagext.TagInfo) TagVariableInfo(jakarta.servlet.jsp.tagext.TagVariableInfo) URISyntaxException(java.net.URISyntaxException) JasperException(org.apache.jasper.JasperException) IOException(java.io.IOException)

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