Search in sources :

Example 6 with ConfigurationException

use of org.thymeleaf.exceptions.ConfigurationException 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);
}
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 ConfigurationException

use of org.thymeleaf.exceptions.ConfigurationException 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 8 with ConfigurationException

use of org.thymeleaf.exceptions.ConfigurationException 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

ConfigurationException (org.thymeleaf.exceptions.ConfigurationException)8 LinkedHashSet (java.util.LinkedHashSet)7 IElementProcessor (org.thymeleaf.processor.element.IElementProcessor)7 MatchingAttributeName (org.thymeleaf.processor.element.MatchingAttributeName)6 MatchingElementName (org.thymeleaf.processor.element.MatchingElementName)6 TemplateMode (org.thymeleaf.templatemode.TemplateMode)5 IDialect (org.thymeleaf.dialect.IDialect)2 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 EnumMap (java.util.EnumMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 IExecutionAttributeDialect (org.thymeleaf.dialect.IExecutionAttributeDialect)1 IExpressionObjectDialect (org.thymeleaf.dialect.IExpressionObjectDialect)1 IPostProcessorDialect (org.thymeleaf.dialect.IPostProcessorDialect)1 IPreProcessorDialect (org.thymeleaf.dialect.IPreProcessorDialect)1 IProcessorDialect (org.thymeleaf.dialect.IProcessorDialect)1 AttributeDefinitions (org.thymeleaf.engine.AttributeDefinitions)1