use of org.thymeleaf.engine.TemplateHandlerAdapterTextHandler in project thymeleaf by thymeleaf.
the class AbstractTextTemplateParser method parse.
private void parse(final IEngineConfiguration configuration, final String ownerTemplate, final String template, final Set<String> templateSelectors, final ITemplateResource resource, final int lineOffset, final int colOffset, final TemplateMode templateMode, final ITemplateHandler templateHandler) {
// For a String template, we will use the ownerTemplate as templateName for its parsed events
final String templateName = (resource != null ? template : ownerTemplate);
try {
// The final step of the handler chain will be the adapter that will convert the text parser's handler chain to thymeleaf's.
ITextHandler handler = new TemplateHandlerAdapterTextHandler(templateName, templateHandler, configuration.getElementDefinitions(), configuration.getAttributeDefinitions(), templateMode, lineOffset, colOffset);
// (which might see text blocks coming as several blocks instead of just one).
if (configuration instanceof EngineConfiguration && ((EngineConfiguration) configuration).isModelReshapeable(templateMode)) {
handler = new InlinedOutputExpressionTextHandler(configuration, templateMode, configuration.getStandardDialectPrefix(), handler);
}
// Obtain the resource reader
Reader templateReader = (resource != null ? resource.reader() : new StringReader(template));
// Add the required reader wrappers in order to process parser-level and prototype-only comment blocks
if (templateMode == TemplateMode.TEXT) {
// There are no /*[+...+]*/ blocks in TEXT mode (it makes no sense)
templateReader = new ParserLevelCommentTextReader(templateReader);
} else {
// TemplateMode.JAVASCRIPT || TemplateMode.CSS
templateReader = new ParserLevelCommentTextReader(new PrototypeOnlyCommentTextReader(templateReader));
}
this.parser.parse(templateReader, handler);
} catch (final IOException e) {
final String message = "An error happened during template parsing";
throw new TemplateInputException(message, (resource != null ? resource.getDescription() : template), e);
} catch (final TextParseException e) {
final String message = "An error happened during template parsing";
if (e.getLine() != null && e.getCol() != null) {
throw new TemplateInputException(message, (resource != null ? resource.getDescription() : template), e.getLine().intValue(), e.getCol().intValue(), e);
}
throw new TemplateInputException(message, (resource != null ? resource.getDescription() : template), e);
}
}
Aggregations