Search in sources :

Example 1 with AttributeDefinitions

use of org.thymeleaf.engine.AttributeDefinitions in project thymeleaf-tests by thymeleaf.

the class DialectSetConfigurationTest method testProcessorComputation03.

@Test
public void testProcessorComputation03() {
    final IProcessorDialect dialect = ProcessorAggregationTestDialect.buildDialect("standard", "TH", "E-20-null-src, E-10-null-src,E-20-null-href,E-20-null-text,E-10-null-text,E-10-*div-text,E-15-*div-src,E-1-form-*action,E-20-form-null,E-10-null-*action,E-50-null-null", "E-200-null-src, E-100-null-src,E-200-null-href,E-200-null-text,E-100-null-text,E-100-*div-text,E-150-*div-src,E-10-form-*action,E-200-form-null,E-100-null-*action,E-500-null-null");
    final DialectConfiguration dialectConfiguration = new DialectConfiguration(dialect);
    final DialectSetConfiguration dialectSetConfiguration = DialectSetConfiguration.build(Collections.singleton(dialectConfiguration));
    final AttributeDefinitions attributeDefinitions = dialectSetConfiguration.getAttributeDefinitions();
    final ElementDefinitions elementDefinitions = dialectSetConfiguration.getElementDefinitions();
    Assert.assertEquals("TH", dialect.getPrefix());
    Assert.assertEquals("[E-10-null-{th:src,data-th-src}, E-15-{div}-{th:src,data-th-src}, E-20-null-{th:src,data-th-src}]", attributeDefinitions.forHTMLName("th:src").getAssociatedProcessors().toString());
    Assert.assertEquals("[E-1-{th:form,th-form}-{action}, E-10-null-{action}]", attributeDefinitions.forHTMLName("action").getAssociatedProcessors().toString());
    Assert.assertEquals("[E-20-{th:form,th-form}-null, E-50-null-null]", elementDefinitions.forHTMLName("th", "form").getAssociatedProcessors().toString());
    Assert.assertEquals("[]", attributeDefinitions.forHTMLName("th", "utext").getAssociatedProcessors().toString());
    Assert.assertEquals("[E-50-null-null]", elementDefinitions.forHTMLName("p").getAssociatedProcessors().toString());
    Assert.assertEquals("[]", attributeDefinitions.forXMLName("th:src").getAssociatedProcessors().toString());
    Assert.assertEquals("[E-100-null-{TH:src}, E-150-{div}-{TH:src}, E-200-null-{TH:src}]", attributeDefinitions.forXMLName("TH:src").getAssociatedProcessors().toString());
    Assert.assertEquals("[E-10-{TH:form}-{action}, E-100-null-{action}]", attributeDefinitions.forXMLName("action").getAssociatedProcessors().toString());
    Assert.assertEquals("[E-200-{TH:form}-null, E-500-null-null]", elementDefinitions.forXMLName("TH", "form").getAssociatedProcessors().toString());
    Assert.assertEquals("[]", attributeDefinitions.forXMLName("th", "utext").getAssociatedProcessors().toString());
    Assert.assertEquals("[]", attributeDefinitions.forXMLName("TH", "utext").getAssociatedProcessors().toString());
    Assert.assertEquals("[E-500-null-null]", elementDefinitions.forXMLName("p").getAssociatedProcessors().toString());
}
Also used : DialectSetConfiguration(org.thymeleaf.DialectSetConfiguration) AttributeDefinitions(org.thymeleaf.engine.AttributeDefinitions) ElementDefinitions(org.thymeleaf.engine.ElementDefinitions) DialectConfiguration(org.thymeleaf.DialectConfiguration) IProcessorDialect(org.thymeleaf.dialect.IProcessorDialect) Test(org.junit.Test)

Example 2 with AttributeDefinitions

use of org.thymeleaf.engine.AttributeDefinitions in project thymeleaf by thymeleaf.

the class DialectSetConfiguration method build.

