Template.java 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package templates;
  7. import java.util.HashMap;
  8. /**
  9. *
  10. * @author EUGENIO CARVALHO
  11. */
  12. public abstract class Template {
  13. public static HashMap<String, String> formats = new HashMap<>();
  14. public static HashMap<String, RenderStmt> renders = new HashMap<>();
  15. public static void AddFormat(String id, String format) {
  16. formats.put(id, format);
  17. }
  18. public static String Format(String id) throws Exception {
  19. if (!formats.containsKey(id)) {
  20. throw new Exception(String.format("Template format '%s' não definido.", id));
  21. }
  22. return formats.get(id);
  23. }
  24. public static RenderStmt FormatRender(String id) throws Exception {
  25. if (!renders.containsKey(id)) {
  26. renders.put(id, new RenderStmt(id, Format(id)));
  27. }
  28. return renders.get(id);
  29. }
  30. public static void Register(TemplateDescription description) throws Exception {
  31. // Adiciona os templates
  32. formats.putAll(description.Formats());
  33. // Registra as funções
  34. HashMap<String, FunctionInterface> functions = description.Functions();
  35. if (functions != null) {
  36. functions.entrySet().forEach((entry) -> {
  37. Functions.Add(entry.getKey(), entry.getValue());
  38. });
  39. }
  40. }
  41. }