View Javadoc

1   /*
2    * Copyright 2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
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.
15   */
16  package org.apache.portals.bridges.jsf;
17  
18  import javax.faces.FacesException;
19  import javax.faces.context.FacesContext;
20  import javax.faces.context.FacesContextFactory;
21  import javax.faces.lifecycle.Lifecycle;
22  
23  import javax.portlet.PortletConfig;
24  import javax.portlet.PortletContext;
25  import javax.portlet.PortletRequest;
26  import javax.portlet.PortletResponse;
27  
28  /***
29   * <p>
30   * Loads the {@link PortletFacesContextImpl}
31   * </p>
32   * 
33   * @author <a href="dlestrat@apache.org">David Le Strat </a>
34   */
35  public class FacesContextFactoryImpl extends FacesContextFactory
36  {
37      /***
38       * @see javax.faces.context.FacesContextFactory#getFacesContext(java.lang.Object,
39       *      java.lang.Object, java.lang.Object, javax.faces.lifecycle.Lifecycle)
40       */
41      public FacesContext getFacesContext(Object config, Object request, Object response, Lifecycle lifecycle) 
42              throws FacesException
43      {
44          if (config instanceof PortletConfig)
45          {
46              PortletConfig pc = (PortletConfig)config;
47              PortletContext context = pc.getPortletContext();
48              PortletFacesContextImpl facesContext = new PortletFacesContextImpl( 
49                      (PortletContext) context,  
50                      (PortletRequest) request,
51                      (PortletResponse) response);
52              String defaultViewName = pc.getInitParameter(FacesPortlet.PARAM_VIEW_PAGE);            
53              // facesContext.resolveViewRoot(defaultViewName, (PortletRequest)request);
54              return facesContext;
55          }
56          else
57          {
58              throw new FacesException("Unsupported context type " + config.getClass().getName());
59          }
60      }
61  }