daily pastebin goal
62%
SHARE
TWEET

Untitled

a guest Feb 19th, 2019 74 in 1 day
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class PageGenerator {
  2.     private static final String HTML_DIR = "templates";
  3.  
  4.     private static PageGenerator pageGenerator;
  5.     private final Configuration cfg;
  6.  
  7.     public static PageGenerator instance() {
  8.         if (pageGenerator == null)
  9.             pageGenerator = new PageGenerator();
  10.         return pageGenerator;
  11.     }
  12.  
  13.     public String getPage(String filename, Map<String, Object> data) {
  14.         Writer stream = new StringWriter();
  15.         try {
  16.             Template template = cfg.getTemplate(HTML_DIR + File.separator + filename);
  17.             template.process(data, stream);
  18.         } catch (IOException | TemplateException e) {
  19.             e.printStackTrace();
  20.         }
  21.         return stream.toString();
  22.     }
  23.  
  24.     private PageGenerator() {
  25.         cfg = new Configuration();
  26.     }
  27. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top