Commit f4ffbde5 authored by Liang Ding's avatar Liang Ding

🔨 #12246

parent 2b9a3622
...@@ -16,12 +16,7 @@ ...@@ -16,12 +16,7 @@
package org.b3log.solo.processor; package org.b3log.solo.processor;
import java.io.IOException; import freemarker.template.Template;
import javax.inject.Inject;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.b3log.latke.Keys; import org.b3log.latke.Keys;
import org.b3log.latke.logging.Level; import org.b3log.latke.logging.Level;
import org.b3log.latke.logging.Logger; import org.b3log.latke.logging.Logger;
...@@ -33,6 +28,7 @@ import org.b3log.latke.servlet.annotation.RequestProcessing; ...@@ -33,6 +28,7 @@ import org.b3log.latke.servlet.annotation.RequestProcessing;
import org.b3log.latke.servlet.annotation.RequestProcessor; import org.b3log.latke.servlet.annotation.RequestProcessor;
import org.b3log.latke.servlet.renderer.JSONRenderer; import org.b3log.latke.servlet.renderer.JSONRenderer;
import org.b3log.latke.util.Requests; import org.b3log.latke.util.Requests;
import org.b3log.latke.util.freemarker.Templates;
import org.b3log.solo.model.Article; import org.b3log.solo.model.Article;
import org.b3log.solo.model.Comment; import org.b3log.solo.model.Comment;
import org.b3log.solo.model.Common; import org.b3log.solo.model.Common;
...@@ -42,13 +38,23 @@ import org.b3log.solo.service.UserMgmtService; ...@@ -42,13 +38,23 @@ import org.b3log.solo.service.UserMgmtService;
import org.b3log.solo.service.UserQueryService; import org.b3log.solo.service.UserQueryService;
import org.json.JSONObject; import org.json.JSONObject;
import javax.inject.Inject;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.Map;
/** /**
* Comment processor. * Comment processor.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author ArmstrongCN * @author ArmstrongCN
* @version 1.2.2.12, Dec 29, 2015 * @version 1.3.2.12, Feb 17, 2017
* @since 0.3.1 * @since 0.3.1
*/ */
@RequestProcessor @RequestProcessor
...@@ -85,8 +91,8 @@ public class CommentProcessor { ...@@ -85,8 +91,8 @@ public class CommentProcessor {
/** /**
* Adds a comment to a page. * Adds a comment to a page.
* * <p>
* <p> Renders the response with a json object, for example, * Renders the response with a json object, for example,
* <pre> * <pre>
* { * {
* "oId": generatedCommentId, * "oId": generatedCommentId,
...@@ -96,11 +102,10 @@ public class CommentProcessor { ...@@ -96,11 +102,10 @@ public class CommentProcessor {
* "commentThumbnailURL": "", * "commentThumbnailURL": "",
* "commentOriginalCommentName": "" // if exists this key, the comment is an reply * "commentOriginalCommentName": "" // if exists this key, the comment is an reply
* } * }
* </pre> </p> * </pre>
* </p>
* *
* @param context the specified context, including a request json object, for example, * @param context the specified context, including a request json object, for example,
* <pre>
* {
* "captcha": "", * "captcha": "",
* "oId": pageId, * "oId": pageId,
* "commentName": "", * "commentName": "",
...@@ -108,8 +113,6 @@ public class CommentProcessor { ...@@ -108,8 +113,6 @@ public class CommentProcessor {
* "commentURL": "", * "commentURL": "",
* "commentContent": "", // HTML * "commentContent": "", // HTML
* "commentOriginalCommentId": "" // optional, if exists this key, the comment is an reply * "commentOriginalCommentId": "" // optional, if exists this key, the comment is an reply
* }
* </pre>
* @throws ServletException servlet exception * @throws ServletException servlet exception
* @throws IOException io exception * @throws IOException io exception
*/ */
...@@ -165,6 +168,16 @@ public class CommentProcessor { ...@@ -165,6 +168,16 @@ public class CommentProcessor {
try { try {
final JSONObject addResult = commentMgmtService.addPageComment(requestJSONObject); final JSONObject addResult = commentMgmtService.addPageComment(requestJSONObject);
final Map<String, Object> dataModel = new HashMap<>();
dataModel.put(Comment.COMMENT, addResult);
final String skinDirName = (String) httpServletRequest.getAttribute(Keys.TEMAPLTE_DIR_NAME);
final Template template = Templates.MAIN_CFG.getTemplate("common-comment.ftl");
final StringWriter stringWriter = new StringWriter();
template.process(dataModel, stringWriter);
stringWriter.close();
addResult.put("cmtTpl", stringWriter.toString());
addResult.put(Keys.STATUS_CODE, true); addResult.put(Keys.STATUS_CODE, true);
renderer.setJSONObject(addResult); renderer.setJSONObject(addResult);
...@@ -178,9 +191,8 @@ public class CommentProcessor { ...@@ -178,9 +191,8 @@ public class CommentProcessor {
/** /**
* Adds a comment to an article. * Adds a comment to an article.
* * <p>
* * Renders the response with a json object, for example,
* <p> Renders the response with a json object, for example,
* <pre> * <pre>
* { * {
* "oId": generatedCommentId, * "oId": generatedCommentId,
...@@ -192,10 +204,9 @@ public class CommentProcessor { ...@@ -192,10 +204,9 @@ public class CommentProcessor {
* "commentContent": "" // HTML * "commentContent": "" // HTML
* } * }
* </pre> * </pre>
* </p>
* *
* @param context the specified context, including a request json object, for example, * @param context the specified context, including a request json object, for example,
* <pre>
* {
* "captcha": "", * "captcha": "",
* "oId": articleId, * "oId": articleId,
* "commentName": "", * "commentName": "",
...@@ -203,8 +214,6 @@ public class CommentProcessor { ...@@ -203,8 +214,6 @@ public class CommentProcessor {
* "commentURL": "", * "commentURL": "",
* "commentContent": "", * "commentContent": "",
* "commentOriginalCommentId": "" // optional, if exists this key, the comment is an reply * "commentOriginalCommentId": "" // optional, if exists this key, the comment is an reply
* }
* </pre>
* @throws ServletException servlet exception * @throws ServletException servlet exception
* @throws IOException io exception * @throws IOException io exception
*/ */
......
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