roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agillil...@apache.org
Subject svn commit: r368813 - in /incubator/roller/trunk: src/org/roller/presentation/ src/org/roller/presentation/servlets/ src/org/roller/presentation/velocity/ web/WEB-INF/classes/ web/theme/scripts/
Date Fri, 13 Jan 2006 18:11:08 GMT
Author: agilliland
Date: Fri Jan 13 10:10:59 2006
New Revision: 368813

URL: http://svn.apache.org/viewcvs?rev=368813&view=rev
Log:
comment authentication via client side javascript.  this is to fix jira issue ROL-935.


Added:
    incubator/roller/trunk/src/org/roller/presentation/servlets/CommentAuthenticatorServlet.java
    incubator/roller/trunk/web/theme/scripts/clientSideInclude.js
Modified:
    incubator/roller/trunk/src/org/roller/presentation/RollerContext.java
    incubator/roller/trunk/src/org/roller/presentation/servlets/CommentServlet.java
    incubator/roller/trunk/src/org/roller/presentation/velocity/PageHelper.java
    incubator/roller/trunk/web/WEB-INF/classes/comments.vm

Modified: incubator/roller/trunk/src/org/roller/presentation/RollerContext.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/RollerContext.java?rev=368813&r1=368812&r2=368813&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/RollerContext.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/RollerContext.java Fri Jan 13 10:10:59
2006
@@ -673,7 +673,7 @@
     }
 
     //-----------------------------------------------------------------------
-
+    /*
     public static CommentAuthenticator getCommentAuthenticator() 
     {
         if (mCommentAuthenticator == null) 
@@ -692,4 +692,5 @@
         }        
         return mCommentAuthenticator;
     }
+    */
 }

Added: incubator/roller/trunk/src/org/roller/presentation/servlets/CommentAuthenticatorServlet.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/servlets/CommentAuthenticatorServlet.java?rev=368813&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/servlets/CommentAuthenticatorServlet.java
(added)
+++ incubator/roller/trunk/src/org/roller/presentation/servlets/CommentAuthenticatorServlet.java
Fri Jan 13 10:10:59 2006
@@ -0,0 +1,80 @@
+/*
+ * CommentAuthenticatorServlet.java
+ *
+ * Created on January 5, 2006, 12:37 PM
+ */
+
+package org.roller.presentation.servlets;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.roller.config.RollerConfig;
+import org.roller.presentation.velocity.CommentAuthenticator;
+import org.roller.presentation.velocity.DefaultCommentAuthenticator;
+
+
+/**
+ * The CommentAuthenticatorServlet is used for generating the html used for
+ * comment authentication.  This is done outside of the normal rendering process
+ * so that we can cache full pages and still set the comment authentication
+ * section dynamically.
+ *
+ * @web.servlet name="CommentAuthenticatorServlet"
+ * @web.servlet-mapping url-pattern="/CommentAuthenticatorServlet"
+ */
+public class CommentAuthenticatorServlet extends HttpServlet {
+    
+    private static Log mLogger = 
+        LogFactory.getLog(CommentAuthenticatorServlet.class);
+    
+    private CommentAuthenticator authenticator = null;
+    
+    
+    /**
+     * Handle incoming http GET requests.
+     *
+     * We only handle get requests.
+     */
+    public void doGet(HttpServletRequest request, HttpServletResponse response)
+        throws IOException, ServletException {
+        
+        PrintWriter out = response.getWriter();
+        
+        response.setContentType("text/html");
+        out.println(this.authenticator.getHtml(null, request, response));
+    }
+    
+    
+    /** 
+     * Initialization.
+     */
+    public void init(ServletConfig config) throws ServletException {
+        super.init(config);
+        
+        // lookup the authenticator we are going to use and instantiate it
+        try {
+            String name = RollerConfig.getProperty("comment.authenticator.classname");
+            
+            Class clazz = Class.forName(name);
+            this.authenticator = (CommentAuthenticator) clazz.newInstance();
+            
+        } catch(Exception e) {
+            mLogger.error(e);
+            this.authenticator = new DefaultCommentAuthenticator();
+        }
+
+    }
+    
+    /** 
+     * Destruction.
+     */
+    public void destroy() {}
+    
+}

Modified: incubator/roller/trunk/src/org/roller/presentation/servlets/CommentServlet.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/servlets/CommentServlet.java?rev=368813&r1=368812&r2=368813&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/servlets/CommentServlet.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/servlets/CommentServlet.java Fri Jan
13 10:10:59 2006
@@ -13,6 +13,7 @@
 import javax.mail.Session;
 import javax.naming.InitialContext;
 import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
@@ -39,6 +40,7 @@
 import org.roller.util.StringUtils;
 import org.roller.presentation.*;
 import org.roller.presentation.cache.CacheManager;
