@SuppressWarnings("unchecked")
public String get(String templateEngineName, String path, Map<String, Object> model) throws Exception {
final Logger log = LoggerFactory.getLogger(path);
StringWriter writer = new StringWriter();
View view = repository.getView(path);
try {
if (view != null && !view.getFiltersBefore().isEmpty()) {
for (Map<String, Object> filterMap : view.getFiltersBefore()) {
Map.Entry<String, Object> filterDef = filterMap.entrySet().iterator().next();
try {
repository.getSite().getControllerManager().execute(
filterDef.getKey(), context, (Map) filterDef.getValue());
} catch (Exception e) {
log.error(String.format("Error while evaluating the BEFORE filter: `%s`", filterDef.getKey()));
e.printStackTrace();
throw new ViewException(e.getMessage());
}
}
}
if (view != null && !CollectionUtils.isEmpty(view.getControllers())) {
executeViewControllers(view.getControllers(), context);
}
ViewRenderer engine = context.getSiteContext().getTemplateEnginesManager().getEngine(templateEngineName);
if (model != null && !model.isEmpty()) {
context.getMap().putAll(model);
}
engine.render(path, repository, context, writer);
return writer.toString();
} finally {
if (view != null && !view.getFiltersAfter().isEmpty()) {
for (Map<String, Object> filterMap : view.getFiltersAfter()) {
Map.Entry<String, Object> filterDef = filterMap.entrySet().iterator().next();
try {
repository.getSite().getControllerManager().execute(
filterDef.getKey(), context, (Map) filterDef.getValue());
} catch (Exception e) {