@SuppressWarnings("unchecked")
protected Map<String, Object> mergeTemplate(final Context context, boolean export) {
final Object templateName;
if ((templateName = templateNameExpr.execute(context)) != null) {
final KeyValues params;
final Object paramsObject;
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));