private void processTemplate(Node context, Template template, Map<String, ?> initialEnv, Writer out) throws IOException, TemplateException { Map<String, Object> root = new HashMap<>(); if(initialEnv != null) { for(Map.Entry<String, ?> entry : initialEnv.entrySet()) { root.put(entry.getKey(), entry.getValue()); } } root.put("namespace", new NamespaceDirective()); root.put("evalLDPath",new LDPathMethod<>(backend)); root.put("ldpath",new LDPathDirective<>(backend)); TemplateStackModel contexts = new TemplateStackModel(); contexts.push(new TemplateNodeModel<>(context,backend)); root.put("context",contexts); template.process(root,out); } }