}
final String templateMode = templateResolution.getTemplateMode();
final ITemplateParser templateParser = this.parsersByTemplateMode.get(templateMode);
if (templateParser == null) {
throw new TemplateInputException(
"Template mode \"" + templateMode + "\" has not been configured");
}
if (logger.isTraceEnabled()) {
logger.trace("[THYMELEAF][{}] Starting parsing of template \"{}\"", TemplateEngine.threadIndex(), templateName);
}
final String characterEncoding = templateResolution.getCharacterEncoding();
Reader reader = null;
if (!StringUtils.isEmptyOrWhitespace(characterEncoding)) {
try {
reader = new InputStreamReader(templateInputStream, characterEncoding);
} catch (final UnsupportedEncodingException e) {
throw new TemplateInputException("Exception parsing document", e);
}
} else {
reader = new InputStreamReader(templateInputStream);
}
final Document document =
templateParser.parseTemplate(configuration, templateName, reader);
if (logger.isTraceEnabled()) {
logger.trace("[THYMELEAF][{}] Finished parsing of template \"{}\"", TemplateEngine.threadIndex(), templateName);
}