File Source: CommentDataServlet.java
/*
P/P * Method: org.apache.roller.weblogger.ui.struts2.ajax.CommentDataServlet__static_init
*/
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. The ASF licenses this file to You
4 * under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License. For additional information regarding
15 * copyright in this work, please see the NOTICE file in the top level
16 * directory of this distribution.
17 */
18
19 package org.apache.roller.weblogger.ui.struts2.ajax;
20
21 import java.io.IOException;
22 import javax.servlet.ServletException;
23 import javax.servlet.http.HttpServlet;
24 import javax.servlet.http.HttpServletRequest;
25 import javax.servlet.http.HttpServletResponse;
26 import org.apache.commons.lang.StringEscapeUtils;
27 import org.apache.commons.lang.WordUtils;
28 import org.apache.roller.weblogger.business.Weblogger;
29 import org.apache.roller.weblogger.business.WebloggerFactory;
30 import org.apache.roller.weblogger.business.WeblogManager;
31 import org.apache.roller.weblogger.pojos.WeblogEntryComment;
32 import org.apache.roller.weblogger.util.Utilities;
33
34
35 /**
36 * Return comment id and content in JavaScript Object Notation (JSON) format.
37 * For example comment with id "3454545346" and content "hi there" will be
38 * represented as: {id : "3454545346", content : "hi there"}
39 */
/*
P/P * Method: void org.apache.roller.weblogger.ui.struts2.ajax.CommentDataServlet()
*/
40 public class CommentDataServlet extends HttpServlet {
41
42 public void doGet(HttpServletRequest request,
43 HttpServletResponse response)
44 throws ServletException, IOException {
45
/*
P/P * Method: void doGet(HttpServletRequest, HttpServletResponse)
*
* Preconditions:
* request != null
* response != null
*
* Presumptions:
* javax.servlet.http.HttpServletResponse:getWriter(...)@55 != null
* javax.servlet.http.HttpServletResponse:getWriter(...)@57 != null
* javax.servlet.http.HttpServletResponse:getWriter(...)@58 != null
* org.apache.roller.weblogger.business.WeblogManager:getComment(...)@49 != null
* org.apache.roller.weblogger.business.Weblogger:getWeblogManager(...)@48 != null
* ...
*/
46 Weblogger roller = WebloggerFactory.getWeblogger();
47 try {
48 WeblogManager wmgr = roller.getWeblogManager();
49 WeblogEntryComment c = wmgr.getComment(request.getParameter("id"));
50 String content = Utilities.escapeHTML(c.getContent());
51 content = WordUtils.wrap(content, 72);
52 content = StringEscapeUtils.escapeJavaScript(content);
53 String json = "{ id: \"" + c.getId() + "\"," + "content: \"" + content + "\" }";
54 response.setContentType("text/html; charset=utf-8");
55 response.getWriter().print(json);
56 response.flushBuffer();
57 response.getWriter().flush();
58 response.getWriter().close();
59 } catch (Exception e) {
60 throw new ServletException(e.getMessage());
61 }
62 }
63
64 }
SofCheck Inspector Build Version : 2.18479
| CommentDataServlet.java |
2009-Jan-02 14:24:58 |
| CommentDataServlet.class |
2009-Sep-04 03:12:45 |