Commit 3a3b812a authored by Liang Ding's avatar Liang Ding

Fix #11984

parent b656bcfe
...@@ -17,18 +17,28 @@ package org.b3log.solo.processor; ...@@ -17,18 +17,28 @@ package org.b3log.solo.processor;
import javax.inject.Inject; import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.b3log.latke.Keys;
import org.b3log.latke.Latkes; import org.b3log.latke.Latkes;
import org.b3log.latke.RuntimeEnv; import org.b3log.latke.RuntimeEnv;
import org.b3log.latke.model.Pagination;
import org.b3log.latke.model.User;
import org.b3log.latke.servlet.HTTPRequestContext; import org.b3log.latke.servlet.HTTPRequestContext;
import org.b3log.latke.servlet.HTTPRequestMethod; import org.b3log.latke.servlet.HTTPRequestMethod;
import org.b3log.latke.servlet.annotation.RequestProcessing; import org.b3log.latke.servlet.annotation.RequestProcessing;
import org.b3log.latke.servlet.annotation.RequestProcessor; import org.b3log.latke.servlet.annotation.RequestProcessor;
import org.b3log.latke.servlet.renderer.JSONRenderer; import org.b3log.latke.servlet.renderer.JSONRenderer;
import org.b3log.latke.util.MD5;
import org.b3log.latke.util.Strings;
import org.b3log.solo.SoloServletListener; import org.b3log.solo.SoloServletListener;
import org.b3log.solo.model.Article;
import org.b3log.solo.model.Statistic; import org.b3log.solo.model.Statistic;
import org.b3log.solo.service.ArticleQueryService; import org.b3log.solo.service.ArticleQueryService;
import org.b3log.solo.service.StatisticQueryService; import org.b3log.solo.service.StatisticQueryService;
import org.b3log.solo.service.TagQueryService; import org.b3log.solo.service.TagQueryService;
import org.b3log.solo.service.UserQueryService;
import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
...@@ -36,7 +46,7 @@ import org.json.JSONObject; ...@@ -36,7 +46,7 @@ import org.json.JSONObject;
* Blog processor. * Blog processor.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.2, Jan 29, 2013 * @version 1.1.0.3, Jul 18, 2014
* @since 0.4.6 * @since 0.4.6
*/ */
@RequestProcessor @RequestProcessor
...@@ -60,6 +70,12 @@ public class BlogProcessor { ...@@ -60,6 +70,12 @@ public class BlogProcessor {
@Inject @Inject
private StatisticQueryService statisticQueryService; private StatisticQueryService statisticQueryService;
/**
* User query service.
*/
@Inject
private UserQueryService userQueryService;
/** /**
* Gets blog information. * Gets blog information.
* *
...@@ -106,4 +122,95 @@ public class BlogProcessor { ...@@ -106,4 +122,95 @@ public class BlogProcessor {
jsonObject.put("runtimeDatabase", Latkes.getRuntimeDatabase()); jsonObject.put("runtimeDatabase", Latkes.getRuntimeDatabase());
} }
} }
/**
* Gets tags of all articles.
*
* <pre>
* {
* "data": [
* ["tag1", "tag2", ....], // tags of one article
* ["tagX", "tagY", ....], // tags of another article
* ....
* ]
* }
* </pre>
*
* @param context the specified context
* @param request the specified HTTP servlet request
* @param response the specified HTTP servlet response
* @throws Exception io exception
*/
@RequestProcessing(value = "/blog/articles-tags", method = HTTPRequestMethod.GET)
public void getArticlesTags(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response)
throws Exception {
final String pwd = request.getParameter("pwd");
if (Strings.isEmptyOrNull(pwd)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
final JSONObject admin = userQueryService.getAdmin();
if (!MD5.hash(pwd).equals(admin.getString(User.USER_PASSWORD))) {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
final JSONObject requestJSONObject = new JSONObject();
requestJSONObject.put(Pagination.PAGINATION_CURRENT_PAGE_NUM, 1);
requestJSONObject.put(Pagination.PAGINATION_PAGE_SIZE, Integer.MAX_VALUE);
requestJSONObject.put(Pagination.PAGINATION_WINDOW_SIZE, Integer.MAX_VALUE);
requestJSONObject.put(Article.ARTICLE_IS_PUBLISHED, true);
final JSONArray excludes = new JSONArray();
excludes.put(Article.ARTICLE_CONTENT);
excludes.put(Article.ARTICLE_UPDATE_DATE);
excludes.put(Article.ARTICLE_CREATE_DATE);
excludes.put(Article.ARTICLE_AUTHOR_EMAIL);
excludes.put(Article.ARTICLE_HAD_BEEN_PUBLISHED);
excludes.put(Article.ARTICLE_IS_PUBLISHED);
excludes.put(Article.ARTICLE_RANDOM_DOUBLE);
requestJSONObject.put(Keys.EXCLUDES, excludes);
final JSONObject result = articleQueryService.getArticles(requestJSONObject);
final JSONArray articles = result.optJSONArray(Article.ARTICLES);
final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer);
final JSONObject ret = new JSONObject();
renderer.setJSONObject(ret);
final JSONArray data = new JSONArray();
ret.put("data", data);
for (int i = 0; i < articles.length(); i++) {
final JSONObject article = articles.optJSONObject(i);
final String tagString = article.optString(Article.ARTICLE_TAGS_REF);
final JSONArray tagArray = new JSONArray();
data.put(tagArray);
final String[] tags = tagString.split(",");
for (final String tag : tags) {
final String trim = tag.trim();
if (!Strings.isEmptyOrNull(trim)) {
tagArray.put(tag);
}
}
}
}
} }
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- <!--
Description: B3log Solo parent POM. Description: B3log Solo parent POM.
Version: 2.0.4.13, Jul 14, 2014 Version: 2.0.4.14, Jul 18, 2014
Author: Liang Ding Author: Liang Ding
--> -->
<project xmlns="http://maven.apache.org/POM/4.0.0" <project xmlns="http://maven.apache.org/POM/4.0.0"
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
<properties> <properties>
<servlet.version>2.5</servlet.version> <servlet.version>2.5</servlet.version>
<slf4j.version>1.7.5</slf4j.version> <slf4j.version>1.7.5</slf4j.version>
<org.b3log.latke.version>1.0.13</org.b3log.latke.version> <org.b3log.latke.version>1.0.15</org.b3log.latke.version>
<maven-gae-plugin.version>0.9.0</maven-gae-plugin.version> <maven-gae-plugin.version>0.9.0</maven-gae-plugin.version>
<gae.version>1.8.1.1</gae.version> <gae.version>1.8.1.1</gae.version>
...@@ -37,7 +37,6 @@ ...@@ -37,7 +37,6 @@
<freemarker-gae.version>2.3.20</freemarker-gae.version> <freemarker-gae.version>2.3.20</freemarker-gae.version>
<jsoup.version>1.5.2</jsoup.version> <jsoup.version>1.5.2</jsoup.version>
<markdownpapers-core.version>1.3.2</markdownpapers-core.version> <markdownpapers-core.version>1.3.2</markdownpapers-core.version>
<!-- <com.google.api.client.version>1.2.1-alpha</com.google.api.client.version>-->
<!-- maven plugin --> <!-- maven plugin -->
<maven-compiler-plugin.version>2.3.2</maven-compiler-plugin.version> <maven-compiler-plugin.version>2.3.2</maven-compiler-plugin.version>
<maven-resources-plugin.version>2.5</maven-resources-plugin.version> <maven-resources-plugin.version>2.5</maven-resources-plugin.version>
......
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