/** * */ public void close() { try { theJar.close(); } catch ( Exception e ) { String msg = "JarHolder: error closing the JAR file"; log.error(msg, e); throw new VelocityException(msg, e); } theJar = null; conn = null; log.trace("JarHolder: JAR file closed"); }
/** * Return our custom message if we have one, else return the default message */ public String getMessage() { if (msg != null) return msg; return super.getMessage(); } }
private void errorHandling(final String templatePath, final PrintWriter writer, final VelocityException e) { writer.write("Exception rendering velocity file " + TextUtils.htmlEncode(templatePath)); writer.write("<br><pre>"); StringWriter stringWriter = new StringWriter(); e.printStackTrace(new PrintWriter(stringWriter)); writer.write(TextUtils.htmlEncode(stringWriter.toString())); writer.write("</pre>"); }
/** * Create a ParseErrorException with the given ParseException. * * @param pex the parsing exception * @since 1.5 */ public ParseErrorException(VelocityException pex) { super(pex.getMessage()); // Don't use a second C'tor, TemplateParseException is a subclass of // ParseException... if (pex instanceof ExtendedParseException) { ExtendedParseException xpex = (ExtendedParseException) pex; columnNumber = xpex.getColumnNumber(); lineNumber = xpex.getLineNumber(); templateName = xpex.getTemplateName(); } else if (pex.getWrappedThrowable() instanceof ParseException) { ParseException pex2 = (ParseException) pex.getWrappedThrowable(); if (pex2.currentToken != null && pex2.currentToken.next != null) { columnNumber = pex2.currentToken.next.beginColumn; lineNumber = pex2.currentToken.next.beginLine; } } }
/** * Create a ParseErrorException with the given ParseException. * * @param pex the parsing exception * @since 1.5 */ public ParseErrorException(VelocityException pex, String templName) { super(pex.getMessage()); if (templName != null) templateName = templName; // Don't use a second C'tor, TemplateParseException is a subclass of // ParseException... if (pex instanceof ExtendedParseException) { ExtendedParseException xpex = (ExtendedParseException) pex; columnNumber = xpex.getColumnNumber(); lineNumber = xpex.getLineNumber(); templateName = xpex.getTemplateName(); } else if (pex.getCause() instanceof ParseException) { ParseException pex2 = (ParseException) pex.getCause(); if (pex2.currentToken != null && pex2.currentToken.next != null) { columnNumber = pex2.currentToken.next.beginColumn; lineNumber = pex2.currentToken.next.beginLine; } } }
/** * Send a simple message based on a Velocity template. * @param msg the message to populate * @param templateName the Velocity template to use (relative to classpath) * @param model a map containing key/value pairs */ @SuppressWarnings("unchecked") public void sendMessage(SimpleMailMessage msg, String templateName, Map model) { String result = null; try { result = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, templateName, "UTF-8", model); } catch (VelocityException e) { e.printStackTrace(); log.error(e.getMessage()); } msg.setText(result); send(msg); }
/** * returns the wrapped Throwable that caused this * MethodInvocationException to be thrown * * @return Throwable thrown by method invocation * @since 1.5 * @deprecated Use {@link java.lang.RuntimeException#getCause()} */ public Throwable getWrappedThrowable() { return getCause(); }
/** * Create a ParseErrorException with the given ParseException. * * @param pex the parsing exception * @since 1.5 */ public ParseErrorException(VelocityException pex, String templName) { super(pex.getMessage()); if (templName != null) templateName = templName; // Don't use a second C'tor, TemplateParseException is a subclass of // ParseException... if (pex instanceof ExtendedParseException) { ExtendedParseException xpex = (ExtendedParseException) pex; columnNumber = xpex.getColumnNumber(); lineNumber = xpex.getLineNumber(); templateName = xpex.getTemplateName(); } else if (pex.getWrappedThrowable() instanceof ParseException) { ParseException pex2 = (ParseException) pex.getWrappedThrowable(); if (pex2.currentToken != null && pex2.currentToken.next != null) { columnNumber = pex2.currentToken.next.beginColumn; lineNumber = pex2.currentToken.next.beginLine; } } }
public void handleStopFileGeneration(VelocityException exception) { if (exception.getCause() instanceof StopFileReachedException) { throw new StopFileReachedException(); } }
/** * Returns a reference to the default static repository. * * @param engine Velocity engine to obtain repository for * * @return the applicable repository * @throw VelocityException if the repository cannot be obtained */ public static StringResourceRepository getRepository(VelocityEngine engine) { String implClass = engine.getProperty("string.resource.loader.class").toString(); if (implClass == null) { throw new VelocityException("Velocity engine did not contain a string.resource.loader.class property"); } try { Method m = Class.forName(implClass).getMethod("getRepository", (Class[]) null); return (StringResourceRepository) m.invoke(null, (Object[]) null); } catch (Exception e) { e.printStackTrace(); throw new VelocityException("Exception obtaining StringResourceRepository", e); } }
/** * Return our custum message if we have one, else return the default message */ public String getMessage() { if (msg != null) return msg; return super.getMessage(); } }
public String generateServer(CProject project) { try { Map model = new HashMap(); model.put("project", project); String content = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "velocity/server.vm", model); FileUtil.writeFile(project.getServerPath()+"/", project.getServerClass() + ".java", project.isAppend(), content); return content; } catch (VelocityException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
public void handleStopFileGeneration(VelocityException exception) { if (exception.getCause() instanceof StopFileReachedException) { throw new StopFileReachedException(); } }
/** * Initialize the Velocity logging system. */ private void initializeLog() { // since the Log we started with was just placeholding, // let's update it with the real LogChute settings. try { LogManager.updateLog(this.log, this); } catch (Exception e) { throw new VelocityException("Error initializing log: " + e.getMessage(), e); } }
/** * @see Exception#getMessage() * @since 1.5 */ public String getMessage() { StringBuilder message = new StringBuilder(); message.append(super.getMessage()); message.append(" at "); message.append(StringUtils.formatFileString(templateName, lineNumber, columnNumber)); return message.toString(); } }
private void applyDecoratorUsingVelocity(HttpServletRequest request, Page page, HttpServletResponse response) throws IOException { String servletPath = (String) request.getAttribute("javax.servlet.include.servlet_path"); if (servletPath == null) { servletPath = request.getServletPath(); } if (servletPath != null && servletPath.startsWith("/")) { servletPath = servletPath.substring(1); // trim leading slash } Map<String, Object> velocityParams = getVelocityParams(request, page, response); final PrintWriter writer = response.getWriter(); try { response.setContentType(getApplicationProperties().getContentType()); final String body = getTemplatingEngine().render(file(servletPath)).applying(velocityParams).asHtml(); writer.write(body); } catch (VelocityException e) { writer.write("Exception rendering velocity file " + servletPath); writer.write("<br><pre>"); e.printStackTrace(writer); writer.write("</pre>"); } request.removeAttribute(RequestConstants.PAGE); }
private void tryToSetTimeout(URLConnection conn) { if (timeout > 0) { Object[] arg = new Object[] { new Integer(timeout) }; try { timeoutMethods[0].invoke(conn, arg); timeoutMethods[1].invoke(conn, arg); } catch (Exception e) { String msg = "Unexpected exception while setting connection timeout for "+conn; log.error(msg, e); throw new VelocityException(msg, e); } } }
/** * @see Exception#getMessage() * @since 1.5 */ public String getMessage() { StringBuffer message = new StringBuffer(); message.append(super.getMessage()); message.append(" at "); message.append(Log.formatFileString(templateName, lineNumber, columnNumber)); return message.toString(); } }
public List<String> generateInterfaces(CProject project) { List<String> ms = new ArrayList(); for (CMold cm : project.getMolds()) { try { Map model = new HashMap(); model.put("cm", cm); String content = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "velocity/interface.vm", model); FileUtil.writeFile(cm.getInterfacePath()+"/", cm.getInterfaceClass() + ".java", project.isAppend(), content); ms.add(content); } catch (VelocityException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return ms; }
/** * Returns a reference to the repository stored statically under the specified name. * * @param engine Velocity engine to obtain repository for * @param name name of repository to access * * @return the applicable repository * @throw VelocityException if the repository cannot be obtained */ public static StringResourceRepository getRepository(VelocityEngine engine, String name) { String implClass = engine.getProperty("string.resource.loader.class").toString(); if (implClass == null) { throw new VelocityException("Velocity engine did not contain a string.resource.loader.class property"); } try { Method m = Class.forName(implClass).getMethod("getRepository", String.class); return (StringResourceRepository) m.invoke(null, name); } catch (Exception e) { e.printStackTrace(); throw new VelocityException("Exception obtaining StringResourceRepository", e); } } }