Commit 81d4b081 authored by Liang Ding's avatar Liang Ding

🎨 摘要生成重构

parent 99ceb1f4
...@@ -67,7 +67,7 @@ import java.util.List; ...@@ -67,7 +67,7 @@ import java.util.List;
* </p> * </p>
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.13, Jun 8, 2017 * @version 1.0.0.14, Jun 25, 2017
* @since 0.4.0 * @since 0.4.0
*/ */
@RequestProcessor @RequestProcessor
...@@ -153,11 +153,6 @@ public class MetaWeblogAPI { ...@@ -153,11 +153,6 @@ public class MetaWeblogAPI {
*/ */
private static final int INDEX_PUBLISH = 4; private static final int INDEX_PUBLISH = 4;
/**
* Article abstract length.
*/
private static final int ARTICLE_ABSTRACT_LENGTH = 500;
/** /**
* Preference query service. * Preference query service.
*/ */
...@@ -375,14 +370,7 @@ public class MetaWeblogAPI { ...@@ -375,14 +370,7 @@ public class MetaWeblogAPI {
final String content = member.getJSONObject("value").getString("string"); final String content = member.getJSONObject("value").getString("string");
ret.put(Article.ARTICLE_CONTENT, content); ret.put(Article.ARTICLE_CONTENT, content);
ret.put(Article.ARTICLE_ABSTRACT, Article.getAbstract(Jsoup.parse(content).text()));
final String plainTextContent = Jsoup.parse(content).text();
if (plainTextContent.length() > ARTICLE_ABSTRACT_LENGTH) {
ret.put(Article.ARTICLE_ABSTRACT, plainTextContent.substring(0, ARTICLE_ABSTRACT_LENGTH));
} else {
ret.put(Article.ARTICLE_ABSTRACT, plainTextContent);
}
} else if ("categories".equals(name)) { } else if ("categories".equals(name)) {
final StringBuilder tagBuilder = new StringBuilder(); final StringBuilder tagBuilder = new StringBuilder();
......
...@@ -34,11 +34,8 @@ import org.b3log.solo.service.ArticleMgmtService; ...@@ -34,11 +34,8 @@ import org.b3log.solo.service.ArticleMgmtService;
import org.b3log.solo.service.ArticleQueryService; import org.b3log.solo.service.ArticleQueryService;
import org.b3log.solo.service.PreferenceQueryService; import org.b3log.solo.service.PreferenceQueryService;
import org.b3log.solo.service.UserQueryService; import org.b3log.solo.service.UserQueryService;
import org.b3log.solo.util.Markdowns;
import org.b3log.solo.util.QueryResults; import org.b3log.solo.util.QueryResults;
import org.json.JSONObject; import org.json.JSONObject;
import org.jsoup.Jsoup;
import org.jsoup.safety.Whitelist;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
...@@ -47,7 +44,7 @@ import javax.servlet.http.HttpServletResponse; ...@@ -47,7 +44,7 @@ import javax.servlet.http.HttpServletResponse;
* Article receiver (from B3log Symphony). * Article receiver (from B3log Symphony).
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.3.7, Jan 15, 2017 * @version 1.0.3.8, Jan 25, 2017
* @since 0.5.5 * @since 0.5.5
*/ */
@RequestProcessor @RequestProcessor
...@@ -56,26 +53,26 @@ public class ArticleReceiver { ...@@ -56,26 +53,26 @@ public class ArticleReceiver {
/** /**
* Logger. * Logger.
*/ */
private static final Logger LOGGER = Logger.getLogger(ArticleReceiver.class.getName()); private static final Logger LOGGER = Logger.getLogger(ArticleReceiver.class);
/**
* Article abstract length.
*/
private static final int ARTICLE_ABSTRACT_LENGTH = 500;
/** /**
* Preference query service. * Preference query service.
*/ */
@Inject @Inject
private PreferenceQueryService preferenceQueryService; private PreferenceQueryService preferenceQueryService;
/** /**
* Article management service. * Article management service.
*/ */
@Inject @Inject
private ArticleMgmtService articleMgmtService; private ArticleMgmtService articleMgmtService;
/** /**
* Article query service. * Article query service.
*/ */
@Inject @Inject
private ArticleQueryService articleQueryService; private ArticleQueryService articleQueryService;
/** /**
* User query service. * User query service.
*/ */
...@@ -134,12 +131,7 @@ public class ArticleReceiver { ...@@ -134,12 +131,7 @@ public class ArticleReceiver {
article.put(Article.ARTICLE_AUTHOR_EMAIL, admin.getString(User.USER_EMAIL)); article.put(Article.ARTICLE_AUTHOR_EMAIL, admin.getString(User.USER_EMAIL));
final String articleContent = article.optString(Article.ARTICLE_CONTENT); final String articleContent = article.optString(Article.ARTICLE_CONTENT);
final String plainTextContent = Jsoup.clean(Markdowns.toHTML(articleContent), Whitelist.none()); article.put(Article.ARTICLE_ABSTRACT, Article.getAbstract(articleContent));
if (plainTextContent.length() > ARTICLE_ABSTRACT_LENGTH) {
article.put(Article.ARTICLE_ABSTRACT, plainTextContent.substring(0, ARTICLE_ABSTRACT_LENGTH) + "....");
} else {
article.put(Article.ARTICLE_ABSTRACT, plainTextContent);
}
article.put(Article.ARTICLE_IS_PUBLISHED, true); article.put(Article.ARTICLE_IS_PUBLISHED, true);
article.put(Common.POST_TO_COMMUNITY, false); // Do not send to rhythm article.put(Common.POST_TO_COMMUNITY, false); // Do not send to rhythm
article.put(Article.ARTICLE_COMMENTABLE, true); article.put(Article.ARTICLE_COMMENTABLE, true);
...@@ -227,12 +219,7 @@ public class ArticleReceiver { ...@@ -227,12 +219,7 @@ public class ArticleReceiver {
} }
final String articleContent = article.optString(Article.ARTICLE_CONTENT); final String articleContent = article.optString(Article.ARTICLE_CONTENT);
final String plainTextContent = Jsoup.clean(Markdowns.toHTML(articleContent), Whitelist.none()); article.put(Article.ARTICLE_ABSTRACT, Article.getAbstract(articleContent));
if (plainTextContent.length() > ARTICLE_ABSTRACT_LENGTH) {
article.put(Article.ARTICLE_ABSTRACT, plainTextContent.substring(0, ARTICLE_ABSTRACT_LENGTH) + "....");
} else {
article.put(Article.ARTICLE_ABSTRACT, plainTextContent);
}
article.put(Article.ARTICLE_IS_PUBLISHED, true); article.put(Article.ARTICLE_IS_PUBLISHED, true);
article.put(Common.POST_TO_COMMUNITY, false); // Do not send to rhythm article.put(Common.POST_TO_COMMUNITY, false); // Do not send to rhythm
article.put(Article.ARTICLE_COMMENTABLE, true); article.put(Article.ARTICLE_COMMENTABLE, true);
......
...@@ -15,12 +15,15 @@ ...@@ -15,12 +15,15 @@
*/ */
package org.b3log.solo.model; package org.b3log.solo.model;
import org.b3log.solo.util.Markdowns;
import org.jsoup.Jsoup;
import org.jsoup.safety.Whitelist;
/** /**
* This class defines all article model relevant keys. * This class defines all article model relevant keys.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.1.6, Jan 8, 2013 * @version 1.1.1.6, Jun 25, 2017
* @since 0.3.1 * @since 0.3.1
*/ */
public final class Article { public final class Article {
...@@ -137,13 +140,34 @@ public final class Article { ...@@ -137,13 +140,34 @@ public final class Article {
/** /**
* Key of article editor type. * Key of article editor type.
*
* @see Preference#EDITOR_TYPE
*/ */
public static final String ARTICLE_EDITOR_TYPE = "articleEditorType"; public static final String ARTICLE_EDITOR_TYPE = "articleEditorType";
//// constants
/**
* Article abstract length.
*/
private static final int ARTICLE_ABSTRACT_LENGTH = 500;
/** /**
* Private default constructor. * Private default constructor.
*/ */
private Article() {} private Article() {
}
/**
* Gets the abstract of the specified content.
*
* @param content the specified content
* @return the abstract
*/
public static String getAbstract(final String content) {
final String plainTextContent = Jsoup.clean(Markdowns.toHTML(content), Whitelist.none());
if (plainTextContent.length() > ARTICLE_ABSTRACT_LENGTH) {
return plainTextContent.substring(0, ARTICLE_ABSTRACT_LENGTH) + "....";
}
return plainTextContent;
}
} }
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