roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agillil...@apache.org
Subject svn commit: r417818 - in /incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets: CommentServlet.java PageServlet.java
Date Wed, 28 Jun 2006 17:02:30 GMT
Author: agilliland
Date: Wed Jun 28 10:02:30 2006
New Revision: 417818

URL: http://svn.apache.org/viewvc?rev=417818&view=rev
Log:
fixing up comment posting process so that we can properly dispatch requests from the comment
servlet to page servlet for rendering.

Comment posting is now working properly.


Modified:
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/CommentServlet.java
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/PageServlet.java

Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/CommentServlet.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/CommentServlet.java?rev=417818&r1=417817&r2=417818&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/CommentServlet.java
(original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/CommentServlet.java
Wed Jun 28 10:02:30 2006
@@ -80,7 +80,7 @@
  * If email notification is turned on, each new comment will result in an
  * email sent to the blog owner and all who have commented on the same post.
  *
- * @web.servlet name="CommentServlet"
+ * @web.servlet name="CommentServlet" load-on-startup="7"
  * @web.servlet-mapping url-pattern="/roller-ui/rendering/comment/*"
  */
 public class CommentServlet extends HttpServlet {
@@ -173,7 +173,7 @@
         
         String error = null;
         String message = null;
-        String entry_permalink = request.getContextPath();
+        String dispatch_url = null;
         
         WebsiteData weblog = null;
         WeblogEntryData entry = null;
@@ -214,8 +214,9 @@
                         commentRequest.getWeblogAnchor());
             }
             
-            // we know what the weblog entry is, so setup our permalink url
-            entry_permalink = entry.getPermaLink();
+            // we know what the weblog entry is, so setup our urls
+            dispatch_url = "/roller-ui/rendering/page"+entry.getPermaLink();
+            
         } catch (Exception e) {
             // some kind of error parsing the request or looking up weblog
             log.debug("error creating page request", e);
@@ -224,22 +225,28 @@
         }
         
         
-        log.debug("Doing comment posting for entry = "+entry_permalink);
+        log.debug("Doing comment posting for entry = "+entry.getPermaLink());
         
         // check if site is allowing comments
-        if(!RollerRuntimeConfig.getBooleanProperty("users.comments.enabled"))
+        if(!RollerRuntimeConfig.getBooleanProperty("users.comments.enabled")) {
             error = "Comments are disabled for this site.";
         
         // check if weblog and entry are allowing comments
-        if (!weblog.getAllowComments().booleanValue() ||
-                !entry.getCommentsStillAllowed())
+        } else if(!weblog.getAllowComments().booleanValue() ||
+                !entry.getCommentsStillAllowed()) {
             error = "Comments not allowed on this entry";
         
+        // make sure comment authentication passed
+        } else if(!this.authenticator.authenticate(request)) {
+            error = bundle.getString("error.commentAuthFailed");
+            log.debug("Comment failed authentication");
+        }
+        
         // bail now if we have already found an error
         if(error != null) {
             HttpSession session = request.getSession();
             session.setAttribute(RollerSession.ERROR_MESSAGE, error);
-            RequestDispatcher dispatcher = request.getRequestDispatcher(entry_permalink);
+            RequestDispatcher dispatcher = request.getRequestDispatcher(dispatch_url);
             dispatcher.forward(request, response);
             return;
         }
@@ -262,7 +269,6 @@
         // we can probably switch this to a CommentData without problems
         CommentFormEx cf = new CommentFormEx();
         RequestUtils.populate(cf, request);
-        //cf.copyTo(comment, request.getLocale());
         cf.setWeblogEntry(entry);
         cf.setPostTime(comment.getPostTime());
         request.setAttribute("commentForm", cf);