public static DialectSetConfiguration build(final Set<DialectConfiguration> dialectConfigurations) {
    Validate.notNull(dialectConfigurations, "Dialect configuration set cannot be null");
    // This set will contain all the dialects - without any additional configuration information
    final Set<IDialect> dialects = new LinkedHashSet<IDialect>(dialectConfigurations.size());
    // If we find a standard dialect among the configured ones (Standard or SpringStandard), we will report its prefix
    boolean standardDialectPresent = false;
    String standardDialectPrefix = null;
    // This map will be used for merging the execution attributes of all the dialects
    final Map<String, Object> executionAttributes = new LinkedHashMap<String, Object>(10, 1.0f);
    // This will aggregate all the expression object factories provided by the different dialects
    final AggregateExpressionObjectFactory aggregateExpressionObjectFactory = new AggregateExpressionObjectFactory();
    // EnumMaps for each type of processor (depending on the structures that they can be applied to)
    final EnumMap<TemplateMode, List<ITemplateBoundariesProcessor>> templateBoundariesProcessorListsByTemplateMode = new EnumMap<TemplateMode, List<ITemplateBoundariesProcessor>>(TemplateMode.class);
    final EnumMap<TemplateMode, List<ICDATASectionProcessor>> cdataSectionProcessorListsByTemplateMode = new EnumMap<TemplateMode, List<ICDATASectionProcessor>>(TemplateMode.class);
    final EnumMap<TemplateMode, List<ICommentProcessor>> commentProcessorListsByTemplateMode = new EnumMap<TemplateMode, List<ICommentProcessor>>(TemplateMode.class);
    final EnumMap<TemplateMode, List<IDocTypeProcessor>> docTypeProcessorListsByTemplateMode = new EnumMap<TemplateMode, List<IDocTypeProcessor>>(TemplateMode.class);
    final EnumMap<TemplateMode, List<IElementProcessor>> elementProcessorListsByTemplateMode = new EnumMap<TemplateMode, List<IElementProcessor>>(TemplateMode.class);
    final EnumMap<TemplateMode, List<IProcessingInstructionProcessor>> processingInstructionProcessorListsByTemplateMode = new EnumMap<TemplateMode, List<IProcessingInstructionProcessor>>(TemplateMode.class);
    final EnumMap<TemplateMode, List<ITextProcessor>> textProcessorListsByTemplateMode = new EnumMap<TemplateMode, List<ITextProcessor>>(TemplateMode.class);
    final EnumMap<TemplateMode, List<IXMLDeclarationProcessor>> xmlDeclarationProcessorListsByTemplateMode = new EnumMap<TemplateMode, List<IXMLDeclarationProcessor>>(TemplateMode.class);
    // Lists for merging all pre and postprocessors from all dialects
    final EnumMap<TemplateMode, List<IPreProcessor>> preProcessorListsByTemplateMode = new EnumMap<TemplateMode, List<IPreProcessor>>(TemplateMode.class);
    final EnumMap<TemplateMode, List<IPostProcessor>> postProcessorListsByTemplateMode = new EnumMap<TemplateMode, List<IPostProcessor>>(TemplateMode.class);
    /*
         * ITERATE ALL DIALECTS, processing each one according to its features
         */
    for (final DialectConfiguration dialectConfiguration : dialectConfigurations) {
        // cannot be null -- ConfigurationDialect checks this
        final IDialect dialect = dialectConfiguration.getDialect();
        /*
             * STEP ONE for each dialect: process, initialize and merge processors
             */
        if (dialect instanceof IProcessorDialect) {
            final IProcessorDialect processorDialect = (IProcessorDialect) dialect;
            // Might be null if the dialect has been specified to use no prefix (or that is the default of such dialect)
            final String dialectPrefix = (dialectConfiguration.isPrefixSpecified() ? dialectConfiguration.getPrefix() : processorDialect.getPrefix());
            if (dialect instanceof StandardDialect) {
                standardDialectPresent = true;
                standardDialectPrefix = dialectPrefix;
            }
            final Set<IProcessor> dialectProcessors = processorDialect.getProcessors(dialectPrefix);
            if (dialectProcessors == null) {
                throw new ConfigurationException("Dialect should not return null processor set: " + dialect.getClass().getName());
            }
            for (final IProcessor dialectProcessor : dialectProcessors) {
                if (dialectProcessor == null) {
                    throw new ConfigurationException("Dialect should not return null processor in processor set: " + dialect.getClass().getName());
                }
                // Obtain and check template mode
                final TemplateMode templateMode = dialectProcessor.getTemplateMode();
                if (templateMode == null) {
                    throw new ConfigurationException("Template mode cannot be null (processor: " + dialectProcessor.getClass().getName() + ")");
                }
                if (dialectProcessor instanceof IElementProcessor) {
                    // can be either a tag processor or a node one
                    List<IElementProcessor> processorsForTemplateMode = elementProcessorListsByTemplateMode.get(templateMode);
                    if (processorsForTemplateMode == null) {
                        processorsForTemplateMode = new ArrayList<IElementProcessor>(5);
                        elementProcessorListsByTemplateMode.put(templateMode, processorsForTemplateMode);
                    }
                    processorsForTemplateMode.add(ProcessorConfigurationUtils.wrap((IElementProcessor) dialectProcessor, processorDialect));
                    Collections.sort(processorsForTemplateMode, ProcessorComparators.PROCESSOR_COMPARATOR);
                } else if (dialectProcessor instanceof ITemplateBoundariesProcessor) {
                    List<ITemplateBoundariesProcessor> processorsForTemplateMode = templateBoundariesProcessorListsByTemplateMode.get(templateMode);
                    if (processorsForTemplateMode == null) {
                        processorsForTemplateMode = new ArrayList<ITemplateBoundariesProcessor>(5);
                        templateBoundariesProcessorListsByTemplateMode.put(templateMode, processorsForTemplateMode);
                    }
                    processorsForTemplateMode.add(ProcessorConfigurationUtils.wrap((ITemplateBoundariesProcessor) dialectProcessor, processorDialect));
                    Collections.sort(processorsForTemplateMode, ProcessorComparators.PROCESSOR_COMPARATOR);
                } else if (dialectProcessor instanceof ICDATASectionProcessor) {
                    List<ICDATASectionProcessor> processorsForTemplateMode = cdataSectionProcessorListsByTemplateMode.get(templateMode);
                    if (processorsForTemplateMode == null) {
                        processorsForTemplateMode = new ArrayList<ICDATASectionProcessor>(5);
                        cdataSectionProcessorListsByTemplateMode.put(templateMode, processorsForTemplateMode);
                    }
                    processorsForTemplateMode.add(ProcessorConfigurationUtils.wrap((ICDATASectionProcessor) dialectProcessor, processorDialect));
                    Collections.sort(processorsForTemplateMode, ProcessorComparators.PROCESSOR_COMPARATOR);
                } else if (dialectProcessor instanceof ICommentProcessor) {
                    List<ICommentProcessor> processorsForTemplateMode = commentProcessorListsByTemplateMode.get(templateMode);
                    if (processorsForTemplateMode == null) {
                        processorsForTemplateMode = new ArrayList<ICommentProcessor>(5);
                        commentProcessorListsByTemplateMode.put(templateMode, processorsForTemplateMode);
                    }
                    processorsForTemplateMode.add(ProcessorConfigurationUtils.wrap((ICommentProcessor) dialectProcessor, processorDialect));
                    Collections.sort(processorsForTemplateMode, ProcessorComparators.PROCESSOR_COMPARATOR);
                } else if (dialectProcessor instanceof IDocTypeProcessor) {
                    List<IDocTypeProcessor> processorsForTemplateMode = docTypeProcessorListsByTemplateMode.get(templateMode);
                    if (processorsForTemplateMode == null) {
                        processorsForTemplateMode = new ArrayList<IDocTypeProcessor>(5);
                        docTypeProcessorListsByTemplateMode.put(templateMode, processorsForTemplateMode);
                    }
                    processorsForTemplateMode.add(ProcessorConfigurationUtils.wrap((IDocTypeProcessor) dialectProcessor, processorDialect));
                    Collections.sort(processorsForTemplateMode, ProcessorComparators.PROCESSOR_COMPARATOR);
                } else if (dialectProcessor instanceof IProcessingInstructionProcessor) {
                    List<IProcessingInstructionProcessor> processorsForTemplateMode = processingInstructionProcessorListsByTemplateMode.get(templateMode);
                    if (processorsForTemplateMode == null) {
                        processorsForTemplateMode = new ArrayList<IProcessingInstructionProcessor>(5);
                        processingInstructionProcessorListsByTemplateMode.put(templateMode, processorsForTemplateMode);
                    }
                    processorsForTemplateMode.add(ProcessorConfigurationUtils.wrap((IProcessingInstructionProcessor) dialectProcessor, processorDialect));
                    Collections.sort(processorsForTemplateMode, ProcessorComparators.PROCESSOR_COMPARATOR);
                } else if (dialectProcessor instanceof ITextProcessor) {
                    List<ITextProcessor> processorsForTemplateMode = textProcessorListsByTemplateMode.get(templateMode);
                    if (processorsForTemplateMode == null) {
                        processorsForTemplateMode = new ArrayList<ITextProcessor>(5);
                        textProcessorListsByTemplateMode.put(templateMode, processorsForTemplateMode);
                    }
                    processorsForTemplateMode.add(ProcessorConfigurationUtils.wrap((ITextProcessor) dialectProcessor, processorDialect));
                    Collections.sort(processorsForTemplateMode, ProcessorComparators.PROCESSOR_COMPARATOR);
                } else if (dialectProcessor instanceof IXMLDeclarationProcessor) {
                    List<IXMLDeclarationProcessor> processorsForTemplateMode = xmlDeclarationProcessorListsByTemplateMode.get(templateMode);
                    if (processorsForTemplateMode == null) {
                        processorsForTemplateMode = new ArrayList<IXMLDeclarationProcessor>(5);
                        xmlDeclarationProcessorListsByTemplateMode.put(templateMode, processorsForTemplateMode);
                    }
                    processorsForTemplateMode.add(ProcessorConfigurationUtils.wrap((IXMLDeclarationProcessor) dialectProcessor, processorDialect));
                    Collections.sort(processorsForTemplateMode, ProcessorComparators.PROCESSOR_COMPARATOR);
                }
            }
        }
        /*
             * STEP TWO for each dialect: merge execution attributes
             */
        if (dialect instanceof IExecutionAttributeDialect) {
            final Map<String, Object> dialectExecutionAttributes = ((IExecutionAttributeDialect) dialect).getExecutionAttributes();
            if (dialectExecutionAttributes != null) {
                for (final Map.Entry<String, Object> entry : dialectExecutionAttributes.entrySet()) {
                    final String executionAttributeName = entry.getKey();
                    if (executionAttributes.containsKey(executionAttributeName)) {
                        throw new ConfigurationException("Conflicting execution attribute. Two or more dialects specify an execution " + "attribute with the same name \"" + executionAttributeName + "\".");
                    }
                    executionAttributes.put(entry.getKey(), entry.getValue());
                }
            }
        }
        /*
             * STEP THREE for each dialect: aggregate all the expression object factories
             */
        if (dialect instanceof IExpressionObjectDialect) {
            final IExpressionObjectFactory factory = ((IExpressionObjectDialect) dialect).getExpressionObjectFactory();
            if (factory != null) {
                aggregateExpressionObjectFactory.add(factory);
            }
        }
        /*
             * STEP FOUR for each dialect: aggregate pre-processors (and check the correctness of the list)
             */
        if (dialect instanceof IPreProcessorDialect) {
            final Set<IPreProcessor> dialectPreProcessors = ((IPreProcessorDialect) dialect).getPreProcessors();
            if (dialectPreProcessors != null) {
                for (final IPreProcessor preProcessor : dialectPreProcessors) {
                    if (preProcessor == null) {
                        throw new ConfigurationException("Pre-Processor list for dialect " + dialect.getClass().getName() + " includes a " + "null entry, which is forbidden.");
                    }
                    // Obtain and check template mode
                    final TemplateMode templateMode = preProcessor.getTemplateMode();
                    if (templateMode == null) {
                        throw new ConfigurationException("Template mode cannot be null (pre-processor: " + preProcessor.getClass().getName() + ", dialect" + dialect.getClass().getName() + ")");
                    }
                    // Check the handler class: should extend ITemplateHandler and have an empty constructor
                    final Class<?> handlerClass = preProcessor.getHandlerClass();
                    if (handlerClass == null) {
                        throw new ConfigurationException("Pre-Processor " + preProcessor.getClass().getName() + " for dialect " + preProcessor.getClass().getName() + " returns a null handler class, which is forbidden.");
                    }
                    if (!ITemplateHandler.class.isAssignableFrom(handlerClass)) {
                        throw new ConfigurationException("Handler class " + handlerClass.getName() + " specified for " + "pre-processor " + preProcessor.getClass().getName() + " in dialect " + dialect.getClass().getName() + " does not implement required " + "interface " + ITemplateHandler.class.getName());
                    }
                    try {
                        // Check the empty constructor is present -- we will need to use it for creating new instances
                        handlerClass.getConstructor(new Class[0]);
                    } catch (final NoSuchMethodException e) {
                        throw new ConfigurationException("Pre-Processor class " + handlerClass.getName() + " specified for " + "pre-processor " + preProcessor.getClass().getName() + " in dialect " + dialect.getClass().getName() + " does not implement required " + "zero-argument constructor.", e);
                    }
                    // Add the pre-processor to its corresponding map and sort
                    List<IPreProcessor> preProcessorsForTemplateMode = preProcessorListsByTemplateMode.get(templateMode);
                    if (preProcessorsForTemplateMode == null) {
                        preProcessorsForTemplateMode = new ArrayList<IPreProcessor>(5);
                        preProcessorListsByTemplateMode.put(templateMode, preProcessorsForTemplateMode);
                    }
                    preProcessorsForTemplateMode.add(preProcessor);
                    Collections.sort(preProcessorsForTemplateMode, ProcessorComparators.PRE_PROCESSOR_COMPARATOR);
                }
            }
        }
        /*
             * STEP FIVE for each dialect: aggregate post-processors (and check the correctness of the list)
             */
        if (dialect instanceof IPostProcessorDialect) {
            final Set<IPostProcessor> dialectPostProcessors = ((IPostProcessorDialect) dialect).getPostProcessors();
            if (dialectPostProcessors != null) {
                for (final IPostProcessor postProcessor : dialectPostProcessors) {
                    if (postProcessor == null) {
                        throw new ConfigurationException("Post-Processor list for dialect " + dialect.getClass().getName() + " includes a " + "null entry, which is forbidden.");
                    }
                    // Obtain and check template mode
                    final TemplateMode templateMode = postProcessor.getTemplateMode();
                    if (templateMode == null) {
                        throw new ConfigurationException("Template mode cannot be null (post-processor: " + postProcessor.getClass().getName() + ", dialect" + dialect.getClass().getName() + ")");
                    }
                    // Check the handler class: should extend ITemplateHandler and have an empty constructor
                    final Class<?> handlerClass = postProcessor.getHandlerClass();
                    if (handlerClass == null) {
                        throw new ConfigurationException("Post-Processor " + postProcessor.getClass().getName() + " for dialect " + postProcessor.getClass().getName() + " returns a null handler class, which is forbidden.");
                    }
                    if (!ITemplateHandler.class.isAssignableFrom(handlerClass)) {
                        throw new ConfigurationException("Handler class " + handlerClass.getName() + " specified for " + "post-processor " + postProcessor.getClass().getName() + " in dialect " + dialect.getClass().getName() + " does not implement required " + "interface " + ITemplateHandler.class.getName());
                    }
                    try {
                        // Check the empty constructor is present -- we will need to use it for creating new instances
                        handlerClass.getConstructor(new Class[0]);
                    } catch (final NoSuchMethodException e) {
                        throw new ConfigurationException("Post-Processor class " + handlerClass.getName() + " specified for " + "post-processor " + postProcessor.getClass().getName() + " in dialect " + dialect.getClass().getName() + " does not implement required " + "zero-argument constructor.", e);
                    }
                    // Add the pre-processor to its corresponding map and sort
                    List<IPostProcessor> postProcessorsForTemplateMode = postProcessorListsByTemplateMode.get(templateMode);
                    if (postProcessorsForTemplateMode == null) {
                        postProcessorsForTemplateMode = new ArrayList<IPostProcessor>(5);
                        postProcessorListsByTemplateMode.put(templateMode, postProcessorsForTemplateMode);
                    }
                    postProcessorsForTemplateMode.add(postProcessor);
                    Collections.sort(postProcessorsForTemplateMode, ProcessorComparators.POST_PROCESSOR_COMPARATOR);
                }
            }
        }
        /*
             * LAST STEP for each dialect: add it to the dialects set
             */
        dialects.add(dialect);
    }
    // Time to turn the list-based structures into sets -- we needed the lists because we needed a way to order them using Collections.sort()
    final EnumMap<TemplateMode, Set<ITemplateBoundariesProcessor>> templateBoundariesProcessorsByTemplateMode = listMapToSetMap(templateBoundariesProcessorListsByTemplateMode);
    final EnumMap<TemplateMode, Set<ICDATASectionProcessor>> cdataSectionProcessorsByTemplateMode = listMapToSetMap(cdataSectionProcessorListsByTemplateMode);
    final EnumMap<TemplateMode, Set<ICommentProcessor>> commentProcessorsByTemplateMode = listMapToSetMap(commentProcessorListsByTemplateMode);
    final EnumMap<TemplateMode, Set<IDocTypeProcessor>> docTypeProcessorsByTemplateMode = listMapToSetMap(docTypeProcessorListsByTemplateMode);
    final EnumMap<TemplateMode, Set<IElementProcessor>> elementProcessorsByTemplateMode = listMapToSetMap(elementProcessorListsByTemplateMode);
    final EnumMap<TemplateMode, Set<IProcessingInstructionProcessor>> processingInstructionProcessorsByTemplateMode = listMapToSetMap(processingInstructionProcessorListsByTemplateMode);
    final EnumMap<TemplateMode, Set<ITextProcessor>> textProcessorsByTemplateMode = listMapToSetMap(textProcessorListsByTemplateMode);
    final EnumMap<TemplateMode, Set<IXMLDeclarationProcessor>> xmlDeclarationProcessorsByTemplateMode = listMapToSetMap(xmlDeclarationProcessorListsByTemplateMode);
    final EnumMap<TemplateMode, Set<IPreProcessor>> preProcessorsByTemplateMode = listMapToSetMap(preProcessorListsByTemplateMode);
    final EnumMap<TemplateMode, Set<IPostProcessor>> postProcessorsByTemplateMode = listMapToSetMap(postProcessorListsByTemplateMode);
    // Initialize the ElementDefinitions and AttributeDefinitions structures -- they need the element processors so that these
    // are directly applied to the element/attribute definitions and therefore per element/attribute matching is not required
    // during template processing.
    final ElementDefinitions elementDefinitions = new ElementDefinitions(elementProcessorsByTemplateMode);
    final AttributeDefinitions attributeDefinitions = new AttributeDefinitions(elementProcessorsByTemplateMode);
    // Traverse the sets of processors in order to set the AttributeDefinitions and/or ElementDefinitions objects
    // to those that need them in order to initialize and cache attribute/element definition-related structures
    initializeDefinitionsForProcessors(templateBoundariesProcessorsByTemplateMode, elementDefinitions, attributeDefinitions);
    initializeDefinitionsForProcessors(cdataSectionProcessorsByTemplateMode, elementDefinitions, attributeDefinitions);
    initializeDefinitionsForProcessors(commentProcessorsByTemplateMode, elementDefinitions, attributeDefinitions);
    initializeDefinitionsForProcessors(docTypeProcessorsByTemplateMode, elementDefinitions, attributeDefinitions);
    initializeDefinitionsForProcessors(elementProcessorsByTemplateMode, elementDefinitions, attributeDefinitions);
    initializeDefinitionsForProcessors(processingInstructionProcessorsByTemplateMode, elementDefinitions, attributeDefinitions);
    initializeDefinitionsForProcessors(textProcessorsByTemplateMode, elementDefinitions, attributeDefinitions);
    initializeDefinitionsForProcessors(xmlDeclarationProcessorsByTemplateMode, elementDefinitions, attributeDefinitions);
    initializeDefinitionsForPreProcessors(preProcessorsByTemplateMode, elementDefinitions, attributeDefinitions);
    initializeDefinitionsForPostProcessors(postProcessorsByTemplateMode, elementDefinitions, attributeDefinitions);
    return new DialectSetConfiguration(new LinkedHashSet<DialectConfiguration>(dialectConfigurations), dialects, standardDialectPresent, standardDialectPrefix, executionAttributes, aggregateExpressionObjectFactory, elementDefinitions, attributeDefinitions, templateBoundariesProcessorsByTemplateMode, cdataSectionProcessorsByTemplateMode, commentProcessorsByTemplateMode, docTypeProcessorsByTemplateMode, elementProcessorsByTemplateMode, processingInstructionProcessorsByTemplateMode, textProcessorsByTemplateMode, xmlDeclarationProcessorsByTemplateMode, preProcessorsByTemplateMode, postProcessorsByTemplateMode);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) IExecutionAttributeDialect(org.thymeleaf.dialect.IExecutionAttributeDialect) IExpressionObjectFactory(org.thymeleaf.expression.IExpressionObjectFactory) ITemplateBoundariesProcessor(org.thymeleaf.processor.templateboundaries.ITemplateBoundariesProcessor) ArrayList(java.util.ArrayList) IDialect(org.thymeleaf.dialect.IDialect) IPostProcessorDialect(org.thymeleaf.dialect.IPostProcessorDialect) LinkedHashMap(java.util.LinkedHashMap) ICommentProcessor(org.thymeleaf.processor.comment.ICommentProcessor) ConfigurationException(org.thymeleaf.exceptions.ConfigurationException) ArrayList(java.util.ArrayList) List(java.util.List) EnumMap(java.util.EnumMap) StandardDialect(org.thymeleaf.standard.StandardDialect) ITemplateHandler(org.thymeleaf.engine.ITemplateHandler) IProcessorDialect(org.thymeleaf.dialect.IProcessorDialect) IElementProcessor(org.thymeleaf.processor.element.IElementProcessor) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) EnumMap(java.util.EnumMap) ICDATASectionProcessor(org.thymeleaf.processor.cdatasection.ICDATASectionProcessor) TemplateMode(org.thymeleaf.templatemode.TemplateMode) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) ElementDefinitions(org.thymeleaf.engine.ElementDefinitions) IDocTypeProcessor(org.thymeleaf.processor.doctype.IDocTypeProcessor) IPreProcessorDialect(org.thymeleaf.dialect.IPreProcessorDialect) AttributeDefinitions(org.thymeleaf.engine.AttributeDefinitions) ITextProcessor(org.thymeleaf.processor.text.ITextProcessor) IPostProcessor(org.thymeleaf.postprocessor.IPostProcessor) IProcessingInstructionProcessor(org.thymeleaf.processor.processinginstruction.IProcessingInstructionProcessor) IProcessor(org.thymeleaf.processor.IProcessor) IExpressionObjectDialect(org.thymeleaf.dialect.IExpressionObjectDialect) IXMLDeclarationProcessor(org.thymeleaf.processor.xmldeclaration.IXMLDeclarationProcessor) IPreProcessor(org.thymeleaf.preprocessor.IPreProcessor)

