void accept(Environment env) throws IOException, TemplateException {
String templateNameString = includedTemplateName.getStringValue(env);
if( templateNameString == null ) {
String msg = "Error " + getStartLocation()
+ "The expression " + includedTemplateName + " is undefined.";
throw new InvalidReferenceException(msg, env);
}
String enc = encoding;
if (encoding == null && encodingExp != null) {
enc = encodingExp.getStringValue(env);
}
boolean parse = this.parse;
if (parseExp != null) {
TemplateModel tm = parseExp.getAsTemplateModel(env);
if(tm == null) {
if(env.isClassicCompatible()) {
parse = false;
}
else {
assertNonNull(tm, parseExp, env);
}
}
if (tm instanceof TemplateScalarModel) {
parse = getYesNo(EvaluationUtil.getString((TemplateScalarModel)tm, parseExp, env));
}
else {
parse = parseExp.isTrue(env);
}
}
Template includedTemplate;
try {
templateNameString = TemplateCache.getFullTemplatePath(env, templatePath, templateNameString);
includedTemplate = env.getTemplateForInclusion(templateNameString, enc, parse);
}
catch (ParseException pe) {
String msg = "Error parsing included template "
+ templateNameString + "\n" + pe.getMessage();
throw new TemplateException(msg, pe, env);
}
catch (IOException ioe) {
String msg = "Error reading included file "
+ templateNameString;
throw new TemplateException(msg, ioe, env);
}
env.include(includedTemplate);
}
|