File Source: CommentAuthenticatorServlet.java

     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.rendering.servlets;
    20  
    21  import java.io.IOException;
    22  import java.io.PrintWriter;
    23  import javax.servlet.ServletConfig;
    24  import javax.servlet.ServletException;
    25  import javax.servlet.http.HttpServlet;
    26  import javax.servlet.http.HttpServletRequest;
    27  import javax.servlet.http.HttpServletResponse;
    28  import org.apache.commons.logging.Log;
    29  import org.apache.commons.logging.LogFactory;
    30  import org.apache.roller.weblogger.config.WebloggerConfig;
    31  import org.apache.roller.weblogger.ui.rendering.plugins.comments.CommentAuthenticator;
    32  import org.apache.roller.weblogger.ui.rendering.plugins.comments.DefaultCommentAuthenticator;
    33  
    34  
    35  /**
    36   * The CommentAuthenticatorServlet is used for generating the html used for
    37   * comment authentication.  This is done outside of the normal rendering process
    38   * so that we can cache full pages and still set the comment authentication
    39   * section dynamically.
    40   *
    41   * @web.servlet name="CommentAuthenticatorServlet" load-on-startup="7"
    42   * @web.servlet-mapping url-pattern="/CommentAuthenticatorServlet"
    43   */
         /* 
    P/P   *  Method: void org.apache.roller.weblogger.ui.rendering.servlets.CommentAuthenticatorServlet()
          * 
          *  Postconditions:
          *    this.authenticator == null
          */
    44  public class CommentAuthenticatorServlet extends HttpServlet {
    45      
             /* 
    P/P       *  Method: org.apache.roller.weblogger.ui.rendering.servlets.CommentAuthenticatorServlet__static_init
              * 
              *  Postconditions:
              *    init'ed(mLogger)
              */
    46      private static Log mLogger = 
    47          LogFactory.getLog(CommentAuthenticatorServlet.class);
    48      
    49      private CommentAuthenticator authenticator = null;
    50      
    51      
    52      /**
    53       * Handle incoming http GET requests.
    54       *
    55       * We only handle get requests.
    56       */
    57      public void doGet(HttpServletRequest request, HttpServletResponse response)
    58          throws IOException, ServletException {
    59  
                 /* 
    P/P           *  Method: void doGet(HttpServletRequest, HttpServletResponse)
                  * 
                  *  Preconditions:
                  *    response != null
                  *    this.authenticator != null
                  * 
                  *  Presumptions:
                  *    javax.servlet.http.HttpServletResponse:getWriter(...)@67 != null
                  */
    60          response.setContentType("text/html; charset=utf-8");
    61  
    62          // Convince proxies and IE not to cache this.
    63          response.addHeader("Pragma", "no-cache");
    64          response.addHeader("Cache-Control", "no-cache");
    65          response.addHeader("Expires", "Thu, 01 Jan 1970 00:00:00 GMT");
    66  
    67          PrintWriter out = response.getWriter();
    68          out.println(this.authenticator.getHtml(request));
    69      }
    70      
    71      
    72      /** 
    73       * Initialization.
    74       */
    75      public void init(ServletConfig config) throws ServletException {
    76          
                 /* 
    P/P           *  Method: void init(ServletConfig)
                  * 
                  *  Preconditions:
                  *    (soft) mLogger != null
                  * 
                  *  Presumptions:
                  *    java.lang.Class:forName(...)@83 != null
                  * 
                  *  Postconditions:
                  *    this.authenticator != null
                  *    new DefaultCommentAuthenticator(init#1) num objects <= 1
                  */
    77          super.init(config);
    78          
    79          // lookup the authenticator we are going to use and instantiate it
    80          try {
    81              String name = WebloggerConfig.getProperty("comment.authenticator.classname");
    82              
    83              Class clazz = Class.forName(name);
    84              this.authenticator = (CommentAuthenticator) clazz.newInstance();
    85              
    86          } catch(Exception e) {
    87              mLogger.error(e);
    88              this.authenticator = new DefaultCommentAuthenticator();
    89          }
    90  
    91      }
    92      
    93      /** 
    94       * Destruction.
    95       */
             /* 
    P/P       *  Method: void destroy()
              */
    96      public void destroy() {}
    97      
    98  }








SofCheck Inspector Build Version : 2.18479
CommentAuthenticatorServlet.java 2009-Jan-02 14:25:32
CommentAuthenticatorServlet.class 2009-Sep-04 03:12:45