01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.jetspeed.login.impl;
18:
19: import java.io.IOException;
20:
21: import javax.servlet.RequestDispatcher;
22: import javax.servlet.ServletException;
23:
24: import org.apache.commons.logging.Log;
25: import org.apache.commons.logging.LogFactory;
26: import org.apache.jetspeed.pipeline.PipelineException;
27: import org.apache.jetspeed.pipeline.valve.AbstractValve;
28: import org.apache.jetspeed.pipeline.valve.LoginViewValve;
29: import org.apache.jetspeed.pipeline.valve.ValveContext;
30: import org.apache.jetspeed.request.RequestContext;
31:
32: /**
33: * LoginJSPViewValveImpl
34: *
35: * TODO: move this class into a new component?
36: * @author <a href="mailto:shinsuke@yahoo.co.jp">Shinsuke Sugaya</a>
37: * @version $Id: LoginJSPViewValve.java 186726 2004-06-05 05:13:09Z shinsuke $
38: */
39: public class LoginJSPViewValve extends AbstractValve implements
40: LoginViewValve {
41: private static final Log log = LogFactory
42: .getLog(LoginJSPViewValve.class);
43:
44: private static final String DEFAULT_TEMPLATE_PATH = "/WEB-INF/templates/login";
45:
46: private String templatePath;
47:
48: public LoginJSPViewValve() {
49: templatePath = DEFAULT_TEMPLATE_PATH;
50: }
51:
52: public LoginJSPViewValve(String templatePath) {
53: this .templatePath = templatePath;
54: }
55:
56: /*
57: * (non-Javadoc)
58: *
59: * @see org.apache.jetspeed.pipeline.valve.AbstractValve#invoke(org.apache.jetspeed.request.RequestContext,
60: * org.apache.jetspeed.pipeline.valve.ValveContext)
61: */
62: public void invoke(RequestContext request, ValveContext context)
63: throws PipelineException {
64: String loginTemplateFile = templatePath + "/"
65: + request.getMediaType() + "/login.jsp";
66:
67: try {
68: RequestDispatcher rd = request.getRequest()
69: .getRequestDispatcher(loginTemplateFile);
70: rd.include(request.getRequest(), request.getResponse());
71: } catch (ServletException e) {
72: log
73: .warn(
74: "The included login template file threw the exception.",
75: e);
76: throw new PipelineException(
77: "The included login template file threw the exception.",
78: e);
79: } catch (IOException e) {
80: log
81: .warn(
82: "I/O error occurred on the included login template file.",
83: e);
84: throw new PipelineException(
85: "I/O error occurred on the included login template file.",
86: e);
87: }
88:
89: // Pass control to the next Valve in the Pipeline
90: context.invokeNext(request);
91: }
92:
93: public String toString() {
94: return "LoginViewValve";
95: }
96: }
|