Advertisement
Guest User

Untitled

a guest
Apr 29th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. package br.edu.uft.util;
  2.  
  3. import com.github.mustachejava.DefaultMustacheFactory;
  4. import com.github.mustachejava.Mustache;
  5. import com.github.mustachejava.MustacheFactory;
  6. import java.io.InputStream;
  7. import java.io.InputStreamReader;
  8. import java.io.Reader;
  9. import java.io.StringReader;
  10. import java.io.StringWriter;
  11. import java.util.Map;
  12.  
  13. /**
  14. *
  15. * @author Thaylon Guedes Santos
  16. * @email thaylongs@gmail.com
  17. */
  18. public class CommonsUtils {
  19.  
  20. public static String applyStringTemplate(String templateName, InputStream templateContent, Map<String, Object> scope) {
  21. return applyStringTemplate(templateName, new InputStreamReader(templateContent), scope);
  22. }
  23.  
  24. public static String applyStringTemplate(String templateName, String templateContent, Map<String, Object> scope) {
  25. return applyStringTemplate(templateName, new StringReader(templateContent), scope);
  26. }
  27.  
  28. public static String applyStringTemplate(String templateName, Reader templateContent, Map<String, Object> scope) {
  29. MustacheFactory mf = new DefaultMustacheFactory();
  30. Mustache mustache = mf.compile(templateContent, templateName);
  31. StringWriter stringWriter = new StringWriter();
  32. mustache.execute(stringWriter, scope);
  33. return stringWriter.toString();
  34. }
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement