private void copyTemplated(String sourceResourcePath, String destinationFileName, VelocityContext velocityContext) throws IOException { try (InputStreamReader reader = new InputStreamReader( EmbulkNew.class.getClassLoader().getResourceAsStream(sourceResourcePath))) { final Path destinationPath = this.pluginBasePath.resolve(destinationFileName); Files.createDirectories(destinationPath.getParent()); try (BufferedWriter writer = Files.newBufferedWriter(destinationPath, StandardCharsets.UTF_8)) { this.velocityEngine.evaluate(velocityContext, writer, "embulk-new", reader); } } }
if (!velocityEngine.evaluate(context, writer, logTag, reader)) { throw new ReportException("Failed to convert the template into html.");
VelocityEngine ve = new VelocityEngine(); ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath"); ve.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName()); ve.init(); final String templatePath = "templates/" + templateName + ".vm"; InputStream input = this.getClass().getClassLoader().getResourceAsStream(templatePath); if (input == null) { throw new IOException("Template file doesn't exist"); } InputStreamReader reader = new InputStreamReader(input); VelocityContext context = new VelocityContext(); if (properties != null) { stringfyNulls(properties); for (Map.Entry<String, Object> property : properties.entrySet()) { context.put(property.getKey(), property.getValue()); } } Template template = ve.getTemplate(templatePath, "UTF-8"); String outFileName = File.createTempFile("report", ".html").getAbsolutePath(); BufferedWriter writer = new BufferedWriter(new FileWriter(new File(outFileName))); if (!ve.evaluate(context, writer, templatePath, reader)) { throw new Exception("Failed to convert the template into html."); } template.merge(context, writer); writer.flush(); writer.close();
v.evaluate(ctx, w, "", templateReader);
velocityEngine.evaluate(velocityContext, httpResponse.getWriter(), this.getClass().getName(), new InputStreamReader(templateInputStream, StandardCharsets.UTF_8));
File f = new File(targetResourceDirectory, targetResourceSpringBeansFile); OutputStreamWriter w = new OutputStreamWriter(new FileOutputStream(f, false), "UTF-8"); v.evaluate(ctx, w, "", templateReader); w.close(); f = new File(configPackageDirectoryBase, "BaseJavaConfig" + capitalize + ".java"); w = new OutputStreamWriter(new FileOutputStream(f, false), "UTF-8"); v.evaluate(ctx, w, "", templateReader); w.close();
v.evaluate(ctx, w, "", templateReader);
v.evaluate(ctx, w, "", templateReader); w.close();
ByteArrayOutputStream byteArrayWriter = new ByteArrayOutputStream(); OutputStreamWriter outputStreamWriter = new OutputStreamWriter(byteArrayWriter, Charsets.UTF_8); v.evaluate(ctx, outputStreamWriter, "", templateReader); outputStreamWriter.flush();
@Override public Message prepare(Template template) throws MessageException { VelocityContext context = new VelocityContext(template.getData()); StringWriter writer = new StringWriter(); try { engine.evaluate(context, writer, "template", // I have no idea what this is used for template.getTemplate()); } catch (Exception e) { // need better error handling log.error("Failed to prepare message using template " + e.getMessage(), e); throw new MessageException(e); } // Prepare the message Message message = new Message(); message.setSubject(template.getSubject()); message.setRecipients(template.getRecipients()); message.setSender(template.getSender()); message.setContent(writer.toString()); return message; } }
ourLog.info("Writing Resources..."); ctx.put("resources", rp.getResources()); v.evaluate(ctx, targetWriter, "", templateReader); targetWriter.close(); } else { ourLog.info("Writing DataTypes..."); ctx.put("datatypes", dtp.getResources()); v.evaluate(ctx, targetWriter, "", templateReader); targetWriter.close();
@Override protected synchronized void eval(final StringWriter out) throws Exception { boolean succeeded = velocityEngine.evaluate(context, out, "", templateText); if (!succeeded) { logger.error("Failed to evaluate velocity template text: " + templateText); } }
public static String writeTemplate(String template, Object bean) throws Exception { VelocityContext vcontext = new VelocityContext(); vcontext.put("bean", bean); StringWriter w = new StringWriter(); getVelocityEngine().evaluate(vcontext, w, "log", template); return w.toString(); }
public static String writeTemplate(String template, Map bean, File templateRoot) throws Exception { VelocityContext context = new VelocityContext(bean); StringWriter w = new StringWriter(); getVelocityEngine(templateRoot).evaluate(context, w, "log", template); return w.toString(); }
public void evaluteString(Context context, Writer writer, String string) { TinyVelocityContext tinyVelocityContext = new TinyVelocityContext( context); VelocityContext velocityContext = new VelocityContext( tinyVelocityContext); velocity.evaluate(velocityContext, writer, "mystring", string); }
@Override public String render(TemplateRenderRequest request) { VelocityEngine velocity = new VelocityEngine(); velocity.init(); VelocityContext context = new VelocityContext(request.getContext()); StringWriter writer = new StringWriter(); velocity.evaluate(context, writer, "render-template", request.getTemplate()); return writer.toString(); }
private String generateSubject( ProjectScmRoot projectScmRoot ) throws Exception { String state = getState( projectScmRoot ); VelocityContext context = new VelocityContext(); context.put( "projectScmRoot", projectScmRoot ); context.put( "state", state ); StringWriter writer = new StringWriter(); boolean velocityResults = velocity.getEngine().evaluate( context, writer, "subjectPattern", prepareBuildSubjectFormat ); return writer.toString(); }
public String evaluate(String expression) throws IOException, ResourceNotFoundException, MethodInvocationException, ParseErrorException { CharArrayWriter writer = new CharArrayWriter(); VelocityManager.getInstance().getVelocityEngine().evaluate(ctx, writer, "Error parsing " + expression, expression); return writer.toString(); }
protected void evalBody(Writer out) throws Exception { VelocityEngine engine = getVelocityView().getVelocityEngine(); engine.evaluate(getViewToolContext(), out, getLogId(), getBodyContent().getReader()); }