@@ -282,55 +288,48 @@
             log.debug("Comment is a preview");
             
         } else {
-            if (this.authenticator.authenticate(request)) {
-                log.debug("Comment passed authentication");
+            // If comment contains blacklisted text, mark as spam
+            SpamChecker checker = new SpamChecker();
+            if (checker.checkComment(comment)) {
+                comment.setSpam(Boolean.TRUE);
+                error = bundle.getString("commentServlet.commentMarkedAsSpam");
+                log.debug("Comment marked as spam");
+            }
+            
+            // If comment moderation is on, set comment as pending
+            if (weblog.getCommentModerationRequired()) {
+                comment.setPending(Boolean.TRUE);
+                comment.setApproved(Boolean.FALSE);
+                message = bundle.getString("commentServlet.submittedToModerator");
+            } else {
+                comment.setPending(Boolean.FALSE);
+                comment.setApproved(Boolean.TRUE);
+            }
+            
+            try {
+                WeblogManager mgr = RollerFactory.getRoller().getWeblogManager();
+                mgr.saveComment(comment);
+                RollerFactory.getRoller().flush();
                 
-                // If comment contains blacklisted text, mark as spam
-                SpamChecker checker = new SpamChecker();
-                if (checker.checkComment(comment)) {
-                    comment.setSpam(Boolean.TRUE);
-                    error = bundle.getString("commentServlet.commentMarkedAsSpam");
-                    log.debug("Comment marked as spam");
-                }
+                reindexEntry(entry);
                 
-                // If comment moderation is on, set comment as pending
-                if (weblog.getCommentModerationRequired()) {
-                    comment.setPending(Boolean.TRUE);
-                    comment.setApproved(Boolean.FALSE);
-                    message = bundle.getString("commentServlet.submittedToModerator");
-                } else {
-                    comment.setPending(Boolean.FALSE);
-                    comment.setApproved(Boolean.TRUE);
-                }
+                // Clear all caches associated with comment
+                CacheManager.invalidate(comment);
                 
-                try {
-                    WeblogManager mgr = RollerFactory.getRoller().getWeblogManager();
-                    mgr.saveComment(comment);
-                    RollerFactory.getRoller().flush();
-                    
-                    reindexEntry(entry);
-                    
-                    // Clear all caches associated with comment
-                    CacheManager.invalidate(comment);
-                    
-                    // Send email notifications
-                    RollerContext rc = RollerContext.getRollerContext();
-                    String rootURL = rc.getAbsoluteContextUrl(request);
-                    if (rootURL == null || rootURL.trim().length()==0) {
-                        rootURL = RequestUtils.serverURL(request) + request.getContextPath();
-                    }
-                    sendEmailNotification(comment, rootURL);
-                    
-                } catch (RollerException re) {
-                    log.error("Error saving comment", re);
-                    error = re.getMessage();
+                // Send email notifications
+                RollerContext rc = RollerContext.getRollerContext();
+                String rootURL = rc.getAbsoluteContextUrl(request);
+                if (rootURL == null || rootURL.trim().length()==0) {
+                    rootURL = RequestUtils.serverURL(request) + request.getContextPath();
                 }
+                sendEmailNotification(comment, rootURL);
                 
+                // comment was successful, clear the comment form
+                request.removeAttribute("commentForm");
                 
-                
-            } else {
-                error = bundle.getString("error.commentAuthFailed");
-                log.debug("Comment failed authentication");
+            } catch (RollerException re) {
+                log.error("Error saving comment", re);
+                error = re.getMessage();
             }
         }
         
@@ -342,18 +341,12 @@
         if (message != null)
             session.setAttribute(RollerSession.STATUS_MESSAGE, message);
         
-        if(error == null && message == null && !preview) {
-            entry_permalink = request.getContextPath()+entry_permalink;            
-            log.debug("comment complete, redirecting to "+entry_permalink);
-            response.sendRedirect(entry_permalink);
-        } else {
-            log.debug("more work needed, forwarding to "+entry_permalink);
-            RequestDispatcher dispatcher = 
-                request.getRequestDispatcher(entry_permalink);
-            dispatcher.forward(request, response);
-        }
+        log.debug("comment processed, forwarding to "+dispatch_url);
+        RequestDispatcher dispatcher =
+                request.getRequestDispatcher(dispatch_url);
+        dispatcher.forward(request, response);
     }
-    
+
     
     /**
      * Re-index the WeblogEntry so that the new comment gets indexed.

Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/PageServlet.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/PageServlet.java?rev=417818&r1=417817&r2=417818&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/PageServlet.java
(original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/PageServlet.java
Wed Jun 28 10:02:30 2006
@@ -123,9 +123,6 @@
         
         log.debug("Entering");
         
-        // used for rendering
-        HashMap model = new HashMap();
-        
         WebsiteData weblog = null;
         
         WeblogPageRequest pageRequest = null;
@@ -147,8 +144,6 @@
             return;
         }
         
-        PageContext pageContext = JspFactory.getDefaultFactory().getPageContext(
-                    this, request, response,"", true, 8192, true);
         
         // figure out what we are going to render
         Template page = null;
@@ -218,7 +213,8 @@
         
         // cached content checking
         String cacheKey = this.CACHE_ID+":"+this.generateKey(pageRequest);
-        if(!this.excludeOwnerPages || !pageRequest.isLoggedIn()) {
+        if((!this.excludeOwnerPages || !pageRequest.isLoggedIn()) &&
+                request.getAttribute("skipCache") == null) {
             // we need the last expiration time for the given weblog
             long lastExpiration = 0;
             Date lastExpirationDate =
@@ -251,6 +247,7 @@
 
         
         // looks like we need to render content
+        HashMap model = new HashMap();
         try {
             RollerContext rollerContext = RollerContext.getRollerContext();
             
@@ -259,6 +256,9 @@
             initData.put("request", request);
             initData.put("pageRequest", pageRequest);
             
+            PageContext pageContext = JspFactory.getDefaultFactory().getPageContext(
+                    this, request, response,"", true, 8192, true);
+            
             // Feeds get the weblog specific page model
             RenderModelLoader.loadPageModels(model, initData);
             
@@ -327,7 +327,8 @@
         response.getOutputStream().write(rendererOutput.getContent());
         
         // cache rendered content.  only cache if user is not logged in?
-        if (!this.excludeOwnerPages || !pageRequest.isLoggedIn()) {
+        if((!this.excludeOwnerPages || !pageRequest.isLoggedIn()) &&
+                request.getAttribute("skipCache") == null) {
             log.debug("PUT "+cacheKey);
             this.contentCache.put(cacheKey, new LazyExpiringCacheEntry(rendererOutput));
         } else {
@@ -338,6 +339,25 @@
         log.debug("Exiting");
     }
         
+    
+    /**
+     * Handle POST requests.
+     *
+     * We have this here because the comment servlet actually forwards some of
+     * its requests on to us to render some pages with cusom messaging.  We
+     * may want to revisit this approach in the future and see if we can do
+     * this in a different way, but for now this is the easy way.
+     */
+    public void doPost(HttpServletRequest request, HttpServletResponse response) 
+            throws ServletException, IOException {
+        
+        // make sure caching is disabled
+        request.setAttribute("skipCache", "true");
+        
+        // handle just like a GET request
+        this.doGet(request, response);
+    }
+    
     
     /**
      * Generate a cache key from a parsed weblog page request.



Mime
View raw message