Search in sources :

Example 11 with JasperException

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

the class OriginalTldLocationsCache method init.

private void init() throws JasperException {
    if (initialized)
        return;
    try {
        processWebDotXml();
        scanJars();
        processTldsInFileSystem("/WEB-INF/");
        initialized = true;
    } catch (Exception ex) {
        throw new JasperException(Localizer.getMessage("jsp.error.internal.tldinit", ex.getMessage()));
    }
}
Also used : JasperException(org.apache.sling.scripting.jsp.jasper.JasperException) MalformedURLException(java.net.MalformedURLException) JasperException(org.apache.sling.scripting.jsp.jasper.JasperException)

Example 12 with JasperException

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

the class OriginalTldLocationsCache method scanJar.

/**
     * Scans the given JarURLConnection for TLD files located in META-INF
     * (or a subdirectory of it), adding an implicit map entry to the taglib
     * map for any TLD that has a <uri> element.
     *
     * @param conn The JarURLConnection to the JAR file to scan
     * @param ignore true if any exceptions raised when processing the given
     * JAR should be ignored, false otherwise
     */
private void scanJar(JarURLConnection conn, boolean ignore) throws JasperException {
    JarFile jarFile = null;
    String resourcePath = conn.getJarFileURL().toString();
    try {
        if (redeployMode) {
            conn.setUseCaches(false);
        }
        jarFile = conn.getJarFile();
        Enumeration entries = jarFile.entries();
        while (entries.hasMoreElements()) {
            JarEntry entry = (JarEntry) entries.nextElement();
            String name = entry.getName();
            if (!name.startsWith("META-INF/"))
                continue;
            if (!name.endsWith(".tld"))
                continue;
            InputStream stream = jarFile.getInputStream(entry);
            try {
                String uri = getUriFromTld(resourcePath, stream);
                // present in the map
                if (uri != null && mappings.get(uri) == null) {
                    mappings.put(uri, new String[] { resourcePath, name });
                }
            } finally {
                if (stream != null) {
                    try {
                        stream.close();
                    } catch (Throwable t) {
                    // do nothing
                    }
                }
            }
        }
    } catch (Exception ex) {
        if (!redeployMode) {
            // if not in redeploy mode, close the jar in case of an error
            if (jarFile != null) {
                try {
                    jarFile.close();
                } catch (Throwable t) {
                // ignore
                }
            }
        }
        if (!ignore) {
            throw new JasperException(ex);
        }
    } finally {
        if (redeployMode) {
            // if in redeploy mode, always close the jar
            if (jarFile != null) {
                try {
                    jarFile.close();
                } catch (Throwable t) {
                // ignore
                }
            }
        }
    }
}
Also used : Enumeration(java.util.Enumeration) JasperException(org.apache.sling.scripting.jsp.jasper.JasperException) InputStream(java.io.InputStream) JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry) MalformedURLException(java.net.MalformedURLException) JasperException(org.apache.sling.scripting.jsp.jasper.JasperException)

Example 13 with JasperException

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

the class ErrorDispatcher method dispatch.

//*********************************************************************
// Private utility methods
/*
     * Dispatches the given JSP parse error to the configured error handler.
     *
     * The given error code is localized. If it is not found in the
     * resource bundle for localized error messages, it is used as the error
     * message.
     *
     * @param where Error location
     * @param errCode Error code
     * @param args Arguments for parametric replacement
     * @param e Parsing exception
     */
private void dispatch(Mark where, String errCode, Object[] args, Exception e) throws JasperException {
    String file = null;
    String errMsg = null;
    int line = -1;
    int column = -1;
    boolean hasLocation = false;
    // Localize
    if (errCode != null) {
        errMsg = Localizer.getMessage(errCode, args);
    } else if (e != null) {
        // give a hint about what's wrong
        errMsg = e.getMessage();
    }
    // Get error location
    if (where != null) {
        if (jspcMode) {
            // Get the full URL of the resource that caused the error
            try {
                file = where.getURL().toString();
            } catch (MalformedURLException me) {
                // Fallback to using context-relative path
                file = where.getFile();
            }
        } else {
            // Get the context-relative resource path, so as to not
            // disclose any local filesystem details
            file = where.getFile();
        }
        line = where.getLineNumber();
        column = where.getColumnNumber();
        hasLocation = true;
    }
    // Get nested exception
    Exception nestedEx = e;
    if ((e instanceof SAXException) && (((SAXException) e).getException() != null)) {
        nestedEx = ((SAXException) e).getException();
    }
    if (hasLocation) {
        errHandler.jspError(file, line, column, errMsg, nestedEx);
    } else {
        errHandler.jspError(errMsg, nestedEx);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) MalformedURLException(java.net.MalformedURLException) SAXException(org.xml.sax.SAXException) IOException(java.io.IOException) JasperException(org.apache.sling.scripting.jsp.jasper.JasperException) SAXException(org.xml.sax.SAXException)

Example 14 with JasperException

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

the class JspServletWrapper method loadServlet.

@SuppressWarnings("unchecked")
private Servlet loadServlet() throws ServletException, IOException {
    Servlet servlet = null;
    try {
        if (log.isDebugEnabled()) {
            log.debug("Loading servlet " + jspUri);
        }
        servlet = (Servlet) ctxt.load().newInstance();
        AnnotationProcessor annotationProcessor = (AnnotationProcessor) config.getServletContext().getAttribute(AnnotationProcessor.class.getName());
        if (annotationProcessor != null) {
            annotationProcessor.processAnnotations(servlet);
            annotationProcessor.postConstruct(servlet);
        }
        // update dependents
        final List<String> oldDeps = this.dependents;
        if (servlet != null && servlet instanceof JspSourceDependent) {
            this.dependents = (List<String>) ((JspSourceDependent) servlet).getDependants();
            if (this.dependents == null) {
                this.dependents = Collections.EMPTY_LIST;
            }
            this.ctxt.getRuntimeContext().addJspDependencies(this, this.dependents);
        }
        if (!equals(oldDeps, this.dependents)) {
            this.persistDependencies();
        }
    } catch (final IllegalAccessException e) {
        throw new JasperException(e);
    } catch (final InstantiationException e) {
        throw new JasperException(e);
    } catch (final Exception e) {
        throw new JasperException(e);
    }
    servlet.init(config);
    return servlet;
}
Also used : JasperException(org.apache.sling.scripting.jsp.jasper.JasperException) Servlet(javax.servlet.Servlet) AnnotationProcessor(org.apache.sling.scripting.jsp.jasper.runtime.AnnotationProcessor) JspSourceDependent(org.apache.sling.scripting.jsp.jasper.runtime.JspSourceDependent) ServletException(javax.servlet.ServletException) SlingServletException(org.apache.sling.api.SlingServletException) SlingException(org.apache.sling.api.SlingException) IOException(java.io.IOException) SlingIOException(org.apache.sling.api.SlingIOException) UnavailableException(javax.servlet.UnavailableException) ScriptEvaluationException(org.apache.sling.api.scripting.ScriptEvaluationException) SlingPageException(org.apache.sling.scripting.jsp.SlingPageException) JasperException(org.apache.sling.scripting.jsp.jasper.JasperException)

Example 15 with JasperException

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

the class MyErrorHandler method parseXMLDocument.

// --------------------------------------------------------- Public Methods
/**
     * Parse the specified XML document, and return a <code>TreeNode</code>
     * that corresponds to the root node of the document tree.
     *
     * @param uri URI of the XML document being parsed
     * @param is Input source containing the deployment descriptor
     *
     * @exception JasperException if an input/output error occurs
     * @exception JasperException if a parsing error occurs
     */
public TreeNode parseXMLDocument(String uri, InputSource is) throws JasperException {
    Document document = null;
    // Perform an XML parse of this document, via JAXP
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        factory.setValidating(validating);
        DocumentBuilder builder = factory.newDocumentBuilder();
        builder.setEntityResolver(entityResolver);
        builder.setErrorHandler(errorHandler);
        document = builder.parse(is);
    } catch (ParserConfigurationException ex) {
        throw new JasperException(Localizer.getMessage("jsp.error.parse.xml", uri), ex);
    } catch (SAXParseException ex) {
        throw new JasperException(Localizer.getMessage("jsp.error.parse.xml.line", uri, Integer.toString(ex.getLineNumber()), Integer.toString(ex.getColumnNumber())), ex);
    } catch (SAXException sx) {
        throw new JasperException(Localizer.getMessage("jsp.error.parse.xml", uri), sx);
    } catch (IOException io) {
        throw new JasperException(Localizer.getMessage("jsp.error.parse.xml", uri), io);
    }
    // Convert the resulting document to a graph of TreeNodes
    return (convert(null, document.getDocumentElement()));
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) JasperException(org.apache.sling.scripting.jsp.jasper.JasperException) SAXParseException(org.xml.sax.SAXParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException)

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