@Test public void shouldNotAcceptEmptyTemplateName() throws Exception { final Map<String, Object> modelObject = new ImmutableMap.Builder<String, Object>().build(); expectedException.expect(IllegalArgumentException.class); templateService.mergeTemplateIntoString(" ", modelObject); fail("IllegalArgumentException expected"); }
@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();  }