View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      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 LoginViewValve
40  {
41      private static final Log log = LogFactory.getLog(LoginJSPViewValve.class);
42  
43      private static final String DEFAULT_TEMPLATE_PATH = "/WEB-INF/templates/login";
44  
45      private String templatePath;
46  
47      public LoginJSPViewValve()
48      {
49          templatePath = DEFAULT_TEMPLATE_PATH;
50      }
51  
52      public LoginJSPViewValve(String templatePath)
53      {
54          this.templatePath = templatePath;
55      }
56  
57      /*
58       * (non-Javadoc)
59       * 
60       * @see org.apache.jetspeed.pipeline.valve.AbstractValve#invoke(org.apache.jetspeed.request.RequestContext,
61       *      org.apache.jetspeed.pipeline.valve.ValveContext)
62       */
63      public void invoke(RequestContext request, ValveContext context) throws PipelineException
64      {
65          String loginTemplateFile = templatePath + "/" + request.getMediaType() + "/login.jsp";
66  
67          try
68          {
69              RequestDispatcher rd = request.getRequest().getRequestDispatcher(loginTemplateFile);
70              rd.include(request.getRequest(), request.getResponse());
71          }
72          catch (ServletException e)
73          {
74              log.warn("The included login template file threw the exception.", e);
75              throw new PipelineException("The included login template file threw the exception.", e);
76          }
77          catch (IOException e)
78          {
79              log.warn("I/O error occurred on the included login template file.", e);
80              throw new PipelineException("I/O error occurred on the included login template file.", e);
81          }
82  
83          // Pass control to the next Valve in the Pipeline
84          context.invokeNext(request);
85      }
86  
87      public String toString()
88      {
89          return "LoginViewValve";
90      }
91  }