if (paramsExpr != null
&& (paramsObject = paramsExpr.execute(context)) != null) {
if (paramsObject instanceof Map) {
params = KeyValuesUtil.wrap((Map) paramsObject);
} else {
throw new ScriptRuntimeException("Template param must be a Map.", paramsExpr);
}
} else {
params = KeyValuesUtil.EMPTY_KEY_VALUES;
}
final Template preTemplate = context.template;
final KeyValues preRootParams = context.rootParams;
final Object[] preVars = context.vars;
final VariantIndexer[] preIndexers = context.indexers;
final int preIndexer = context.indexer;
try {
Template template = engine.getTemplate(myTemplateName, String.valueOf(templateName));
context.template = template;
context.rootParams = engine.isShareRootData() ? KeyValuesUtil.wrap(preRootParams, params) : params;
template.merge(context, params);
if (export) {
Map<String, Object> result = new HashMap<String, Object>();
context.exportTo(result);
return result;
}
return null;
} catch (Exception e) {
throw new ScriptRuntimeException(e, this);
} finally {
context.template = preTemplate;
context.rootParams = preRootParams;
context.vars = preVars;
context.indexers = preIndexers;
context.indexer = preIndexer;
}
} else {
throw new ScriptRuntimeException("Template name should not be null.", templateNameExpr);
}
}