Search in sources :

Example 11 with IElementProcessor

use of org.thymeleaf.processor.element.IElementProcessor 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 12 with IElementProcessor

use of org.thymeleaf.processor.element.IElementProcessor 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)

Example 13 with IElementProcessor

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

the class ElementProcessorIterator method next.

IElementProcessor next(final AbstractProcessableElementTag tag) {
    // calling 'next' again, so we are fine checking this flag before checking for recomputes
    if (this.lastToBeRepeated) {
        final IElementProcessor repeatedLast = computeRepeatedLast(tag);
        this.lastToBeRepeated = false;
        this.lastWasRepeated = true;
        return repeatedLast;
    }
    this.lastWasRepeated = false;
    if (this.currentTag != tag) {
        // tags are immutable, so we will use them as a marker of being updated
        recompute(tag);
        this.currentTag = tag;
        this.last = -1;
    }
    if (this.processors == null) {
        return null;
    }
    // We use 'last' as a starting index in order save some iterations (except after recomputes)
    int i = this.last + 1;
    int n = this.size - i;
    while (n-- != 0) {
        if (!this.visited[i]) {
            this.visited[i] = true;
            this.last = i;
            return this.processors[i];
        }
        i++;
    }
    this.last = this.size;
    return null;
}
Also used : IElementProcessor(org.thymeleaf.processor.element.IElementProcessor)

Aggregations

IElementProcessor (org.thymeleaf.processor.element.IElementProcessor)13 LinkedHashSet (java.util.LinkedHashSet)7 ConfigurationException (org.thymeleaf.exceptions.ConfigurationException)7 MatchingElementName (org.thymeleaf.processor.element.MatchingElementName)7 MatchingAttributeName (org.thymeleaf.processor.element.MatchingAttributeName)6 TemplateMode (org.thymeleaf.templatemode.TemplateMode)5 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)2 TemplateProcessingException (org.thymeleaf.exceptions.TemplateProcessingException)2 IText (org.thymeleaf.model.IText)2 IProcessor (org.thymeleaf.processor.IProcessor)2 ICDATASectionProcessor (org.thymeleaf.processor.cdatasection.ICDATASectionProcessor)2 ICommentProcessor (org.thymeleaf.processor.comment.ICommentProcessor)2 IDocTypeProcessor (org.thymeleaf.processor.doctype.IDocTypeProcessor)2 IElementModelProcessor (org.thymeleaf.processor.element.IElementModelProcessor)2 IProcessingInstructionProcessor (org.thymeleaf.processor.processinginstruction.IProcessingInstructionProcessor)2 ITemplateBoundariesProcessor (org.thymeleaf.processor.templateboundaries.ITemplateBoundariesProcessor)2 ITextProcessor (org.thymeleaf.processor.text.ITextProcessor)2 IXMLDeclarationProcessor (org.thymeleaf.processor.xmldeclaration.IXMLDeclarationProcessor)2 EnumMap (java.util.EnumMap)1