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.portals.bridges.jsf;
    18
    19  import javax.faces.FacesException;
    20  import javax.faces.context.FacesContext;
    21  import javax.faces.context.FacesContextFactory;
    22  import javax.faces.lifecycle.Lifecycle;
    23  import javax.portlet.PortletContext;
    24  import javax.portlet.PortletRequest;
    25  import javax.portlet.PortletResponse;
    26  import javax.servlet.ServletContext;
    27  import javax.servlet.ServletRequest;
    28  import javax.servlet.ServletResponse;
    29
    30  /***
    31   * <p>
    32   * Loads the {@link PortletFacesContextImpl}
    33   * </p>
    34   *
    35   * @author <a href="dlestrat@apache.org">David Le Strat </a>
    36   */
    37  public class FacesContextFactoryImpl extends FacesContextFactory
    38  {
    39      /***
    40       * @see javax.faces.context.FacesContextFactory#getFacesContext(java.lang.Object,
    41       *      java.lang.Object, java.lang.Object, javax.faces.lifecycle.Lifecycle)
    42       */
    43      public FacesContext getFacesContext(Object context, Object request, Object response, Lifecycle lifecycle)
    44              throws FacesException
    45      {
    46          if (context instanceof PortletContext)
    47          {
    48              return new PortletFacesContextImpl(
    49                      (PortletContext) context,
    50                      (PortletRequest) request,
    51                      (PortletResponse) response);
    52          }
    53          else if (context instanceof ServletContext)
    54          {
    55              return new ServletFacesContextImpl(
    56                      (ServletContext) context,
    57                      (ServletRequest) request,
    58                      (ServletResponse) response);
    59          }
    60          else
    61          {
    62              throw new FacesException("Unsupported context type " + context.getClass().getName());
    63          }
    64      }
    65  }