You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@roller.apache.org by sn...@apache.org on 2006/11/22 16:28:00 UTC

svn commit: r478192 - in /incubator/roller/trunk: src/org/apache/roller/ui/authoring/ajax/CommentDataServlet.java web/WEB-INF/classes/ApplicationResources.properties web/WEB-INF/jsps/authoring/CommentManagement.jsp

Author: snoopdave
Date: Wed Nov 22 07:27:59 2006
New Revision: 478192

URL: http://svn.apache.org/viewvc?view=rev&rev=478192
Log:
Option to show full comment text

Added:
    incubator/roller/trunk/src/org/apache/roller/ui/authoring/ajax/CommentDataServlet.java
Modified:
    incubator/roller/trunk/web/WEB-INF/classes/ApplicationResources.properties
    incubator/roller/trunk/web/WEB-INF/jsps/authoring/CommentManagement.jsp

Added: incubator/roller/trunk/src/org/apache/roller/ui/authoring/ajax/CommentDataServlet.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/ui/authoring/ajax/CommentDataServlet.java?view=auto&rev=478192
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/ui/authoring/ajax/CommentDataServlet.java (added)
+++ incubator/roller/trunk/src/org/apache/roller/ui/authoring/ajax/CommentDataServlet.java Wed Nov 22 07:27:59 2006
@@ -0,0 +1,67 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+*  contributor license agreements.  The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.roller.ui.authoring.ajax;
+
+import java.io.IOException;
+import java.util.Iterator;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.commons.lang.WordUtils;
+
+import org.apache.roller.RollerException;
+import org.apache.roller.business.Roller;
+import org.apache.roller.business.RollerFactory;
+import org.apache.roller.business.WeblogManager;
+import org.apache.roller.pojos.CommentData;
+import org.apache.roller.pojos.UserData;
+import org.apache.roller.util.Utilities;
+
+/**
+ * Return comment id and content in JavaScript Object Notation (JSON) format. 
+ * For example comment with id "3454545346" and content "hi there" will be 
+ * represented as: {id : "3454545346", content : "hi there"}
+ *
+ * @web.servlet name="CommentDataServlet" 
+ * @web.servlet-mapping url-pattern="/roller-ui/authoring/commentdata/*"
+ */
+public class CommentDataServlet extends HttpServlet {
+ 
+    public void doGet(HttpServletRequest request, HttpServletResponse response)
+            throws ServletException, IOException {    
+                
+        Roller roller = RollerFactory.getRoller();
+        try {
+            WeblogManager wmgr = roller.getWeblogManager();
+            CommentData c = wmgr.getComment(request.getParameter("id"));
+            String content = Utilities.escapeHTML(c.getContent());
+            content = WordUtils.wrap(content, 72);
+            content = StringEscapeUtils.escapeJavaScript(content);
+            String json = "{ id: \"" + c.getId() + "\"," + "content: \"" + content + "\" }"; 
+            response.getWriter().print(json);   
+            response.flushBuffer();
+            response.getWriter().flush();
+            response.getWriter().close();
+        } catch (RollerException e) {
+            throw new ServletException(e.getMessage());
+        }
+    }
+}

Modified: incubator/roller/trunk/web/WEB-INF/classes/ApplicationResources.properties
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/web/WEB-INF/classes/ApplicationResources.properties?view=diff&rev=478192&r1=478191&r2=478192
==============================================================================
--- incubator/roller/trunk/web/WEB-INF/classes/ApplicationResources.properties (original)
+++ incubator/roller/trunk/web/WEB-INF/classes/ApplicationResources.properties Wed Nov 22 07:27:59 2006
@@ -280,6 +280,7 @@
 commentManagement.select=Select
 commentManagement.all=All
 commentManagement.none=None
+commentManagement.readmore=View full comment...
 
 # -------------------------------------------------------------- CommentServlet
 

Modified: incubator/roller/trunk/web/WEB-INF/jsps/authoring/CommentManagement.jsp
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/web/WEB-INF/jsps/authoring/CommentManagement.jsp?view=diff&rev=478192&r1=478191&r2=478192
==============================================================================
--- incubator/roller/trunk/web/WEB-INF/jsps/authoring/CommentManagement.jsp (original)
+++ incubator/roller/trunk/web/WEB-INF/jsps/authoring/CommentManagement.jsp Wed Nov 22 07:27:59 2006
@@ -16,6 +16,7 @@
   directory of this distribution.
 -->
 <%@ include file="/taglibs.jsp" %>
+<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
 <%@ page import="org.apache.roller.ui.authoring.struts.actions.CommentManagementAction" %>
 <%
 CommentManagementAction.CommentManagementPageModel model = 
@@ -38,6 +39,40 @@
         document.commentQueryForm.submit();
     }
 }
+
+function createRequestObject() {
+    var ro;
+    var browser = navigator.appName;
+    if (browser == "Microsoft Internet Explorer") {
+        ro = new ActiveXObject("Microsoft.XMLHTTP");
+    } else {
+        ro = new XMLHttpRequest();
+    }
+    return ro;
+}
+var http = createRequestObject();
+var init = false;
+var isBusy = false;
+
+function readMoreComment(id) {
+    url = "<%= request.getContextPath() %>" + "/roller-ui/authoring/commentdata?id="; + id;
+    if (isBusy) return;
+    isBusy = true;
+    http.open('get', url);
+    http.onreadystatechange = handleCommentResponse;
+    http.send(null);
+}
+
+function handleCommentResponse() {
+    if (http.readyState == 4) {
+        comment = eval("(" + http.responseText + ")"); 
+        commentDiv = document.getElementById("comment-" + comment.id);
+        commentDiv.textContent = comment.content;
+        linkDiv = document.getElementById("link-" + comment.id);
+        linkDiv.parentNode.removeChild(linkDiv);
+    }
+    isBusy = false;
+}
 -->
 </script>
 
@@ -370,11 +405,21 @@
                     <%-- comment content --%>
                     <br />
                     <span class="details">
-                       <pre><str:wordWrap>
-                            <str:truncateNicely upper="3000" appendToEnd="...">
-                                <c:out value="${comment.content}" escapeXml="true" />
-                            </str:truncateNicely>
-                       </str:wordWrap></pre>
+                                                
+                        <c:choose>
+                            <c:when test="${fn:length(comment.content) > 1000}">
+                                <pre><div id="comment-<c:out value="${comment.id}"/>"><str:wordWrap width="72"><str:truncateNicely upper="1000" appendToEnd="..."><c:out value="${comment.content}" escapeXml="true" /></str:truncateNicely></str:wordWrap></div></pre>                                    
+                                <div id="link-<c:out value="${comment.id}"/>">
+                                    <a onclick='readMoreComment("<c:out value="${comment.id}"/>")'>
+                                        <fmt:message key="commentManagement.readmore" />
+                                    </a>
+                                </div>
+                            </c:when>
+                            <c:otherwise>
+                                <pre><str:wordWrap><c:out value="${comment.content}" escapeXml="true" /></str:wordWrap></pre>   
+                            </c:otherwise>
+                        </c:choose> 
+                       
                     </span>
                     
                 </td>