use of org.thymeleaf.processor.element.MatchingAttributeName in project thymeleaf by thymeleaf.
the class ElementDefinitions method buildTextElementDefinition.
private static TextElementDefinition buildTextElementDefinition(final TemplateMode templateMode, final TextElementName name, final Set<IElementProcessor> elementProcessors) {
// No need to use a list for sorting - the elementProcessors set has already been ordered
final Set<IElementProcessor> associatedProcessors = new LinkedHashSet<IElementProcessor>(2);
if (elementProcessors != null) {
for (final IElementProcessor processor : elementProcessors) {
if (processor.getTemplateMode() != templateMode) {
// We are creating an element definition for a specific template mode
continue;
}
final MatchingElementName matchingElementName = processor.getMatchingElementName();
final MatchingAttributeName matchingAttributeName = processor.getMatchingAttributeName();
if ((matchingElementName != null && matchingElementName.getTemplateMode() != templateMode) || (matchingAttributeName != null && matchingAttributeName.getTemplateMode() != templateMode)) {
throw new ConfigurationException(templateMode + " processors must return " + templateMode + "element names and " + templateMode + " attribute names (processor: " + processor.getClass().getName() + ")");
}
if (matchingAttributeName != null && !matchingAttributeName.isMatchingAllAttributes()) {
// (will be instead associated with the attribute).
continue;
}
if (matchingElementName != null && !matchingElementName.matches(name)) {
// Note that elementName == null means "apply to all processors"
continue;
}
associatedProcessors.add(processor);
}
}
// Build the final instance
return new TextElementDefinition(name, associatedProcessors);
}
use of org.thymeleaf.processor.element.MatchingAttributeName in project thymeleaf by thymeleaf.
the class ConfigurationPrinterHelper method printProcessorsForTemplateMode.
private static void printProcessorsForTemplateMode(final ConfigLogBuilder logBuilder, final Set<IProcessor> processors, final TemplateMode templateMode) {
if (processors == null || processors.isEmpty()) {
return;
}
final List<ICDATASectionProcessor> cdataSectionProcessors = new ArrayList<ICDATASectionProcessor>();
final List<ICommentProcessor> commentProcessors = new ArrayList<ICommentProcessor>();
final List<IDocTypeProcessor> docTypeProcessors = new ArrayList<IDocTypeProcessor>();
final List<IElementTagProcessor> elementTagProcessors = new ArrayList<IElementTagProcessor>();
final List<IElementModelProcessor> elementModelProcessors = new ArrayList<IElementModelProcessor>();
final List<IProcessingInstructionProcessor> processingInstructionProcessors = new ArrayList<IProcessingInstructionProcessor>();
final List<ITextProcessor> textProcessors = new ArrayList<ITextProcessor>();
final List<IXMLDeclarationProcessor> xmlDeclarationProcessors = new ArrayList<IXMLDeclarationProcessor>();
boolean processorsForTemplateModeExist = false;
for (final IProcessor processor : processors) {
if (!templateMode.equals(processor.getTemplateMode())) {
continue;
}
processorsForTemplateModeExist = true;
if (processor instanceof ICDATASectionProcessor) {
cdataSectionProcessors.add((ICDATASectionProcessor) processor);
} else if (processor instanceof ICommentProcessor) {
commentProcessors.add((ICommentProcessor) processor);
} else if (processor instanceof IDocTypeProcessor) {
docTypeProcessors.add((IDocTypeProcessor) processor);
} else if (processor instanceof IElementTagProcessor) {
elementTagProcessors.add((IElementTagProcessor) processor);
} else if (processor instanceof IElementModelProcessor) {
elementModelProcessors.add((IElementModelProcessor) processor);
} else if (processor instanceof IProcessingInstructionProcessor) {
processingInstructionProcessors.add((IProcessingInstructionProcessor) processor);
} else if (processor instanceof ITextProcessor) {
textProcessors.add((ITextProcessor) processor);
} else if (processor instanceof IXMLDeclarationProcessor) {
xmlDeclarationProcessors.add((IXMLDeclarationProcessor) processor);
}
}
if (!processorsForTemplateModeExist) {
// Nothing to show, there are no processors for this template mode
return;
}
logBuilder.line("[THYMELEAF] * Processors for Template Mode: {}", templateMode);
Collections.sort(cdataSectionProcessors, ProcessorComparators.PROCESSOR_COMPARATOR);
Collections.sort(commentProcessors, ProcessorComparators.PROCESSOR_COMPARATOR);
Collections.sort(docTypeProcessors, ProcessorComparators.PROCESSOR_COMPARATOR);
Collections.sort(elementTagProcessors, ProcessorComparators.PROCESSOR_COMPARATOR);
Collections.sort(elementModelProcessors, ProcessorComparators.PROCESSOR_COMPARATOR);
Collections.sort(processingInstructionProcessors, ProcessorComparators.PROCESSOR_COMPARATOR);
Collections.sort(textProcessors, ProcessorComparators.PROCESSOR_COMPARATOR);
Collections.sort(xmlDeclarationProcessors, ProcessorComparators.PROCESSOR_COMPARATOR);
if (!elementTagProcessors.isEmpty()) {
logBuilder.line("[THYMELEAF] * Element Tag Processors by [matching element and attribute name] [precedence]:");
for (final IElementTagProcessor processor : elementTagProcessors) {
final MatchingElementName matchingElementName = processor.getMatchingElementName();
final MatchingAttributeName matchingAttributeName = processor.getMatchingAttributeName();
final String elementName = (matchingElementName == null ? "*" : matchingElementName.toString());
final String attributeName = (matchingAttributeName == null ? "*" : matchingAttributeName.toString());
logBuilder.line("[THYMELEAF] * [{} {}] [{}]: {}", new Object[] { elementName, attributeName, Integer.valueOf(processor.getPrecedence()), processor.getClass().getName() });
}
}
if (!elementModelProcessors.isEmpty()) {
logBuilder.line("[THYMELEAF] * Element Model Processors by [matching element and attribute name] [precedence]:");
for (final IElementModelProcessor processor : elementModelProcessors) {
final MatchingElementName matchingElementName = processor.getMatchingElementName();
final MatchingAttributeName matchingAttributeName = processor.getMatchingAttributeName();
final String elementName = (matchingElementName == null ? "*" : matchingElementName.toString());
final String attributeName = (matchingAttributeName == null ? "*" : matchingAttributeName.toString());
logBuilder.line("[THYMELEAF] * [{} {}] [{}]: {}", new Object[] { elementName, attributeName, Integer.valueOf(processor.getPrecedence()), processor.getClass().getName() });
}
}
if (!textProcessors.isEmpty()) {
logBuilder.line("[THYMELEAF] * Text Processors by [precedence]:");
for (final ITextProcessor processor : textProcessors) {
logBuilder.line("[THYMELEAF] * [{}]: {}", new Object[] { Integer.valueOf(processor.getPrecedence()), processor.getClass().getName() });
}
}
if (!docTypeProcessors.isEmpty()) {
logBuilder.line("[THYMELEAF] * DOCTYPE Processors by [precedence]:");
for (final IDocTypeProcessor processor : docTypeProcessors) {
logBuilder.line("[THYMELEAF] * [{}]: {}", new Object[] { Integer.valueOf(processor.getPrecedence()), processor.getClass().getName() });
}
}
if (!cdataSectionProcessors.isEmpty()) {
logBuilder.line("[THYMELEAF] * CDATA Section Processors by [precedence]:");
for (final ICDATASectionProcessor processor : cdataSectionProcessors) {
logBuilder.line("[THYMELEAF] * [{}]: {}", new Object[] { Integer.valueOf(processor.getPrecedence()), processor.getClass().getName() });
}
}
if (!commentProcessors.isEmpty()) {
logBuilder.line("[THYMELEAF] * Comment Processors by [precedence]:");
for (final ICommentProcessor processor : commentProcessors) {
logBuilder.line("[THYMELEAF] * [{}]: {}", new Object[] { Integer.valueOf(processor.getPrecedence()), processor.getClass().getName() });
}
}
if (!xmlDeclarationProcessors.isEmpty()) {
logBuilder.line("[THYMELEAF] * XML Declaration Processors by [precedence]:");
for (final IXMLDeclarationProcessor processor : xmlDeclarationProcessors) {
logBuilder.line("[THYMELEAF] * [{}]: {}", new Object[] { Integer.valueOf(processor.getPrecedence()), processor.getClass().getName() });
}
}
if (!processingInstructionProcessors.isEmpty()) {
logBuilder.line("[THYMELEAF] * Processing Instruction Processors by [precedence]:");
for (final IProcessingInstructionProcessor processor : processingInstructionProcessors) {
logBuilder.line("[THYMELEAF] * [{}]: {}", new Object[] { Integer.valueOf(processor.getPrecedence()), processor.getClass().getName() });
}
}
}
use of org.thymeleaf.processor.element.MatchingAttributeName in project thymeleaf by thymeleaf.
the class AttributeDefinitions method buildTextAttributeDefinition.
private static TextAttributeDefinition buildTextAttributeDefinition(final TemplateMode templateMode, final TextAttributeName name, final Set<IElementProcessor> elementProcessors) {
// No need to use a list for sorting - the elementProcessors set has already been ordered
final Set<IElementProcessor> associatedProcessors = new LinkedHashSet<IElementProcessor>(2);
if (elementProcessors != null) {
for (final IElementProcessor processor : elementProcessors) {
if (processor.getTemplateMode() != templateMode) {
// We are creating a text element definition, therefore we are only interested on XML processors
continue;
}
final MatchingElementName matchingElementName = processor.getMatchingElementName();
final MatchingAttributeName matchingAttributeName = processor.getMatchingAttributeName();
if ((matchingElementName != null && matchingElementName.getTemplateMode() != templateMode) || (matchingAttributeName != null && matchingAttributeName.getTemplateMode() != templateMode)) {
throw new ConfigurationException(templateMode + " processors must return " + templateMode + "element names and " + templateMode + " attribute names (processor: " + processor.getClass().getName() + ")");
}
if (matchingAttributeName == null || matchingAttributeName.isMatchingAllAttributes()) {
// This processor does not relate to a specific attribute - surely an element processor
continue;
}
if (!matchingAttributeName.matches(name)) {
// Doesn't match. This processor is not associated with this attribute
continue;
}
associatedProcessors.add(processor);
}
}
// Build the final instance
return new TextAttributeDefinition(name, associatedProcessors);
}
use of org.thymeleaf.processor.element.MatchingAttributeName in project thymeleaf by thymeleaf.
the class AttributeDefinitions method buildHTMLAttributeDefinition.
private static HTMLAttributeDefinition buildHTMLAttributeDefinition(final HTMLAttributeName name, final Set<IElementProcessor> elementProcessors) {
// No need to use a list for sorting - the elementProcessors set has already been ordered
final Set<IElementProcessor> associatedProcessors = new LinkedHashSet<IElementProcessor>(2);
if (elementProcessors != null) {
for (final IElementProcessor processor : elementProcessors) {
// Cannot be null -- has been previously validated
final TemplateMode templateMode = processor.getTemplateMode();
if (templateMode != TemplateMode.HTML) {
// We are creating an HTML element definition, therefore we are only interested on HTML processors
continue;
}
final MatchingElementName matchingElementName = processor.getMatchingElementName();
final MatchingAttributeName matchingAttributeName = processor.getMatchingAttributeName();
if ((matchingElementName != null && matchingElementName.getTemplateMode() != TemplateMode.HTML) || (matchingAttributeName != null && matchingAttributeName.getTemplateMode() != TemplateMode.HTML)) {
throw new ConfigurationException("HTML processors must return HTML element names and HTML attribute names (processor: " + processor.getClass().getName() + ")");
}
if (matchingAttributeName == null || matchingAttributeName.isMatchingAllAttributes()) {
// This processor does not relate to a specific attribute - surely an element processor
continue;
}
if (!matchingAttributeName.matches(name)) {
// Doesn't match. This processor is not associated with this attribute
continue;
}
associatedProcessors.add(processor);
}
}
// Compute whether this attribute is to be considered boolean or not
boolean booleanAttribute = false;
for (final String completeAttributeName : name.getCompleteAttributeNames()) {
if (ALL_STANDARD_BOOLEAN_HTML_ATTRIBUTE_NAMES.contains(completeAttributeName)) {
booleanAttribute = true;
}
}
// Build the final instance
return new HTMLAttributeDefinition(name, booleanAttribute, associatedProcessors);
}
use of org.thymeleaf.processor.element.MatchingAttributeName in project thymeleaf by thymeleaf.
the class AttributeDefinitions method buildXMLAttributeDefinition.
private static XMLAttributeDefinition buildXMLAttributeDefinition(final XMLAttributeName name, final Set<IElementProcessor> elementProcessors) {
// No need to use a list for sorting - the elementProcessors set has already been ordered
final Set<IElementProcessor> associatedProcessors = new LinkedHashSet<IElementProcessor>(2);
if (elementProcessors != null) {
for (final IElementProcessor processor : elementProcessors) {
// Cannot be null -- has been previously validated
final TemplateMode templateMode = processor.getTemplateMode();
if (templateMode != TemplateMode.XML) {
// We are creating an XML element definition, therefore we are only interested on XML processors
continue;
}
final MatchingElementName matchingElementName = processor.getMatchingElementName();
final MatchingAttributeName matchingAttributeName = processor.getMatchingAttributeName();
if ((matchingElementName != null && matchingElementName.getTemplateMode() != TemplateMode.XML) || (matchingAttributeName != null && matchingAttributeName.getTemplateMode() != TemplateMode.XML)) {
throw new ConfigurationException("XML processors must return XML element names and XML attribute names (processor: " + processor.getClass().getName() + ")");
}
if (matchingAttributeName == null || matchingAttributeName.isMatchingAllAttributes()) {
// This processor does not relate to a specific attribute - surely an element processor
continue;
}
if (!matchingAttributeName.matches(name)) {
// Doesn't match. This processor is not associated with this attribute
continue;
}
associatedProcessors.add(processor);
}
}
// Build the final instance
return new XMLAttributeDefinition(name, associatedProcessors);
}
Aggregations