/** * Send an error message. * * <p>Single call to the templet loader giving purpose (error) and Exception class. * * <p>This will look in the purpose directory, the standard templet directory and the classpath, * in that order, for a templet. This can no longer fail with NotFoundException, as the Object * templet will always be found (or this is a broken installation). * * @param melati the {@link Melati} * @param e the {@link Exception} to report */ public void error(Melati melati, Exception e) { melati.getResponse().setStatus(httpStatusCode(e)); ServletTemplateContext templateContext = melati.getServletTemplateContext(); // If this a DB error which has occurred prior to // the establishment of a template context if (templateContext == null) { super.error(melati, e); } else // has it been trapped already, if so, we don't need to relog it here if (!(e instanceof TrappedException)) { try { // log it e.printStackTrace(System.err); // and put it on the page MelatiWriter mw = melati.getWriter(); // get rid of anything that has been written so far mw.reset(); templateContext.put("melati", melati); templateContext.put("ml", melati.getMarkupLanguage()); templateContext.put("object", e); StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); templateContext.put("error", sw); templateContext.put("sysAdminName", getSysAdminName()); templateContext.put("sysAdminEmail", getSysAdminEmail()); Template errorTemplate; errorTemplate = melati .getConfig() .getTempletLoader() .templet( melati.getTemplateEngine(), melati.getMarkupLanguage(), "error", e.getClass()); templateEngine.expandTemplate(mw, errorTemplate, templateContext); melati.write(); } catch (Exception f) { System.err.println("Error finding/writing error template:"); f.printStackTrace(); super.error(melati, e); } } }
/** * Inititialise the template engine. * * @param config a <code>ServletConfig</code> * @throws ServletException if the ServletTemplateEngine has a problem */ public void init(ServletConfig config) throws ServletException { super.init(config); templateEngine = melatiConfig.getServletTemplateEngine(); templateEngine.init(melatiConfig, this); }