View Javadoc

1   package com.atlassian.selenium.visualcomparison.utils;
2   
3   import org.apache.velocity.Template;
4   import org.apache.velocity.VelocityContext;
5   import org.apache.velocity.app.Velocity;
6   
7   import java.io.StringWriter;
8   import java.util.Properties;
9   
10  public class ReportRenderer
11  {
12      private static boolean initialised = false;
13  
14      public static VelocityContext createContext() throws Exception
15      {
16          if (!initialised)
17          {
18              Properties p = new Properties();
19              p.setProperty("resource.loader", "class");
20              p.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
21              Velocity.init(p);
22              initialised = true;
23          }
24          return new VelocityContext();
25      }
26  
27      public static String render(VelocityContext context, String templateName) throws Exception
28      {
29          Template template = Velocity.getTemplate(templateName);
30          StringWriter sw = new StringWriter();
31          template.merge(context, sw);
32          return sw.toString();
33      }
34   }