12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package templates;
- import java.util.HashMap;
- /**
- *
- * @author EUGENIO CARVALHO
- */
- public abstract class Template {
- public static HashMap<String, String> formats = new HashMap<>();
- public static HashMap<String, RenderStmt> renders = new HashMap<>();
- public static void AddFormat(String id, String format) {
- formats.put(id, format);
- }
- public static String Format(String id) throws Exception {
- if (!formats.containsKey(id)) {
- throw new Exception(String.format("Template format '%s' não definido.", id));
- }
- return formats.get(id);
- }
- public static RenderStmt FormatRender(String id) throws Exception {
- if (!renders.containsKey(id)) {
- renders.put(id, new RenderStmt(id, Format(id)));
- }
- return renders.get(id);
- }
- public static void Register(TemplateDescription description) throws Exception {
- // Adiciona os templates
- formats.putAll(description.Formats());
- // Registra as funções
- HashMap<String, FunctionInterface> functions = description.Functions();
- if (functions != null) {
- functions.entrySet().forEach((entry) -> {
- Functions.Add(entry.getKey(), entry.getValue());
- });
- }
- }
- }
|