use of org.thymeleaf.processor.IProcessor in project thymeleaf-tests by thymeleaf.
the class ProcessorAggregationTestDialect method buildProcessors.
private static Set<IProcessor> buildProcessors(final IProcessorDialect dialect, final TemplateMode templateMode, final String dialectPrefix, final String specification) {
final Set<IProcessor> processors = new LinkedHashSet<IProcessor>();
final StringTokenizer specTok = new StringTokenizer(specification, ", ");
while (specTok.hasMoreTokens()) {
final String procSpec = specTok.nextToken();
final StringTokenizer procSpecTok = new StringTokenizer(procSpec, "-");
final String type = procSpecTok.nextToken();
if (type.equals("CD")) {
final int precedence = Integer.valueOf(procSpecTok.nextToken());
processors.add(new CDATASectionProcessorAggregationTestProcessor(procSpecTok.nextToken(), templateMode, precedence));
} else if (type.equals("C")) {
final int precedence = Integer.valueOf(procSpecTok.nextToken());
processors.add(new CommentProcessorAggregationTestProcessor(procSpecTok.nextToken(), templateMode, precedence));
} else if (type.equals("DT")) {
final int precedence = Integer.valueOf(procSpecTok.nextToken());
processors.add(new DocTypeProcessorAggregationTestProcessor(procSpecTok.nextToken(), templateMode, precedence));
} else if (type.equals("PI")) {
final int precedence = Integer.valueOf(procSpecTok.nextToken());
processors.add(new ProcessingInstructionProcessorAggregationTestProcessor(procSpecTok.nextToken(), templateMode, precedence));
} else if (type.equals("T")) {
final int precedence = Integer.valueOf(procSpecTok.nextToken());
processors.add(new TextProcessorAggregationTestProcessor(procSpecTok.nextToken(), templateMode, precedence));
} else if (type.equals("XD")) {
final int precedence = Integer.valueOf(procSpecTok.nextToken());
processors.add(new XMLDeclarationProcessorAggregationTestProcessor(procSpecTok.nextToken(), templateMode, precedence));
} else if (type.equals("E")) {
final int precedence = Integer.valueOf(procSpecTok.nextToken());
String elementName = procSpecTok.nextToken();
boolean prefixElementName = true;
if (elementName.startsWith("*")) {
prefixElementName = false;
elementName = elementName.substring(1);
}
String attributeName = procSpecTok.nextToken();
boolean prefixAttributeName = true;
if (attributeName.startsWith("*")) {
prefixAttributeName = false;
attributeName = attributeName.substring(1);
}
processors.add(new ElementProcessorAggregationTestTagProcessor(dialectPrefix, (elementName.equals("null") ? null : elementName), prefixElementName, (attributeName.equals("null") ? null : attributeName), prefixAttributeName, templateMode, precedence));
} else if (type.equals("N")) {
// This will just be "ELEMENT"
procSpecTok.nextToken();
final int precedence = Integer.valueOf(procSpecTok.nextToken());
String elementName = procSpecTok.nextToken();
boolean prefixElementName = true;
if (elementName.startsWith("*")) {
prefixElementName = false;
elementName = elementName.substring(1);
}
String attributeName = procSpecTok.nextToken();
boolean prefixAttributeName = true;
if (attributeName.startsWith("*")) {
prefixAttributeName = false;
attributeName = attributeName.substring(1);
}
processors.add(new ElementModelProcessorAggregationTestProcessor(dialectPrefix, (elementName.equals("null") ? null : elementName), prefixElementName, (attributeName.equals("null") ? null : attributeName), prefixAttributeName, templateMode, precedence));
} else {
throw new IllegalArgumentException("Unrecognized: " + type);
}
}
return processors;
}
use of org.thymeleaf.processor.IProcessor in project thymeleaf-tests by thymeleaf.
the class DialectOrderingTest method testDialectOrder.
@Test
public void testDialectOrder() throws Exception {
final Dialect01 dialect01 = new Dialect01();
final Dialect02 dialect02 = new Dialect02();
final Dialect03 dialect03 = new Dialect03();
final Dialect04 dialect04 = new Dialect04();
final Set<IElementProcessor> dialect01Processors = combineDialects(dialect01);
final Set<IElementProcessor> dialect02Processors = combineDialects(dialect02);
final Set<IElementProcessor> dialect03Processors = combineDialects(dialect03);
final Set<IElementProcessor> dialect04Processors = combineDialects(dialect04);
List<IProcessor> d01ProcList = new ArrayList<IProcessor>(dialect01Processors);
List<IProcessor> d02ProcList = new ArrayList<IProcessor>(dialect02Processors);
List<IProcessor> d03ProcList = new ArrayList<IProcessor>(dialect03Processors);
List<IProcessor> d04ProcList = new ArrayList<IProcessor>(dialect04Processors);
Assert.assertEquals(2, d01ProcList.size());
Assert.assertEquals(2, d02ProcList.size());
Assert.assertEquals(2, d03ProcList.size());
Assert.assertEquals(3, d04ProcList.size());
// 110 - 1000
Assert.assertEquals(P1Processor.class.getSimpleName(), unwrappedClassName(d01ProcList.get(0)));
// 110 - 1100
Assert.assertEquals(Div1Processor.class.getSimpleName(), unwrappedClassName(d01ProcList.get(1)));
// 100 - 900
Assert.assertEquals(Div2Processor.class.getSimpleName(), unwrappedClassName(d02ProcList.get(0)));
// 100 - 1100
Assert.assertEquals(P2Processor.class.getSimpleName(), unwrappedClassName(d02ProcList.get(1)));
// 90 - 800
Assert.assertEquals(P3Processor.class.getSimpleName(), unwrappedClassName(d03ProcList.get(0)));
// 90 - 900
Assert.assertEquals(Span3Processor.class.getSimpleName(), unwrappedClassName(d03ProcList.get(1)));
// 100 - 700
Assert.assertEquals(Span4Processor.class.getSimpleName(), unwrappedClassName(d04ProcList.get(0)));
// 100 - 1000
Assert.assertEquals(Div4Processor.class.getSimpleName(), unwrappedClassName(d04ProcList.get(1)));
// 100 - 1200
Assert.assertEquals(P4Processor.class.getSimpleName(), unwrappedClassName(d04ProcList.get(2)));
List<IElementProcessor> d0102ProcList = new ArrayList<IElementProcessor>(combineDialects(dialect01, dialect02));
Assert.assertEquals(Div2Processor.class.getSimpleName(), unwrappedClassName(d0102ProcList.get(0)));
Assert.assertEquals(P2Processor.class.getSimpleName(), unwrappedClassName(d0102ProcList.get(1)));
Assert.assertEquals(P1Processor.class.getSimpleName(), unwrappedClassName(d0102ProcList.get(2)));
Assert.assertEquals(Div1Processor.class.getSimpleName(), unwrappedClassName(d0102ProcList.get(3)));
List<IElementProcessor> d0103ProcList = new ArrayList<IElementProcessor>(combineDialects(dialect01, dialect03));
Assert.assertEquals(P3Processor.class.getSimpleName(), unwrappedClassName(d0103ProcList.get(0)));
Assert.assertEquals(Span3Processor.class.getSimpleName(), unwrappedClassName(d0103ProcList.get(1)));
Assert.assertEquals(P1Processor.class.getSimpleName(), unwrappedClassName(d0103ProcList.get(2)));
Assert.assertEquals(Div1Processor.class.getSimpleName(), unwrappedClassName(d0103ProcList.get(3)));
List<IElementProcessor> d0203ProcList = new ArrayList<IElementProcessor>(combineDialects(dialect02, dialect03));
Assert.assertEquals(P3Processor.class.getSimpleName(), unwrappedClassName(d0203ProcList.get(0)));
Assert.assertEquals(Span3Processor.class.getSimpleName(), unwrappedClassName(d0203ProcList.get(1)));
Assert.assertEquals(Div2Processor.class.getSimpleName(), unwrappedClassName(d0203ProcList.get(2)));
Assert.assertEquals(P2Processor.class.getSimpleName(), unwrappedClassName(d0203ProcList.get(3)));
List<IElementProcessor> d010204ProcList = new ArrayList<IElementProcessor>(combineDialects(dialect01, dialect02, dialect04));
Assert.assertEquals(Span4Processor.class.getSimpleName(), unwrappedClassName(d010204ProcList.get(0)));
Assert.assertEquals(Div2Processor.class.getSimpleName(), unwrappedClassName(d010204ProcList.get(1)));
Assert.assertEquals(Div4Processor.class.getSimpleName(), unwrappedClassName(d010204ProcList.get(2)));
Assert.assertEquals(P2Processor.class.getSimpleName(), unwrappedClassName(d010204ProcList.get(3)));
Assert.assertEquals(P4Processor.class.getSimpleName(), unwrappedClassName(d010204ProcList.get(4)));
Assert.assertEquals(P1Processor.class.getSimpleName(), unwrappedClassName(d010204ProcList.get(5)));
Assert.assertEquals(Div1Processor.class.getSimpleName(), unwrappedClassName(d010204ProcList.get(6)));
List<IElementProcessor> d010402ProcList = new ArrayList<IElementProcessor>(combineDialects(dialect01, dialect04, dialect02));
Assert.assertEquals(Span4Processor.class.getSimpleName(), unwrappedClassName(d010402ProcList.get(0)));
Assert.assertEquals(Div2Processor.class.getSimpleName(), unwrappedClassName(d010402ProcList.get(1)));
Assert.assertEquals(Div4Processor.class.getSimpleName(), unwrappedClassName(d010402ProcList.get(2)));
Assert.assertEquals(P2Processor.class.getSimpleName(), unwrappedClassName(d010402ProcList.get(3)));
Assert.assertEquals(P4Processor.class.getSimpleName(), unwrappedClassName(d010402ProcList.get(4)));
Assert.assertEquals(P1Processor.class.getSimpleName(), unwrappedClassName(d010402ProcList.get(5)));
Assert.assertEquals(Div1Processor.class.getSimpleName(), unwrappedClassName(d010402ProcList.get(6)));
List<IElementProcessor> d030402ProcList = new ArrayList<IElementProcessor>(combineDialects(dialect03, dialect04, dialect02));
Assert.assertEquals(P3Processor.class.getSimpleName(), unwrappedClassName(d030402ProcList.get(0)));
Assert.assertEquals(Span3Processor.class.getSimpleName(), unwrappedClassName(d030402ProcList.get(1)));
Assert.assertEquals(Span4Processor.class.getSimpleName(), unwrappedClassName(d030402ProcList.get(2)));
Assert.assertEquals(Div2Processor.class.getSimpleName(), unwrappedClassName(d030402ProcList.get(3)));
Assert.assertEquals(Div4Processor.class.getSimpleName(), unwrappedClassName(d030402ProcList.get(4)));
Assert.assertEquals(P2Processor.class.getSimpleName(), unwrappedClassName(d030402ProcList.get(5)));
Assert.assertEquals(P4Processor.class.getSimpleName(), unwrappedClassName(d030402ProcList.get(6)));
List<IElementProcessor> d020403ProcList = new ArrayList<IElementProcessor>(combineDialects(dialect02, dialect04, dialect03));
Assert.assertEquals(P3Processor.class.getSimpleName(), unwrappedClassName(d020403ProcList.get(0)));
Assert.assertEquals(Span3Processor.class.getSimpleName(), unwrappedClassName(d020403ProcList.get(1)));
Assert.assertEquals(Span4Processor.class.getSimpleName(), unwrappedClassName(d020403ProcList.get(2)));
Assert.assertEquals(Div2Processor.class.getSimpleName(), unwrappedClassName(d020403ProcList.get(3)));
Assert.assertEquals(Div4Processor.class.getSimpleName(), unwrappedClassName(d020403ProcList.get(4)));
Assert.assertEquals(P2Processor.class.getSimpleName(), unwrappedClassName(d020403ProcList.get(5)));
Assert.assertEquals(P4Processor.class.getSimpleName(), unwrappedClassName(d020403ProcList.get(6)));
}
use of org.thymeleaf.processor.IProcessor in project thymeleaf-tests by thymeleaf.
the class ProcessorAggregationTestDialect method buildProcessors.
private static Set<IProcessor> buildProcessors(final TemplateMode templateMode, final String specification) {
final Set<IProcessor> processors = new LinkedHashSet<IProcessor>();
final StringTokenizer specTok = new StringTokenizer(specification, ", ");
while (specTok.hasMoreTokens()) {
final String procSpec = specTok.nextToken();
final StringTokenizer procSpecTok = new StringTokenizer(procSpec, "-");
final String type = procSpecTok.nextToken();
if (type.equals("CD")) {
final int precedence = Integer.valueOf(procSpecTok.nextToken());
processors.add(new CDATASectionProcessorAggregationTestProcessor(procSpecTok.nextToken(), templateMode, precedence));
} else if (type.equals("C")) {
final int precedence = Integer.valueOf(procSpecTok.nextToken());
processors.add(new CommentProcessorAggregationTestProcessor(procSpecTok.nextToken(), templateMode, precedence));
} else if (type.equals("DT")) {
final int precedence = Integer.valueOf(procSpecTok.nextToken());
processors.add(new DocTypeProcessorAggregationTestProcessor(procSpecTok.nextToken(), templateMode, precedence));
} else if (type.equals("PI")) {
final int precedence = Integer.valueOf(procSpecTok.nextToken());
processors.add(new ProcessingInstructionProcessorAggregationTestProcessor(procSpecTok.nextToken(), templateMode, precedence));
} else if (type.equals("T")) {
final int precedence = Integer.valueOf(procSpecTok.nextToken());
processors.add(new TextProcessorAggregationTestProcessor(procSpecTok.nextToken(), templateMode, precedence));
} else if (type.equals("XD")) {
final int precedence = Integer.valueOf(procSpecTok.nextToken());
processors.add(new XMLDeclarationProcessorAggregationTestProcessor(procSpecTok.nextToken(), templateMode, precedence));
} else if (type.equals("E")) {
final int precedence = Integer.valueOf(procSpecTok.nextToken());
String elementName = procSpecTok.nextToken();
boolean prefixElementName = true;
if (elementName.startsWith("*")) {
prefixElementName = false;
elementName = elementName.substring(1);
}
String attributeName = procSpecTok.nextToken();
boolean prefixAttributeName = true;
if (attributeName.startsWith("*")) {
prefixAttributeName = false;
attributeName = attributeName.substring(1);
}
processors.add(new ElementProcessorAggregationTestTagProcessor((elementName.equals("null") ? null : elementName), prefixElementName, (attributeName.equals("null") ? null : attributeName), prefixAttributeName, templateMode, precedence));
} else if (type.equals("N")) {
// This will just be "ELEMENT"
procSpecTok.nextToken();
final int precedence = Integer.valueOf(procSpecTok.nextToken());
String elementName = procSpecTok.nextToken();
boolean prefixElementName = true;
if (elementName.startsWith("*")) {
prefixElementName = false;
elementName = elementName.substring(1);
}
String attributeName = procSpecTok.nextToken();
boolean prefixAttributeName = true;
if (attributeName.startsWith("*")) {
prefixAttributeName = false;
attributeName = attributeName.substring(1);
}
processors.add(new ElementNodeProcessorAggregationTestProcessor((elementName.equals("null") ? null : elementName), prefixElementName, (attributeName.equals("null") ? null : attributeName), prefixAttributeName, templateMode, precedence));
} else {
throw new IllegalArgumentException("Unrecognized: " + type);
}
}
return processors;
}
use of org.thymeleaf.processor.IProcessor in project sling by apache.
the class SlingDialect method getProcessors.
@Override
public Set<IProcessor> getProcessors(final String prefix) {
final Set<IProcessor> processors = new HashSet<IProcessor>();
processors.add(new SlingIncludeAttributeTagProcessor(prefix));
return processors;
}
use of org.thymeleaf.processor.IProcessor in project thymeleaf by thymeleaf.
the class ConfigurationPrinterHelper method printProcessorsForTemplateMode.
private static void printProcessorsForTemplateMode(final ConfigLogBuilder logBuilder, final Set<IProcessor> processors, final TemplateMode templateMode) {
if (processors == null || processors.isEmpty()) {
return;
}
final List<ICDATASectionProcessor> cdataSectionProcessors = new ArrayList<ICDATASectionProcessor>();
final List<ICommentProcessor> commentProcessors = new ArrayList<ICommentProcessor>();
final List<IDocTypeProcessor> docTypeProcessors = new ArrayList<IDocTypeProcessor>();
final List<IElementTagProcessor> elementTagProcessors = new ArrayList<IElementTagProcessor>();
final List<IElementModelProcessor> elementModelProcessors = new ArrayList<IElementModelProcessor>();
final List<IProcessingInstructionProcessor> processingInstructionProcessors = new ArrayList<IProcessingInstructionProcessor>();
final List<ITextProcessor> textProcessors = new ArrayList<ITextProcessor>();
final List<IXMLDeclarationProcessor> xmlDeclarationProcessors = new ArrayList<IXMLDeclarationProcessor>();
boolean processorsForTemplateModeExist = false;
for (final IProcessor processor : processors) {
if (!templateMode.equals(processor.getTemplateMode())) {
continue;
}
processorsForTemplateModeExist = true;
if (processor instanceof ICDATASectionProcessor) {
cdataSectionProcessors.add((ICDATASectionProcessor) processor);
} else if (processor instanceof ICommentProcessor) {
commentProcessors.add((ICommentProcessor) processor);
} else if (processor instanceof IDocTypeProcessor) {
docTypeProcessors.add((IDocTypeProcessor) processor);
} else if (processor instanceof IElementTagProcessor) {
elementTagProcessors.add((IElementTagProcessor) processor);
} else if (processor instanceof IElementModelProcessor) {
elementModelProcessors.add((IElementModelProcessor) processor);
} else if (processor instanceof IProcessingInstructionProcessor) {
processingInstructionProcessors.add((IProcessingInstructionProcessor) processor);
} else if (processor instanceof ITextProcessor) {
textProcessors.add((ITextProcessor) processor);
} else if (processor instanceof IXMLDeclarationProcessor) {
xmlDeclarationProcessors.add((IXMLDeclarationProcessor) processor);
}
}
if (!processorsForTemplateModeExist) {
// Nothing to show, there are no processors for this template mode
return;
}
logBuilder.line("[THYMELEAF] * Processors for Template Mode: {}", templateMode);
Collections.sort(cdataSectionProcessors, ProcessorComparators.PROCESSOR_COMPARATOR);
Collections.sort(commentProcessors, ProcessorComparators.PROCESSOR_COMPARATOR);
Collections.sort(docTypeProcessors, ProcessorComparators.PROCESSOR_COMPARATOR);
Collections.sort(elementTagProcessors, ProcessorComparators.PROCESSOR_COMPARATOR);
Collections.sort(elementModelProcessors, ProcessorComparators.PROCESSOR_COMPARATOR);
Collections.sort(processingInstructionProcessors, ProcessorComparators.PROCESSOR_COMPARATOR);
Collections.sort(textProcessors, ProcessorComparators.PROCESSOR_COMPARATOR);
Collections.sort(xmlDeclarationProcessors, ProcessorComparators.PROCESSOR_COMPARATOR);
if (!elementTagProcessors.isEmpty()) {
logBuilder.line("[THYMELEAF] * Element Tag Processors by [matching element and attribute name] [precedence]:");
for (final IElementTagProcessor processor : elementTagProcessors) {
final MatchingElementName matchingElementName = processor.getMatchingElementName();
final MatchingAttributeName matchingAttributeName = processor.getMatchingAttributeName();
final String elementName = (matchingElementName == null ? "*" : matchingElementName.toString());
final String attributeName = (matchingAttributeName == null ? "*" : matchingAttributeName.toString());
logBuilder.line("[THYMELEAF] * [{} {}] [{}]: {}", new Object[] { elementName, attributeName, Integer.valueOf(processor.getPrecedence()), processor.getClass().getName() });
}
}
if (!elementModelProcessors.isEmpty()) {
logBuilder.line("[THYMELEAF] * Element Model Processors by [matching element and attribute name] [precedence]:");
for (final IElementModelProcessor processor : elementModelProcessors) {
final MatchingElementName matchingElementName = processor.getMatchingElementName();
final MatchingAttributeName matchingAttributeName = processor.getMatchingAttributeName();
final String elementName = (matchingElementName == null ? "*" : matchingElementName.toString());
final String attributeName = (matchingAttributeName == null ? "*" : matchingAttributeName.toString());
logBuilder.line("[THYMELEAF] * [{} {}] [{}]: {}", new Object[] { elementName, attributeName, Integer.valueOf(processor.getPrecedence()), processor.getClass().getName() });
}
}
if (!textProcessors.isEmpty()) {
logBuilder.line("[THYMELEAF] * Text Processors by [precedence]:");
for (final ITextProcessor processor : textProcessors) {
logBuilder.line("[THYMELEAF] * [{}]: {}", new Object[] { Integer.valueOf(processor.getPrecedence()), processor.getClass().getName() });
}
}
if (!docTypeProcessors.isEmpty()) {
logBuilder.line("[THYMELEAF] * DOCTYPE Processors by [precedence]:");
for (final IDocTypeProcessor processor : docTypeProcessors) {
logBuilder.line("[THYMELEAF] * [{}]: {}", new Object[] { Integer.valueOf(processor.getPrecedence()), processor.getClass().getName() });
}
}
if (!cdataSectionProcessors.isEmpty()) {
logBuilder.line("[THYMELEAF] * CDATA Section Processors by [precedence]:");
for (final ICDATASectionProcessor processor : cdataSectionProcessors) {
logBuilder.line("[THYMELEAF] * [{}]: {}", new Object[] { Integer.valueOf(processor.getPrecedence()), processor.getClass().getName() });
}
}
if (!commentProcessors.isEmpty()) {
logBuilder.line("[THYMELEAF] * Comment Processors by [precedence]:");
for (final ICommentProcessor processor : commentProcessors) {
logBuilder.line("[THYMELEAF] * [{}]: {}", new Object[] { Integer.valueOf(processor.getPrecedence()), processor.getClass().getName() });
}
}
if (!xmlDeclarationProcessors.isEmpty()) {
logBuilder.line("[THYMELEAF] * XML Declaration Processors by [precedence]:");
for (final IXMLDeclarationProcessor processor : xmlDeclarationProcessors) {
logBuilder.line("[THYMELEAF] * [{}]: {}", new Object[] { Integer.valueOf(processor.getPrecedence()), processor.getClass().getName() });
}
}
if (!processingInstructionProcessors.isEmpty()) {
logBuilder.line("[THYMELEAF] * Processing Instruction Processors by [precedence]:");
for (final IProcessingInstructionProcessor processor : processingInstructionProcessors) {
logBuilder.line("[THYMELEAF] * [{}]: {}", new Object[] { Integer.valueOf(processor.getPrecedence()), processor.getClass().getName() });
}
}
}
Aggregations