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 SpringResourceResourceResolverSpring3Test method testGetResourceAsStream.
@Test
public void testGetResourceAsStream() throws Exception {
final String templateLocation = "spring321/view/test.html";
final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring321/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(SpringResourceResourceResolverSpring3Test.class).getResourceAsStream(templateLocation), "US-ASCII", true);
Assert.assertEquals(expected, testResource);
}
use of org.thymeleaf.Configuration in project thymeleaf-tests by thymeleaf.
the class TemplateParserTest method initialize.
// -----
@Before
public void initialize() {
this.templateResolver = new StringTemplateResolver("!!!");
this.configuration = new Configuration();
this.configuration.setDialect(new TestDialect());
this.configuration.setTemplateResolver(this.templateResolver);
this.configuration.setMessageResolver(new StandardMessageResolver());
this.configuration.setTemplateModeHandlers(StandardTemplateModeHandlers.ALL_TEMPLATE_MODE_HANDLERS);
this.configuration.initialize();
this.xmlDomDocumentParser = new XhtmlAndHtml5NonValidatingDOMTemplateParser(2);
this.xmlSaxDocumentParser = new XhtmlAndHtml5NonValidatingSAXTemplateParser(2);
}
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 SpringResourceTemplateResolverSpring4Test method testResolveTemplate.
@Test
public void testResolveTemplate() throws Exception {
final String templateLocation = "spring421/view/test.html";
final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring421/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(SpringResourceTemplateResolverSpring4Test.class).getResourceAsStream(templateLocation), "US-ASCII", true);
Assert.assertEquals(expected, testResource);
}
Aggregations