View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.myfaces.trinidad.webapp;
20  
21  import java.io.IOException;
22  
23  import javax.servlet.Filter;
24  import javax.servlet.FilterChain;
25  import javax.servlet.FilterConfig;
26  import javax.servlet.ServletException;
27  import javax.servlet.ServletRequest;
28  import javax.servlet.ServletResponse;
29  
30  import org.apache.myfaces.trinidad.logging.TrinidadLogger;
31  
32  /**
33   * Servlet filter that ensures that Trinidad is properly initialized
34   * by establishing a RequestContext object;  this filter also processes file
35   * uploads.
36   * <p>
37   * @version $Name:  $ ($Revision: adfrt/faces/adf-faces-api/src/main/java/oracle/adf/view/faces/webapp/AdfFacesFilter.java#0 $) $Date: 10-nov-2005.19:08:29 $
38   */
39  public class TrinidadFilter implements Filter
40  {
41    public void init(
42      FilterConfig filterConfig) throws ServletException
43    {
44      ClassLoader loader = Thread.currentThread().getContextClassLoader();
45      if (loader == null)
46        _LOG.severe("CANNOT_FIND_CONTEXT_CLASS_LOADER");
47      else
48      {
49        try
50        {
51          Class<?> proxiedClass = loader.loadClass(
52                        "org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl");
53          _proxied = (Filter) proxiedClass.newInstance();
54          _proxied.init(filterConfig);
55        }
56        catch (ClassNotFoundException cnfe)
57        {
58          _LOG.severe(cnfe);
59        }
60        catch (IllegalAccessException iae)
61        {
62          _LOG.severe(iae);
63        }
64        catch (InstantiationException ie)
65        {
66          _LOG.severe(ie);
67        }
68        catch (RuntimeException e)
69        {
70          // OC4J was not reporting these errors properly:
71          _LOG.severe(e);
72          throw e;
73        }
74      }
75  
76  
77    }
78  
79    public void destroy()
80    {
81      if (_proxied != null)
82        _proxied.destroy();
83      _proxied = null;
84    }
85  
86    public void doFilter(
87      ServletRequest  request,
88      ServletResponse response,
89      FilterChain     chain) throws IOException, ServletException
90    {
91      if (_proxied != null)
92        _proxied.doFilter(request, response, chain);
93      else
94        chain.doFilter(request, response);
95    }
96  
97    private static final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(TrinidadFilter.class);
98  
99    private Filter _proxied;
100 }