use of org.thymeleaf.templateresource.StringTemplateResource in project thymeleaf-tests by thymeleaf.
the class BareHtmlEngineTest method check.
private static void check(final String input, final String output, final Set<String> blockSelectors) throws Exception {
final String templateName = "test";
final StringWriter writer = new StringWriter();
final ITemplateHandler handler = new OutputTemplateHandler(writer);
PARSER.parseStandalone(TEMPLATE_ENGINE_CONFIGURATION, templateName, templateName, blockSelectors, new StringTemplateResource(input), TemplateMode.HTML, false, handler);
Assert.assertEquals("Test failed for file: " + templateName, output, writer.toString());
}
use of org.thymeleaf.templateresource.StringTemplateResource in project thymeleaf-tests by thymeleaf.
the class TestTemplateResolver method resolveTemplate.
public TemplateResolution resolveTemplate(final IEngineConfiguration configuration, final String ownerTemplate, final String template, final Map<String, Object> templateResolutionAttributes) {
final int placeholderPos = this.template.indexOf("{%%}");
final String resource = this.template.substring(0, placeholderPos) + template + this.template.substring(placeholderPos + 4);
final ITemplateResource templateResource = new StringTemplateResource(resource);
final TemplateResolution templateResolution = new TemplateResolution(templateResource, // For the sake of these tests, considering resource existence verified is fine
true, TemplateMode.HTML, false, new NonCacheableCacheEntryValidity());
return templateResolution;
}
use of org.thymeleaf.templateresource.StringTemplateResource in project cas by apereo.
the class RestfulUrlTemplateResolver method computeTemplateResource.
@Override
protected ITemplateResource computeTemplateResource(final IEngineConfiguration configuration, final String ownerTemplate, final String template, final String resourceName, final String characterEncoding, final Map<String, Object> templateResolutionAttributes) {
val rest = casProperties.getView().getRest();
val request = HttpRequestUtils.getHttpServletRequestFromRequestAttributes();
val themeName = this.themeResolver.resolveThemeName(request);
val headers = new LinkedHashMap<String, Object>();
headers.put("owner", ownerTemplate);
headers.put("template", template);
headers.put("resource", resourceName);
if (StringUtils.isNotBlank(themeName)) {
headers.put("theme", themeName);
}
headers.put("locale", request.getLocale().getCountry());
headers.putAll(HttpRequestUtils.getRequestHeaders(request));
headers.putAll(rest.getHeaders());
HttpResponse response = null;
try {
val exec = HttpUtils.HttpExecutionRequest.builder().basicAuthPassword(rest.getBasicAuthPassword()).basicAuthUsername(rest.getBasicAuthUsername()).method(HttpMethod.valueOf(rest.getMethod().toUpperCase().trim())).url(rest.getUrl()).headers(headers).build();
response = HttpUtils.execute(exec);
val statusCode = response.getStatusLine().getStatusCode();
if (HttpStatus.valueOf(statusCode).is2xxSuccessful()) {
val result = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
return new StringTemplateResource(result);
}
} catch (final Exception e) {
LoggingUtils.error(LOGGER, e);
} finally {
HttpUtils.close(response);
}
return super.computeTemplateResource(configuration, ownerTemplate, template, resourceName, characterEncoding, templateResolutionAttributes);
}
use of org.thymeleaf.templateresource.StringTemplateResource in project thymeleaf-tests by thymeleaf.
the class HtmlBlockSelectorMarkupHandlerTest method check.
private static void check(final HTMLTemplateParser parser, final IEngineConfiguration templateEngineContext, final String templateName, final String input, final String output, final Set<String> blockSelectors) throws Exception {
final StringWriter writer = new StringWriter();
final ITemplateHandler handler = new OutputTemplateHandler(writer);
parser.parseStandalone(templateEngineContext, templateName, templateName, blockSelectors, new StringTemplateResource(input), TemplateMode.HTML, false, handler);
assertEquals("Test failed for file: " + templateName, output, writer.toString());
}
Aggregations