public void render(Writer newOut) throws TemplateException, IOException { Writer prevOut = out; out = newOut; try { visit(childBuffer); } finally { out = prevOut; } }
env.visit(getChildBuffer(), (TemplateDirectiveModel) tm, args, bodyParameterNames); } else { env.visitAndTransform(getChildBuffer(), (TemplateTransformModel) tm, args);
/** * Visits the elements while temporarily using the parameter output {@link Writer}. * * @since 2.3.27 */ final void visit(TemplateElement[] elementBuffer, Writer out) throws IOException, TemplateException { Writer prevOut = this.out; this.out = out; try { visit(elementBuffer); } finally { this.out = prevOut; } }
String renderElementToString(TemplateElement te) throws IOException, TemplateException { Writer prevOut = out; try { StringWriter sw = new StringWriter(); this.out = sw; visit(te); return sw.toString(); } finally { this.out = prevOut; } }
/** * Processes the template to which this environment belongs to. */ public void process() throws TemplateException, IOException { Object savedEnv = threadEnv.get(); threadEnv.set(this); try { // Cached values from a previous execution are possibly outdated. clearCachedValues(); try { doAutoImportsAndIncludes(this); visit(getTemplate().getRootTreeNode()); // It's here as we must not flush if there was an exception. if (getAutoFlush()) { out.flush(); } } finally { // It's just to allow the GC to free memory... clearCachedValues(); } } finally { threadEnv.set(savedEnv); } }
/** * "Visit" the template element. */ void visit(TemplateElement element) throws IOException, TemplateException { // ATTENTION: This method body is manually "inlined" into visit(TemplateElement[]); keep them in sync! pushElement(element); try { TemplateElement[] templateElementsToVisit = element.accept(this); if (templateElementsToVisit != null) { for (TemplateElement el : templateElementsToVisit) { if (el == null) { break; // Skip unused trailing buffer capacity } visit(el); } } } catch (TemplateException te) { handleTemplateException(te); } finally { popElement(); } // ATTENTION: This method body above is manually "inlined" into visit(TemplateElement[]); keep them in sync! }
void visit(final TemplateElement[] childBuffer, TemplateDirectiveModel directiveModel, Map args, final List bodyParameterNames) throws TemplateException, IOException { TemplateDirectiveBody nested; if (childBuffer == null) { nested = null; } else { nested = new NestedElementTemplateDirectiveBody(childBuffer); } final TemplateModel[] outArgs; if (bodyParameterNames == null || bodyParameterNames.isEmpty()) { outArgs = NO_OUT_ARGS; } else { outArgs = new TemplateModel[bodyParameterNames.size()]; } if (outArgs.length > 0) { pushLocalContext(new LocalContext() { public TemplateModel getLocalVariable(String name) { int index = bodyParameterNames.indexOf(name); return index != -1 ? outArgs[index] : null; } public Collection getLocalVariableNames() { return bodyParameterNames; } }); } try { directiveModel.execute(this, args, outArgs, nested);
break; // Skip unused trailing buffer capacity visit(el);
@Override TemplateElement[] accept(Environment env) throws TemplateException, IOException { TemplateElement[] children = getChildBuffer(); TemplateModel value; if (children != null) { StringWriter out = new StringWriter(); env.visit(children, out); value = capturedStringToModel(out.toString()); } else { value = capturedStringToModel(""); } if (namespaceExp != null) { ((Environment.Namespace) namespaceExp.eval(env)).put(varName, value); } else if (scope == Assignment.NAMESPACE) { env.setVariable(varName, value); } else if (scope == Assignment.GLOBAL) { env.setGlobalVariable(varName, value); } else if (scope == Assignment.LOCAL) { env.setLocalVariable(varName, value); } else { throw new BugException("Unhandled scope"); } return null; }
hasNext = iterModel.hasNext(); try { env.visit(childBuffer); } catch (BreakOrContinueException br) { if (br == BreakOrContinueException.BREAK_INSTANCE) { env.visit(childBuffer); hasNext = (size > index + 1); try { env.visit(childBuffer); } catch (BreakOrContinueException br) { if (br == BreakOrContinueException.BREAK_INSTANCE) { env.visit(childBuffer); env.visit(childBuffer); } catch (BreakOrContinueException br) {
/** * Processes a Template in the context of this <code>Environment</code>, including its output in the * <code>Environment</code>'s Writer. * * @param includedTemplate * the template to process. Note that it does <em>not</em> need to be a template returned by * {@link #getTemplateForInclusion(String name, String encoding, boolean parse)}. */ public void include(Template includedTemplate) throws TemplateException, IOException { final Template prevTemplate; final boolean parentReplacementOn = isBeforeIcI2322(); prevTemplate = getTemplate(); if (parentReplacementOn) { setParent(includedTemplate); } else { legacyParent = includedTemplate; } importMacros(includedTemplate); try { visit(includedTemplate.getRootTreeNode()); } finally { if (parentReplacementOn) { setParent(prevTemplate); } else { legacyParent = prevTemplate; } } }
visit(macro.getChildBuffer()); } catch (ReturnInstruction.Return re) {
hasNext = kvpIter.hasNext(); try { env.visit(childBuffer); } catch (BreakOrContinueException br) { if (br == BreakOrContinueException.BREAK_INSTANCE) { env.visit(childBuffer); hasNext = keysIter.hasNext(); try { env.visit(childBuffer); } catch (BreakOrContinueException br) { if (br == BreakOrContinueException.BREAK_INSTANCE) { } while (hasNext); } else { env.visit(childBuffer);
if (tc == null || tc.onStart() != TransformControl.SKIP_BODY) { do { visit(elementBuffer); } while (tc != null && tc.afterBody() == TransformControl.REPEAT_EVALUATION);
visit(nestedContentBuffer); } finally { if (invokingMacroContext.nestedContentParameterNames != null) {
void accept(Environment env) throws TemplateException, IOException { if (nestedBlock != null) { env.visit(nestedBlock); } }
String renderElementToString(TemplateElement te) throws IOException, TemplateException { Writer prevOut = out; try { StringWriter sw = new StringWriter(); this.out = sw; visit(te); return sw.toString(); } finally { this.out = prevOut; } }
void accept(Environment env) throws TemplateException, IOException { for (int i = 0; i<nestedElements.size(); i++) { ConditionalBlock cblock = (ConditionalBlock) nestedElements.get(i); Expression condition = cblock.condition; if (condition == null || condition.isTrue(env)) { if (cblock.nestedBlock != null) { env.visit(cblock.nestedBlock); } return; } } }