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

🎨 摘要生成重构

parent 99ceb1f4
......@@ -67,7 +67,7 @@ import java.util.List;
* </p>
*
* @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
*/
@RequestProcessor
......@@ -153,11 +153,6 @@ public class MetaWeblogAPI {
*/
private static final int INDEX_PUBLISH = 4;
/**
* Article abstract length.
*/
private static final int ARTICLE_ABSTRACT_LENGTH = 500;
/**
* Preference query service.
*/
......@@ -375,14 +370,7 @@ public class MetaWeblogAPI {
final String content = member.getJSONObject("value").getString("string");
ret.put(Article.ARTICLE_CONTENT, content);
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);
}
ret.put(Article.ARTICLE_ABSTRACT, Article.getAbstract(Jsoup.parse(content).text()));
} else if ("categories".equals(name)) {
final StringBuilder tagBuilder = new StringBuilder();
......
......@@ -34,11 +34,8 @@ import org.b3log.solo.service.ArticleMgmtService;
import org.b3log.solo.service.ArticleQueryService;
import org.b3log.solo.service.PreferenceQueryService;
import org.b3log.solo.service.UserQueryService;
import org.b3log.solo.util.Markdowns;
import org.b3log.solo.util.QueryResults;
import org.json.JSONObject;
import org.jsoup.Jsoup;
import org.jsoup.safety.Whitelist;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
......@@ -47,7 +44,7 @@ import javax.servlet.http.HttpServletResponse;
* Article receiver (from B3log Symphony).
*
* @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
*/
@RequestProcessor
......@@ -56,26 +53,26 @@ public class ArticleReceiver {
/**
* Logger.
*/
private static final Logger LOGGER = Logger.getLogger(ArticleReceiver.class.getName());
/**
* Article abstract length.
*/
private static final int ARTICLE_ABSTRACT_LENGTH = 500;
private static final Logger LOGGER = Logger.getLogger(ArticleReceiver.class);
/**
* Preference query service.
*/
@Inject
private PreferenceQueryService preferenceQueryService;
/**
* Article management service.
*/
@Inject
private ArticleMgmtService articleMgmtService;
/**
* Article query service.
*/
@Inject
private ArticleQueryService articleQueryService;
/**
* User query service.
*/
......@@ -134,12 +131,7 @@ public class ArticleReceiver {
article.put(Article.ARTICLE_AUTHOR_EMAIL, admin.getString(User.USER_EMAIL));
final String articleContent = article.optString(Article.ARTICLE_CONTENT);
final String plainTextContent = Jsoup.clean(Markdowns.toHTML(articleContent), Whitelist.none());
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_ABSTRACT, Article.getAbstract(articleContent));
article.put(Article.ARTICLE_IS_PUBLISHED, true);
article.put(Common.POST_TO_COMMUNITY, false); // Do not send to rhythm
article.put(Article.ARTICLE_COMMENTABLE, true);
......@@ -227,12 +219,7 @@ public class ArticleReceiver {
}
final String articleContent = article.optString(Article.ARTICLE_CONTENT);
final String plainTextContent = Jsoup.clean(Markdowns.toHTML(articleContent), Whitelist.none());
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_ABSTRACT, Article.getAbstract(articleContent));
article.put(Article.ARTICLE_IS_PUBLISHED, true);
article.put(Common.POST_TO_COMMUNITY, false); // Do not send to rhythm
article.put(Article.ARTICLE_COMMENTABLE, true);
......
......@@ -15,12 +15,15 @@
*/
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.
*
* @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
*/
public final class Article {
......@@ -137,13 +140,34 @@ public final class Article {
/**
* Key of article editor type.
*
* @see Preference#EDITOR_TYPE
*/
public static final String ARTICLE_EDITOR_TYPE = "articleEditorType";
//// constants
/**
* Article abstract length.
*/
private static final int ARTICLE_ABSTRACT_LENGTH = 500;
/**
* 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