Commit ee7df903 authored by Liang Ding's avatar Liang Ding

格式化

parent b8464070
...@@ -27,10 +27,10 @@ import org.b3log.latke.mail.MailServiceFactory; ...@@ -27,10 +27,10 @@ import org.b3log.latke.mail.MailServiceFactory;
import org.b3log.latke.util.Strings; import org.b3log.latke.util.Strings;
import org.b3log.solo.SoloServletListener; import org.b3log.solo.SoloServletListener;
import org.b3log.solo.event.EventTypes; import org.b3log.solo.event.EventTypes;
import org.b3log.solo.model.Article;
import org.b3log.solo.model.Comment; import org.b3log.solo.model.Comment;
import org.b3log.solo.model.Preference; import org.b3log.solo.model.Preference;
import org.b3log.solo.repository.CommentRepository; import org.b3log.solo.repository.CommentRepository;
import org.b3log.solo.model.Article;
import org.b3log.solo.repository.impl.CommentRepositoryImpl; import org.b3log.solo.repository.impl.CommentRepositoryImpl;
import org.b3log.solo.service.PreferenceQueryService; import org.b3log.solo.service.PreferenceQueryService;
import org.json.JSONObject; import org.json.JSONObject;
...@@ -39,22 +39,19 @@ import org.json.JSONObject; ...@@ -39,22 +39,19 @@ import org.json.JSONObject;
* This listener is responsible for processing article comment reply. * This listener is responsible for processing article comment reply.
* *
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a> * @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.0.1.4, Oct 31, 2011 * @version 1.0.1.5, Dec 13, 2012
* @since 0.3.1 * @since 0.3.1
*/ */
public final class ArticleCommentReplyNotifier public final class ArticleCommentReplyNotifier extends AbstractEventListener<JSONObject> {
extends AbstractEventListener<JSONObject> {
/** /**
* Logger. * Logger.
*/ */
private static final Logger LOGGER = private static final Logger LOGGER = Logger.getLogger(ArticleCommentReplyNotifier.class.getName());
Logger.getLogger(ArticleCommentReplyNotifier.class.getName());
/** /**
* Comment repository. * Comment repository.
*/ */
private CommentRepository commentRepository = private CommentRepository commentRepository = CommentRepositoryImpl.getInstance();
CommentRepositoryImpl.getInstance();
/** /**
* Mail service. * Mail service.
*/ */
...@@ -62,33 +59,25 @@ public final class ArticleCommentReplyNotifier ...@@ -62,33 +59,25 @@ public final class ArticleCommentReplyNotifier
/** /**
* Preference query service. * Preference query service.
*/ */
private PreferenceQueryService preferenceQueryService = private PreferenceQueryService preferenceQueryService = PreferenceQueryService.getInstance();
PreferenceQueryService.getInstance();
@Override @Override
public void action(final Event<JSONObject> event) throws EventException { public void action(final Event<JSONObject> event) throws EventException {
final JSONObject eventData = event.getData(); final JSONObject eventData = event.getData();
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.FINER, LOGGER.log(Level.FINER, "Processing an event[type={0}, data={1}] in listener[className={2}]",
"Processing an event[type={0}, data={1}] in listener[className={2}]", new Object[]{event.getType(), eventData, ArticleCommentReplyNotifier.class.getName()});
new Object[]{event.getType(), final String originalCommentId = comment.optString(Comment.COMMENT_ORIGINAL_COMMENT_ID);
eventData,
ArticleCommentReplyNotifier.class.getName()});
final String originalCommentId =
comment.optString(Comment.COMMENT_ORIGINAL_COMMENT_ID);
if (Strings.isEmptyOrNull(originalCommentId)) { if (Strings.isEmptyOrNull(originalCommentId)) {
LOGGER.log(Level.FINER, "This comment[id={0}] is not a reply", LOGGER.log(Level.FINER, "This comment[id={0}] is not a reply", comment.optString(Keys.OBJECT_ID));
comment.optString(Keys.OBJECT_ID));
return; return;
} }
try { try {
final String commentEmail = comment.getString(Comment.COMMENT_EMAIL); final String commentEmail = comment.getString(Comment.COMMENT_EMAIL);
final JSONObject originalComment = final JSONObject originalComment = commentRepository.get(originalCommentId);
commentRepository.get(originalCommentId); final String originalCommentEmail = originalComment.getString(Comment.COMMENT_EMAIL);
final String originalCommentEmail =
originalComment.getString(Comment.COMMENT_EMAIL);
if (originalCommentEmail.equalsIgnoreCase(commentEmail)) { if (originalCommentEmail.equalsIgnoreCase(commentEmail)) {
return; return;
} }
...@@ -98,34 +87,25 @@ public final class ArticleCommentReplyNotifier ...@@ -98,34 +87,25 @@ public final class ArticleCommentReplyNotifier
throw new EventException("Not found preference"); throw new EventException("Not found preference");
} }
final String blogTitle = final String blogTitle = preference.getString(Preference.BLOG_TITLE);
preference.getString(Preference.BLOG_TITLE); final String adminEmail = preference.getString(Preference.ADMIN_EMAIL);
final String adminEmail =
preference.getString(Preference.ADMIN_EMAIL);
final String commentContent = final String commentContent = comment.getString(Comment.COMMENT_CONTENT).replaceAll(SoloServletListener.ENTER_ESC, "<br/>");
comment.getString(Comment.COMMENT_CONTENT). final String commentSharpURL = comment.getString(Comment.COMMENT_SHARP_URL);
replaceAll(SoloServletListener.ENTER_ESC, "<br/>");
final String commentSharpURL =
comment.getString(Comment.COMMENT_SHARP_URL);
final Message message = new Message(); final Message message = new Message();
message.setFrom(adminEmail); message.setFrom(adminEmail);
message.addRecipient(originalCommentEmail); message.addRecipient(originalCommentEmail);
final JSONObject replyNotificationTemplate = final JSONObject replyNotificationTemplate = preferenceQueryService.getReplyNotificationTemplate();
preferenceQueryService.getReplyNotificationTemplate(); final String mailSubject = replyNotificationTemplate.getString("subject").replace("${blogTitle}", blogTitle);
final String mailSubject = replyNotificationTemplate.getString(
"subject").replace("${blogTitle}", blogTitle);
message.setSubject(mailSubject); message.setSubject(mailSubject);
final String articleTitle = article.getString(Article.ARTICLE_TITLE); final String articleTitle = article.getString(Article.ARTICLE_TITLE);
final String blogHost = preference.getString(Preference.BLOG_HOST); final String blogHost = preference.getString(Preference.BLOG_HOST);
final String articleLink = "http://" + blogHost + article.getString( final String articleLink = "http://" + blogHost + article.getString(Article.ARTICLE_PERMALINK);
Article.ARTICLE_PERMALINK);
final String commentName = comment.getString(Comment.COMMENT_NAME); final String commentName = comment.getString(Comment.COMMENT_NAME);
final String commentURL = comment.getString(Comment.COMMENT_URL); final String commentURL = comment.getString(Comment.COMMENT_URL);
String commenter = null; String commenter;
if (!"http://".equals(commentURL)) { if (!"http://".equals(commentURL)) {
commenter = "<a target=\"_blank\" " + "href=\"" + commentURL commenter = "<a target=\"_blank\" " + "href=\"" + commentURL + "\">" + commentName + "</a>";
+ "\">" + commentName + "</a>";
} else { } else {
commenter = commentName; commenter = commentName;
} }
...@@ -138,10 +118,8 @@ public final class ArticleCommentReplyNotifier ...@@ -138,10 +118,8 @@ public final class ArticleCommentReplyNotifier
+ commentSharpURL). + commentSharpURL).
replace("${replyContent}", commentContent); replace("${replyContent}", commentContent);
message.setHtmlBody(mailBody); message.setHtmlBody(mailBody);
LOGGER.log(Level.FINER, LOGGER.log(Level.FINER, "Sending a mail[mailSubject={0}, mailBody=[{1}] to [{2}]",
"Sending a mail[mailSubject={0}, mailBody=[{1}] to [{2}]", new Object[]{mailSubject, mailBody, originalCommentEmail});
new Object[]{mailSubject, mailBody,
originalCommentEmail});
mailService.send(message); mailService.send(message);
} catch (final Exception e) { } catch (final Exception e) {
......
...@@ -28,9 +28,9 @@ import org.b3log.latke.util.Strings; ...@@ -28,9 +28,9 @@ import org.b3log.latke.util.Strings;
import org.b3log.solo.SoloServletListener; import org.b3log.solo.SoloServletListener;
import org.b3log.solo.event.EventTypes; import org.b3log.solo.event.EventTypes;
import org.b3log.solo.model.Comment; import org.b3log.solo.model.Comment;
import org.b3log.solo.model.Page;
import org.b3log.solo.model.Preference; import org.b3log.solo.model.Preference;
import org.b3log.solo.repository.CommentRepository; import org.b3log.solo.repository.CommentRepository;
import org.b3log.solo.model.Page;
import org.b3log.solo.repository.impl.CommentRepositoryImpl; import org.b3log.solo.repository.impl.CommentRepositoryImpl;
import org.b3log.solo.service.PreferenceQueryService; import org.b3log.solo.service.PreferenceQueryService;
import org.json.JSONObject; import org.json.JSONObject;
...@@ -42,19 +42,16 @@ import org.json.JSONObject; ...@@ -42,19 +42,16 @@ import org.json.JSONObject;
* @version 1.0.1.1, Oct 31, 2011 * @version 1.0.1.1, Oct 31, 2011
* @since 0.3.1 * @since 0.3.1
*/ */
public final class PageCommentReplyNotifier public final class PageCommentReplyNotifier extends AbstractEventListener<JSONObject> {
extends AbstractEventListener<JSONObject> {
/** /**
* Logger. * Logger.
*/ */
private static final Logger LOGGER = private static final Logger LOGGER = Logger.getLogger(PageCommentReplyNotifier.class.getName());
Logger.getLogger(PageCommentReplyNotifier.class.getName());
/** /**
* Comment repository. * Comment repository.
*/ */
private CommentRepository commentRepository = private CommentRepository commentRepository = CommentRepositoryImpl.getInstance();
CommentRepositoryImpl.getInstance();
/** /**
* Mail service. * Mail service.
*/ */
...@@ -62,33 +59,25 @@ public final class PageCommentReplyNotifier ...@@ -62,33 +59,25 @@ public final class PageCommentReplyNotifier
/** /**
* Preference query service. * Preference query service.
*/ */
private PreferenceQueryService preferenceQueryService = private PreferenceQueryService preferenceQueryService = PreferenceQueryService.getInstance();
PreferenceQueryService.getInstance();
@Override @Override
public void action(final Event<JSONObject> event) throws EventException { public void action(final Event<JSONObject> event) throws EventException {
final JSONObject eventData = event.getData(); final JSONObject eventData = event.getData();
final JSONObject comment = eventData.optJSONObject(Comment.COMMENT); final JSONObject comment = eventData.optJSONObject(Comment.COMMENT);
final JSONObject page = eventData.optJSONObject(Page.PAGE); final JSONObject page = eventData.optJSONObject(Page.PAGE);
LOGGER.log(Level.FINER, LOGGER.log(Level.FINER, "Processing an event[type={0}, data={1}] in listener[className={2}]",
"Processing an event[type={0}, data={1}] in listener[className={2}]", new Object[]{event.getType(), eventData, PageCommentReplyNotifier.class.getName()});
new Object[]{event.getType(), final String originalCommentId = comment.optString(Comment.COMMENT_ORIGINAL_COMMENT_ID);
eventData,
PageCommentReplyNotifier.class.getName()});
final String originalCommentId =
comment.optString(Comment.COMMENT_ORIGINAL_COMMENT_ID);
if (Strings.isEmptyOrNull(originalCommentId)) { if (Strings.isEmptyOrNull(originalCommentId)) {
LOGGER.log(Level.FINER, "This comment[id={0}] is not a reply", LOGGER.log(Level.FINER, "This comment[id={0}] is not a reply", comment.optString(Keys.OBJECT_ID));
comment.optString(Keys.OBJECT_ID));
return; return;
} }
try { try {
final String commentEmail = comment.getString(Comment.COMMENT_EMAIL); final String commentEmail = comment.getString(Comment.COMMENT_EMAIL);
final JSONObject originalComment = final JSONObject originalComment = commentRepository.get(originalCommentId);
commentRepository.get(originalCommentId); final String originalCommentEmail = originalComment.getString(Comment.COMMENT_EMAIL);
final String originalCommentEmail =
originalComment.getString(Comment.COMMENT_EMAIL);
if (originalCommentEmail.equalsIgnoreCase(commentEmail)) { if (originalCommentEmail.equalsIgnoreCase(commentEmail)) {
return; return;
} }
...@@ -98,34 +87,26 @@ public final class PageCommentReplyNotifier ...@@ -98,34 +87,26 @@ public final class PageCommentReplyNotifier
throw new EventException("Not found preference"); throw new EventException("Not found preference");
} }
final String blogTitle = final String blogTitle = preference.getString(Preference.BLOG_TITLE);
preference.getString(Preference.BLOG_TITLE); final String adminEmail = preference.getString(Preference.ADMIN_EMAIL);
final String adminEmail =
preference.getString(Preference.ADMIN_EMAIL);
final String commentContent = final String commentContent = comment.getString(Comment.COMMENT_CONTENT).
comment.getString(Comment.COMMENT_CONTENT).
replaceAll(SoloServletListener.ENTER_ESC, "<br/>"); replaceAll(SoloServletListener.ENTER_ESC, "<br/>");
final String commentSharpURL = final String commentSharpURL = comment.getString(Comment.COMMENT_SHARP_URL);
comment.getString(Comment.COMMENT_SHARP_URL);
final Message message = new Message(); final Message message = new Message();
message.setFrom(adminEmail); message.setFrom(adminEmail);
message.addRecipient(originalCommentEmail); message.addRecipient(originalCommentEmail);
final JSONObject replyNotificationTemplate = final JSONObject replyNotificationTemplate = preferenceQueryService.getReplyNotificationTemplate();
preferenceQueryService.getReplyNotificationTemplate(); final String mailSubject = replyNotificationTemplate.getString("subject").replace("${blogTitle}", blogTitle);
final String mailSubject = replyNotificationTemplate.getString(
"subject").replace("${blogTitle}", blogTitle);
message.setSubject(mailSubject); message.setSubject(mailSubject);
final String pageTitle = page.getString(Page.PAGE_TITLE); final String pageTitle = page.getString(Page.PAGE_TITLE);
final String blogHost = preference.getString(Preference.BLOG_HOST); final String blogHost = preference.getString(Preference.BLOG_HOST);
final String pageLink = "http://" + blogHost final String pageLink = "http://" + blogHost + page.getString(Page.PAGE_PERMALINK);
+ page.getString(Page.PAGE_PERMALINK);
final String commentName = comment.getString(Comment.COMMENT_NAME); final String commentName = comment.getString(Comment.COMMENT_NAME);
final String commentURL = comment.getString(Comment.COMMENT_URL); final String commentURL = comment.getString(Comment.COMMENT_URL);
String commenter = null; String commenter;
if (!"http://".equals(commentURL)) { if (!"http://".equals(commentURL)) {
commenter = "<a target=\"_blank\" " + "href=\"" + commentURL commenter = "<a target=\"_blank\" " + "href=\"" + commentURL + "\">" + commentName + "</a>";
+ "\">" + commentName + "</a>";
} else { } else {
commenter = commentName; commenter = commentName;
} }
...@@ -138,10 +119,8 @@ public final class PageCommentReplyNotifier ...@@ -138,10 +119,8 @@ public final class PageCommentReplyNotifier
+ commentSharpURL). + commentSharpURL).
replace("${replyContent}", commentContent); replace("${replyContent}", commentContent);
message.setHtmlBody(mailBody); message.setHtmlBody(mailBody);
LOGGER.log(Level.FINER, LOGGER.log(Level.FINER, "Sending a mail[mailSubject={0}, mailBody=[{1}] to [{2}]",
"Sending a mail[mailSubject={0}, mailBody=[{1}] to [{2}]", new Object[]{mailSubject, mailBody, originalCommentEmail});
new Object[]{mailSubject, mailBody,
originalCommentEmail});
mailService.send(message); mailService.send(message);
} catch (final Exception e) { } catch (final Exception e) {
LOGGER.log(Level.SEVERE, e.getMessage(), e); LOGGER.log(Level.SEVERE, e.getMessage(), 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