use of org.thymeleaf.processor.IProcessor in project thymeleaf by thymeleaf.
the class ConfigurationPrinterHelper method printDebugConfiguration.
private static void printDebugConfiguration(final ConfigLogBuilder logBuilder, final IDialect idialect, final String dialectPrefix) {
if (idialect instanceof IProcessorDialect) {
final IProcessorDialect dialect = (IProcessorDialect) idialect;
final Set<IProcessor> processors = dialect.getProcessors(dialectPrefix);
printProcessorsForTemplateMode(logBuilder, processors, TemplateMode.HTML);
printProcessorsForTemplateMode(logBuilder, processors, TemplateMode.XML);
printProcessorsForTemplateMode(logBuilder, processors, TemplateMode.TEXT);
printProcessorsForTemplateMode(logBuilder, processors, TemplateMode.JAVASCRIPT);
printProcessorsForTemplateMode(logBuilder, processors, TemplateMode.CSS);
printProcessorsForTemplateMode(logBuilder, processors, TemplateMode.RAW);
}
if (idialect instanceof IPreProcessorDialect) {
final IPreProcessorDialect dialect = (IPreProcessorDialect) idialect;
final Set<IPreProcessor> preProcessors = dialect.getPreProcessors();
printPreProcessorsForTemplateMode(logBuilder, preProcessors, TemplateMode.HTML);
printPreProcessorsForTemplateMode(logBuilder, preProcessors, TemplateMode.XML);
printPreProcessorsForTemplateMode(logBuilder, preProcessors, TemplateMode.TEXT);
printPreProcessorsForTemplateMode(logBuilder, preProcessors, TemplateMode.JAVASCRIPT);
printPreProcessorsForTemplateMode(logBuilder, preProcessors, TemplateMode.CSS);
printPreProcessorsForTemplateMode(logBuilder, preProcessors, TemplateMode.RAW);
}
if (idialect instanceof IPostProcessorDialect) {
final IPostProcessorDialect dialect = (IPostProcessorDialect) idialect;
final Set<IPostProcessor> postProcessors = dialect.getPostProcessors();
printPostProcessorsForTemplateMode(logBuilder, postProcessors, TemplateMode.HTML);
printPostProcessorsForTemplateMode(logBuilder, postProcessors, TemplateMode.XML);
printPostProcessorsForTemplateMode(logBuilder, postProcessors, TemplateMode.TEXT);
printPostProcessorsForTemplateMode(logBuilder, postProcessors, TemplateMode.JAVASCRIPT);
printPostProcessorsForTemplateMode(logBuilder, postProcessors, TemplateMode.CSS);
printPostProcessorsForTemplateMode(logBuilder, postProcessors, TemplateMode.RAW);
}
if (idialect instanceof IExpressionObjectDialect) {
final IExpressionObjectDialect dialect = (IExpressionObjectDialect) idialect;
final IExpressionObjectFactory expressionObjectFactory = dialect.getExpressionObjectFactory();
if (expressionObjectFactory != null) {
final Set<String> expressionObjectNames = expressionObjectFactory.getAllExpressionObjectNames();
if (expressionObjectNames != null && !expressionObjectNames.isEmpty()) {
logBuilder.line("[THYMELEAF] * Expression Objects:");
for (final String expressionObjectName : expressionObjectNames) {
logBuilder.line("[THYMELEAF] * #{}", new Object[] { expressionObjectName });
}
}
}
}
if (idialect instanceof IExecutionAttributeDialect) {
final IExecutionAttributeDialect dialect = (IExecutionAttributeDialect) idialect;
final Map<String, Object> executionAttributes = dialect.getExecutionAttributes();
if (executionAttributes != null && !executionAttributes.isEmpty()) {
logBuilder.line("[THYMELEAF] * Execution Attributes:");
for (final Map.Entry<String, Object> executionAttributesEntry : executionAttributes.entrySet()) {
final String attrName = executionAttributesEntry.getKey();
final String attrValue = (executionAttributesEntry.getValue() == null ? null : executionAttributesEntry.getValue().toString());
logBuilder.line("[THYMELEAF] * \"{}\": {}", new Object[] { attrName, attrValue });
}
}
}
}
use of org.thymeleaf.processor.IProcessor in project thymeleaf by thymeleaf.
the class DialectSetConfiguration method build.
public static DialectSetConfiguration build(final Set<DialectConfiguration> dialectConfigurations) {
Validate.notNull(dialectConfigurations, "Dialect configuration set cannot be null");
// This set will contain all the dialects - without any additional configuration information
final Set<IDialect> dialects = new LinkedHashSet<IDialect>(dialectConfigurations.size());
// If we find a standard dialect among the configured ones (Standard or SpringStandard), we will report its prefix
boolean standardDialectPresent = false;
String standardDialectPrefix = null;
// This map will be used for merging the execution attributes of all the dialects
final Map<String, Object> executionAttributes = new LinkedHashMap<String, Object>(10, 1.0f);
// This will aggregate all the expression object factories provided by the different dialects
final AggregateExpressionObjectFactory aggregateExpressionObjectFactory = new AggregateExpressionObjectFactory();
// EnumMaps for each type of processor (depending on the structures that they can be applied to)
final EnumMap<TemplateMode, List<ITemplateBoundariesProcessor>> templateBoundariesProcessorListsByTemplateMode = new EnumMap<TemplateMode, List<ITemplateBoundariesProcessor>>(TemplateMode.class);
final EnumMap<TemplateMode, List<ICDATASectionProcessor>> cdataSectionProcessorListsByTemplateMode = new EnumMap<TemplateMode, List<ICDATASectionProcessor>>(TemplateMode.class);
final EnumMap<TemplateMode, List<ICommentProcessor>> commentProcessorListsByTemplateMode = new EnumMap<TemplateMode, List<ICommentProcessor>>(TemplateMode.class);
final EnumMap<TemplateMode, List<IDocTypeProcessor>> docTypeProcessorListsByTemplateMode = new EnumMap<TemplateMode, List<IDocTypeProcessor>>(TemplateMode.class);
final EnumMap<TemplateMode, List<IElementProcessor>> elementProcessorListsByTemplateMode = new EnumMap<TemplateMode, List<IElementProcessor>>(TemplateMode.class);
final EnumMap<TemplateMode, List<IProcessingInstructionProcessor>> processingInstructionProcessorListsByTemplateMode = new EnumMap<TemplateMode, List<IProcessingInstructionProcessor>>(TemplateMode.class);
final EnumMap<TemplateMode, List<ITextProcessor>> textProcessorListsByTemplateMode = new EnumMap<TemplateMode, List<ITextProcessor>>(TemplateMode.class);
final EnumMap<TemplateMode, List<IXMLDeclarationProcessor>> xmlDeclarationProcessorListsByTemplateMode = new EnumMap<TemplateMode, List<IXMLDeclarationProcessor>>(TemplateMode.class);
// Lists for merging all pre and postprocessors from all dialects
final EnumMap<TemplateMode, List<IPreProcessor>> preProcessorListsByTemplateMode = new EnumMap<TemplateMode, List<IPreProcessor>>(TemplateMode.class);
final EnumMap<TemplateMode, List<IPostProcessor>> postProcessorListsByTemplateMode = new EnumMap<TemplateMode, List<IPostProcessor>>(TemplateMode.class);
/*
* ITERATE ALL DIALECTS, processing each one according to its features
*/
for (final DialectConfiguration dialectConfiguration : dialectConfigurations) {
// cannot be null -- ConfigurationDialect checks this
final IDialect dialect = dialectConfiguration.getDialect();
/*
* STEP ONE for each dialect: process, initialize and merge processors
*/
if (dialect instanceof IProcessorDialect) {
final IProcessorDialect processorDialect = (IProcessorDialect) dialect;
// Might be null if the dialect has been specified to use no prefix (or that is the default of such dialect)
final String dialectPrefix = (dialectConfiguration.isPrefixSpecified() ? dialectConfiguration.getPrefix() : processorDialect.getPrefix());
if (dialect instanceof StandardDialect) {
standardDialectPresent = true;
standardDialectPrefix = dialectPrefix;
}
final Set<IProcessor> dialectProcessors = processorDialect.getProcessors(dialectPrefix);
if (dialectProcessors == null) {
throw new ConfigurationException("Dialect should not return null processor set: " + dialect.getClass().getName());
}
for (final IProcessor dialectProcessor : dialectProcessors) {
if (dialectProcessor == null) {
throw new ConfigurationException("Dialect should not return null processor in processor set: " + dialect.getClass().getName());
}
// Obtain and check template mode
final TemplateMode templateMode = dialectProcessor.getTemplateMode();
if (templateMode == null) {
throw new ConfigurationException("Template mode cannot be null (processor: " + dialectProcessor.getClass().getName() + ")");
}
if (dialectProcessor instanceof IElementProcessor) {
// can be either a tag processor or a node one
List<IElementProcessor> processorsForTemplateMode = elementProcessorListsByTemplateMode.get(templateMode);
if (processorsForTemplateMode == null) {
processorsForTemplateMode = new ArrayList<IElementProcessor>(5);
elementProcessorListsByTemplateMode.put(templateMode, processorsForTemplateMode);
}
processorsForTemplateMode.add(ProcessorConfigurationUtils.wrap((IElementProcessor) dialectProcessor, processorDialect));
Collections.sort(processorsForTemplateMode, ProcessorComparators.PROCESSOR_COMPARATOR);
} else if (dialectProcessor instanceof ITemplateBoundariesProcessor) {
List<ITemplateBoundariesProcessor> processorsForTemplateMode = templateBoundariesProcessorListsByTemplateMode.get(templateMode);
if (processorsForTemplateMode == null) {
processorsForTemplateMode = new ArrayList<ITemplateBoundariesProcessor>(5);
templateBoundariesProcessorListsByTemplateMode.put(templateMode, processorsForTemplateMode);
}
processorsForTemplateMode.add(ProcessorConfigurationUtils.wrap((ITemplateBoundariesProcessor) dialectProcessor, processorDialect));
Collections.sort(processorsForTemplateMode, ProcessorComparators.PROCESSOR_COMPARATOR);
} else if (dialectProcessor instanceof ICDATASectionProcessor) {
List<ICDATASectionProcessor> processorsForTemplateMode = cdataSectionProcessorListsByTemplateMode.get(templateMode);
if (processorsForTemplateMode == null) {
processorsForTemplateMode = new ArrayList<ICDATASectionProcessor>(5);
cdataSectionProcessorListsByTemplateMode.put(templateMode, processorsForTemplateMode);
}
processorsForTemplateMode.add(ProcessorConfigurationUtils.wrap((ICDATASectionProcessor) dialectProcessor, processorDialect));
Collections.sort(processorsForTemplateMode, ProcessorComparators.PROCESSOR_COMPARATOR);
} else if (dialectProcessor instanceof ICommentProcessor) {
List<ICommentProcessor> processorsForTemplateMode = commentProcessorListsByTemplateMode.get(templateMode);
if (processorsForTemplateMode == null) {
processorsForTemplateMode = new ArrayList<ICommentProcessor>(5);
commentProcessorListsByTemplateMode.put(templateMode, processorsForTemplateMode);
}
processorsForTemplateMode.add(ProcessorConfigurationUtils.wrap((ICommentProcessor) dialectProcessor, processorDialect));
Collections.sort(processorsForTemplateMode, ProcessorComparators.PROCESSOR_COMPARATOR);
} else if (dialectProcessor instanceof IDocTypeProcessor) {
List<IDocTypeProcessor> processorsForTemplateMode = docTypeProcessorListsByTemplateMode.get(templateMode);
if (processorsForTemplateMode == null) {
processorsForTemplateMode = new ArrayList<IDocTypeProcessor>(5);
docTypeProcessorListsByTemplateMode.put(templateMode, processorsForTemplateMode);
}
processorsForTemplateMode.add(ProcessorConfigurationUtils.wrap((IDocTypeProcessor) dialectProcessor, processorDialect));
Collections.sort(processorsForTemplateMode, ProcessorComparators.PROCESSOR_COMPARATOR);
} else if (dialectProcessor instanceof IProcessingInstructionProcessor) {
List<IProcessingInstructionProcessor> processorsForTemplateMode = processingInstructionProcessorListsByTemplateMode.get(templateMode);
if (processorsForTemplateMode == null) {
processorsForTemplateMode = new ArrayList<IProcessingInstructionProcessor>(5);
processingInstructionProcessorListsByTemplateMode.put(templateMode, processorsForTemplateMode);
}
processorsForTemplateMode.add(ProcessorConfigurationUtils.wrap((IProcessingInstructionProcessor) dialectProcessor, processorDialect));
Collections.sort(processorsForTemplateMode, ProcessorComparators.PROCESSOR_COMPARATOR);
} else if (dialectProcessor instanceof ITextProcessor) {
List<ITextProcessor> processorsForTemplateMode = textProcessorListsByTemplateMode.get(templateMode);
if (processorsForTemplateMode == null) {
processorsForTemplateMode = new ArrayList<ITextProcessor>(5);
textProcessorListsByTemplateMode.put(templateMode, processorsForTemplateMode);
}
processorsForTemplateMode.add(ProcessorConfigurationUtils.wrap((ITextProcessor) dialectProcessor, processorDialect));
Collections.sort(processorsForTemplateMode, ProcessorComparators.PROCESSOR_COMPARATOR);
} else if (dialectProcessor instanceof IXMLDeclarationProcessor) {
List<IXMLDeclarationProcessor> processorsForTemplateMode = xmlDeclarationProcessorListsByTemplateMode.get(templateMode);
if (processorsForTemplateMode == null) {
processorsForTemplateMode = new ArrayList<IXMLDeclarationProcessor>(5);
xmlDeclarationProcessorListsByTemplateMode.put(templateMode, processorsForTemplateMode);
}
processorsForTemplateMode.add(ProcessorConfigurationUtils.wrap((IXMLDeclarationProcessor) dialectProcessor, processorDialect));
Collections.sort(processorsForTemplateMode, ProcessorComparators.PROCESSOR_COMPARATOR);
}
}
}
/*
* STEP TWO for each dialect: merge execution attributes
*/
if (dialect instanceof IExecutionAttributeDialect) {
final Map<String, Object> dialectExecutionAttributes = ((IExecutionAttributeDialect) dialect).getExecutionAttributes();
if (dialectExecutionAttributes != null) {
for (final Map.Entry<String, Object> entry : dialectExecutionAttributes.entrySet()) {
final String executionAttributeName = entry.getKey();
if (executionAttributes.containsKey(executionAttributeName)) {
throw new ConfigurationException("Conflicting execution attribute. Two or more dialects specify an execution " + "attribute with the same name \"" + executionAttributeName + "\".");
}
executionAttributes.put(entry.getKey(), entry.getValue());
}
}
}
/*
* STEP THREE for each dialect: aggregate all the expression object factories
*/
if (dialect instanceof IExpressionObjectDialect) {
final IExpressionObjectFactory factory = ((IExpressionObjectDialect) dialect).getExpressionObjectFactory();
if (factory != null) {
aggregateExpressionObjectFactory.add(factory);
}
}
/*
* STEP FOUR for each dialect: aggregate pre-processors (and check the correctness of the list)
*/
if (dialect instanceof IPreProcessorDialect) {
final Set<IPreProcessor> dialectPreProcessors = ((IPreProcessorDialect) dialect).getPreProcessors();
if (dialectPreProcessors != null) {
for (final IPreProcessor preProcessor : dialectPreProcessors) {
if (preProcessor == null) {
throw new ConfigurationException("Pre-Processor list for dialect " + dialect.getClass().getName() + " includes a " + "null entry, which is forbidden.");
}
// Obtain and check template mode
final TemplateMode templateMode = preProcessor.getTemplateMode();
if (templateMode == null) {
throw new ConfigurationException("Template mode cannot be null (pre-processor: " + preProcessor.getClass().getName() + ", dialect" + dialect.getClass().getName() + ")");
}
// Check the handler class: should extend ITemplateHandler and have an empty constructor
final Class<?> handlerClass = preProcessor.getHandlerClass();
if (handlerClass == null) {
throw new ConfigurationException("Pre-Processor " + preProcessor.getClass().getName() + " for dialect " + preProcessor.getClass().getName() + " returns a null handler class, which is forbidden.");
}
if (!ITemplateHandler.class.isAssignableFrom(handlerClass)) {
throw new ConfigurationException("Handler class " + handlerClass.getName() + " specified for " + "pre-processor " + preProcessor.getClass().getName() + " in dialect " + dialect.getClass().getName() + " does not implement required " + "interface " + ITemplateHandler.class.getName());
}
try {
// Check the empty constructor is present -- we will need to use it for creating new instances
handlerClass.getConstructor(new Class[0]);
} catch (final NoSuchMethodException e) {
throw new ConfigurationException("Pre-Processor class " + handlerClass.getName() + " specified for " + "pre-processor " + preProcessor.getClass().getName() + " in dialect " + dialect.getClass().getName() + " does not implement required " + "zero-argument constructor.", e);
}
// Add the pre-processor to its corresponding map and sort
List<IPreProcessor> preProcessorsForTemplateMode = preProcessorListsByTemplateMode.get(templateMode);
if (preProcessorsForTemplateMode == null) {
preProcessorsForTemplateMode = new ArrayList<IPreProcessor>(5);
preProcessorListsByTemplateMode.put(templateMode, preProcessorsForTemplateMode);
}
preProcessorsForTemplateMode.add(preProcessor);
Collections.sort(preProcessorsForTemplateMode, ProcessorComparators.PRE_PROCESSOR_COMPARATOR);
}
}
}
/*
* STEP FIVE for each dialect: aggregate post-processors (and check the correctness of the list)
*/
if (dialect instanceof IPostProcessorDialect) {
final Set<IPostProcessor> dialectPostProcessors = ((IPostProcessorDialect) dialect).getPostProcessors();
if (dialectPostProcessors != null) {
for (final IPostProcessor postProcessor : dialectPostProcessors) {
if (postProcessor == null) {
throw new ConfigurationException("Post-Processor list for dialect " + dialect.getClass().getName() + " includes a " + "null entry, which is forbidden.");
}
// Obtain and check template mode
final TemplateMode templateMode = postProcessor.getTemplateMode();
if (templateMode == null) {
throw new ConfigurationException("Template mode cannot be null (post-processor: " + postProcessor.getClass().getName() + ", dialect" + dialect.getClass().getName() + ")");
}
// Check the handler class: should extend ITemplateHandler and have an empty constructor
final Class<?> handlerClass = postProcessor.getHandlerClass();
if (handlerClass == null) {
throw new ConfigurationException("Post-Processor " + postProcessor.getClass().getName() + " for dialect " + postProcessor.getClass().getName() + " returns a null handler class, which is forbidden.");
}
if (!ITemplateHandler.class.isAssignableFrom(handlerClass)) {
throw new ConfigurationException("Handler class " + handlerClass.getName() + " specified for " + "post-processor " + postProcessor.getClass().getName() + " in dialect " + dialect.getClass().getName() + " does not implement required " + "interface " + ITemplateHandler.class.getName());
}
try {
// Check the empty constructor is present -- we will need to use it for creating new instances
handlerClass.getConstructor(new Class[0]);
} catch (final NoSuchMethodException e) {
throw new ConfigurationException("Post-Processor class " + handlerClass.getName() + " specified for " + "post-processor " + postProcessor.getClass().getName() + " in dialect " + dialect.getClass().getName() + " does not implement required " + "zero-argument constructor.", e);
}
// Add the pre-processor to its corresponding map and sort
List<IPostProcessor> postProcessorsForTemplateMode = postProcessorListsByTemplateMode.get(templateMode);
if (postProcessorsForTemplateMode == null) {
postProcessorsForTemplateMode = new ArrayList<IPostProcessor>(5);
postProcessorListsByTemplateMode.put(templateMode, postProcessorsForTemplateMode);
}
postProcessorsForTemplateMode.add(postProcessor);
Collections.sort(postProcessorsForTemplateMode, ProcessorComparators.POST_PROCESSOR_COMPARATOR);
}
}
}
/*
* LAST STEP for each dialect: add it to the dialects set
*/
dialects.add(dialect);
}
// Time to turn the list-based structures into sets -- we needed the lists because we needed a way to order them using Collections.sort()
final EnumMap<TemplateMode, Set<ITemplateBoundariesProcessor>> templateBoundariesProcessorsByTemplateMode = listMapToSetMap(templateBoundariesProcessorListsByTemplateMode);
final EnumMap<TemplateMode, Set<ICDATASectionProcessor>> cdataSectionProcessorsByTemplateMode = listMapToSetMap(cdataSectionProcessorListsByTemplateMode);
final EnumMap<TemplateMode, Set<ICommentProcessor>> commentProcessorsByTemplateMode = listMapToSetMap(commentProcessorListsByTemplateMode);
final EnumMap<TemplateMode, Set<IDocTypeProcessor>> docTypeProcessorsByTemplateMode = listMapToSetMap(docTypeProcessorListsByTemplateMode);
final EnumMap<TemplateMode, Set<IElementProcessor>> elementProcessorsByTemplateMode = listMapToSetMap(elementProcessorListsByTemplateMode);
final EnumMap<TemplateMode, Set<IProcessingInstructionProcessor>> processingInstructionProcessorsByTemplateMode = listMapToSetMap(processingInstructionProcessorListsByTemplateMode);
final EnumMap<TemplateMode, Set<ITextProcessor>> textProcessorsByTemplateMode = listMapToSetMap(textProcessorListsByTemplateMode);
final EnumMap<TemplateMode, Set<IXMLDeclarationProcessor>> xmlDeclarationProcessorsByTemplateMode = listMapToSetMap(xmlDeclarationProcessorListsByTemplateMode);
final EnumMap<TemplateMode, Set<IPreProcessor>> preProcessorsByTemplateMode = listMapToSetMap(preProcessorListsByTemplateMode);
final EnumMap<TemplateMode, Set<IPostProcessor>> postProcessorsByTemplateMode = listMapToSetMap(postProcessorListsByTemplateMode);
// Initialize the ElementDefinitions and AttributeDefinitions structures -- they need the element processors so that these
// are directly applied to the element/attribute definitions and therefore per element/attribute matching is not required
// during template processing.
final ElementDefinitions elementDefinitions = new ElementDefinitions(elementProcessorsByTemplateMode);
final AttributeDefinitions attributeDefinitions = new AttributeDefinitions(elementProcessorsByTemplateMode);
// Traverse the sets of processors in order to set the AttributeDefinitions and/or ElementDefinitions objects
// to those that need them in order to initialize and cache attribute/element definition-related structures
initializeDefinitionsForProcessors(templateBoundariesProcessorsByTemplateMode, elementDefinitions, attributeDefinitions);
initializeDefinitionsForProcessors(cdataSectionProcessorsByTemplateMode, elementDefinitions, attributeDefinitions);
initializeDefinitionsForProcessors(commentProcessorsByTemplateMode, elementDefinitions, attributeDefinitions);
initializeDefinitionsForProcessors(docTypeProcessorsByTemplateMode, elementDefinitions, attributeDefinitions);
initializeDefinitionsForProcessors(elementProcessorsByTemplateMode, elementDefinitions, attributeDefinitions);
initializeDefinitionsForProcessors(processingInstructionProcessorsByTemplateMode, elementDefinitions, attributeDefinitions);
initializeDefinitionsForProcessors(textProcessorsByTemplateMode, elementDefinitions, attributeDefinitions);
initializeDefinitionsForProcessors(xmlDeclarationProcessorsByTemplateMode, elementDefinitions, attributeDefinitions);
initializeDefinitionsForPreProcessors(preProcessorsByTemplateMode, elementDefinitions, attributeDefinitions);
initializeDefinitionsForPostProcessors(postProcessorsByTemplateMode, elementDefinitions, attributeDefinitions);
return new DialectSetConfiguration(new LinkedHashSet<DialectConfiguration>(dialectConfigurations), dialects, standardDialectPresent, standardDialectPrefix, executionAttributes, aggregateExpressionObjectFactory, elementDefinitions, attributeDefinitions, templateBoundariesProcessorsByTemplateMode, cdataSectionProcessorsByTemplateMode, commentProcessorsByTemplateMode, docTypeProcessorsByTemplateMode, elementProcessorsByTemplateMode, processingInstructionProcessorsByTemplateMode, textProcessorsByTemplateMode, xmlDeclarationProcessorsByTemplateMode, preProcessorsByTemplateMode, postProcessorsByTemplateMode);
}
use of org.thymeleaf.processor.IProcessor in project thymeleaf by thymeleaf.
the class StandardDialect method createStandardProcessorsSet.
/**
* <p>
* Create a the set of Standard processors, all of them freshly instanced.
* </p>
*
* @param dialectPrefix the prefix established for the Standard Dialect, needed for initialization
* @return the set of Standard processors.
*/
public static Set<IProcessor> createStandardProcessorsSet(final String dialectPrefix) {
/*
* It is important that we create new instances here because, if there are
* several dialects in the TemplateEngine that extend StandardDialect, they should
* not be returning the exact same instances for their processors in order
* to allow specific instances to be directly linked with their owner dialect.
*/
final Set<IProcessor> processors = new LinkedHashSet<IProcessor>();
/*
* ------------------------
* ------------------------
* HTML TEMPLATE MODE
* ------------------------
* ------------------------
*/
/*
* HTML: ATTRIBUTE TAG PROCESSORS
*/
processors.add(new StandardActionTagProcessor(dialectPrefix));
processors.add(new StandardAltTitleTagProcessor(dialectPrefix));
processors.add(new StandardAssertTagProcessor(TemplateMode.HTML, dialectPrefix));
processors.add(new StandardAttrTagProcessor(TemplateMode.HTML, dialectPrefix));
processors.add(new StandardAttrappendTagProcessor(TemplateMode.HTML, dialectPrefix));
processors.add(new StandardAttrprependTagProcessor(TemplateMode.HTML, dialectPrefix));
processors.add(new StandardCaseTagProcessor(TemplateMode.HTML, dialectPrefix));
processors.add(new StandardClassappendTagProcessor(dialectPrefix));
for (final String attrName : StandardConditionalFixedValueTagProcessor.ATTR_NAMES) {
processors.add(new StandardConditionalFixedValueTagProcessor(dialectPrefix, attrName));
}
for (final String attrName : StandardDOMEventAttributeTagProcessor.ATTR_NAMES) {
processors.add(new StandardDOMEventAttributeTagProcessor(dialectPrefix, attrName));
}
processors.add(new StandardEachTagProcessor(TemplateMode.HTML, dialectPrefix));
processors.add(new StandardFragmentTagProcessor(TemplateMode.HTML, dialectPrefix));
processors.add(new StandardHrefTagProcessor(dialectPrefix));
processors.add(new StandardIfTagProcessor(TemplateMode.HTML, dialectPrefix));
processors.add(new StandardIncludeTagProcessor(TemplateMode.HTML, dialectPrefix));
processors.add(new StandardInlineHTMLTagProcessor(dialectPrefix));
processors.add(new StandardInsertTagProcessor(TemplateMode.HTML, dialectPrefix));
processors.add(new StandardLangXmlLangTagProcessor(dialectPrefix));
processors.add(new StandardMethodTagProcessor(dialectPrefix));
for (final String attrName : StandardNonRemovableAttributeTagProcessor.ATTR_NAMES) {
processors.add(new StandardNonRemovableAttributeTagProcessor(dialectPrefix, attrName));
}
processors.add(new StandardObjectTagProcessor(TemplateMode.HTML, dialectPrefix));
for (final String attrName : StandardRemovableAttributeTagProcessor.ATTR_NAMES) {
processors.add(new StandardRemovableAttributeTagProcessor(dialectPrefix, attrName));
}
processors.add(new StandardRemoveTagProcessor(TemplateMode.HTML, dialectPrefix));
processors.add(new StandardReplaceTagProcessor(TemplateMode.HTML, dialectPrefix));
processors.add(new StandardSrcTagProcessor(dialectPrefix));
processors.add(new StandardStyleappendTagProcessor(dialectPrefix));
processors.add(new StandardSubstituteByTagProcessor(TemplateMode.HTML, dialectPrefix));
processors.add(new StandardSwitchTagProcessor(TemplateMode.HTML, dialectPrefix));
processors.add(new StandardTextTagProcessor(TemplateMode.HTML, dialectPrefix));
processors.add(new StandardUnlessTagProcessor(TemplateMode.HTML, dialectPrefix));
processors.add(new StandardUtextTagProcessor(TemplateMode.HTML, dialectPrefix));
processors.add(new StandardValueTagProcessor(dialectPrefix));
processors.add(new StandardWithTagProcessor(TemplateMode.HTML, dialectPrefix));
processors.add(new StandardXmlBaseTagProcessor(dialectPrefix));
processors.add(new StandardXmlLangTagProcessor(dialectPrefix));
processors.add(new StandardXmlSpaceTagProcessor(dialectPrefix));
processors.add(new StandardXmlNsTagProcessor(TemplateMode.HTML, dialectPrefix));
processors.add(new StandardRefAttributeTagProcessor(TemplateMode.HTML, dialectPrefix));
processors.add(new StandardDefaultAttributesTagProcessor(TemplateMode.HTML, dialectPrefix));
/*
* HTML: ELEMENT TAG PROCESSORS
*/
processors.add(new StandardBlockTagProcessor(TemplateMode.HTML, dialectPrefix, StandardBlockTagProcessor.ELEMENT_NAME));
/*
* HTML: TEXT PROCESSORS
*
* NOTE the ability of the Standard Inlining mechanism to directly write to output instead of generating
* internal Strings relies on the fact that there is only ONE ITextProcessor instance for each
* template mode in the StandardDialect (see AbstractStandardInliner for details). So if new processors
* are added here, it should be for a really compelling reason.
* See EngineConfiguration#isModelReshapable()
*/
processors.add(new StandardInliningTextProcessor(TemplateMode.HTML));
/*
* HTML: CDATASection PROCESSORS
*
* NOTE as happens with text processors, adding a processor here would convert models in non-reshapable.
* See EngineConfiguration#isModelReshapable()
*/
processors.add(new StandardInliningCDATASectionProcessor(TemplateMode.HTML));
/*
* HTML: DOCTYPE PROCESSORS
*/
processors.add(new StandardTranslationDocTypeProcessor());
/*
* HTML: COMMENT PROCESSORS
*
* NOTE as happens with text processors, adding a processor here would convert models in non-reshapable.
* See EngineConfiguration#isModelReshapable()
*/
processors.add(new StandardInliningCommentProcessor(TemplateMode.HTML));
processors.add(new StandardConditionalCommentProcessor());
/*
* HTML: TEMPLATE BOUNDARIES PROCESSORS
*/
processors.add(new StandardInlineEnablementTemplateBoundariesProcessor(TemplateMode.HTML));
/*
* ------------------------
* ------------------------
* XML TEMPLATE MODE
* ------------------------
* ------------------------
*/
/*
* XML: ATTRIBUTE TAG PROCESSORS
*/
processors.add(new StandardAssertTagProcessor(TemplateMode.XML, dialectPrefix));
processors.add(new StandardAttrTagProcessor(TemplateMode.XML, dialectPrefix));
processors.add(new StandardAttrappendTagProcessor(TemplateMode.XML, dialectPrefix));
processors.add(new StandardAttrprependTagProcessor(TemplateMode.XML, dialectPrefix));
processors.add(new StandardCaseTagProcessor(TemplateMode.XML, dialectPrefix));
processors.add(new StandardEachTagProcessor(TemplateMode.XML, dialectPrefix));
processors.add(new StandardFragmentTagProcessor(TemplateMode.XML, dialectPrefix));
processors.add(new StandardIfTagProcessor(TemplateMode.XML, dialectPrefix));
processors.add(new StandardIncludeTagProcessor(TemplateMode.XML, dialectPrefix));
processors.add(new StandardInlineXMLTagProcessor(dialectPrefix));
processors.add(new StandardInsertTagProcessor(TemplateMode.XML, dialectPrefix));
processors.add(new StandardObjectTagProcessor(TemplateMode.XML, dialectPrefix));
processors.add(new StandardRemoveTagProcessor(TemplateMode.XML, dialectPrefix));
processors.add(new StandardReplaceTagProcessor(TemplateMode.XML, dialectPrefix));
processors.add(new StandardSubstituteByTagProcessor(TemplateMode.XML, dialectPrefix));
processors.add(new StandardSwitchTagProcessor(TemplateMode.XML, dialectPrefix));
processors.add(new StandardTextTagProcessor(TemplateMode.XML, dialectPrefix));
processors.add(new StandardUnlessTagProcessor(TemplateMode.XML, dialectPrefix));
processors.add(new StandardUtextTagProcessor(TemplateMode.XML, dialectPrefix));
processors.add(new StandardWithTagProcessor(TemplateMode.XML, dialectPrefix));
processors.add(new StandardXmlNsTagProcessor(TemplateMode.XML, dialectPrefix));
processors.add(new StandardRefAttributeTagProcessor(TemplateMode.XML, dialectPrefix));
processors.add(new StandardDefaultAttributesTagProcessor(TemplateMode.XML, dialectPrefix));
/*
* XML: ELEMENT TAG PROCESSORS
*/
processors.add(new StandardBlockTagProcessor(TemplateMode.XML, dialectPrefix, StandardBlockTagProcessor.ELEMENT_NAME));
/*
* XML: TEXT PROCESSORS
*
* NOTE the ability of the Standard Inlining mechanism to directly write to output instead of generating
* internal Strings relies on the fact that there is only ONE ITextProcessor instance for each template mode
* in the StandardDialect (see AbstractStandardInliner for details). So if new processors are added here,
* it should be for a really compelling reason.
* See EngineConfiguration#isModelReshapable()
*/
processors.add(new StandardInliningTextProcessor(TemplateMode.XML));
/*
* XML: CDATASection PROCESSORS
*
* NOTE as happens with text processors, adding a processor here would convert models in non-reshapable.
* See EngineConfiguration#isModelReshapable()
*/
processors.add(new StandardInliningCDATASectionProcessor(TemplateMode.XML));
/*
* XML: COMMENT PROCESSORS
*
* NOTE as happens with text processors, adding a processor here would convert models in non-reshapable.
* See EngineConfiguration#isModelReshapable()
*/
processors.add(new StandardInliningCommentProcessor(TemplateMode.XML));
/*
* XML: TEMPLATE BOUNDARIES PROCESSORS
*/
processors.add(new StandardInlineEnablementTemplateBoundariesProcessor(TemplateMode.XML));
/*
* ------------------------
* ------------------------
* TEXT TEMPLATE MODE
* ------------------------
* ------------------------
*/
/*
* TEXT: ATTRIBUTE TAG PROCESSORS
*/
processors.add(new StandardAssertTagProcessor(TemplateMode.TEXT, dialectPrefix));
processors.add(new StandardCaseTagProcessor(TemplateMode.TEXT, dialectPrefix));
processors.add(new StandardEachTagProcessor(TemplateMode.TEXT, dialectPrefix));
// No th:fragment attribute in text modes: no fragment selection available!
processors.add(new StandardIfTagProcessor(TemplateMode.TEXT, dialectPrefix));
// No th:include to be added here, as it is already deprecated since 3.0
processors.add(new StandardInlineTextualTagProcessor(TemplateMode.TEXT, dialectPrefix));
processors.add(new StandardInsertTagProcessor(TemplateMode.TEXT, dialectPrefix));
processors.add(new StandardObjectTagProcessor(TemplateMode.TEXT, dialectPrefix));
processors.add(new StandardRemoveTagProcessor(TemplateMode.TEXT, dialectPrefix));
processors.add(new StandardReplaceTagProcessor(TemplateMode.TEXT, dialectPrefix));
// No th:substituteby to be added here, as it is already deprecated since 2.1
processors.add(new StandardSwitchTagProcessor(TemplateMode.TEXT, dialectPrefix));
processors.add(new StandardTextTagProcessor(TemplateMode.TEXT, dialectPrefix));
processors.add(new StandardUnlessTagProcessor(TemplateMode.TEXT, dialectPrefix));
processors.add(new StandardUtextTagProcessor(TemplateMode.TEXT, dialectPrefix));
processors.add(new StandardWithTagProcessor(TemplateMode.TEXT, dialectPrefix));
/*
* TEXT: ELEMENT TAG PROCESSORS
*/
processors.add(new StandardBlockTagProcessor(TemplateMode.TEXT, dialectPrefix, StandardBlockTagProcessor.ELEMENT_NAME));
// With no name, will process [# th....] elements
processors.add(new StandardBlockTagProcessor(TemplateMode.TEXT, null, ""));
/*
* TEXT: TEXT PROCESSORS
*
* NOTE the ability of the Standard Inlining mechanism to directly write to output instead of generating
* internal Strings relies on the fact that there is only ONE ITextProcessor instance for each template mode
* in the StandardDialect (see AbstractStandardInliner for details). So if new processors are added here,
* it should be for a really compelling reason.
*/
processors.add(new StandardInliningTextProcessor(TemplateMode.TEXT));
/*
* TEXT: TEMPLATE BOUNDARIES PROCESSORS
*/
processors.add(new StandardInlineEnablementTemplateBoundariesProcessor(TemplateMode.TEXT));
/*
* ------------------------
* ------------------------
* JAVASCRIPT TEMPLATE MODE
* ------------------------
* ------------------------
*/
/*
* JAVASCRIPT: ATTRIBUTE TAG PROCESSORS
*/
processors.add(new StandardAssertTagProcessor(TemplateMode.JAVASCRIPT, dialectPrefix));
processors.add(new StandardCaseTagProcessor(TemplateMode.JAVASCRIPT, dialectPrefix));
processors.add(new StandardEachTagProcessor(TemplateMode.JAVASCRIPT, dialectPrefix));
// No th:fragment attribute in text modes: no fragment selection available!
processors.add(new StandardIfTagProcessor(TemplateMode.JAVASCRIPT, dialectPrefix));
// No th:include to be added here, as it is already deprecated since 3.0
processors.add(new StandardInlineTextualTagProcessor(TemplateMode.JAVASCRIPT, dialectPrefix));
processors.add(new StandardInsertTagProcessor(TemplateMode.JAVASCRIPT, dialectPrefix));
processors.add(new StandardObjectTagProcessor(TemplateMode.JAVASCRIPT, dialectPrefix));
processors.add(new StandardRemoveTagProcessor(TemplateMode.JAVASCRIPT, dialectPrefix));
processors.add(new StandardReplaceTagProcessor(TemplateMode.JAVASCRIPT, dialectPrefix));
// No th:substituteby to be added here, as it is already deprecated since 2.1
processors.add(new StandardSwitchTagProcessor(TemplateMode.JAVASCRIPT, dialectPrefix));
processors.add(new StandardTextTagProcessor(TemplateMode.JAVASCRIPT, dialectPrefix));
processors.add(new StandardUnlessTagProcessor(TemplateMode.JAVASCRIPT, dialectPrefix));
processors.add(new StandardUtextTagProcessor(TemplateMode.JAVASCRIPT, dialectPrefix));
processors.add(new StandardWithTagProcessor(TemplateMode.JAVASCRIPT, dialectPrefix));
/*
* JAVASCRIPT: ELEMENT TAG PROCESSORS
*/
processors.add(new StandardBlockTagProcessor(TemplateMode.JAVASCRIPT, dialectPrefix, StandardBlockTagProcessor.ELEMENT_NAME));
// With no name, will process [# th....] elements
processors.add(new StandardBlockTagProcessor(TemplateMode.JAVASCRIPT, null, ""));
/*
* JAVASCRIPT: TEXT PROCESSORS
*
* NOTE the ability of the Standard Inlining mechanism to directly write to output instead of generating
* internal Strings relies on the fact that there is only ONE ITextProcessor instance for each template mode
* in the StandardDialect (see AbstractStandardInliner for details). So if new processors are added here,
* it should be for a really compelling reason.
*/
processors.add(new StandardInliningTextProcessor(TemplateMode.JAVASCRIPT));
/*
* JAVASCRIPT: TEMPLATE BOUNDARIES PROCESSORS
*/
processors.add(new StandardInlineEnablementTemplateBoundariesProcessor(TemplateMode.JAVASCRIPT));
/*
* ------------------------
* ------------------------
* CSS TEMPLATE MODE
* ------------------------
* ------------------------
*/
/*
* CSS: ATTRIBUTE TAG PROCESSORS
*/
processors.add(new StandardAssertTagProcessor(TemplateMode.CSS, dialectPrefix));
processors.add(new StandardCaseTagProcessor(TemplateMode.CSS, dialectPrefix));
processors.add(new StandardEachTagProcessor(TemplateMode.CSS, dialectPrefix));
// No th:fragment attribute in text modes: no fragment selection available!
processors.add(new StandardIfTagProcessor(TemplateMode.CSS, dialectPrefix));
// No th:include to be added here, as it is already deprecated since 3.0
processors.add(new StandardInlineTextualTagProcessor(TemplateMode.CSS, dialectPrefix));
processors.add(new StandardInsertTagProcessor(TemplateMode.CSS, dialectPrefix));
processors.add(new StandardObjectTagProcessor(TemplateMode.CSS, dialectPrefix));
processors.add(new StandardRemoveTagProcessor(TemplateMode.CSS, dialectPrefix));
processors.add(new StandardReplaceTagProcessor(TemplateMode.CSS, dialectPrefix));
// No th:substituteby to be added here, as it is already deprecated since 2.1
processors.add(new StandardSwitchTagProcessor(TemplateMode.CSS, dialectPrefix));
processors.add(new StandardTextTagProcessor(TemplateMode.CSS, dialectPrefix));
processors.add(new StandardUnlessTagProcessor(TemplateMode.CSS, dialectPrefix));
processors.add(new StandardUtextTagProcessor(TemplateMode.CSS, dialectPrefix));
processors.add(new StandardWithTagProcessor(TemplateMode.CSS, dialectPrefix));
/*
* CSS: ELEMENT TAG PROCESSORS
*/
processors.add(new StandardBlockTagProcessor(TemplateMode.CSS, dialectPrefix, StandardBlockTagProcessor.ELEMENT_NAME));
// With no name, will process [# th....] elements
processors.add(new StandardBlockTagProcessor(TemplateMode.CSS, null, ""));
/*
* CSS: TEXT PROCESSORS
*
* NOTE the ability of the Standard Inlining mechanism to directly write to output instead of generating
* internal Strings relies on the fact that there is only ONE ITextProcessor instance for each template mode
* in the StandardDialect (see AbstractStandardInliner for details). So if new processors are added here,
* it should be for a really compelling reason.
*/
processors.add(new StandardInliningTextProcessor(TemplateMode.CSS));
/*
* CSS: TEMPLATE BOUNDARIES PROCESSORS
*/
processors.add(new StandardInlineEnablementTemplateBoundariesProcessor(TemplateMode.CSS));
return processors;
}
use of org.thymeleaf.processor.IProcessor in project tutorials by eugenp.
the class CustomDialect method getProcessors.
@Override
public Set<IProcessor> getProcessors() {
final Set<IProcessor> processors = new HashSet<IProcessor>();
processors.add(new NameProcessor());
return processors;
}
Aggregations