@Test public void testProcessTemplateBasic() throws Exception { final CacheManager cacheManager = context.mock(CacheManager.class); final Cache cache = context.mock(Cache.class); final TemplateCacheKey tcc = new TemplateCacheKey(null, "[[${name}]] is awesome!", null, 0, 0, null, null); final ExpressionCacheKey ecc = new ExpressionCacheKey("expr", "${name}"); final ExpressionCacheKey ecc2 = new ExpressionCacheKey("spel", "name"); context.checking(new Expectations() {{ allowing(cacheManager).getCache("contentService-templateSupport"); will(returnValue(cache)); allowing(cache).get(tcc); will(returnValue(null)); allowing(cache).put(with(equal(tcc)), with(any(Object.class))); allowing(cache).get(ecc); will(returnValue(null)); allowing(cache).put(with(equal(ecc)), with(any(Object.class))); allowing(cache).get(ecc2); will(returnValue(null)); allowing(cache).put(with(equal(ecc2)), with(any(Object.class))); }}); final TemplateSupport templates = new ThymeleafTemplateSupportImpl(cacheManager); final TemplateProcessortThymeleafImpl support = new TemplateProcessortThymeleafImpl(templates); final String out = support.processTemplate("[[${name}]] is awesome!", "en", new HashMap<String, Object>() {{ put("name", "YC"); }}); assertEquals("YC is awesome!", out); context.assertIsSatisfied(); }
@Override public String processTemplate(final String template, final String locale, final Map<String, Object> context) { final Map<String, Object> fullContext = new HashMap<>(context); fullContext.put("locale", locale); fullContext.put("localeObject", lazyLoad(locale)); appendFunctions(locale, fullContext); fullContext.put("context", fullContext); return this.templateSupport.get(template).make(fullContext); }
TemplateProcessortThymeleafImpl implements TemplateProcessor { @Override public String processTemplate(final String template, final String locale, final Map<String, Object> context) { final Map<String, Object> fullContext = new HashMap<>(context); fullContext.put("locale", locale); fullContext.put("localeObject", lazyLoad(locale)); appendFunctions(locale, fullContext); fullContext.put("context", fullContext); return this.templateSupport.get(template).make(fullContext); } }
TemplateProcessortThymeleafImpl implements TemplateProcessor { @Override public String processTemplate(final String template, final String locale, final Map<String, Object> context) { final Map<String, Object> fullContext = new HashMap<>(context); fullContext.put("locale", locale); fullContext.put("localeObject", lazyLoad(locale)); appendFunctions(locale, fullContext); fullContext.put("context", fullContext); return this.templateSupport.get(template).make(fullContext); } TemplateProcessortThymeleafImpl(final TemplateSupport templateSupport); }
TemplateProcessortThymeleafImpl implements TemplateProcessor { @Override public String processTemplate(final String template, final String locale, final Map<String, Object> context) { final Map<String, Object> fullContext = new HashMap<>(context); fullContext.put("locale", locale); fullContext.put("localeObject", lazyLoad(locale)); appendFunctions(locale, fullContext); fullContext.put("context", fullContext); return this.templateSupport.get(template).make(fullContext); } TemplateProcessortThymeleafImpl(final TemplateSupport templateSupport); @Override boolean supports(final String template, final String locale, final Map<String, Object> context); @Override String processTemplate(final String template, final String locale, final Map<String, Object> context); @Override void registerFunction(final String name, final FunctionProvider functionProvider); }
TemplateProcessortThymeleafImpl implements TemplateProcessor { @Override public String processTemplate(final String template, final String locale, final Map<String, Object> context) { final Map<String, Object> fullContext = new HashMap<>(context); fullContext.put("locale", locale); fullContext.put("localeObject", lazyLoad(locale)); appendFunctions(locale, fullContext); fullContext.put("context", fullContext); return this.templateSupport.get(template).make(fullContext); } TemplateProcessortThymeleafImpl(final TemplateSupport templateSupport); @Override boolean supports(final String template, final String locale, final Map<String, Object> context); @Override String processTemplate(final String template, final String locale, final Map<String, Object> context); @Override void registerFunction(final String name, final FunctionProvider functionProvider);  }