Commit 347b3701 authored by Liang Ding's avatar Liang Ding

🎨 Cleanup code

parent 227b727b
...@@ -21,7 +21,6 @@ import org.b3log.latke.ioc.inject.Inject; ...@@ -21,7 +21,6 @@ import org.b3log.latke.ioc.inject.Inject;
import org.b3log.latke.logging.Level; import org.b3log.latke.logging.Level;
import org.b3log.latke.logging.Logger; import org.b3log.latke.logging.Logger;
import org.b3log.latke.model.User; import org.b3log.latke.model.User;
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;
...@@ -41,7 +40,7 @@ import java.util.Date; ...@@ -41,7 +40,7 @@ import java.util.Date;
* Generates some dummy articles for development testing. * Generates some dummy articles for development testing.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.5, Jul 9, 2017 * @version 1.0.0.6, Apr 15, 2018
* @since 0.4.0 * @since 0.4.0
*/ */
@RequestProcessor @RequestProcessor
...@@ -67,13 +66,12 @@ public class ArticleGenerator { ...@@ -67,13 +66,12 @@ public class ArticleGenerator {
/** /**
* Generates some dummy articles with the specified context. * Generates some dummy articles with the specified context.
* *
* @param context the specified context
* @param request the specified request * @param request the specified request
* @param response the specified response * @param response the specified response
* @throws IOException io exception * @throws IOException io exception
*/ */
@RequestProcessing(value = "/dev/articles/gen/*", method = HTTPRequestMethod.GET) @RequestProcessing(value = "/dev/articles/gen/*", method = HTTPRequestMethod.GET)
public void genArticles(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) public void genArticles(final HttpServletRequest request, final HttpServletResponse response)
throws IOException { throws IOException {
if (Latkes.RuntimeMode.DEVELOPMENT != Latkes.getRuntimeMode()) { if (Latkes.RuntimeMode.DEVELOPMENT != Latkes.getRuntimeMode()) {
LOGGER.log(Level.WARN, "Article generation just for development mode, " + "current runtime mode is [{0}]", LOGGER.log(Level.WARN, "Article generation just for development mode, " + "current runtime mode is [{0}]",
......
...@@ -43,7 +43,7 @@ import org.json.JSONObject; ...@@ -43,7 +43,7 @@ import org.json.JSONObject;
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="http://www.wanglay.com">Lei Wang</a> * @author <a href="http://www.wanglay.com">Lei Wang</a>
* @version 1.2.2.8, Jul 20, 2017 * @version 1.2.2.9, Apr 15, 2018
* @since 0.3.1 * @since 0.3.1
*/ */
public final class ArticleCommentReplyNotifier extends AbstractEventListener<JSONObject> { public final class ArticleCommentReplyNotifier extends AbstractEventListener<JSONObject> {
...@@ -64,11 +64,9 @@ public final class ArticleCommentReplyNotifier extends AbstractEventListener<JSO ...@@ -64,11 +64,9 @@ public final class ArticleCommentReplyNotifier extends AbstractEventListener<JSO
final JSONObject comment = eventData.optJSONObject(Comment.COMMENT); final JSONObject comment = eventData.optJSONObject(Comment.COMMENT);
final JSONObject article = eventData.optJSONObject(Article.ARTICLE); final JSONObject article = eventData.optJSONObject(Article.ARTICLE);
LOGGER.log(Level.DEBUG, LOGGER.log(Level.DEBUG, "Processing an event[type={0}, data={1}] in listener[className={2}]",
"Processing an event[type={0}, data={1}] in listener[className={2}]",
event.getType(), eventData, ArticleCommentReplyNotifier.class.getName()); event.getType(), eventData, ArticleCommentReplyNotifier.class.getName());
final String originalCommentId = comment.optString(Comment.COMMENT_ORIGINAL_COMMENT_ID); final String originalCommentId = comment.optString(Comment.COMMENT_ORIGINAL_COMMENT_ID);
if (Strings.isEmptyOrNull(originalCommentId)) { if (Strings.isEmptyOrNull(originalCommentId)) {
LOGGER.log(Level.DEBUG, "This comment[id={0}] is not a reply", comment.optString(Keys.OBJECT_ID)); LOGGER.log(Level.DEBUG, "This comment[id={0}] is not a reply", comment.optString(Keys.OBJECT_ID));
...@@ -87,7 +85,6 @@ public final class ArticleCommentReplyNotifier extends AbstractEventListener<JSO ...@@ -87,7 +85,6 @@ public final class ArticleCommentReplyNotifier extends AbstractEventListener<JSO
final LatkeBeanManager beanManager = Lifecycle.getBeanManager(); final LatkeBeanManager beanManager = Lifecycle.getBeanManager();
final PreferenceQueryService preferenceQueryService = beanManager.getReference(PreferenceQueryService.class); final PreferenceQueryService preferenceQueryService = beanManager.getReference(PreferenceQueryService.class);
final CommentRepository commentRepository = beanManager.getReference(CommentRepositoryImpl.class); final CommentRepository commentRepository = beanManager.getReference(CommentRepositoryImpl.class);
try { try {
......
...@@ -42,7 +42,7 @@ import org.json.JSONObject; ...@@ -42,7 +42,7 @@ import org.json.JSONObject;
* This listener is responsible for processing page comment reply. * This listener is responsible for processing page comment reply.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.2.4, Jul 20, 2017 * @version 1.0.2.5, Apr 15, 2018
* @since 0.3.1 * @since 0.3.1
*/ */
public final class PageCommentReplyNotifier extends AbstractEventListener<JSONObject> { public final class PageCommentReplyNotifier extends AbstractEventListener<JSONObject> {
...@@ -78,7 +78,6 @@ public final class PageCommentReplyNotifier extends AbstractEventListener<JSONOb ...@@ -78,7 +78,6 @@ public final class PageCommentReplyNotifier extends AbstractEventListener<JSONOb
final LatkeBeanManager beanManager = Lifecycle.getBeanManager(); final LatkeBeanManager beanManager = Lifecycle.getBeanManager();
final PreferenceQueryService preferenceQueryService = beanManager.getReference(PreferenceQueryService.class); final PreferenceQueryService preferenceQueryService = beanManager.getReference(PreferenceQueryService.class);
final CommentRepository commentRepository = beanManager.getReference(CommentRepositoryImpl.class); final CommentRepository commentRepository = beanManager.getReference(CommentRepositoryImpl.class);
try { try {
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
*/ */
package org.b3log.solo.event.ping; package org.b3log.solo.event.ping;
import org.b3log.latke.Latkes; import org.b3log.latke.Latkes;
import org.b3log.latke.event.AbstractEventListener; import org.b3log.latke.event.AbstractEventListener;
import org.b3log.latke.event.Event; import org.b3log.latke.event.Event;
...@@ -36,20 +35,17 @@ import org.json.JSONObject; ...@@ -36,20 +35,17 @@ import org.json.JSONObject;
import java.net.URL; import java.net.URL;
import java.net.URLEncoder; import java.net.URLEncoder;
/** /**
* This listener is responsible for pinging <a href="http://blogsearch.google.com"> * This listener is responsible for pinging <a href="http://blogsearch.google.com">Google Blog Search Service</a>
* Google Blog Search Service</a> asynchronously while adding an article. * asynchronously while adding an article.
* *
* <p> * <li>
* <li> * <a href="http://www.google.com/help/blogsearch/pinging_API.html">
* <a href="http://www.google.com/help/blogsearch/pinging_API.html"> * About Google Blog Search Pinging Service API</a>
* About Google Blog Search Pinging Service API</a> * </li>
* </li>
* </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.4, Nov 20, 2015 * @version 1.0.0.5, Apr 15, 2018
* @see UpdateArticleGoogleBlogSearchPinger * @see UpdateArticleGoogleBlogSearchPinger
* @since 0.3.1 * @since 0.3.1
*/ */
...@@ -92,25 +88,26 @@ public final class AddArticleGoogleBlogSearchPinger extends AbstractEventListene ...@@ -92,25 +88,26 @@ public final class AddArticleGoogleBlogSearchPinger extends AbstractEventListene
final String blogTitle = preference.getString(Option.ID_C_BLOG_TITLE); final String blogTitle = preference.getString(Option.ID_C_BLOG_TITLE);
if (Latkes.getServePath().contains("localhost")) { if (Latkes.getServePath().contains("localhost")) {
LOGGER.log(Level.TRACE, LOGGER.log(Level.TRACE, "Solo runs on local server, so should not ping " +
"Solo runs on local server, so should not ping " + "Google Blog Search Service for the article[title={0}]", "Google Blog Search Service for the article[title={0}]",
article.getString(Article.ARTICLE_TITLE)); article.getString(Article.ARTICLE_TITLE));
return; return;
} }
final String articlePermalink = Latkes.getServePath() + article.getString(Article.ARTICLE_PERMALINK); final String articlePermalink = Latkes.getServePath() + article.getString(Article.ARTICLE_PERMALINK);
final String spec = "http://blogsearch.google.com/ping?name=" + URLEncoder.encode(blogTitle, "UTF-8") + "&url=" final String spec = "http://blogsearch.google.com/ping?name=" + URLEncoder.encode(blogTitle, "UTF-8") +
+ URLEncoder.encode(Latkes.getServePath(), "UTF-8") + "&changesURL=" + URLEncoder.encode(articlePermalink, "UTF-8"); "&url=" + URLEncoder.encode(Latkes.getServePath(), "UTF-8") +
"&changesURL=" + URLEncoder.encode(articlePermalink, "UTF-8");
LOGGER.log(Level.DEBUG, "Request Google Blog Search Service API[{0}] while adding an " + "article[title=" + articleTitle + "]", LOGGER.log(Level.DEBUG, "Request Google Blog Search Service API[{0}] while adding an "
spec); + "article[title=" + articleTitle + "]", spec);
final HTTPRequest request = new HTTPRequest(); final HTTPRequest request = new HTTPRequest();
request.setURL(new URL(spec)); request.setURL(new URL(spec));
URL_FETCH_SERVICE.fetchAsync(request); URL_FETCH_SERVICE.fetchAsync(request);
} catch (final Exception e) { } catch (final Exception e) {
LOGGER.log(Level.ERROR, "Ping Google Blog Search Service fail while adding an article[title=" + articleTitle + "]", e); LOGGER.log(Level.ERROR, "Ping Google Blog Search Service fail while adding an article[title="
+ articleTitle + "]", e);
} }
} }
} }
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
*/ */
package org.b3log.solo.event.ping; package org.b3log.solo.event.ping;
import org.b3log.latke.Latkes; import org.b3log.latke.Latkes;
import org.b3log.latke.event.AbstractEventListener; import org.b3log.latke.event.AbstractEventListener;
import org.b3log.latke.event.Event; import org.b3log.latke.event.Event;
...@@ -36,20 +35,17 @@ import org.json.JSONObject; ...@@ -36,20 +35,17 @@ import org.json.JSONObject;
import java.net.URL; import java.net.URL;
import java.net.URLEncoder; import java.net.URLEncoder;
/** /**
* This listener is responsible for pinging <a href="http://blogsearch.google.com"> * This listener is responsible for pinging <a href="http://blogsearch.google.com">Google Blog Search Service</a>
* Google Blog Search Service</a> asynchronously while updating an article. * asynchronously while updating an article.
* *
* <p> * <li>
* <li> * <a href="http://www.google.com/help/blogsearch/pinging_API.html">
* <a href="http://www.google.com/help/blogsearch/pinging_API.html"> * About Google Blog Search Pinging Service API</a>
* About Google Blog Search Pinging Service API</a> * </li>
* </li>
* </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.4, Nov 20, 2015 * @version 1.0.0.5, Apr 15, 2018
* @see AddArticleGoogleBlogSearchPinger * @see AddArticleGoogleBlogSearchPinger
* @since 0.3.1 * @since 0.3.1
*/ */
...@@ -86,30 +82,30 @@ public final class UpdateArticleGoogleBlogSearchPinger extends AbstractEventList ...@@ -86,30 +82,30 @@ public final class UpdateArticleGoogleBlogSearchPinger extends AbstractEventList
try { try {
final JSONObject article = eventData.getJSONObject(Article.ARTICLE); final JSONObject article = eventData.getJSONObject(Article.ARTICLE);
articleTitle = article.getString(Article.ARTICLE_TITLE); articleTitle = article.getString(Article.ARTICLE_TITLE);
final JSONObject preference = preferenceQueryService.getPreference(); final JSONObject preference = preferenceQueryService.getPreference();
final String blogTitle = preference.getString(Option.ID_C_BLOG_TITLE); final String blogTitle = preference.getString(Option.ID_C_BLOG_TITLE);
if (Latkes.getServePath().contains("localhost")) { if (Latkes.getServePath().contains("localhost")) {
LOGGER.log(Level.TRACE, LOGGER.log(Level.TRACE, "Solo runs on local server, so should not ping " +
"Solo runs on local server, so should not ping " + "Google Blog Search Service for the article[title={0}]", "Google Blog Search Service for the article[title={0}]", article.getString(Article.ARTICLE_TITLE));
article.getString(Article.ARTICLE_TITLE));
return; return;
} }
final String articlePermalink = Latkes.getServePath() + article.getString(Article.ARTICLE_PERMALINK); final String articlePermalink = Latkes.getServePath() + article.getString(Article.ARTICLE_PERMALINK);
final String spec = "http://blogsearch.google.com/ping?name=" + URLEncoder.encode(blogTitle, "UTF-8") + "&url=" final String spec = "http://blogsearch.google.com/ping?name=" + URLEncoder.encode(blogTitle, "UTF-8") +
+ URLEncoder.encode(Latkes.getServePath(), "UTF-8") + "&changesURL=" + URLEncoder.encode(articlePermalink, "UTF-8"); "&url=" + URLEncoder.encode(Latkes.getServePath(), "UTF-8") + "&changesURL=" +
URLEncoder.encode(articlePermalink, "UTF-8");
LOGGER.log(Level.DEBUG, LOGGER.log(Level.DEBUG, "Request Google Blog Search Service API[{0}] while updateing " +
"Request Google Blog Search Service API[{0}] while updateing " + "an article[title=" + articleTitle + "]", spec); "an article[title=" + articleTitle + "]", spec);
final HTTPRequest request = new HTTPRequest(); final HTTPRequest request = new HTTPRequest();
request.setURL(new URL(spec)); request.setURL(new URL(spec));
URL_FETCH_SERVICE.fetchAsync(request); URL_FETCH_SERVICE.fetchAsync(request);
} catch (final Exception e) { } catch (final Exception e) {
LOGGER.log(Level.ERROR, "Ping Google Blog Search Service fail while updating an " + "article[title=" + articleTitle + "]", e); LOGGER.log(Level.ERROR, "Ping Google Blog Search Service fail while updating an " + "article[title="
+ articleTitle + "]", e);
} }
} }
} }
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