* @throws JSONException json exception
*/
@RequestProcessing(value = "/authors/**", method = HTTPRequestMethod.GET)
public void showAuthorArticles(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response)
throws IOException, JSONException {
final AbstractFreeMarkerRenderer renderer = new FrontRenderer();
context.setRenderer(renderer);
renderer.setTemplateName("author-articles.ftl");
try {
String requestURI = request.getRequestURI();
if (!requestURI.endsWith("/")) {
requestURI += "/";
}
final String authorId = getAuthorId(requestURI);
LOGGER.log(Level.FINER, "Request author articles[requestURI={0}, authorId={1}]",
new Object[]{requestURI, authorId});
final int currentPageNum = getAuthorCurrentPageNum(requestURI, authorId);
if (-1 == currentPageNum) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
LOGGER.log(Level.FINER, "Request author articles[authorId={0}, currentPageNum={1}]",
new Object[]{authorId, currentPageNum});
final JSONObject preference = preferenceQueryService.getPreference();
if (null == preference) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
final int pageSize = preference.getInt(Preference.ARTICLE_LIST_DISPLAY_COUNT);
final int windowSize = preference.getInt(Preference.ARTICLE_LIST_PAGINATION_WINDOW_SIZE);
final JSONObject result = userQueryService.getUser(authorId);
final JSONObject author = result.getJSONObject(User.USER);
final Map<String, String> langs = langPropsService.getAll(Latkes.getLocale());
request.setAttribute(CACHED_TYPE, langs.get(PageTypes.AUTHOR_ARTICLES));
request.setAttribute(CACHED_OID, "No id");
request.setAttribute(CACHED_TITLE,
langs.get(PageTypes.AUTHOR_ARTICLES) + " ["
+ langs.get("pageNumLabel") + "=" + currentPageNum + ", "
+ langs.get("authorLabel") + "=" + author.getString(User.USER_NAME) + "]");
request.setAttribute(CACHED_LINK, requestURI);
final String authorEmail = author.getString(User.USER_EMAIL);
final List<JSONObject> articles = articleQueryService.getArticlesByAuthorEmail(authorEmail, currentPageNum, pageSize);
if (articles.isEmpty()) {
try {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
} catch (final IOException ex) {
LOGGER.severe(ex.getMessage());
}
}
filler.setArticlesExProperties(articles, author, preference);
if (preference.optBoolean(Preference.ENABLE_ARTICLE_UPDATE_HINT)) {
Collections.sort(articles, Comparators.ARTICLE_UPDATE_DATE_COMPARATOR);
} else {
Collections.sort(articles, Comparators.ARTICLE_CREATE_DATE_COMPARATOR);
}
final int articleCount = author.getInt(UserExt.USER_PUBLISHED_ARTICLE_COUNT);
final int pageCount = (int) Math.ceil((double) articleCount / (double) pageSize);
final List<Integer> pageNums = Paginator.paginate(currentPageNum, pageSize, pageCount, windowSize);
final Map<String, Object> dataModel = renderer.getDataModel();
prepareShowAuthorArticles(pageNums, dataModel, pageCount, currentPageNum, articles, author, preference);
filler.fillBlogHeader(request, dataModel, preference);
filler.fillSide(request, dataModel, preference);
Skins.fillSkinLangs(preference.optString(Preference.LOCALE_STRING),
(String) request.getAttribute(Keys.TEMAPLTE_DIR_NAME), dataModel);