Example 3 with AttributeDefinitions

use of org.thymeleaf.engine.AttributeDefinitions in project thymeleaf-tests by thymeleaf.

the class DialectSetConfigurationTest method testProcessorComputation02.

@Test
public void testProcessorComputation02() {
    final IProcessorDialect dialect = ProcessorAggregationTestDialect.buildHTMLDialect("standard", "TH", "E-20-null-src, E-10-null-src,E-20-null-href,E-20-null-text,E-10-null-text,E-10-*div-text,E-15-*div-src,E-1-form-*action,E-20-form-null,E-10-null-*action,E-50-null-null");
    final DialectConfiguration dialectConfiguration = new DialectConfiguration(dialect);
    final DialectSetConfiguration dialectSetConfiguration = DialectSetConfiguration.build(Collections.singleton(dialectConfiguration));
    final AttributeDefinitions attributeDefinitions = dialectSetConfiguration.getAttributeDefinitions();
    final ElementDefinitions elementDefinitions = dialectSetConfiguration.getElementDefinitions();
    Assert.assertEquals("TH", dialect.getPrefix());
    Assert.assertEquals("[E-10-null-{th:src,data-th-src}, E-15-{div}-{th:src,data-th-src}, E-20-null-{th:src,data-th-src}]", attributeDefinitions.forHTMLName("th:src").getAssociatedProcessors().toString());
    Assert.assertEquals("[E-1-{th:form,th-form}-{action}, E-10-null-{action}]", attributeDefinitions.forHTMLName("action").getAssociatedProcessors().toString());
    Assert.assertEquals("[E-20-{th:form,th-form}-null, E-50-null-null]", elementDefinitions.forHTMLName("th", "form").getAssociatedProcessors().toString());
    Assert.assertEquals("[]", attributeDefinitions.forHTMLName("th", "utext").getAssociatedProcessors().toString());
    Assert.assertEquals("[E-50-null-null]", elementDefinitions.forHTMLName("p").getAssociatedProcessors().toString());
}
Also used : DialectSetConfiguration(org.thymeleaf.DialectSetConfiguration) AttributeDefinitions(org.thymeleaf.engine.AttributeDefinitions) ElementDefinitions(org.thymeleaf.engine.ElementDefinitions) DialectConfiguration(org.thymeleaf.DialectConfiguration) IProcessorDialect(org.thymeleaf.dialect.IProcessorDialect) Test(org.junit.Test)

