use of org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer in project symphony by b3log.
the class ErrorProcessor method handleErrorPage.
/**
* Handles the error.
*
* @param context the specified context
* @param request the specified HTTP servlet request
* @param response the specified HTTP servlet response
* @param statusCode the specified status code
* @throws Exception exception
*/
@RequestProcessing(value = "/error/{statusCode}", method = { HTTPRequestMethod.GET, HTTPRequestMethod.POST })
@Before(adviceClass = StopwatchStartAdvice.class)
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void handleErrorPage(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response, final String statusCode) throws Exception {
if (StringUtils.equals("GET", request.getMethod())) {
final String requestURI = request.getRequestURI();
final String templateName = statusCode + ".ftl";
LOGGER.log(Level.TRACE, "Shows error page[requestURI={0}, templateName={1}]", requestURI, templateName);
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
renderer.setTemplateName("error/" + templateName);
context.setRenderer(renderer);
final Map<String, Object> dataModel = renderer.getDataModel();
dataModel.putAll(langPropsService.getAll(Locales.getLocale()));
dataModelService.fillHeaderAndFooter(request, response, dataModel);
if (HttpServletResponse.SC_FORBIDDEN == Integer.valueOf(statusCode)) {
dataModelService.fillSideHotArticles(UserExt.USER_AVATAR_VIEW_MODE_C_ORIGINAL, dataModel);
dataModelService.fillRandomArticles(UserExt.USER_AVATAR_VIEW_MODE_C_ORIGINAL, dataModel);
dataModelService.fillSideTags(dataModel);
}
} else {
context.renderJSON().renderMsg(statusCode);
}
}
use of org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer in project symphony by b3log.
the class TopProcessor method showCheckin.
/**
* Shows checkin ranking list.
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
* @throws Exception exception
*/
@RequestProcessing(value = "/top/checkin", method = HTTPRequestMethod.GET)
@Before(adviceClass = { StopwatchStartAdvice.class, AnonymousViewCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void showCheckin(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
;
context.setRenderer(renderer);
renderer.setTemplateName("/top/checkin.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
final int avatarViewMode = (int) request.getAttribute(UserExt.USER_AVATAR_VIEW_MODE);
final List<JSONObject> users = activityQueryService.getTopCheckinUsers(avatarViewMode, Symphonys.getInt("topCheckinCnt"));
dataModel.put(Common.TOP_CHECKIN_USERS, users);
dataModelService.fillHeaderAndFooter(request, response, dataModel);
dataModelService.fillRandomArticles(avatarViewMode, dataModel);
dataModelService.fillSideHotArticles(avatarViewMode, dataModel);
dataModelService.fillSideTags(dataModel);
dataModelService.fillLatestCmts(dataModel);
}
use of org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer in project symphony by b3log.
the class UserProcessor method showHomeAnonymousComments.
/**
* Shows user home anonymous comments page.
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
* @param userName the specified user name
* @throws Exception exception
*/
@RequestProcessing(value = "/member/{userName}/comments/anonymous", method = HTTPRequestMethod.GET)
@Before(adviceClass = { StopwatchStartAdvice.class, UserBlockCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void showHomeAnonymousComments(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response, final String userName) throws Exception {
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
context.setRenderer(renderer);
renderer.setTemplateName("/home/comments.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
dataModelService.fillHeaderAndFooter(request, response, dataModel);
final boolean isLoggedIn = (Boolean) dataModel.get(Common.IS_LOGGED_IN);
JSONObject currentUser = null;
if (isLoggedIn) {
currentUser = (JSONObject) dataModel.get(Common.CURRENT_USER);
}
final JSONObject user = (JSONObject) request.getAttribute(User.USER);
if (null == currentUser || (!currentUser.optString(Keys.OBJECT_ID).equals(user.optString(Keys.OBJECT_ID))) && !Role.ROLE_ID_C_ADMIN.equals(currentUser.optString(User.USER_ROLE))) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
String pageNumStr = request.getParameter("p");
if (Strings.isEmptyOrNull(pageNumStr) || !Strings.isNumeric(pageNumStr)) {
pageNumStr = "1";
}
final int pageNum = Integer.valueOf(pageNumStr);
final int pageSize = Symphonys.getInt("userHomeCmtsCnt");
final int windowSize = Symphonys.getInt("userHomeCmtsWindowSize");
fillHomeUser(dataModel, user, roleQueryService);
final int avatarViewMode = (int) request.getAttribute(UserExt.USER_AVATAR_VIEW_MODE);
avatarQueryService.fillUserAvatarURL(avatarViewMode, user);
final String followingId = user.optString(Keys.OBJECT_ID);
dataModel.put(Follow.FOLLOWING_ID, followingId);
if (isLoggedIn) {
currentUser = (JSONObject) dataModel.get(Common.CURRENT_USER);
final String followerId = currentUser.optString(Keys.OBJECT_ID);
final boolean isFollowing = followQueryService.isFollowing(followerId, followingId, Follow.FOLLOWING_TYPE_C_USER);
dataModel.put(Common.IS_FOLLOWING, isFollowing);
}
user.put(UserExt.USER_T_CREATE_TIME, new Date(user.getLong(Keys.OBJECT_ID)));
final List<JSONObject> userComments = commentQueryService.getUserComments(avatarViewMode, user.optString(Keys.OBJECT_ID), Comment.COMMENT_ANONYMOUS_C_ANONYMOUS, pageNum, pageSize, currentUser);
dataModel.put(Common.USER_HOME_COMMENTS, userComments);
int recordCount = 0;
int pageCount = 0;
if (!userComments.isEmpty()) {
final JSONObject first = userComments.get(0);
pageCount = first.optInt(Pagination.PAGINATION_PAGE_COUNT);
recordCount = first.optInt(Pagination.PAGINATION_RECORD_COUNT);
}
final List<Integer> pageNums = Paginator.paginate(pageNum, pageSize, pageCount, windowSize);
if (!pageNums.isEmpty()) {
dataModel.put(Pagination.PAGINATION_FIRST_PAGE_NUM, pageNums.get(0));
dataModel.put(Pagination.PAGINATION_LAST_PAGE_NUM, pageNums.get(pageNums.size() - 1));
}
dataModel.put(Pagination.PAGINATION_CURRENT_PAGE_NUM, pageNum);
dataModel.put(Pagination.PAGINATION_PAGE_COUNT, pageCount);
dataModel.put(Pagination.PAGINATION_PAGE_NUMS, pageNums);
dataModel.put(Pagination.PAGINATION_RECORD_COUNT, recordCount);
dataModel.put(Common.TYPE, "commentsAnonymous");
}
use of org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer in project symphony by b3log.
the class UserProcessor method showHomeFollowingUsers.
/**
* Shows user home following users page.
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
* @param userName the specified user name
* @throws Exception exception
*/
@RequestProcessing(value = "/member/{userName}/following/users", method = HTTPRequestMethod.GET)
@Before(adviceClass = { StopwatchStartAdvice.class, AnonymousViewCheck.class, UserBlockCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void showHomeFollowingUsers(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response, final String userName) throws Exception {
final JSONObject user = (JSONObject) request.getAttribute(User.USER);
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
context.setRenderer(renderer);
renderer.setTemplateName("/home/following-users.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
dataModelService.fillHeaderAndFooter(request, response, dataModel);
String pageNumStr = request.getParameter("p");
if (Strings.isEmptyOrNull(pageNumStr) || !Strings.isNumeric(pageNumStr)) {
pageNumStr = "1";
}
final int pageNum = Integer.valueOf(pageNumStr);
final int pageSize = Symphonys.getInt("userHomeFollowingUsersCnt");
final int windowSize = Symphonys.getInt("userHomeFollowingUsersWindowSize");
fillHomeUser(dataModel, user, roleQueryService);
final String followingId = user.optString(Keys.OBJECT_ID);
dataModel.put(Follow.FOLLOWING_ID, followingId);
final int avatarViewMode = (int) request.getAttribute(UserExt.USER_AVATAR_VIEW_MODE);
avatarQueryService.fillUserAvatarURL(avatarViewMode, user);
final JSONObject followingUsersResult = followQueryService.getFollowingUsers(avatarViewMode, followingId, pageNum, pageSize);
final List<JSONObject> followingUsers = (List<JSONObject>) followingUsersResult.opt(Keys.RESULTS);
dataModel.put(Common.USER_HOME_FOLLOWING_USERS, followingUsers);
final boolean isLoggedIn = (Boolean) dataModel.get(Common.IS_LOGGED_IN);
if (isLoggedIn) {
final JSONObject currentUser = (JSONObject) dataModel.get(Common.CURRENT_USER);
final String followerId = currentUser.optString(Keys.OBJECT_ID);
final boolean isFollowing = followQueryService.isFollowing(followerId, followingId, Follow.FOLLOWING_TYPE_C_USER);
dataModel.put(Common.IS_FOLLOWING, isFollowing);
for (final JSONObject followingUser : followingUsers) {
final String homeUserFollowingUserId = followingUser.optString(Keys.OBJECT_ID);
followingUser.put(Common.IS_FOLLOWING, followQueryService.isFollowing(followerId, homeUserFollowingUserId, Follow.FOLLOWING_TYPE_C_USER));
}
}
user.put(UserExt.USER_T_CREATE_TIME, new Date(user.getLong(Keys.OBJECT_ID)));
final int followingUserCnt = followingUsersResult.optInt(Pagination.PAGINATION_RECORD_COUNT);
final int pageCount = (int) Math.ceil((double) followingUserCnt / (double) pageSize);
final List<Integer> pageNums = Paginator.paginate(pageNum, pageSize, pageCount, windowSize);
if (!pageNums.isEmpty()) {
dataModel.put(Pagination.PAGINATION_FIRST_PAGE_NUM, pageNums.get(0));
dataModel.put(Pagination.PAGINATION_LAST_PAGE_NUM, pageNums.get(pageNums.size() - 1));
}
dataModel.put(Pagination.PAGINATION_CURRENT_PAGE_NUM, pageNum);
dataModel.put(Pagination.PAGINATION_PAGE_COUNT, pageCount);
dataModel.put(Pagination.PAGINATION_PAGE_NUMS, pageNums);
dataModel.put(Pagination.PAGINATION_RECORD_COUNT, followingUserCnt);
dataModel.put(Common.TYPE, "followingUsers");
}
use of org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer in project symphony by b3log.
the class UserProcessor method showHome.
/**
* Shows user home page.
*
* @param context the specified context
* @param request the specified request
* @param response the specified response
* @param userName the specified user name
* @throws Exception exception
*/
@RequestProcessing(value = "/member/{userName}", method = HTTPRequestMethod.GET)
@Before(adviceClass = { StopwatchStartAdvice.class, AnonymousViewCheck.class, UserBlockCheck.class })
@After(adviceClass = { PermissionGrant.class, StopwatchEndAdvice.class })
public void showHome(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response, final String userName) throws Exception {
final JSONObject user = (JSONObject) request.getAttribute(User.USER);
String pageNumStr = request.getParameter("p");
if (Strings.isEmptyOrNull(pageNumStr) || !Strings.isNumeric(pageNumStr)) {
pageNumStr = "1";
}
int pageNum = 1;
try {
pageNum = Integer.valueOf(pageNumStr);
} catch (final Exception e) {
pageNum = 1;
}
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(request);
context.setRenderer(renderer);
final Map<String, Object> dataModel = renderer.getDataModel();
dataModelService.fillHeaderAndFooter(request, response, dataModel);
final String followingId = user.optString(Keys.OBJECT_ID);
dataModel.put(Follow.FOLLOWING_ID, followingId);
renderer.setTemplateName("/home/home.ftl");
dataModel.put(User.USER, user);
fillHomeUser(dataModel, user, roleQueryService);
final int avatarViewMode = (int) request.getAttribute(UserExt.USER_AVATAR_VIEW_MODE);
avatarQueryService.fillUserAvatarURL(avatarViewMode, user);
final boolean isLoggedIn = (Boolean) dataModel.get(Common.IS_LOGGED_IN);
if (isLoggedIn) {
final JSONObject currentUser = (JSONObject) dataModel.get(Common.CURRENT_USER);
final String followerId = currentUser.optString(Keys.OBJECT_ID);
final boolean isFollowing = followQueryService.isFollowing(followerId, followingId, Follow.FOLLOWING_TYPE_C_USER);
dataModel.put(Common.IS_FOLLOWING, isFollowing);
}
user.put(UserExt.USER_T_CREATE_TIME, new Date(user.getLong(Keys.OBJECT_ID)));
final int pageSize = Symphonys.getInt("userHomeArticlesCnt");
final int windowSize = Symphonys.getInt("userHomeArticlesWindowSize");
final List<JSONObject> userArticles = articleQueryService.getUserArticles(avatarViewMode, user.optString(Keys.OBJECT_ID), Article.ARTICLE_ANONYMOUS_C_PUBLIC, pageNum, pageSize);
dataModel.put(Common.USER_HOME_ARTICLES, userArticles);
int recordCount = 0;
int pageCount = 0;
if (!userArticles.isEmpty()) {
final JSONObject first = userArticles.get(0);
pageCount = first.optInt(Pagination.PAGINATION_PAGE_COUNT);
recordCount = first.optInt(Pagination.PAGINATION_RECORD_COUNT);
}
final List<Integer> pageNums = Paginator.paginate(pageNum, pageSize, pageCount, windowSize);
if (!pageNums.isEmpty()) {
dataModel.put(Pagination.PAGINATION_FIRST_PAGE_NUM, pageNums.get(0));
dataModel.put(Pagination.PAGINATION_LAST_PAGE_NUM, pageNums.get(pageNums.size() - 1));
}
dataModel.put(Pagination.PAGINATION_CURRENT_PAGE_NUM, pageNum);
dataModel.put(Pagination.PAGINATION_PAGE_COUNT, pageCount);
dataModel.put(Pagination.PAGINATION_PAGE_NUMS, pageNums);
dataModel.put(Pagination.PAGINATION_RECORD_COUNT, recordCount);
final JSONObject currentUser = Sessions.currentUser(request);
if (null == currentUser) {
dataModel.put(Common.IS_MY_ARTICLE, false);
} else {
dataModel.put(Common.IS_MY_ARTICLE, userName.equals(currentUser.optString(User.USER_NAME)));
}
dataModel.put(Common.TYPE, "home");
}
Aggregations