use of freemarker.template.TemplateModel in project freemarker by apache.
the class CollectionAndSequence method initSequence.
private void initSequence() throws TemplateModelException {
if (data == null) {
data = new ArrayList<TemplateModel>();
TemplateModelIterator it = collection.iterator();
while (it.hasNext()) {
data.add(it.next());
}
}
}
use of freemarker.template.TemplateModel in project be5 by DevelopmentOnTheEdge.
the class Environment method getNodeProcessor.
TemplateModel getNodeProcessor(TemplateNodeModel node) throws TemplateException {
String nodeName = node.getNodeName();
if (nodeName == null) {
throw new _MiscTemplateException(this, "Node name is null.");
}
TemplateModel result = getNodeProcessor(nodeName, node.getNodeNamespace(), 0);
if (result == null) {
String type = node.getNodeType();
/* DD: Original version: */
if (type == null) {
type = "default";
}
result = getNodeProcessor("@" + type, null, 0);
/* DD: Jonathan's non-BC version and IMHO otherwise wrong version:
if (type != null) {
result = getNodeProcessor("@" + type, null, 0);
}
if (result == null) {
result = getNodeProcessor("@default", null, 0);
}
*/
}
return result;
}
use of freemarker.template.TemplateModel in project be5 by DevelopmentOnTheEdge.
the class Environment method getLocalVariable.
/**
* Returns the loop or macro local variable corresponding to this
* variable name. Possibly null.
* (Note that the misnomer is kept for backward compatibility: loop variables
* are not local variables according to our terminology.)
*/
public TemplateModel getLocalVariable(String name) throws TemplateModelException {
if (localContextStack != null) {
for (int i = localContextStack.size() - 1; i >= 0; i--) {
LocalContext lc = (LocalContext) localContextStack.get(i);
TemplateModel tm = lc.getLocalVariable(name);
if (tm != null) {
return tm;
}
}
}
return currentMacroContext == null ? null : currentMacroContext.getLocalVariable(name);
}
use of freemarker.template.TemplateModel in project be5 by DevelopmentOnTheEdge.
the class Environment method getTransform.
TemplateTransformModel getTransform(Expression exp) throws TemplateException {
TemplateTransformModel ttm = null;
TemplateModel tm = exp.eval(this);
if (tm instanceof TemplateTransformModel) {
ttm = (TemplateTransformModel) tm;
} else if (exp instanceof Identifier) {
tm = getConfiguration().getSharedVariable(exp.toString());
if (tm instanceof TemplateTransformModel) {
ttm = (TemplateTransformModel) tm;
}
}
return ttm;
}
use of freemarker.template.TemplateModel in project be5 by DevelopmentOnTheEdge.
the class Environment method visit.
public void visit(final TemplateElement element, TemplateDirectiveModel directiveModel, Map args, final List bodyParameterNames) throws TemplateException, IOException {
TemplateDirectiveBody nested;
if (element == null) {
nested = null;
} else {
nested = new TemplateDirectiveBody() {
public void render(Writer newOut) throws TemplateException, IOException {
Writer prevOut = out;
out = newOut;
try {
Environment.this.visit(element);
} finally {
out = prevOut;
}
}
};
}
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);
} finally {
if (outArgs.length > 0) {
popLocalContext();
}
}
}
Aggregations