public String getErrorMessage(Exception e) { java.io.StringWriter sw = new StringWriter(); VelocityEngine ve = VelocityUtil.getEngine(); VelocityContext context = new VelocityContext(); context.put("veloError", e); context.put("prettyError", UtilMethods.htmlifyString(e.toString())); org.apache.velocity.Template template; try { template = ve.getTemplate(errorTemplate); context.put("error", this); template.merge(context, sw); } catch (Exception ex) { Logger.error(this.getClass(), "Unable to show velocityError", ex); } return sw.toString(); }
private String getLuceneParseErrorMessage( org.apache.lucene.queryparser.classic.ParseException pee) { String msg = pee.toString(); msg = msg.replaceAll( "org.apache.lucene.queryparser.classic.ParseException", "Lucene Parse Error\n"); java.io.StringWriter sw = new StringWriter(); VelocityEngine ve = VelocityUtil.getEngine(); VelocityContext context = new VelocityContext(); context.put("veloError", UtilMethods.htmlifyString(msg)); // context.put("prettyError", UtilMethods.htmlifyString(msg)); org.apache.velocity.Template template; try { template = ve.getTemplate(errorTemplate); template.merge(context, sw); } catch (Exception ex) { Logger.error(this.getClass(), "Unable to show velocityError", ex); } return sw.toString(); }
private String getParseErrorMessage(ParseErrorException pee) { String msg = pee.toString().replaceAll("at " + pee.getTemplateName(), ""); msg = msg.replaceAll("org.apache.velocity.exception.ParseErrorException:", ""); msg = msg.replaceAll("\\.\\.\\.", ","); if (pee.getLineNumber() > -1) { msg = msg.replaceAll("\\[.*\\]", ""); } else { msg = msg.replaceAll("\\[", "\n\\["); } msg = UtilMethods.replace(msg, "\"<EOF>\"", "end of file"); msg = UtilMethods.htmlifyString(msg); msg = UtilMethods.htmlLineBreak(msg); while (msg.endsWith(",")) { msg = msg.substring(0, msg.length() - 1); } int showLines = 2; List<Map<String, String>> badCode = new ArrayList<Map<String, String>>(); if (pee.getLineNumber() > -1) { BufferedReader buff = null; try { buff = new BufferedReader( new InputStreamReader( DotResourceLoader.getInstance().getResourceStream(pee.getTemplateName()))); String x; int here = 1; while ((x = buff.readLine()) != null) { Map m = new HashMap<String, String>(); if (pee.getLineNumber() == here) { m.put("code", UtilMethods.htmlifyString(x)); m.put("lineNumber", here); m.put("badLine", "true"); badCode.add(m); } else if (here >= pee.getLineNumber() - showLines && here <= pee.getLineNumber() + showLines) { if (UtilMethods.isSet(x)) { m.put("code", UtilMethods.htmlifyString(x)); m.put("lineNumber", here); badCode.add(m); } else { m.put("code", " "); m.put("lineNumber", here); badCode.add(m); } } else if (here - showLines > pee.getLineNumber()) { break; } here++; } } catch (IOException e1) { Logger.error(this.getClass(), "Unable to open buffy!" + e1); } finally { try { buff.close(); } catch (Exception die) { Logger.error(this.getClass(), "Unable to close buffy!" + die); } } } java.io.StringWriter sw = new StringWriter(); VelocityEngine ve = VelocityUtil.getEngine(); VelocityContext context = new VelocityContext(); context.put("veloError", pee); context.put("subErrorTemplate", "/static/preview_mode/error_template_parseexception.vtl"); context.put("badCode", badCode); context.put("prettyError", msg); org.apache.velocity.Template template; try { template = ve.getTemplate(errorTemplate); context.put("error", this); template.merge(context, sw); } catch (Exception ex) { Logger.error(this.getClass(), "Unable to show velocityError", ex); } return sw.toString(); }