@Test public void shouldMergeTemplateIntoString() throws Exception { final String expectedBody = TemplatingTestUtils.getExpectedBody(); final String templateWithExtension = TemplatingTestUtils.TEMPLATE; assertions.assertThat(templateWithExtension).endsWith(".ftl"); final String body = templateService.mergeTemplateIntoString(TemplatingTestUtils.TEMPLATE, TemplatingTestUtils.MODEL_OBJECT); assertions.assertThat(body).isEqualTo(expectedBody); }
@Override @NonNull public String mergeTemplateIntoString(final @NonNull String templateReference, final @NonNull Map<String, Object> model) throws IOException, TemplateException { final String trimmedTemplateReference = templateReference.trim(); checkArgument(!isNullOrEmpty(trimmedTemplateReference), "The given template is null, empty or blank"); if (trimmedTemplateReference.contains(".")) checkArgument(Objects.equals(getFileExtension(trimmedTemplateReference), expectedTemplateExtension()), "Expected a Freemarker template file with extension 'ftl', while '%s' was given", getFileExtension(trimmedTemplateReference)); try { final String normalizedTemplateReference = trimmedTemplateReference.endsWith(expectedTemplateExtension()) ? trimmedTemplateReference : trimmedTemplateReference + '.' + expectedTemplateExtension(); return FreeMarkerTemplateUtils.processTemplateIntoString( freemarkerConfiguration.getTemplate(normalizedTemplateReference, Charset.forName("UTF-8").name()), model); } catch (Exception e) { throw new TemplateException(e); } }
FreemarkerTemplateService implements TemplateService { @Override @NonNull public String mergeTemplateIntoString(final @NonNull String templateReference, final @NonNull Map<String, Object> model) throws IOException, TemplateException { final String trimmedTemplateReference = templateReference.trim(); checkArgument(!isNullOrEmpty(trimmedTemplateReference), "The given template is null, empty or blank"); if (trimmedTemplateReference.contains(".")) checkArgument(Objects.equals(getFileExtension(trimmedTemplateReference), expectedTemplateExtension()), "Expected a Freemarker template file with extension 'ftl', while '%s' was given", getFileExtension(trimmedTemplateReference)); try { final String normalizedTemplateReference = trimmedTemplateReference.endsWith(expectedTemplateExtension()) ? trimmedTemplateReference : trimmedTemplateReference + '.' + expectedTemplateExtension(); return FreeMarkerTemplateUtils.processTemplateIntoString( freemarkerConfiguration.getTemplate(normalizedTemplateReference, Charset.forName("UTF-8").name()), model); } catch (Exception e) { throw new TemplateException(e); } } }
FreemarkerTemplateService implements TemplateService { @Override @NonNull public String mergeTemplateIntoString(final @NonNull String templateReference, final @NonNull Map<String, Object> model) throws IOException, TemplateException { final String trimmedTemplateReference = templateReference.trim(); checkArgument(!isNullOrEmpty(trimmedTemplateReference), "The given template is null, empty or blank"); if (trimmedTemplateReference.contains(".")) checkArgument(Objects.equals(getFileExtension(trimmedTemplateReference), expectedTemplateExtension()), "Expected a Freemarker template file with extension 'ftl', while '%s' was given", getFileExtension(trimmedTemplateReference)); try { final String normalizedTemplateReference = trimmedTemplateReference.endsWith(expectedTemplateExtension()) ? trimmedTemplateReference : trimmedTemplateReference + '.' + expectedTemplateExtension(); return FreeMarkerTemplateUtils.processTemplateIntoString( freemarkerConfiguration.getTemplate(normalizedTemplateReference, Charset.forName("UTF-8").name()), model); } catch (Exception e) { throw new TemplateException(e); } }  }
FreemarkerTemplateService implements TemplateService { @Override @NonNull public String mergeTemplateIntoString(final @NonNull String templateReference, final @NonNull Map<String, Object> model) throws IOException, TemplateException { final String trimmedTemplateReference = templateReference.trim(); checkArgument(!isNullOrEmpty(trimmedTemplateReference), "The given template is null, empty or blank"); if (trimmedTemplateReference.contains(".")) checkArgument(Objects.equals(getFileExtension(trimmedTemplateReference), expectedTemplateExtension()), "Expected a Freemarker template file with extension 'ftl', while '%s' was given", getFileExtension(trimmedTemplateReference)); try { final String normalizedTemplateReference = trimmedTemplateReference.endsWith(expectedTemplateExtension()) ? trimmedTemplateReference : trimmedTemplateReference + '.' + expectedTemplateExtension(); return FreeMarkerTemplateUtils.processTemplateIntoString( freemarkerConfiguration.getTemplate(normalizedTemplateReference, Charset.forName("UTF-8").name()), model); } catch (Exception e) { throw new TemplateException(e); } }  @Override @NonNull String mergeTemplateIntoString(final @NonNull String templateReference,
                                          final @NonNull Map<String, Object> model); @Override String expectedTemplateExtension(); }
FreemarkerTemplateService implements TemplateService { @Override @NonNull public String mergeTemplateIntoString(final @NonNull String templateReference, final @NonNull Map<String, Object> model) throws IOException, TemplateException { final String trimmedTemplateReference = templateReference.trim(); checkArgument(!isNullOrEmpty(trimmedTemplateReference), "The given template is null, empty or blank"); if (trimmedTemplateReference.contains(".")) checkArgument(Objects.equals(getFileExtension(trimmedTemplateReference), expectedTemplateExtension()), "Expected a Freemarker template file with extension 'ftl', while '%s' was given", getFileExtension(trimmedTemplateReference)); try { final String normalizedTemplateReference = trimmedTemplateReference.endsWith(expectedTemplateExtension()) ? trimmedTemplateReference : trimmedTemplateReference + '.' + expectedTemplateExtension(); return FreeMarkerTemplateUtils.processTemplateIntoString( freemarkerConfiguration.getTemplate(normalizedTemplateReference, Charset.forName("UTF-8").name()), model); } catch (Exception e) { throw new TemplateException(e); } }  @Override @NonNull String mergeTemplateIntoString(final @NonNull String templateReference,
                                          final @NonNull Map<String, Object> model); @Override String expectedTemplateExtension();  }