KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > ui > rendering > servlets > CommentAuthenticatorServlet


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.ui.rendering.servlets;
20
21 import java.io.IOException JavaDoc;
22 import java.io.PrintWriter JavaDoc;
23 import javax.servlet.ServletConfig JavaDoc;
24 import javax.servlet.ServletException JavaDoc;
25 import javax.servlet.http.HttpServlet JavaDoc;
26 import javax.servlet.http.HttpServletRequest JavaDoc;
27 import javax.servlet.http.HttpServletResponse JavaDoc;
28 import org.apache.commons.logging.Log;
29 import org.apache.commons.logging.LogFactory;
30 import org.apache.roller.config.RollerConfig;
31 import org.apache.roller.ui.rendering.util.CommentAuthenticator;
32 import org.apache.roller.ui.rendering.util.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  */

44 public class CommentAuthenticatorServlet extends HttpServlet JavaDoc {
45     
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 JavaDoc request, HttpServletResponse JavaDoc response)
58         throws IOException JavaDoc, ServletException JavaDoc {
59
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 JavaDoc out = response.getWriter();
68         out.println(this.authenticator.getHtml(request));
69     }
70     
71     
72     /**
73      * Initialization.
74      */

75     public void init(ServletConfig JavaDoc config) throws ServletException JavaDoc {
76         
77         super.init(config);
78         
79         // lookup the authenticator we are going to use and instantiate it
80
try {
81             String JavaDoc name = RollerConfig.getProperty("comment.authenticator.classname");
82             
83             Class JavaDoc clazz = Class.forName(name);
84             this.authenticator = (CommentAuthenticator) clazz.newInstance();
85             
86         } catch(Exception JavaDoc e) {
87             mLogger.error(e);
88             this.authenticator = new DefaultCommentAuthenticator();
89         }
90
91     }
92     
93     /**
94      * Destruction.
95      */

96     public void destroy() {}
97     
98 }
99
Popular Tags