Example 4 with AttributeDefinitions

use of org.thymeleaf.engine.AttributeDefinitions in project thymeleaf-tests by thymeleaf.

the class DialectSetConfigurationTest method testProcessorComputation04.

@Test
public void testProcessorComputation04() {
    final IProcessorDialect dialect = ProcessorAggregationTestDialect.buildDialect("standard", "TH", "N-ELEMENT-20-null-src, N-ELEMENT-10-null-src,N-ELEMENT-20-null-href,N-ELEMENT-20-null-text,N-ELEMENT-10-null-text,N-ELEMENT-10-*div-text,N-ELEMENT-15-*div-src,N-ELEMENT-1-form-*action,N-ELEMENT-20-form-null,N-ELEMENT-10-null-*action,N-ELEMENT-50-null-null", "N-ELEMENT-200-null-src, N-ELEMENT-100-null-src,N-ELEMENT-200-null-href,N-ELEMENT-200-null-text,N-ELEMENT-100-null-text,N-ELEMENT-100-*div-text,N-ELEMENT-150-*div-src,N-ELEMENT-10-form-*action,N-ELEMENT-200-form-null,N-ELEMENT-100-null-*action,N-ELEMENT-500-null-null");
    final DialectConfiguration dialectConfiguration = new DialectConfiguration(dialect);
    final DialectSetConfiguration dialectSetConfiguration = DialectSetConfiguration.build(Collections.singleton(dialectConfiguration));
    final AttributeDefinitions attributeDefinitions = dialectSetConfiguration.getAttributeDefinitions();
    final ElementDefinitions elementDefinitions = dialectSetConfiguration.getElementDefinitions();
    Assert.assertEquals("TH", dialect.getPrefix());
    Assert.assertEquals("[N-ELEMENT-10-null-{th:src,data-th-src}, N-ELEMENT-15-{div}-{th:src,data-th-src}, N-ELEMENT-20-null-{th:src,data-th-src}]", attributeDefinitions.forHTMLName("th:src").getAssociatedProcessors().toString());
    Assert.assertEquals("[N-ELEMENT-1-{th:form,th-form}-{action}, N-ELEMENT-10-null-{action}]", attributeDefinitions.forHTMLName("action").getAssociatedProcessors().toString());
    Assert.assertEquals("[N-ELEMENT-20-{th:form,th-form}-null, N-ELEMENT-50-null-null]", elementDefinitions.forHTMLName("th", "form").getAssociatedProcessors().toString());
    Assert.assertEquals("[]", attributeDefinitions.forHTMLName("th", "utext").getAssociatedProcessors().toString());
    Assert.assertEquals("[N-ELEMENT-50-null-null]", elementDefinitions.forHTMLName("p").getAssociatedProcessors().toString());
    Assert.assertEquals("[]", attributeDefinitions.forXMLName("th:src").getAssociatedProcessors().toString());
    Assert.assertEquals("[N-ELEMENT-100-null-{TH:src}, N-ELEMENT-150-{div}-{TH:src}, N-ELEMENT-200-null-{TH:src}]", attributeDefinitions.forXMLName("TH:src").getAssociatedProcessors().toString());
    Assert.assertEquals("[N-ELEMENT-10-{TH:form}-{action}, N-ELEMENT-100-null-{action}]", attributeDefinitions.forXMLName("action").getAssociatedProcessors().toString());
    Assert.assertEquals("[N-ELEMENT-200-{TH:form}-null, N-ELEMENT-500-null-null]", elementDefinitions.forXMLName("TH", "form").getAssociatedProcessors().toString());
    Assert.assertEquals("[]", attributeDefinitions.forXMLName("th", "utext").getAssociatedProcessors().toString());
    Assert.assertEquals("[]", attributeDefinitions.forXMLName("TH", "utext").getAssociatedProcessors().toString());
    Assert.assertEquals("[N-ELEMENT-500-null-null]", elementDefinitions.forXMLName("p").getAssociatedProcessors().toString());
}
Also used : DialectSetConfiguration(org.thymeleaf.DialectSetConfiguration) AttributeDefinitions(org.thymeleaf.engine.AttributeDefinitions) ElementDefinitions(org.thymeleaf.engine.ElementDefinitions) DialectConfiguration(org.thymeleaf.DialectConfiguration) IProcessorDialect(org.thymeleaf.dialect.IProcessorDialect) Test(org.junit.Test)

