Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
solo
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
solo
Commits
ee7df903
Commit
ee7df903
authored
Dec 13, 2012
by
Liang Ding
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
格式化
parent
b8464070
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
90 deletions
+47
-90
core/src/main/java/org/b3log/solo/event/comment/ArticleCommentReplyNotifier.java
...b3log/solo/event/comment/ArticleCommentReplyNotifier.java
+24
-46
core/src/main/java/org/b3log/solo/event/comment/PageCommentReplyNotifier.java
...rg/b3log/solo/event/comment/PageCommentReplyNotifier.java
+23
-44
No files found.
core/src/main/java/org/b3log/solo/event/comment/ArticleCommentReplyNotifier.java
View file @
ee7df903
...
...
@@ -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
;
}
...
...
@@ -138,10 +118,8 @@ public final class ArticleCommentReplyNotifier
+
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
)
{
...
...
core/src/main/java/org/b3log/solo/event/comment/PageCommentReplyNotifier.java
View file @
ee7df903
...
...
@@ -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
;
}
...
...
@@ -138,10 +119,8 @@ public final class PageCommentReplyNotifier
+
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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment