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