protected Template loadTemplate(String name) { try { Reader template; template = this.mustache.loader.getTemplate(name); return this.mustache.compile(template); } catch (Exception ex) { throw new IllegalStateException("Cannot load template " + name, ex); } }
/** Loads and compiles the template {@code name} using this compiler's configured template * loader. Note that this does no caching: the caller should cache the loaded template if * they expect to use it multiple times. * @return the compiled template. * @throw MustacheException if the template could not be loaded (due to I/O exception) or * compiled (due to syntax error, etc.). */ public Template loadTemplate (String name) throws MustacheException { Reader tin = null; try { tin = loader.getTemplate(name); return compile(tin); } catch (Exception e) { if (e instanceof RuntimeException) { throw (RuntimeException)e; } else { throw new MustacheException("Unable to load template: " + name, e); } } finally { if (tin != null) try { tin.close(); } catch (IOException ioe) { throw new RuntimeException(ioe); } } }
try { Template template = this.compiler .compile(this.templateLoader.getTemplate("bom-dependencies")); Map<String, Object> context = new HashMap<>(); context.put("dependencies", dependenciesToVerify);
@Override public void execute (Template tmpl, Template.Context ctx, Writer out) { // we compile our template lazily to avoid infinie recursion if a template includes // itself (see issue #13) if (_template == null) { Reader tin = null; try { tin = _comp.loader.getTemplate(_name); _template = _comp.compile(tin); } catch (Exception e) { if (e instanceof RuntimeException) { throw (RuntimeException)e; } else { throw new MustacheException("Unable to load template: " + _name, e); } } finally { if (tin != null) try { tin.close(); } catch (IOException ioe) { throw new RuntimeException(ioe); } } } // we must take care to preserve our context rather than creating a new one, which // would happen if we just called execute() with ctx.data _template.executeSegs(ctx, out); } @Override public void decompile (Delims delims, StringBuilder into) {