Commit ee7df903 authored by Liang Ding's avatar Liang Ding

格式化

parent b8464070
......@@ -27,10 +27,10 @@ import org.b3log.latke.mail.MailServiceFactory;
import org.b3log.latke.util.Strings;
import org.b3log.solo.SoloServletListener;
import org.b3log.solo.event.EventTypes;
import org.b3log.solo.model.Article;
import org.b3log.solo.model.Comment;
import org.b3log.solo.model.Preference;
import org.b3log.solo.repository.CommentRepository;
import org.b3log.solo.model.Article;
import org.b3log.solo.repository.impl.CommentRepositoryImpl;
import org.b3log.solo.service.PreferenceQueryService;
import org.json.JSONObject;
......@@ -39,22 +39,19 @@ import org.json.JSONObject;
* This listener is responsible for processing article comment reply.
*
* @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
*/
public final class ArticleCommentReplyNotifier
extends AbstractEventListener<JSONObject> {
public final class ArticleCommentReplyNotifier extends AbstractEventListener<JSONObject> {
/**
* Logger.
*/
private static final Logger LOGGER =
Logger.getLogger(ArticleCommentReplyNotifier.class.getName());
private static final Logger LOGGER = Logger.getLogger(ArticleCommentReplyNotifier.class.getName());
/**
* Comment repository.
*/
private CommentRepository commentRepository =
CommentRepositoryImpl.getInstance();
private CommentRepository commentRepository = CommentRepositoryImpl.getInstance();
/**
* Mail service.
*/
......@@ -62,33 +59,25 @@ public final class ArticleCommentReplyNotifier
/**
* Preference query service.
*/
private PreferenceQueryService preferenceQueryService =
PreferenceQueryService.getInstance();
private PreferenceQueryService preferenceQueryService = PreferenceQueryService.getInstance();
@Override
public void action(final Event<JSONObject> event) throws EventException {
final JSONObject eventData = event.getData();
final JSONObject comment = eventData.optJSONObject(Comment.COMMENT);
final JSONObject article = eventData.optJSONObject(Article.ARTICLE);
LOGGER.log(Level.FINER,
"Processing an event[type={0}, data={1}] in listener[className={2}]",
new Object[]{event.getType(),
eventData,
ArticleCommentReplyNotifier.class.getName()});
final String originalCommentId =
comment.optString(Comment.COMMENT_ORIGINAL_COMMENT_ID);
LOGGER.log(Level.FINER, "Processing an event[type={0}, data={1}] in listener[className={2}]",
new Object[]{event.getType(), eventData, ArticleCommentReplyNotifier.class.getName()});
final String originalCommentId = comment.optString(Comment.COMMENT_ORIGINAL_COMMENT_ID);
if (Strings.isEmptyOrNull(originalCommentId)) {
LOGGER.log(Level.FINER, "This comment[id={0}] is not a reply",
comment.optString(Keys.OBJECT_ID));
LOGGER.log(Level.FINER, "This comment[id={0}] is not a reply", comment.optString(Keys.OBJECT_ID));
return;
}
try {
final String commentEmail = comment.getString(Comment.COMMENT_EMAIL);
final JSONObject originalComment =
commentRepository.get(originalCommentId);
final String originalCommentEmail =
originalComment.getString(Comment.COMMENT_EMAIL);
final JSONObject originalComment = commentRepository.get(originalCommentId);
final String originalCommentEmail = originalComment.getString(Comment.COMMENT_EMAIL);
if (originalCommentEmail.equalsIgnoreCase(commentEmail)) {
return;
}
......@@ -98,34 +87,25 @@ public final class ArticleCommentReplyNotifier
throw new EventException("Not found preference");
}
final String blogTitle =
preference.getString(Preference.BLOG_TITLE);
final String adminEmail =
preference.getString(Preference.ADMIN_EMAIL);
final String blogTitle = preference.getString(Preference.BLOG_TITLE);
final String adminEmail = preference.getString(Preference.ADMIN_EMAIL);
final String commentContent =
comment.getString(Comment.COMMENT_CONTENT).
replaceAll(SoloServletListener.ENTER_ESC, "<br/>");
final String commentSharpURL =
comment.getString(Comment.COMMENT_SHARP_URL);
final String commentContent = comment.getString(Comment.COMMENT_CONTENT).replaceAll(SoloServletListener.ENTER_ESC, "<br/>");
final String commentSharpURL = comment.getString(Comment.COMMENT_SHARP_URL);
final Message message = new Message();
message.setFrom(adminEmail);
message.addRecipient(originalCommentEmail);
final JSONObject replyNotificationTemplate =
preferenceQueryService.getReplyNotificationTemplate();
final String mailSubject = replyNotificationTemplate.getString(
"subject").replace("${blogTitle}", blogTitle);
final JSONObject replyNotificationTemplate = preferenceQueryService.getReplyNotificationTemplate();
final String mailSubject = replyNotificationTemplate.getString("subject").replace("${blogTitle}", blogTitle);
message.setSubject(mailSubject);
final String articleTitle = article.getString(Article.ARTICLE_TITLE);
final String blogHost = preference.getString(Preference.BLOG_HOST);
final String articleLink = "http://" + blogHost + article.getString(
Article.ARTICLE_PERMALINK);
final String articleLink = "http://" + blogHost + article.getString(Article.ARTICLE_PERMALINK);
final String commentName = comment.getString(Comment.COMMENT_NAME);
final String commentURL = comment.getString(Comment.COMMENT_URL);
String commenter = null;
String commenter;
if (!"http://".equals(commentURL)) {
commenter = "<a target=\"_blank\" " + "href=\"" + commentURL
+ "\">" + commentName + "</a>";
commenter = "<a target=\"_blank\" " + "href=\"" + commentURL + "\">" + commentName + "</a>";
} else {
commenter = commentName;
}
......@@ -135,13 +115,11 @@ public final class ArticleCommentReplyNotifier
replace("${postTitle}", articleTitle).
replace("${replier}", commenter).
replace("${replyURL}", "http://" + blogHost
+ commentSharpURL).
+ commentSharpURL).
replace("${replyContent}", commentContent);
message.setHtmlBody(mailBody);
LOGGER.log(Level.FINER,
"Sending a mail[mailSubject={0}, mailBody=[{1}] to [{2}]",
new Object[]{mailSubject, mailBody,
originalCommentEmail});
LOGGER.log(Level.FINER, "Sending a mail[mailSubject={0}, mailBody=[{1}] to [{2}]",
new Object[]{mailSubject, mailBody, originalCommentEmail});
mailService.send(message);
} catch (final Exception e) {
......
......@@ -28,9 +28,9 @@ import org.b3log.latke.util.Strings;
import org.b3log.solo.SoloServletListener;
import org.b3log.solo.event.EventTypes;
import org.b3log.solo.model.Comment;
import org.b3log.solo.model.Page;
import org.b3log.solo.model.Preference;
import org.b3log.solo.repository.CommentRepository;
import org.b3log.solo.model.Page;
import org.b3log.solo.repository.impl.CommentRepositoryImpl;
import org.b3log.solo.service.PreferenceQueryService;
import org.json.JSONObject;
......@@ -42,19 +42,16 @@ import org.json.JSONObject;
* @version 1.0.1.1, Oct 31, 2011
* @since 0.3.1
*/
public final class PageCommentReplyNotifier
extends AbstractEventListener<JSONObject> {
public final class PageCommentReplyNotifier extends AbstractEventListener<JSONObject> {
/**
* Logger.
*/
private static final Logger LOGGER =
Logger.getLogger(PageCommentReplyNotifier.class.getName());
private static final Logger LOGGER = Logger.getLogger(PageCommentReplyNotifier.class.getName());
/**
* Comment repository.
*/
private CommentRepository commentRepository =
CommentRepositoryImpl.getInstance();
private CommentRepository commentRepository = CommentRepositoryImpl.getInstance();
/**
* Mail service.
*/
......@@ -62,33 +59,25 @@ public final class PageCommentReplyNotifier
/**
* Preference query service.
*/
private PreferenceQueryService preferenceQueryService =
PreferenceQueryService.getInstance();
private PreferenceQueryService preferenceQueryService = PreferenceQueryService.getInstance();
@Override
public void action(final Event<JSONObject> event) throws EventException {
final JSONObject eventData = event.getData();
final JSONObject comment = eventData.optJSONObject(Comment.COMMENT);
final JSONObject page = eventData.optJSONObject(Page.PAGE);
LOGGER.log(Level.FINER,
"Processing an event[type={0}, data={1}] in listener[className={2}]",
new Object[]{event.getType(),
eventData,
PageCommentReplyNotifier.class.getName()});
final String originalCommentId =
comment.optString(Comment.COMMENT_ORIGINAL_COMMENT_ID);
LOGGER.log(Level.FINER, "Processing an event[type={0}, data={1}] in listener[className={2}]",
new Object[]{event.getType(), eventData, PageCommentReplyNotifier.class.getName()});
final String originalCommentId = comment.optString(Comment.COMMENT_ORIGINAL_COMMENT_ID);
if (Strings.isEmptyOrNull(originalCommentId)) {
LOGGER.log(Level.FINER, "This comment[id={0}] is not a reply",
comment.optString(Keys.OBJECT_ID));
LOGGER.log(Level.FINER, "This comment[id={0}] is not a reply", comment.optString(Keys.OBJECT_ID));
return;
}
try {
final String commentEmail = comment.getString(Comment.COMMENT_EMAIL);
final JSONObject originalComment =
commentRepository.get(originalCommentId);
final String originalCommentEmail =
originalComment.getString(Comment.COMMENT_EMAIL);
final JSONObject originalComment = commentRepository.get(originalCommentId);
final String originalCommentEmail = originalComment.getString(Comment.COMMENT_EMAIL);
if (originalCommentEmail.equalsIgnoreCase(commentEmail)) {
return;
}
......@@ -98,34 +87,26 @@ public final class PageCommentReplyNotifier
throw new EventException("Not found preference");
}
final String blogTitle =
preference.getString(Preference.BLOG_TITLE);
final String adminEmail =
preference.getString(Preference.ADMIN_EMAIL);
final String blogTitle = preference.getString(Preference.BLOG_TITLE);
final String adminEmail = preference.getString(Preference.ADMIN_EMAIL);
final String commentContent =
comment.getString(Comment.COMMENT_CONTENT).
final String commentContent = comment.getString(Comment.COMMENT_CONTENT).
replaceAll(SoloServletListener.ENTER_ESC, "<br/>");
final String commentSharpURL =
comment.getString(Comment.COMMENT_SHARP_URL);
final String commentSharpURL = comment.getString(Comment.COMMENT_SHARP_URL);
final Message message = new Message();
message.setFrom(adminEmail);
message.addRecipient(originalCommentEmail);
final JSONObject replyNotificationTemplate =
preferenceQueryService.getReplyNotificationTemplate();
final String mailSubject = replyNotificationTemplate.getString(
"subject").replace("${blogTitle}", blogTitle);
final JSONObject replyNotificationTemplate = preferenceQueryService.getReplyNotificationTemplate();
final String mailSubject = replyNotificationTemplate.getString("subject").replace("${blogTitle}", blogTitle);
message.setSubject(mailSubject);
final String pageTitle = page.getString(Page.PAGE_TITLE);
final String blogHost = preference.getString(Preference.BLOG_HOST);
final String pageLink = "http://" + blogHost
+ page.getString(Page.PAGE_PERMALINK);
final String pageLink = "http://" + blogHost + page.getString(Page.PAGE_PERMALINK);
final String commentName = comment.getString(Comment.COMMENT_NAME);
final String commentURL = comment.getString(Comment.COMMENT_URL);
String commenter = null;
String commenter;
if (!"http://".equals(commentURL)) {
commenter = "<a target=\"_blank\" " + "href=\"" + commentURL
+ "\">" + commentName + "</a>";
commenter = "<a target=\"_blank\" " + "href=\"" + commentURL + "\">" + commentName + "</a>";
} else {
commenter = commentName;
}
......@@ -135,13 +116,11 @@ public final class PageCommentReplyNotifier
replace("${postTitle}", pageTitle).
replace("${replier}", commenter).
replace("${replyURL}", "http://" + blogHost
+ commentSharpURL).
+ commentSharpURL).
replace("${replyContent}", commentContent);
message.setHtmlBody(mailBody);
LOGGER.log(Level.FINER,
"Sending a mail[mailSubject={0}, mailBody=[{1}] to [{2}]",
new Object[]{mailSubject, mailBody,
originalCommentEmail});
LOGGER.log(Level.FINER, "Sending a mail[mailSubject={0}, mailBody=[{1}] to [{2}]",
new Object[]{mailSubject, mailBody, originalCommentEmail});
mailService.send(message);
} catch (final Exception e) {
LOGGER.log(Level.SEVERE, e.getMessage(), e);
......
......@@ -163,7 +163,7 @@ public final class CommentMgmtService {
ret.put(Comment.COMMENT_ORIGINAL_COMMENT_NAME, originalCommentName);
} else {
LOGGER.log(Level.WARNING, "Not found orginal comment[id={0}] of reply[name={1}, content={2}]",
new String[]{originalCommentId, commentName, commentContent});
new String[]{originalCommentId, commentName, commentContent});
}
}
setCommentThumbnailURL(comment);
......@@ -276,7 +276,7 @@ public final class CommentMgmtService {
ret.put(Comment.COMMENT_ORIGINAL_COMMENT_NAME, originalCommentName);
} else {
LOGGER.log(Level.WARNING, "Not found orginal comment[id={0}] of reply[name={1}, content={2}]",
new String[]{originalCommentId, commentName, commentContent});
new String[]{originalCommentId, commentName, commentContent});
}
}
CommentMgmtService.setCommentThumbnailURL(comment);
......@@ -455,7 +455,7 @@ public final class CommentMgmtService {
final String hashedEmail = MD5.hash(commentEmail.toLowerCase());
String thumbnailURL = "http://secure.gravatar.com/avatar/" + hashedEmail + "?s=60&d="
+ Latkes.getStaticServePath() + "/images/default-user-thumbnail.png";
+ Latkes.getStaticServePath() + "/images/default-user-thumbnail.png";
final URL gravatarURL = new URL(thumbnailURL);
......
This diff is collapsed.
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