+import org.roller.presentation.velocity.DefaultCommentAuthenticator;
 
 /**
  * The CommentServlet handles all incoming weblog entry comment posts.
@@ -59,13 +61,35 @@
  */
 public class CommentServlet extends HttpServlet {
     
+    private static Log mLogger = LogFactory.getLog(CommentServlet.class);
+    
     private static final String EMAIL_ADDR_REGEXP = "^.*@.*[.].{2,}$";
-        
-    private transient ResourceBundle bundle =
+    
+    private ResourceBundle bundle =
         ResourceBundle.getBundle("ApplicationResources");
     
-    private static Log mLogger = 
-        LogFactory.getFactory().getInstance(CommentServlet.class);
+    private CommentAuthenticator authenticator = null;
+    
+    
+    /** 
+     * Initialization.
+     */
+    public void init(ServletConfig config) throws ServletException {
+        super.init(config);
+        
+        // lookup the authenticator we are going to use and instantiate it
+        try {
+            String name = RollerConfig.getProperty("comment.authenticator.classname");
+            
+            Class clazz = Class.forName(name);
+            this.authenticator = (CommentAuthenticator) clazz.newInstance();
+            
+        } catch(Exception e) {
+            mLogger.error(e);
+            this.authenticator = new DefaultCommentAuthenticator();
+        }
+
+    }
     
     
     /**
@@ -158,10 +182,8 @@
                 request.setAttribute("previewComments", "dummy");
                 mLogger.debug("Comment is a preview");
                 
-            } else {                
-                CommentAuthenticator commentAuth = 
-                        RollerContext.getCommentAuthenticator();
-                if (commentAuth.authenticate(comment, request)) {
+            } else {
+                if (this.authenticator.authenticate(comment, request)) {
                     mLogger.debug("Comment passed authentication");
                     
                     // If comment contains blacklisted text, mark as spam

Modified: incubator/roller/trunk/src/org/roller/presentation/velocity/PageHelper.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/velocity/PageHelper.java?rev=368813&r1=368812&r2=368813&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/velocity/PageHelper.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/velocity/PageHelper.java Fri Jan 13
10:10:59 2006
@@ -530,9 +530,13 @@
     
     public String getCommentAuthenticatorHtml()
     {
+        /* no longer used -- Allen G
         RollerContext rctx = 
             RollerContext.getRollerContext(mRollerReq.getRequest());
         return rctx.getCommentAuthenticator().getHtml(
             mVelocityContext, mRollerReq.getRequest(), mResponse);
+         */
+        
+        return "";
     }
 }

Modified: incubator/roller/trunk/web/WEB-INF/classes/comments.vm
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/web/WEB-INF/classes/comments.vm?rev=368813&r1=368812&r2=368813&view=diff
==============================================================================
--- incubator/roller/trunk/web/WEB-INF/classes/comments.vm (original)
+++ incubator/roller/trunk/web/WEB-INF/classes/comments.vm Fri Jan 13 10:10:59 2006
@@ -188,6 +188,9 @@
 #macro( showCommentForm $entry )
     <div class="comments-form">
     <div class="comments-head">$text.get("macro.weblog.postcommentHeader")</div><br/>
+
+    #showStatusMessage()
+
     <form method="post" action="$ctxPath/comment" focus="name"
         name="form" onsubmit="fixURL(this); return validateComments(this)">
         
@@ -247,10 +250,8 @@
         </tr>
         </table>
         
-        #showStatusMessage()
-        <p class="commentAuthenticator">
-        $pageHelper.commentAuthenticatorHtml
-        </p>
+        <script type="text/javascript" src="$ctxPath/theme/scripts/clientSideInclude.js"></script>
+        <div id="commentAuthenticator"></div>
  
         <table cellspacing="0" cellpadding="1" border="0" width="95%">
         <tr>
@@ -269,6 +270,8 @@
 
     <script type="text/javascript" src="$ctxPath/theme/scripts/roller.js"></script>
     <script type="text/javascript">
+    clientSideInclude('commentAuthenticator', '$ctxPath/CommentAuthenticatorServlet');
+
     var author = getCookie("commentAuthor");
     var email = getCookie("commentEmail");
     var url = getCookie("commentUrl");

Added: incubator/roller/trunk/web/theme/scripts/clientSideInclude.js
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/web/theme/scripts/clientSideInclude.js?rev=368813&view=auto
==============================================================================
--- incubator/roller/trunk/web/theme/scripts/clientSideInclude.js (added)
+++ incubator/roller/trunk/web/theme/scripts/clientSideInclude.js Fri Jan 13 10:10:59 2006
@@ -0,0 +1,43 @@
+function clientSideInclude(id, url) {
+  var req = false;
+  // For Safari, Firefox, and other non-MS browsers
+  if (window.XMLHttpRequest) {
+    try {
+      req = new XMLHttpRequest();
+    } catch (e) {
+      req = false;
+    }
+  } else if (window.ActiveXObject) {
+    // For Internet Explorer on Windows
+    try {
+      req = new ActiveXObject("Msxml2.XMLHTTP");
+    } catch (e) {
+      try {
+        req = new ActiveXObject("Microsoft.XMLHTTP");
+      } catch (e) {
+        req = false;
+      }
+    }
+  }
+ var element = document.getElementById(id);
+ if (!element) {
+  alert("Bad id " + id +
+   "passed to clientSideInclude." +
+   "You need a div or span element " +
+   "with this id in your page.");
+  return;
+ }
+  if (req) {
+    // Synchronous request, wait till we have it all
+    req.open('GET', url, false);
+    req.send(null);
+    element.innerHTML = req.responseText;
+  } else {
+    element.innerHTML =
+   "Sorry, your browser does not support " +
+      "XMLHTTPRequest objects. This page requires " +
+      "Internet Explorer 5 or better for Windows, " +
+      "or Firefox for any system, or Safari. Other " +
+      "compatible browsers may also exist.";
+  }
+}
\ No newline at end of file



Mime
View raw message