@Override
public void renderDocument(final Map<String, Object> model, final String templateName, final Writer writer) throws RenderingException {
String localeString = config.getString(Keys.THYMELEAF_LOCALE);
Locale locale = localeString != null ? LocaleUtils.toLocale(localeString) : Locale.getDefault();
Context context = new Context(locale, wrap(model));
lock.lock();
try {
initializeTemplateEngine();
@SuppressWarnings("unchecked")
Map<String, Object> config = (Map<String, Object>) model.get("config");