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);
}
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);
}
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;
}
Aggregations