View Javadoc

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