private void executeViewControllers(List<Map<String, Object>> controllers, MicroContext context)
throws ControllerException, ControllerNotFoundException {
if (context != null && !CollectionUtils.isEmpty(controllers)) {
ControllerManager controllerManager = context.getSiteContext().getControllerManager();
for (Map<String, Object> map : controllers) {
final Map controllerMap = (Map) map.get(Globals.CONTROLLER);
if (!CollectionUtils.isEmpty(controllerMap)) {
String controllerName = (String) controllerMap.get(Globals.NAME);
String wrapperName = (String) controllerMap.get(Globals.WRAPPER);
// StringUtils.isNotBlank too heavy for this crowded space ... sorry Commons::Lang
if (controllerName != null && !controllerName.isEmpty()) {
if (wrapperName != null && !wrapperName.isEmpty()) {
try {
ControllerWrapper controller =
(ControllerWrapper) ClassUtilities.loadClass(wrapperName).newInstance();
Class[] paramTypes = {String.class, MicroContext.class, Map.class};
Object[] params = {controllerName, context, (Map) controllerMap.get(Globals.OPTIONS)};
Method method = controller.getClass()
.getDeclaredMethod(ControllerManager.EXECUTE_METHOD, paramTypes);
method.invoke(controller, params);
} catch (Exception e) {
repository.getLog().error(String.format("%s, error: %s", controllerName, e.getMessage()));
e.printStackTrace();
throw new ControllerException(e.getMessage());
}
} else {
controllerManager.execute(controllerName, context, (Map) controllerMap.get(Globals.OPTIONS));
}
}
}
}
}