Search in sources :

Example 6 with MatchingAttributeName

use of org.thymeleaf.processor.element.MatchingAttributeName in project thymeleaf by thymeleaf.

the class ElementDefinitions method buildXMLElementDefinition.

private static XMLElementDefinition buildXMLElementDefinition(final XMLElementName 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()) {
                // (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 XMLElementDefinition(name, associatedProcessors);
}
Also used : IElementProcessor(org.thymeleaf.processor.element.IElementProcessor) LinkedHashSet(java.util.LinkedHashSet) MatchingElementName(org.thymeleaf.processor.element.MatchingElementName) TemplateMode(org.thymeleaf.templatemode.TemplateMode) MatchingAttributeName(org.thymeleaf.processor.element.MatchingAttributeName) ConfigurationException(org.thymeleaf.exceptions.ConfigurationException)

Example 7 with MatchingAttributeName

use of org.thymeleaf.processor.element.MatchingAttributeName in project thymeleaf by thymeleaf.

the class ElementDefinitions method buildHTMLElementDefinition.

private static HTMLElementDefinition buildHTMLElementDefinition(final HTMLElementName name, final HTMLElementType type, 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()) {
                // (will be instead associated with the attribute).
                continue;
            }
            if (matchingElementName != null && !matchingElementName.matches(name)) {
                // Doesn't match. This processor cannot be associated with this element
                continue;
            }
            associatedProcessors.add(processor);
        }
    }
    // Build the final instance
    return new HTMLElementDefinition(name, type, associatedProcessors);
}
Also used : IElementProcessor(org.thymeleaf.processor.element.IElementProcessor) LinkedHashSet(java.util.LinkedHashSet) MatchingElementName(org.thymeleaf.processor.element.MatchingElementName) TemplateMode(org.thymeleaf.templatemode.TemplateMode) MatchingAttributeName(org.thymeleaf.processor.element.MatchingAttributeName) ConfigurationException(org.thymeleaf.exceptions.ConfigurationException)

Aggregations

MatchingAttributeName (org.thymeleaf.processor.element.MatchingAttributeName)7 MatchingElementName (org.thymeleaf.processor.element.MatchingElementName)7 LinkedHashSet (java.util.LinkedHashSet)6 ConfigurationException (org.thymeleaf.exceptions.ConfigurationException)6 IElementProcessor (org.thymeleaf.processor.element.IElementProcessor)6 TemplateMode (org.thymeleaf.templatemode.TemplateMode)4 ArrayList (java.util.ArrayList)1 IProcessor (org.thymeleaf.processor.IProcessor)1 ICDATASectionProcessor (org.thymeleaf.processor.cdatasection.ICDATASectionProcessor)1 ICommentProcessor (org.thymeleaf.processor.comment.ICommentProcessor)1 IDocTypeProcessor (org.thymeleaf.processor.doctype.IDocTypeProcessor)1 IElementModelProcessor (org.thymeleaf.processor.element.IElementModelProcessor)1 IElementTagProcessor (org.thymeleaf.processor.element.IElementTagProcessor)1 IProcessingInstructionProcessor (org.thymeleaf.processor.processinginstruction.IProcessingInstructionProcessor)1 ITextProcessor (org.thymeleaf.processor.text.ITextProcessor)1 IXMLDeclarationProcessor (org.thymeleaf.processor.xmldeclaration.IXMLDeclarationProcessor)1