Example 5 with AttributeDefinitions

use of org.thymeleaf.engine.AttributeDefinitions in project thymeleaf-tests by thymeleaf.

the class DialectSetConfigurationTest method testProcessorComputation05.

@Test
public void testProcessorComputation05() {
    final IProcessorDialect dialect = ProcessorAggregationTestDialect.buildDialect("standard", "TH", "N-ELEMENT-20-null-src, N-CDATA_SECTION-10-some,N-DOC_TYPE-20-other,E-20-null-text,E-10-null-text,N-TEXT-10-whoa!,E-15-*div-src,E-1-form-*action,N-ELEMENT-20-form-null,E-10-null-*action,E-50-null-null,N-CDATA_SECTION-5-someother,T-25-uye,T-10-eo", "N-TEXT-20-whoaX!,T-10-eoX");
    final DialectConfiguration dialectConfiguration = new DialectConfiguration(dialect);
    final DialectSetConfiguration dialectSetConfiguration = DialectSetConfiguration.build(Collections.singleton(dialectConfiguration));
    final AttributeDefinitions attributeDefinitions = dialectSetConfiguration.getAttributeDefinitions();
    final ElementDefinitions elementDefinitions = dialectSetConfiguration.getElementDefinitions();
    Assert.assertEquals("TH", dialect.getPrefix());
    Assert.assertEquals("[E-15-{div}-{th:src,data-th-src}, N-ELEMENT-20-null-{th:src,data-th-src}]", attributeDefinitions.forHTMLName("th:src").getAssociatedProcessors().toString());
    Assert.assertEquals("[E-1-{th:form,th-form}-{action}, E-10-null-{action}]", attributeDefinitions.forHTMLName("action").getAssociatedProcessors().toString());
    Assert.assertEquals("[N-ELEMENT-20-{th:form,th-form}-null, E-50-null-null]", elementDefinitions.forHTMLName("th", "form").getAssociatedProcessors().toString());
    Assert.assertEquals("[]", attributeDefinitions.forHTMLName("th", "utext").getAssociatedProcessors().toString());
    Assert.assertEquals("[E-50-null-null]", elementDefinitions.forHTMLName("p").getAssociatedProcessors().toString());
    Assert.assertEquals("[N-CDATA_SECTION-5-someother, N-CDATA_SECTION-10-some]", dialectSetConfiguration.getCDATASectionProcessors(TemplateMode.HTML).toString());
    Assert.assertEquals("[N-TEXT-10-whoa!, T-10-eo, T-25-uye]", dialectSetConfiguration.getTextProcessors(TemplateMode.HTML).toString());
    Assert.assertEquals("[T-10-eoX, N-TEXT-20-whoaX!]", dialectSetConfiguration.getTextProcessors(TemplateMode.XML).toString());
    Assert.assertEquals("[N-DOC_TYPE-20-other]", dialectSetConfiguration.getDocTypeProcessors(TemplateMode.HTML).toString());
    Assert.assertEquals("[]", dialectSetConfiguration.getCommentProcessors(TemplateMode.HTML).toString());
    Assert.assertEquals("[]", dialectSetConfiguration.getProcessingInstructionProcessors(TemplateMode.HTML).toString());
    Assert.assertEquals("[]", dialectSetConfiguration.getXMLDeclarationProcessors(TemplateMode.HTML).toString());
    Assert.assertEquals("[]", dialectSetConfiguration.getCDATASectionProcessors(TemplateMode.XML).toString());
    Assert.assertEquals("[]", dialectSetConfiguration.getCommentProcessors(TemplateMode.XML).toString());
    Assert.assertEquals("[]", dialectSetConfiguration.getDocTypeProcessors(TemplateMode.XML).toString());
    Assert.assertEquals("[]", dialectSetConfiguration.getProcessingInstructionProcessors(TemplateMode.XML).toString());
    Assert.assertEquals("[]", dialectSetConfiguration.getXMLDeclarationProcessors(TemplateMode.XML).toString());
}
Also used : DialectSetConfiguration(org.thymeleaf.DialectSetConfiguration) AttributeDefinitions(org.thymeleaf.engine.AttributeDefinitions) ElementDefinitions(org.thymeleaf.engine.ElementDefinitions) DialectConfiguration(org.thymeleaf.DialectConfiguration) IProcessorDialect(org.thymeleaf.dialect.IProcessorDialect) Test(org.junit.Test)

Aggregations

IProcessorDialect (org.thymeleaf.dialect.IProcessorDialect)5 AttributeDefinitions (org.thymeleaf.engine.AttributeDefinitions)5 ElementDefinitions (org.thymeleaf.engine.ElementDefinitions)5 Test (org.junit.Test)4 DialectConfiguration (org.thymeleaf.DialectConfiguration)4 DialectSetConfiguration (org.thymeleaf.DialectSetConfiguration)4 ArrayList (java.util.ArrayList)1 EnumMap (java.util.EnumMap)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 IDialect (org.thymeleaf.dialect.IDialect)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 ITemplateHandler (org.thymeleaf.engine.ITemplateHandler)1 ConfigurationException (org.thymeleaf.exceptions.ConfigurationException)1