Commit 21d5a0d5 authored by Liang Ding's avatar Liang Ding

🎨 Cleanup code

parent be750f29
...@@ -65,7 +65,7 @@ import java.util.*; ...@@ -65,7 +65,7 @@ import java.util.*;
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="http://zephyr.b3log.org">Zephyr</a> * @author <a href="http://zephyr.b3log.org">Zephyr</a>
* @version 1.4.4.0, Nov 24, 2017 * @version 1.4.4.1, Apr 13, 2018
* @since 0.3.1 * @since 0.3.1
*/ */
@RequestProcessor @RequestProcessor
...@@ -161,8 +161,7 @@ public class ArticleProcessor { ...@@ -161,8 +161,7 @@ public class ArticleProcessor {
* @return page number, returns {@code -1} if the specified request URI can not convert to an number * @return page number, returns {@code -1} if the specified request URI can not convert to an number
*/ */
private static int getArchiveCurrentPageNum(final String requestURI) { private static int getArchiveCurrentPageNum(final String requestURI) {
final String pageNumString = final String pageNumString = StringUtils.substring(requestURI, (Latkes.getContextPath() + "/archives/yyyy/MM/").length());
StringUtils.substring(requestURI, (Latkes.getContextPath() + "/archives/yyyy/MM/").length());
return Requests.getCurrentPageNum(pageNumString); return Requests.getCurrentPageNum(pageNumString);
} }
...@@ -175,11 +174,9 @@ public class ArticleProcessor { ...@@ -175,11 +174,9 @@ public class ArticleProcessor {
*/ */
private static String getAuthorId(final String requestURI) { private static String getAuthorId(final String requestURI) {
final String path = requestURI.substring((Latkes.getContextPath() + "/authors/").length()); final String path = requestURI.substring((Latkes.getContextPath() + "/authors/").length());
final int idx = path.indexOf("/"); final int idx = path.indexOf("/");
if (-1 == idx) { if (-1 == idx) {
return path.substring(0); return path;
} else { } else {
return path.substring(0, idx); return path.substring(0, idx);
} }
...@@ -215,7 +212,6 @@ public class ArticleProcessor { ...@@ -215,7 +212,6 @@ public class ArticleProcessor {
*/ */
private static String getTagArticlesPagedTag(final String requestURI) { private static String getTagArticlesPagedTag(final String requestURI) {
String tagAndPageNum = requestURI.substring((Latkes.getContextPath() + "/articles/tags/").length()); String tagAndPageNum = requestURI.substring((Latkes.getContextPath() + "/articles/tags/").length());
if (tagAndPageNum.endsWith("/")) { if (tagAndPageNum.endsWith("/")) {
tagAndPageNum = StringUtils.removeEnd(tagAndPageNum, "/"); tagAndPageNum = StringUtils.removeEnd(tagAndPageNum, "/");
} }
...@@ -241,7 +237,6 @@ public class ArticleProcessor { ...@@ -241,7 +237,6 @@ public class ArticleProcessor {
*/ */
private static String getArchivesArticlesPagedArchive(final String requestURI) { private static String getArchivesArticlesPagedArchive(final String requestURI) {
String archiveAndPageNum = requestURI.substring((Latkes.getContextPath() + "/articles/archives/").length()); String archiveAndPageNum = requestURI.substring((Latkes.getContextPath() + "/articles/archives/").length());
if (archiveAndPageNum.endsWith("/")) { if (archiveAndPageNum.endsWith("/")) {
archiveAndPageNum = StringUtils.removeEnd(archiveAndPageNum, "/"); archiveAndPageNum = StringUtils.removeEnd(archiveAndPageNum, "/");
} }
...@@ -267,7 +262,6 @@ public class ArticleProcessor { ...@@ -267,7 +262,6 @@ public class ArticleProcessor {
*/ */
private static String getAuthorsArticlesPagedAuthorId(final String requestURI) { private static String getAuthorsArticlesPagedAuthorId(final String requestURI) {
String authorIdAndPageNum = requestURI.substring((Latkes.getContextPath() + "/articles/authors/").length()); String authorIdAndPageNum = requestURI.substring((Latkes.getContextPath() + "/articles/authors/").length());
if (authorIdAndPageNum.endsWith("/")) { if (authorIdAndPageNum.endsWith("/")) {
authorIdAndPageNum = StringUtils.removeEnd(authorIdAndPageNum, "/"); authorIdAndPageNum = StringUtils.removeEnd(authorIdAndPageNum, "/");
} }
...@@ -300,26 +294,22 @@ public class ArticleProcessor { ...@@ -300,26 +294,22 @@ public class ArticleProcessor {
public void showArticlePwdForm(final HTTPRequestContext context, public void showArticlePwdForm(final HTTPRequestContext context,
final HttpServletRequest request, final HttpServletResponse response) throws Exception { final HttpServletRequest request, final HttpServletResponse response) throws Exception {
final String articleId = request.getParameter("articleId"); final String articleId = request.getParameter("articleId");
if (Strings.isEmptyOrNull(articleId)) { if (Strings.isEmptyOrNull(articleId)) {
response.sendError(HttpServletResponse.SC_NOT_FOUND); response.sendError(HttpServletResponse.SC_NOT_FOUND);
return; return;
} }
final JSONObject article = articleQueryService.getArticleById(articleId); final JSONObject article = articleQueryService.getArticleById(articleId);
if (null == article) { if (null == article) {
response.sendError(HttpServletResponse.SC_NOT_FOUND); response.sendError(HttpServletResponse.SC_NOT_FOUND);
return; return;
} }
final AbstractFreeMarkerRenderer renderer = new ConsoleRenderer(); final AbstractFreeMarkerRenderer renderer = new ConsoleRenderer();
context.setRenderer(renderer); context.setRenderer(renderer);
renderer.setTemplateName("article-pwd.ftl"); renderer.setTemplateName("article-pwd.ftl");
final Map<String, Object> dataModel = renderer.getDataModel(); final Map<String, Object> dataModel = renderer.getDataModel();
dataModel.put("articleId", articleId); dataModel.put("articleId", articleId);
dataModel.put("articlePermalink", article.optString(Article.ARTICLE_PERMALINK)); dataModel.put("articlePermalink", article.optString(Article.ARTICLE_PERMALINK));
dataModel.put("articleTitle", article.optString(Article.ARTICLE_TITLE)); dataModel.put("articleTitle", article.optString(Article.ARTICLE_TITLE));
...@@ -331,11 +321,9 @@ public class ArticleProcessor { ...@@ -331,11 +321,9 @@ public class ArticleProcessor {
} }
final Map<String, String> langs = langPropsService.getAll(Latkes.getLocale()); final Map<String, String> langs = langPropsService.getAll(Latkes.getLocale());
dataModel.putAll(langs); dataModel.putAll(langs);
final JSONObject preference = preferenceQueryService.getPreference(); final JSONObject preference = preferenceQueryService.getPreference();
dataModel.put(Option.ID_C_BLOG_TITLE, preference.getString(Option.ID_C_BLOG_TITLE)); dataModel.put(Option.ID_C_BLOG_TITLE, preference.getString(Option.ID_C_BLOG_TITLE));
dataModel.put(Common.VERSION, SoloServletListener.VERSION); dataModel.put(Common.VERSION, SoloServletListener.VERSION);
dataModel.put(Common.STATIC_RESOURCE_VERSION, Latkes.getStaticResourceVersion()); dataModel.put(Common.STATIC_RESOURCE_VERSION, Latkes.getStaticResourceVersion());
...@@ -364,17 +352,14 @@ public class ArticleProcessor { ...@@ -364,17 +352,14 @@ public class ArticleProcessor {
if (article.getString(Article.ARTICLE_VIEW_PWD).equals(pwdTyped)) { if (article.getString(Article.ARTICLE_VIEW_PWD).equals(pwdTyped)) {
final HttpSession session = request.getSession(false); final HttpSession session = request.getSession(false);
if (null != session) { if (null != session) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, String> viewPwds = (Map<String, String>) session.getAttribute(Common.ARTICLES_VIEW_PWD); Map<String, String> viewPwds = (Map<String, String>) session.getAttribute(Common.ARTICLES_VIEW_PWD);
if (null == viewPwds) { if (null == viewPwds) {
viewPwds = new HashMap<String, String>(); viewPwds = new HashMap<String, String>();
} }
viewPwds.put(articleId, pwdTyped); viewPwds.put(articleId, pwdTyped);
session.setAttribute(Common.ARTICLES_VIEW_PWD, viewPwds); session.setAttribute(Common.ARTICLES_VIEW_PWD, viewPwds);
} }
...@@ -403,12 +388,10 @@ public class ArticleProcessor { ...@@ -403,12 +388,10 @@ public class ArticleProcessor {
final JSONObject preference = preferenceQueryService.getPreference(); final JSONObject preference = preferenceQueryService.getPreference();
final int displayCnt = preference.getInt(Option.ID_C_RANDOM_ARTICLES_DISPLAY_CNT); final int displayCnt = preference.getInt(Option.ID_C_RANDOM_ARTICLES_DISPLAY_CNT);
if (0 == displayCnt) { if (0 == displayCnt) {
jsonObject.put(Common.RANDOM_ARTICLES, new ArrayList<JSONObject>()); jsonObject.put(Common.RANDOM_ARTICLES, new ArrayList<JSONObject>());
final JSONRenderer renderer = new JSONRenderer(); final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer); context.setRenderer(renderer);
renderer.setJSONObject(jsonObject); renderer.setJSONObject(jsonObject);
...@@ -421,7 +404,6 @@ public class ArticleProcessor { ...@@ -421,7 +404,6 @@ public class ArticleProcessor {
jsonObject.put(Common.RANDOM_ARTICLES, randomArticles); jsonObject.put(Common.RANDOM_ARTICLES, randomArticles);
final JSONRenderer renderer = new JSONRenderer(); final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer); context.setRenderer(renderer);
renderer.setJSONObject(jsonObject); renderer.setJSONObject(jsonObject);
...@@ -444,12 +426,10 @@ public class ArticleProcessor { ...@@ -444,12 +426,10 @@ public class ArticleProcessor {
final JSONObject preference = preferenceQueryService.getPreference(); final JSONObject preference = preferenceQueryService.getPreference();
final int displayCnt = preference.getInt(Option.ID_C_RELEVANT_ARTICLES_DISPLAY_CNT); final int displayCnt = preference.getInt(Option.ID_C_RELEVANT_ARTICLES_DISPLAY_CNT);
if (0 == displayCnt) { if (0 == displayCnt) {
jsonObject.put(Common.RANDOM_ARTICLES, new ArrayList<JSONObject>()); jsonObject.put(Common.RANDOM_ARTICLES, new ArrayList<JSONObject>());
final JSONRenderer renderer = new JSONRenderer(); final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer); context.setRenderer(renderer);
renderer.setJSONObject(jsonObject); renderer.setJSONObject(jsonObject);
...@@ -460,7 +440,6 @@ public class ArticleProcessor { ...@@ -460,7 +440,6 @@ public class ArticleProcessor {
final String requestURI = request.getRequestURI(); final String requestURI = request.getRequestURI();
final String articleId = StringUtils.substringBetween(requestURI, "/article/id/", "/relevant/articles"); final String articleId = StringUtils.substringBetween(requestURI, "/article/id/", "/relevant/articles");
if (Strings.isEmptyOrNull(articleId)) { if (Strings.isEmptyOrNull(articleId)) {
response.sendError(HttpServletResponse.SC_NOT_FOUND); response.sendError(HttpServletResponse.SC_NOT_FOUND);
...@@ -468,7 +447,6 @@ public class ArticleProcessor { ...@@ -468,7 +447,6 @@ public class ArticleProcessor {
} }
final JSONObject article = articleQueryService.getArticleById(articleId); final JSONObject article = articleQueryService.getArticleById(articleId);
if (null == article) { if (null == article) {
response.sendError(HttpServletResponse.SC_NOT_FOUND); response.sendError(HttpServletResponse.SC_NOT_FOUND);
...@@ -476,11 +454,9 @@ public class ArticleProcessor { ...@@ -476,11 +454,9 @@ public class ArticleProcessor {
} }
final List<JSONObject> relevantArticles = articleQueryService.getRelevantArticles(article, preference); final List<JSONObject> relevantArticles = articleQueryService.getRelevantArticles(article, preference);
jsonObject.put(Common.RELEVANT_ARTICLES, relevantArticles); jsonObject.put(Common.RELEVANT_ARTICLES, relevantArticles);
final JSONRenderer renderer = new JSONRenderer(); final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer); context.setRenderer(renderer);
renderer.setJSONObject(jsonObject); renderer.setJSONObject(jsonObject);
...@@ -496,17 +472,14 @@ public class ArticleProcessor { ...@@ -496,17 +472,14 @@ public class ArticleProcessor {
@RequestProcessing(value = "/get-article-content", method = HTTPRequestMethod.GET) @RequestProcessing(value = "/get-article-content", method = HTTPRequestMethod.GET)
public void getArticleContent(final HTTPRequestContext context, final HttpServletRequest request) { public void getArticleContent(final HTTPRequestContext context, final HttpServletRequest request) {
final String articleId = request.getParameter("id"); final String articleId = request.getParameter("id");
if (Strings.isEmptyOrNull(articleId)) { if (Strings.isEmptyOrNull(articleId)) {
return; return;
} }
final TextHTMLRenderer renderer = new TextHTMLRenderer(); final TextHTMLRenderer renderer = new TextHTMLRenderer();
context.setRenderer(renderer); context.setRenderer(renderer);
String content; String content;
try { try {
content = articleQueryService.getArticleContent(request, articleId); content = articleQueryService.getArticleContent(request, articleId);
} catch (final ServiceException e) { } catch (final ServiceException e) {
...@@ -582,7 +555,6 @@ public class ArticleProcessor { ...@@ -582,7 +555,6 @@ public class ArticleProcessor {
final JSONObject jsonObject = new JSONObject(); final JSONObject jsonObject = new JSONObject();
String tagTitle = getTagArticlesPagedTag(request.getRequestURI()); String tagTitle = getTagArticlesPagedTag(request.getRequestURI());
try { try {
tagTitle = URLDecoder.decode(tagTitle, "UTF-8"); tagTitle = URLDecoder.decode(tagTitle, "UTF-8");
} catch (final UnsupportedEncodingException e) { } catch (final UnsupportedEncodingException e) {
...@@ -593,7 +565,6 @@ public class ArticleProcessor { ...@@ -593,7 +565,6 @@ public class ArticleProcessor {
final int currentPageNum = getTagArticlesPagedCurrentPageNum(request.getRequestURI()); final int currentPageNum = getTagArticlesPagedCurrentPageNum(request.getRequestURI());
Stopwatchs.start("Get Tag-Articles Paged[tagTitle=" + tagTitle + ", pageNum=" + currentPageNum + ']'); Stopwatchs.start("Get Tag-Articles Paged[tagTitle=" + tagTitle + ", pageNum=" + currentPageNum + ']');
try { try {
jsonObject.put(Keys.STATUS_CODE, true); jsonObject.put(Keys.STATUS_CODE, true);
...@@ -601,7 +572,6 @@ public class ArticleProcessor { ...@@ -601,7 +572,6 @@ public class ArticleProcessor {
final int pageSize = preference.getInt(Option.ID_C_ARTICLE_LIST_DISPLAY_COUNT); final int pageSize = preference.getInt(Option.ID_C_ARTICLE_LIST_DISPLAY_COUNT);
final JSONObject tagQueryResult = tagQueryService.getTagByTitle(tagTitle); final JSONObject tagQueryResult = tagQueryService.getTagByTitle(tagTitle);
if (null == tagQueryResult) { if (null == tagQueryResult) {
throw new Exception("Can not foud tag[title=" + tagTitle + "]"); throw new Exception("Can not foud tag[title=" + tagTitle + "]");
} }
...@@ -614,7 +584,6 @@ public class ArticleProcessor { ...@@ -614,7 +584,6 @@ public class ArticleProcessor {
final int pageCount = (int) Math.ceil((double) tagArticleCount / (double) pageSize); final int pageCount = (int) Math.ceil((double) tagArticleCount / (double) pageSize);
final boolean hasMultipleUsers = userQueryService.hasMultipleUsers(); final boolean hasMultipleUsers = userQueryService.hasMultipleUsers();
if (hasMultipleUsers) { if (hasMultipleUsers) {
filler.setArticlesExProperties(request, articles, preference); filler.setArticlesExProperties(request, articles, preference);
} else if (!articles.isEmpty()) { } else if (!articles.isEmpty()) {
...@@ -627,12 +596,9 @@ public class ArticleProcessor { ...@@ -627,12 +596,9 @@ public class ArticleProcessor {
final JSONObject result = new JSONObject(); final JSONObject result = new JSONObject();
final JSONObject pagination = new JSONObject(); final JSONObject pagination = new JSONObject();
pagination.put(Pagination.PAGINATION_PAGE_COUNT, pageCount); pagination.put(Pagination.PAGINATION_PAGE_COUNT, pageCount);
result.put(Pagination.PAGINATION, pagination); result.put(Pagination.PAGINATION, pagination);
result.put(Article.ARTICLES, articles); result.put(Article.ARTICLES, articles);
jsonObject.put(Keys.RESULTS, result); jsonObject.put(Keys.RESULTS, result);
} catch (final Exception e) { } catch (final Exception e) {
jsonObject.put(Keys.STATUS_CODE, false); jsonObject.put(Keys.STATUS_CODE, false);
...@@ -642,7 +608,6 @@ public class ArticleProcessor { ...@@ -642,7 +608,6 @@ public class ArticleProcessor {
} }
final JSONRenderer renderer = new JSONRenderer(); final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer); context.setRenderer(renderer);
renderer.setJSONObject(jsonObject); renderer.setJSONObject(jsonObject);
} }
...@@ -661,7 +626,6 @@ public class ArticleProcessor { ...@@ -661,7 +626,6 @@ public class ArticleProcessor {
final int currentPageNum = getArchivesArticlesPagedCurrentPageNum(request.getRequestURI()); final int currentPageNum = getArchivesArticlesPagedCurrentPageNum(request.getRequestURI());
Stopwatchs.start("Get Archive-Articles Paged[archive=" + archiveDateString + ", pageNum=" + currentPageNum + ']'); Stopwatchs.start("Get Archive-Articles Paged[archive=" + archiveDateString + ", pageNum=" + currentPageNum + ']');
try { try {
jsonObject.put(Keys.STATUS_CODE, true); jsonObject.put(Keys.STATUS_CODE, true);
...@@ -682,7 +646,6 @@ public class ArticleProcessor { ...@@ -682,7 +646,6 @@ public class ArticleProcessor {
final List<JSONObject> articles = articleQueryService.getArticlesByArchiveDate(archiveDateId, currentPageNum, pageSize); final List<JSONObject> articles = articleQueryService.getArticlesByArchiveDate(archiveDateId, currentPageNum, pageSize);
final boolean hasMultipleUsers = userQueryService.hasMultipleUsers(); final boolean hasMultipleUsers = userQueryService.hasMultipleUsers();
if (hasMultipleUsers) { if (hasMultipleUsers) {
filler.setArticlesExProperties(request, articles, preference); filler.setArticlesExProperties(request, articles, preference);
} else if (!articles.isEmpty()) { } else if (!articles.isEmpty()) {
...@@ -695,12 +658,9 @@ public class ArticleProcessor { ...@@ -695,12 +658,9 @@ public class ArticleProcessor {
final JSONObject result = new JSONObject(); final JSONObject result = new JSONObject();
final JSONObject pagination = new JSONObject(); final JSONObject pagination = new JSONObject();
pagination.put(Pagination.PAGINATION_PAGE_COUNT, pageCount); pagination.put(Pagination.PAGINATION_PAGE_COUNT, pageCount);
result.put(Pagination.PAGINATION, pagination); result.put(Pagination.PAGINATION, pagination);
result.put(Article.ARTICLES, articles); result.put(Article.ARTICLES, articles);
jsonObject.put(Keys.RESULTS, result); jsonObject.put(Keys.RESULTS, result);
} catch (final Exception e) { } catch (final Exception e) {
jsonObject.put(Keys.STATUS_CODE, false); jsonObject.put(Keys.STATUS_CODE, false);
...@@ -710,7 +670,6 @@ public class ArticleProcessor { ...@@ -710,7 +670,6 @@ public class ArticleProcessor {
} }
final JSONRenderer renderer = new JSONRenderer(); final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer); context.setRenderer(renderer);
renderer.setJSONObject(jsonObject); renderer.setJSONObject(jsonObject);
} }
...@@ -730,7 +689,6 @@ public class ArticleProcessor { ...@@ -730,7 +689,6 @@ public class ArticleProcessor {
final int currentPageNum = getAuthorsArticlesPagedCurrentPageNum(request.getRequestURI()); final int currentPageNum = getAuthorsArticlesPagedCurrentPageNum(request.getRequestURI());
Stopwatchs.start("Get Author-Articles Paged[authorId=" + authorId + ", pageNum=" + currentPageNum + ']'); Stopwatchs.start("Get Author-Articles Paged[authorId=" + authorId + ", pageNum=" + currentPageNum + ']');
try { try {
jsonObject.put(Keys.STATUS_CODE, true); jsonObject.put(Keys.STATUS_CODE, true);
...@@ -738,7 +696,6 @@ public class ArticleProcessor { ...@@ -738,7 +696,6 @@ public class ArticleProcessor {
final int pageSize = preference.getInt(Option.ID_C_ARTICLE_LIST_DISPLAY_COUNT); final int pageSize = preference.getInt(Option.ID_C_ARTICLE_LIST_DISPLAY_COUNT);
final JSONObject authorRet = userQueryService.getUser(authorId); final JSONObject authorRet = userQueryService.getUser(authorId);
if (null == authorRet) { if (null == authorRet) {
context.getResponse().sendError(HttpServletResponse.SC_NOT_FOUND); context.getResponse().sendError(HttpServletResponse.SC_NOT_FOUND);
...@@ -749,7 +706,6 @@ public class ArticleProcessor { ...@@ -749,7 +706,6 @@ public class ArticleProcessor {
final String authorEmail = author.optString(User.USER_EMAIL); final String authorEmail = author.optString(User.USER_EMAIL);
final List<JSONObject> articles = articleQueryService.getArticlesByAuthorEmail(authorEmail, currentPageNum, pageSize); final List<JSONObject> articles = articleQueryService.getArticlesByAuthorEmail(authorEmail, currentPageNum, pageSize);
if (!articles.isEmpty()) { if (!articles.isEmpty()) {
filler.setArticlesExProperties(request, articles, author, preference); filler.setArticlesExProperties(request, articles, author, preference);
} }
...@@ -759,12 +715,9 @@ public class ArticleProcessor { ...@@ -759,12 +715,9 @@ public class ArticleProcessor {
final JSONObject result = new JSONObject(); final JSONObject result = new JSONObject();
final JSONObject pagination = new JSONObject(); final JSONObject pagination = new JSONObject();
pagination.put(Pagination.PAGINATION_PAGE_COUNT, pageCount); pagination.put(Pagination.PAGINATION_PAGE_COUNT, pageCount);
result.put(Pagination.PAGINATION, pagination); result.put(Pagination.PAGINATION, pagination);
result.put(Article.ARTICLES, articles); result.put(Article.ARTICLES, articles);
jsonObject.put(Keys.RESULTS, result); jsonObject.put(Keys.RESULTS, result);
} catch (final Exception e) { } catch (final Exception e) {
jsonObject.put(Keys.STATUS_CODE, false); jsonObject.put(Keys.STATUS_CODE, false);
...@@ -774,7 +727,6 @@ public class ArticleProcessor { ...@@ -774,7 +727,6 @@ public class ArticleProcessor {
} }
final JSONRenderer renderer = new JSONRenderer(); final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer); context.setRenderer(renderer);
renderer.setJSONObject(jsonObject); renderer.setJSONObject(jsonObject);
} }
...@@ -792,24 +744,19 @@ public class ArticleProcessor { ...@@ -792,24 +744,19 @@ public class ArticleProcessor {
public void showAuthorArticles(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) public void showAuthorArticles(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response)
throws IOException, JSONException { throws IOException, JSONException {
final AbstractFreeMarkerRenderer renderer = new FreeMarkerRenderer(); final AbstractFreeMarkerRenderer renderer = new FreeMarkerRenderer();
context.setRenderer(renderer); context.setRenderer(renderer);
renderer.setTemplateName("author-articles.ftl"); renderer.setTemplateName("author-articles.ftl");
try { try {
String requestURI = request.getRequestURI(); String requestURI = request.getRequestURI();
if (!requestURI.endsWith("/")) { if (!requestURI.endsWith("/")) {
requestURI += "/"; requestURI += "/";
} }
final String authorId = getAuthorId(requestURI); final String authorId = getAuthorId(requestURI);
LOGGER.log(Level.DEBUG, "Request author articles[requestURI={0}, authorId={1}]", requestURI, authorId); LOGGER.log(Level.DEBUG, "Request author articles[requestURI={0}, authorId={1}]", requestURI, authorId);
final int currentPageNum = getAuthorCurrentPageNum(requestURI, authorId); final int currentPageNum = getAuthorCurrentPageNum(requestURI, authorId);
if (-1 == currentPageNum) { if (-1 == currentPageNum) {
response.sendError(HttpServletResponse.SC_NOT_FOUND); response.sendError(HttpServletResponse.SC_NOT_FOUND);
return; return;
...@@ -818,7 +765,6 @@ public class ArticleProcessor { ...@@ -818,7 +765,6 @@ public class ArticleProcessor {
LOGGER.log(Level.DEBUG, "Request author articles[authorId={0}, currentPageNum={1}]", authorId, currentPageNum); LOGGER.log(Level.DEBUG, "Request author articles[authorId={0}, currentPageNum={1}]", authorId, currentPageNum);
final JSONObject preference = preferenceQueryService.getPreference(); final JSONObject preference = preferenceQueryService.getPreference();
if (null == preference) { if (null == preference) {
response.sendError(HttpServletResponse.SC_NOT_FOUND); response.sendError(HttpServletResponse.SC_NOT_FOUND);
...@@ -829,7 +775,6 @@ public class ArticleProcessor { ...@@ -829,7 +775,6 @@ public class ArticleProcessor {
final int windowSize = preference.getInt(Option.ID_C_ARTICLE_LIST_PAGINATION_WINDOW_SIZE); final int windowSize = preference.getInt(Option.ID_C_ARTICLE_LIST_PAGINATION_WINDOW_SIZE);
final JSONObject result = userQueryService.getUser(authorId); final JSONObject result = userQueryService.getUser(authorId);
if (null == result) { if (null == result) {
response.sendError(HttpServletResponse.SC_NOT_FOUND); response.sendError(HttpServletResponse.SC_NOT_FOUND);
...@@ -839,7 +784,6 @@ public class ArticleProcessor { ...@@ -839,7 +784,6 @@ public class ArticleProcessor {
final JSONObject author = result.getJSONObject(User.USER); final JSONObject author = result.getJSONObject(User.USER);
final String authorEmail = author.getString(User.USER_EMAIL); final String authorEmail = author.getString(User.USER_EMAIL);
final List<JSONObject> articles = articleQueryService.getArticlesByAuthorEmail(authorEmail, currentPageNum, pageSize); final List<JSONObject> articles = articleQueryService.getArticlesByAuthorEmail(authorEmail, currentPageNum, pageSize);
if (articles.isEmpty()) { if (articles.isEmpty()) {
try { try {
response.sendError(HttpServletResponse.SC_NOT_FOUND); response.sendError(HttpServletResponse.SC_NOT_FOUND);
...@@ -893,14 +837,11 @@ public class ArticleProcessor { ...@@ -893,14 +837,11 @@ public class ArticleProcessor {
public void showArchiveArticles(final HTTPRequestContext context, public void showArchiveArticles(final HTTPRequestContext context,
final HttpServletRequest request, final HttpServletResponse response) { final HttpServletRequest request, final HttpServletResponse response) {
final AbstractFreeMarkerRenderer renderer = new FreeMarkerRenderer(); final AbstractFreeMarkerRenderer renderer = new FreeMarkerRenderer();
context.setRenderer(renderer); context.setRenderer(renderer);
renderer.setTemplateName("archive-articles.ftl"); renderer.setTemplateName("archive-articles.ftl");
try { try {
String requestURI = request.getRequestURI(); String requestURI = request.getRequestURI();
if (!requestURI.endsWith("/")) { if (!requestURI.endsWith("/")) {
requestURI += "/"; requestURI += "/";
} }
...@@ -913,7 +854,6 @@ public class ArticleProcessor { ...@@ -913,7 +854,6 @@ public class ArticleProcessor {
} }
final String archiveDateString = getArchiveDate(requestURI); final String archiveDateString = getArchiveDate(requestURI);
LOGGER.log(Level.DEBUG, "Request archive date[string={0}, currentPageNum={1}]", archiveDateString, currentPageNum); LOGGER.log(Level.DEBUG, "Request archive date[string={0}, currentPageNum={1}]", archiveDateString, currentPageNum);
final JSONObject result = archiveDateQueryService.getByArchiveDateString(archiveDateString); final JSONObject result = archiveDateQueryService.getByArchiveDateString(archiveDateString);
if (null == result) { if (null == result) {
...@@ -933,7 +873,6 @@ public class ArticleProcessor { ...@@ -933,7 +873,6 @@ public class ArticleProcessor {
final int pageCount = (int) Math.ceil((double) articleCount / (double) pageSize); final int pageCount = (int) Math.ceil((double) articleCount / (double) pageSize);
final List<JSONObject> articles = articleQueryService.getArticlesByArchiveDate(archiveDateId, currentPageNum, pageSize); final List<JSONObject> articles = articleQueryService.getArticlesByArchiveDate(archiveDateId, currentPageNum, pageSize);
if (articles.isEmpty()) { if (articles.isEmpty()) {
try { try {
response.sendError(HttpServletResponse.SC_NOT_FOUND); response.sendError(HttpServletResponse.SC_NOT_FOUND);
...@@ -944,7 +883,6 @@ public class ArticleProcessor { ...@@ -944,7 +883,6 @@ public class ArticleProcessor {
} }
final boolean hasMultipleUsers = userQueryService.hasMultipleUsers(); final boolean hasMultipleUsers = userQueryService.hasMultipleUsers();
if (hasMultipleUsers) { if (hasMultipleUsers) {
filler.setArticlesExProperties(request, articles, preference); filler.setArticlesExProperties(request, articles, preference);
} else if (!articles.isEmpty()) { } else if (!articles.isEmpty()) {
...@@ -1012,7 +950,6 @@ public class ArticleProcessor { ...@@ -1012,7 +950,6 @@ public class ArticleProcessor {
throws IOException { throws IOException {
// See PermalinkFilter#dispatchToArticleOrPageProcessor() // See PermalinkFilter#dispatchToArticleOrPageProcessor()
final JSONObject article = (JSONObject) request.getAttribute(Article.ARTICLE); final JSONObject article = (JSONObject) request.getAttribute(Article.ARTICLE);
if (null == article) { if (null == article) {
response.sendError(HttpServletResponse.SC_NOT_FOUND); response.sendError(HttpServletResponse.SC_NOT_FOUND);
return; return;
...@@ -1021,8 +958,8 @@ public class ArticleProcessor { ...@@ -1021,8 +958,8 @@ public class ArticleProcessor {
final String articleId = article.optString(Keys.OBJECT_ID); final String articleId = article.optString(Keys.OBJECT_ID);
LOGGER.log(Level.DEBUG, "Article[id={0}]", articleId); LOGGER.log(Level.DEBUG, "Article[id={0}]", articleId);
final AbstractFreeMarkerRenderer renderer = new FreeMarkerRenderer();
final AbstractFreeMarkerRenderer renderer = new FreeMarkerRenderer();
context.setRenderer(renderer); context.setRenderer(renderer);
renderer.setTemplateName("article.ftl"); renderer.setTemplateName("article.ftl");
...@@ -1030,7 +967,6 @@ public class ArticleProcessor { ...@@ -1030,7 +967,6 @@ public class ArticleProcessor {
final JSONObject preference = preferenceQueryService.getPreference(); final JSONObject preference = preferenceQueryService.getPreference();
final boolean allowVisitDraftViaPermalink = preference.getBoolean(Option.ID_C_ALLOW_VISIT_DRAFT_VIA_PERMALINK); final boolean allowVisitDraftViaPermalink = preference.getBoolean(Option.ID_C_ALLOW_VISIT_DRAFT_VIA_PERMALINK);
if (!article.optBoolean(Article.ARTICLE_IS_PUBLISHED) && !allowVisitDraftViaPermalink) { if (!article.optBoolean(Article.ARTICLE_IS_PUBLISHED) && !allowVisitDraftViaPermalink) {
response.sendError(HttpServletResponse.SC_NOT_FOUND); response.sendError(HttpServletResponse.SC_NOT_FOUND);
...@@ -1108,11 +1044,10 @@ public class ArticleProcessor { ...@@ -1108,11 +1044,10 @@ public class ArticleProcessor {
* *
* @param preference the specified preference * @param preference the specified preference
* @param articles the specified articles * @param articles the specified articles
* @throws JSONException json exception
* @see Comparators#ARTICLE_UPDATE_DATE_COMPARATOR * @see Comparators#ARTICLE_UPDATE_DATE_COMPARATOR
* @see Comparators#ARTICLE_CREATE_DATE_COMPARATOR * @see Comparators#ARTICLE_CREATE_DATE_COMPARATOR
*/ */
private void sort(final JSONObject preference, final List<JSONObject> articles) throws JSONException { private void sort(final JSONObject preference, final List<JSONObject> articles) {
// if (preference.getBoolean(Option.ID_C_ENABLE_ARTICLE_UPDATE_HINT)) { // if (preference.getBoolean(Option.ID_C_ENABLE_ARTICLE_UPDATE_HINT)) {
// Collections.sort(articles, Comparators.ARTICLE_UPDATE_DATE_COMPARATOR); // Collections.sort(articles, Comparators.ARTICLE_UPDATE_DATE_COMPARATOR);
// } else { // } else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment