@Override public JtwigResource resolve(String relativePath) throws ResourceException { throw new ResourceException("Cannot resolve relative resources in a String resource"); } }
boolean throwException(ParseException exception) throws ParseBypassException { throw new ParseBypassException(exception); }
@Override public boolean render(OutputStream outputStream, JtwigContext context) throws RenderException { try { outputStream.write(String.valueOf(expression.calculate(context)).getBytes()); return true; } catch (IOException e) { throw new RenderException(e); } catch (CalculateException e) { throw new RenderException(e); } }
@Override public Object calculate(JtwigContext context) throws CalculateException { try { return context.function(getName()).execute(arguments(context)); } catch (FunctionException e) { throw new CalculateException(e); } catch (FunctionNotFoundException e) { throw new CalculateException(e); } }
boolean assertEqual(String value1, String value2) { if (!value1.equals(value2)) return throwException(new ParseException("Start statement and ending block names do not match")); else return true; }
@Override public Content compile(JtwigResource resource) throws CompileException { try { JtwigResource jtwigResource = resource.resolve(path); JtwigDocument jtwigDocument = JtwigParser.parse(jtwigResource); return jtwigDocument.compile(jtwigResource); } catch (ParseException e) { throw new CompileException(e); } catch (ResourceException e) { throw new CompileException(e); } }
@Override public JtwigResource resolve(String relativePath) throws ResourceException { throw new ResourceException("Cannot resolve relative resources in a String resource"); } }
boolean throwException(ParseException exception) throws ParseBypassException { throw new ParseBypassException(exception); }
@Override public Object calculate(JtwigContext context) throws CalculateException { try { return context.function(getName()).execute(arguments(context)); } catch (FunctionException e) { throw new CalculateException(e); } catch (FunctionNotFoundException e) { throw new CalculateException(e); } }
@Override public boolean render(OutputStream outputStream, JtwigContext context) throws RenderException { try { context.set(name.getIdentifier(), assignment.calculate(context)); return true; } catch (CalculateException e) { throw new RenderException(e); } }
boolean assertEqual(String value1, String value2) { if (!value1.equals(value2)) return throwException(new ParseException("Start statement and ending block names do not match")); else return true; }
@Override public InputStream retrieve() throws ResourceException { try { return new FileInputStream(file); } catch (FileNotFoundException e) { throw new ResourceException(e); } }
boolean throwException(ParseException exception) throws ParseBypassException { throw new ParseBypassException(exception); }
@Override public Object calculate(JtwigContext context) throws CalculateException { switch (operator) { case NOT: return BooleanOperations.not(operand.calculate(context)); case SUB: return MathOperations.mul(-1, operand.calculate(context)); } throw new CalculateException("Unknown operator "+operator); } }
@Override public boolean render(OutputStream outputStream, JtwigContext context) throws RenderException { try { if (isTrue(condition.calculate(context))) { return content.render(outputStream, context); } return false; } catch (CalculateException e) { throw new RenderException(e); } }
@Override public InputStream retrieve() throws ResourceException { InputStream resourceAsStream = servletContext.getResourceAsStream(url); if (resourceAsStream == null) throw new ResourceException("Resource "+url+" not found"); return resourceAsStream; }
boolean throwException(ParseException exception) throws ParseBypassException { throw new ParseBypassException(exception); }
@Override public InputStream retrieve() throws ResourceException { try { return new FileInputStream(file); } catch (FileNotFoundException e) { throw new ResourceException(e); } }
@Override public InputStream retrieve() throws ResourceException { try { return new FileInputStream(resourcePath.toFile()); } catch (FileNotFoundException e) { throw new ResourceException(e); } }
@Override public InputStream retrieve() throws ResourceException { InputStream resourceAsStream = this.getClass().getClassLoader().getResourceAsStream(this.resource); if (resourceAsStream == null) throw new ResourceException("Resource '"+ this.resource +"' not found"); return resourceAsStream; }