use of org.thymeleaf.Configuration in project thymeleaf-tests by thymeleaf.
the class SpringResourceResourceResolverSpring4Test method testGetResourceAsStream.
@Test
public void testGetResourceAsStream() throws Exception {
final String templateLocation = "spring421/view/test.html";
final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring421/view/applicationContext.xml");
final SpringResourceResourceResolver resolver = (SpringResourceResourceResolver) context.getBean("springResourceResourceResolver");
final TemplateProcessingParameters parameters = new TemplateProcessingParameters(new Configuration(), "test", new Context());
final InputStream is = resolver.getResourceAsStream(parameters, "classpath:" + templateLocation);
final String testResource = ResourceUtils.normalize(ResourceUtils.read(is, "US-ASCII"));
final String expected = ResourceUtils.read(ClassLoaderUtils.getClassLoader(SpringResourceResourceResolverSpring4Test.class).getResourceAsStream(templateLocation), "US-ASCII", true);
Assert.assertEquals(expected, testResource);
}
use of org.thymeleaf.Configuration in project thymeleaf-tests by thymeleaf.
the class ExpressionBenchmark method main.
public static void main(String[] args) throws Exception {
final Map<String, String> expressionsMap = ExpressionBenchmarkDefinitions.createExpressionsMap();
final Configuration configuration = new Configuration();
final IProcessingContext processingContext = new ProcessingContext(new Context());
final IStandardExpressionParser parser = new StandardExpressionParser();
for (final Map.Entry<String, String> expressionEntry : expressionsMap.entrySet()) {
final String expression = expressionEntry.getKey();
final String expectedParsingResult = expressionEntry.getValue();
final IStandardExpression parsedExpression = parser.parseExpression(configuration, processingContext, expression);
Assert.assertNotNull(parsedExpression);
final String exp = parsedExpression.getStringRepresentation();
Assert.assertEquals(expectedParsingResult, exp);
}
final StopWatch sw = new StopWatch();
sw.start();
for (int x = 0; x < 1000; x++) for (final String expression : expressionsMap.keySet()) parser.parseExpression(configuration, processingContext, expression);
sw.stop();
System.out.println("First pass: " + sw.toString());
sw.reset();
sw.start();
for (int x = 0; x < 1000; x++) for (final String expression : expressionsMap.keySet()) parser.parseExpression(configuration, processingContext, expression);
sw.stop();
System.out.println("Second pass: " + sw.toString());
}
use of org.thymeleaf.Configuration in project thymeleaf-tests by thymeleaf.
the class AddLocalVariableToResult method processAttribute.
@Override
protected ProcessorResult processAttribute(final Arguments arguments, final Element element, final String attributeName) {
final String attributeValue = element.getAttributeValue(attributeName);
final Configuration configuration = arguments.getConfiguration();
final AssignationSequence assignationSequence = AssignationUtils.parseAssignationSequence(configuration, arguments, attributeValue, false);
final Map<String, Object> localVariables = new HashMap<String, Object>();
for (final Assignation assignation : assignationSequence.getAssignations()) {
final IStandardExpression varNameExpr = assignation.getLeft();
final IStandardExpression varValueExpr = assignation.getRight();
final Object varName = varNameExpr.execute(configuration, arguments);
final Object varValue = varValueExpr.execute(configuration, arguments);
localVariables.put((varName == null ? null : varName.toString()), varValue);
}
element.removeAttribute(attributeName);
return ProcessorResult.setLocalVariables(localVariables);
}
use of org.thymeleaf.Configuration in project thymeleaf-tests by thymeleaf.
the class AddLocalVariableToNode method processAttribute.
@Override
protected ProcessorResult processAttribute(final Arguments arguments, final Element element, final String attributeName) {
final String attributeValue = element.getAttributeValue(attributeName);
final Configuration configuration = arguments.getConfiguration();
final IStandardExpressionParser expressionParser = StandardExpressions.getExpressionParser(configuration);
final AssignationSequence assignationSequence = AssignationUtils.parseAssignationSequence(configuration, arguments, attributeValue, false);
for (final Assignation assignation : assignationSequence.getAssignations()) {
final IStandardExpression varNameExpr = assignation.getLeft();
final IStandardExpression varValueExpr = assignation.getRight();
final Object varName = varNameExpr.execute(configuration, arguments);
final Object varValue = varValueExpr.execute(configuration, arguments);
element.setNodeLocalVariable((varName == null ? null : varName.toString()), varValue);
}
element.removeAttribute(attributeName);
return ProcessorResult.OK;
}
use of org.thymeleaf.Configuration in project thymeleaf-tests by thymeleaf.
the class SpringResourceTemplateResolverSpring3Test method testResolveTemplate.
@Test
public void testResolveTemplate() throws Exception {
final String templateLocation = "spring321/view/test.html";
final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring321/view/applicationContext.xml");
final SpringResourceTemplateResolver resolver = (SpringResourceTemplateResolver) context.getBean("springResourceTemplateResolver");
resolver.initialize();
final String templateMode = resolver.getTemplateMode();
Assert.assertEquals("HTML5", templateMode);
final TemplateProcessingParameters parameters = new TemplateProcessingParameters(new Configuration(), "classpath:" + templateLocation, new Context());
final TemplateResolution resolution = resolver.resolveTemplate(parameters);
final IResourceResolver resourceResolver = resolution.getResourceResolver();
final InputStream is = resourceResolver.getResourceAsStream(parameters, resolution.getResourceName());
final String testResource = ResourceUtils.normalize(ResourceUtils.read(is, "US-ASCII"));
final String expected = ResourceUtils.read(ClassLoaderUtils.getClassLoader(SpringResourceTemplateResolverSpring3Test.class).getResourceAsStream(templateLocation), "US-ASCII", true);
Assert.assertEquals(expected, testResource);
}
Aggregations