use of org.b3log.latke.plugin.ViewLoadEventData in project solo by b3log.
the class AdminConsole method fireFreeMarkerActionEvent.
/**
* Fires FreeMarker action event with the host template name and data model.
*
* @param hostTemplateName the specified host template name
* @param dataModel the specified data model
*/
private void fireFreeMarkerActionEvent(final String hostTemplateName, final Map<String, Object> dataModel) {
try {
final ViewLoadEventData data = new ViewLoadEventData();
data.setViewName(hostTemplateName);
data.setDataModel(dataModel);
eventManager.fireEventSynchronously(new Event<ViewLoadEventData>(Keys.FREEMARKER_ACTION, data));
if (Strings.isEmptyOrNull((String) dataModel.get(Plugin.PLUGINS))) {
// There is no plugin for this template, fill ${plugins} with blank.
dataModel.put(Plugin.PLUGINS, "");
}
} catch (final EventException e) {
LOGGER.log(Level.WARN, "Event[FREEMARKER_ACTION] handle failed, ignores this exception for kernel health", e);
}
}
use of org.b3log.latke.plugin.ViewLoadEventData in project solo by b3log.
the class Filler method fillBlogFooter.
/**
* Fills footer.ftl.
*
* @param request the specified HTTP servlet request
* @param dataModel data model
* @param preference the specified preference
* @throws ServiceException service exception
*/
public void fillBlogFooter(final HttpServletRequest request, final Map<String, Object> dataModel, final JSONObject preference) throws ServiceException {
Stopwatchs.start("Fill Footer");
try {
LOGGER.debug("Filling footer....");
final String blogTitle = preference.getString(Option.ID_C_BLOG_TITLE);
dataModel.put(Option.ID_C_BLOG_TITLE, blogTitle);
dataModel.put("blogHost", Latkes.getServerHost() + ":" + Latkes.getServerPort());
dataModel.put(Common.VERSION, SoloServletListener.VERSION);
dataModel.put(Common.STATIC_RESOURCE_VERSION, Latkes.getStaticResourceVersion());
dataModel.put(Common.YEAR, String.valueOf(Calendar.getInstance().get(Calendar.YEAR)));
String footerContent = "";
final JSONObject opt = optionQueryService.getOptionById(Option.ID_C_FOOTER_CONTENT);
if (null != opt) {
footerContent = opt.optString(Option.OPTION_VALUE);
}
dataModel.put(Option.ID_C_FOOTER_CONTENT, footerContent);
dataModel.put(Keys.Server.STATIC_SERVER, Latkes.getStaticServer());
dataModel.put(Keys.Server.SERVER, Latkes.getServer());
dataModel.put(Common.IS_INDEX, "/".equals(request.getRequestURI()));
dataModel.put(User.USER_NAME, "");
final JSONObject currentUser = userQueryService.getCurrentUser(request);
if (null != currentUser) {
final String userAvatar = currentUser.optString(UserExt.USER_AVATAR);
if (!Strings.isEmptyOrNull(userAvatar)) {
dataModel.put(Common.GRAVATAR, userAvatar);
} else {
final String email = currentUser.optString(User.USER_EMAIL);
final String gravatar = Thumbnails.getGravatarURL(email, "128");
dataModel.put(Common.GRAVATAR, gravatar);
}
dataModel.put(User.USER_NAME, currentUser.optString(User.USER_NAME));
}
// Activates plugins
try {
final ViewLoadEventData data = new ViewLoadEventData();
data.setViewName("footer.ftl");
data.setDataModel(dataModel);
eventManager.fireEventSynchronously(new Event<ViewLoadEventData>(Keys.FREEMARKER_ACTION, data));
if (Strings.isEmptyOrNull((String) dataModel.get(Plugin.PLUGINS))) {
// There is no plugin for this template, fill ${plugins} with blank.
dataModel.put(Plugin.PLUGINS, "");
}
} catch (final EventException e) {
LOGGER.log(Level.WARN, "Event[FREEMARKER_ACTION] handle failed, ignores this exception for kernel health", e);
}
} catch (final JSONException e) {
LOGGER.log(Level.ERROR, "Fills blog footer failed", e);
throw new ServiceException(e);
} finally {
Stopwatchs.end();
}
}
Aggregations