01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. The ASF licenses this file to You
04: * under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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;
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.config.RollerConfig;
31: import org.apache.roller.ui.rendering.util.CommentAuthenticator;
32: import org.apache.roller.ui.rendering.util.DefaultCommentAuthenticator;
33:
34: /**
35: * The CommentAuthenticatorServlet is used for generating the html used for
36: * comment authentication. This is done outside of the normal rendering process
37: * so that we can cache full pages and still set the comment authentication
38: * section dynamically.
39: *
40: * @web.servlet name="CommentAuthenticatorServlet" load-on-startup="7"
41: * @web.servlet-mapping url-pattern="/CommentAuthenticatorServlet"
42: */
43: public class CommentAuthenticatorServlet extends HttpServlet {
44:
45: private static Log mLogger = LogFactory
46: .getLog(CommentAuthenticatorServlet.class);
47:
48: private CommentAuthenticator authenticator = null;
49:
50: /**
51: * Handle incoming http GET requests.
52: *
53: * We only handle get requests.
54: */
55: public void doGet(HttpServletRequest request,
56: HttpServletResponse response) throws IOException,
57: ServletException {
58:
59: response.setContentType("text/html; charset=utf-8");
60:
61: // Convince proxies and IE not to cache this.
62: response.addHeader("Pragma", "no-cache");
63: response.addHeader("Cache-Control", "no-cache");
64: response.addHeader("Expires", "Thu, 01 Jan 1970 00:00:00 GMT");
65:
66: PrintWriter out = response.getWriter();
67: out.println(this .authenticator.getHtml(request));
68: }
69:
70: /**
71: * Initialization.
72: */
73: public void init(ServletConfig config) throws ServletException {
74:
75: super .init(config);
76:
77: // lookup the authenticator we are going to use and instantiate it
78: try {
79: String name = RollerConfig
80: .getProperty("comment.authenticator.classname");
81:
82: Class clazz = Class.forName(name);
83: this .authenticator = (CommentAuthenticator) clazz
84: .newInstance();
85:
86: } catch (Exception 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: }
|