public Writer getWriter() { if (writer == null) return (Writer) Context.getContext().getOut(); return writer; }
private Map<String, Object> getContext(int scope) { if (scope == GLOBAL_SCOPE) { return GlobalResolver.getGlobal(); } return Context.getContext(); }
/** * Push the current context to thread local. * * @param current - current variables */ public static Context pushContext(Map<String, Object> current) { Context context = new Context(getContext(), current); LOCAL.set(context); return context; }
@Override public void render(Object parameters, Object out) throws IOException, ParseException { listener.render(Context.getContext()); }
public static void setResponse(HttpServletResponse response) { if (response != null) { checkResponseEncoding(response); RESPONSE_LOCAL.set(response); } else { RESPONSE_LOCAL.remove(); } Context.getContext().put("response", response); }
public static void setResponse(HttpServletResponse response) { if (response != null) { checkResponseEncoding(response); RESPONSE_LOCAL.set(response); } else { RESPONSE_LOCAL.remove(); } Context.getContext().put("response", response); }
public Template render(byte[] source) throws IOException, ParseException { Template template = Context.getContext().getTemplate(); if (template == null) { throw new IllegalArgumentException("display context template == null"); } String encoding = template.getEncoding(); return render(encoding == null ? new String(source) : new String(source, encoding)); }
public Template $extends(String name, Locale locale, String encoding, Map<String, Object> parameters) throws IOException, ParseException { if (parameters != null) { Context.getContext().putAll(parameters); } return $extends(name, locale, encoding); }
public Template include(String name, Locale locale, String encoding, Map<String, Object> parameters) throws IOException, ParseException { if (parameters != null) { Context.getContext().putAll(parameters); } return include(name, locale, encoding); }
public static Engine getEngine() { if (ENGINE == null) { Object request = Context.getContext().get("request"); if (request instanceof HttpServletRequest && ((HttpServletRequest) request).getSession() != null) { setServletContext(((HttpServletRequest) request).getSession().getServletContext()); } else { setServletContext(ServletLoader.getAndCheckServletContext()); } } return ENGINE; }
@Override public boolean visit(Template node) throws IOException, ParseException { for (Node child : node.getChildren()) { child.accept(this); if (ClassUtils.isTrue(Context.getContext().get(breakVariable))) { Context.getContext().remove(breakVariable); break; } } return false; }
public Object evaluate() throws ParseException { // Context.getOut() only OutputStream or Writer if (Context.getContext().getOut() instanceof OutputStream) { return streamTemplate.evaluate(); } else { return writerTemplate.evaluate(); } }
public Object evaluate(Object context) throws ParseException { // Context.getOut() only OutputStream or Writer if (Context.getContext().getOut() instanceof OutputStream) { return streamTemplate.evaluate(context); } else { return writerTemplate.evaluate(context); } }
public Object evaluate(Object context) throws ParseException { // Context.getOut() only OutputStream or Writer if (Context.getContext().getOut() instanceof OutputStream) { return streamTemplate.evaluate(context); } else { return writerTemplate.evaluate(context); } }
public Object evaluate() throws ParseException { // Context.getOut() only OutputStream or Writer if (Context.getContext().getOut() instanceof OutputStream) { return streamTemplate.evaluate(); } else { return writerTemplate.evaluate(); } }
@Override public void visit(SetDirective node) throws IOException, ParseException { if (node.getExpression() != null) { Object result = popExpressionResult(node.getOffset()); if (node.isExport() && Context.getContext().getParent() != null) { Context.getContext().getParent().put(node.getName(), result); } else { Context.getContext().put(node.getName(), result); } } }
@Override public boolean visit(ElseDirective node) throws IOException, ParseException { boolean result = true; if (node.getExpression() != null) { result = ClassUtils.isTrue(popExpressionResult(node.getOffset())); } result = result && !ClassUtils.isTrue(Context.getContext().get(ifVariable)); if (result) { Context.getContext().put(ifVariable, true); } return result; }
@Override public boolean visit(IfDirective node) throws IOException, ParseException { boolean result = ClassUtils.isTrue(popExpressionResult(node.getOffset())); Context.getContext().put(ifVariable, result); return result; }
@Override public void visit(BreakDirective node) throws IOException, ParseException { boolean result = true; if (node.getExpression() != null) { result = ClassUtils.isTrue(popExpressionResult(node.getOffset())); } if (result) { Context.getContext().put(breakVariable, true); } }
@Override public void visit(BreakDirective node) throws IOException, ParseException { boolean result = true; if (node.getExpression() != null) { result = ClassUtils.isTrue(popExpressionResult(node.getOffset())); } if (result) { Context.getContext().put(breakVariable, true); } }