/** * Gets a template for a certain source. * * @param template * the template source * @param sourceName * the template name * @return the prepared template */ public Template getTemplate(String template, String sourceName) { return new InterpretedTemplate(template, sourceName, this); }
@Override @SuppressWarnings("unchecked") public synchronized Set<String> getUsedVariables() { if (this.usedVariables != null) { return this.usedVariables; } this.usedVariables = new TreeSet<String>(); final List<VariableDescription> variableDescriptions = this.getUsedVariableDescriptions(); for (VariableDescription variableDescription : variableDescriptions) { this.usedVariables.add(variableDescription.name); } return this.usedVariables; }
tokenStream.consume(); if (!skip) { this.context.engine.getOutputAppender().append(this.getOutput(), token.getText(), token); if (!skip) { String expanded = (String) token.evaluate(context); this.context.engine.getOutputAppender().append(this.getOutput(), expanded, token); foreach(skip); } else if (token instanceof IfToken) { condition(skip); } else if (token instanceof ElseToken) { tokenStream.consume(); this.context.engine.getErrorHandler().error(ELSE_OUT_OF_SCOPE, token); this.context.engine.getOutputAppender().append(this.getOutput(), "", token); } else if (token instanceof EndToken) { tokenStream.consume(); this.context.engine.getErrorHandler().error(UNMATCHED_END, token); this.context.engine.getOutputAppender().append(this.getOutput(), "", token); } else if (token instanceof InvalidToken) { tokenStream.consume(); this.context.engine.getErrorHandler().error(INVALID_EXPRESSION, token); this.context.engine.getOutputAppender().append(this.getOutput(), "", token); } else { tokenStream.consume(); this.context.engine.getOutputAppender().append(this.getOutput(), evaluated, token);
if (feToken.getVarName() == ForEachToken.UNDEFINED_VARNAME) { this.context.engine.getErrorHandler().error(FOR_EACH_UNDEFINED_VARNAME, feToken); this.context.engine.getOutputAppender().append(this.getOutput(), "", feToken); while ((contentToken = tokenStream.currentToken()) != null && !(contentToken instanceof EndToken)) { content(true); this.context.engine.getOutputAppender().append(this.getOutput(), "", feToken); } else { tokenStream.consume(); addSpecialVariables(feToken, context.model); while ((contentToken = tokenStream.currentToken()) != null && !(contentToken instanceof EndToken)) { content(false); this.context.engine.getOutputAppender().append(this.getOutput(), "", feToken); } else { tokenStream.consume(); this.context.engine.getOutputAppender().append(this.getOutput(), feToken.getSeparator(), feToken);
@Override public synchronized String transform(Map<String, Object> model, Locale locale, ModelAdaptor modelAdaptor, ProcessListener processListener) { try { context = new TemplateContext(template, locale, sourceName, new ScopedMap( model), modelAdaptor, engine, engine.getErrorHandler(), processListener); String transformed = transformPure(context); return transformed; } finally { context = null; } }
while ((contentToken = tokenStream.currentToken()) != null && !(contentToken instanceof EndToken)) { content(true); addSpecialVariables(feToken, context.model); while ((contentToken = tokenStream.currentToken()) != null && !(contentToken instanceof EndToken)) { content(false);
protected String transformPure(TemplateContext context) { tokenStream.reset(); output = new StringBuilder( (int) (context.template.length() * context.engine .getExpansionSizeFactor())); tokenStream.nextToken(); while (tokenStream.currentToken() != null) { content(false); } return output.toString(); }
@Override public List<ErrorEntry> getStaticErrors() { final Engine engine = new Engine(); final JournalingErrorHandler errorHandler = new JournalingErrorHandler(); engine.setErrorHandler(errorHandler); final ScopedMap scopedMap = new ScopedMap(Collections.EMPTY_MAP); final Locale locale = Locale.getDefault(); this.context = new TemplateContext(this.template, locale, this.sourceName, scopedMap, new DefaultModelAdaptor(), engine, errorHandler, null); transformPure(this.context); final List<ErrorEntry> staticErrors = new ArrayList<>(); for (ErrorEntry entry: errorHandler.entries) { if (entry.errorMessage.isStatic) { staticErrors.add(entry); } } return staticErrors; }
@Override public synchronized String transform(Map<String, Object> model, Locale locale, ModelAdaptor modelAdaptor, ProcessListener processListener) { try { context = new TemplateContext(template, locale, sourceName, new ScopedMap( model), modelAdaptor, engine, engine.getErrorHandler(), processListener); String transformed = transformPure(context); return transformed; } finally { context = null; output = null; } }
templateImpl = interpretedTemplates.get(template); if (templateImpl == null) { templateImpl = new InterpretedTemplate(template, sourceName, this); interpretedTemplates.put(template, templateImpl); templateImpl = new InterpretedTemplate(template, sourceName, this);
new DefaultModelAdaptor(), engine, engine.getErrorHandler(), processListener); transformPure(context); return usedVariables;
this.context = new TemplateContext(this.template, locale, this.sourceName, scopedMap, new DefaultModelAdaptor(), engine, engine.getErrorHandler(), processListener); transformPure(this.context);