You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by dl...@apache.org on 2004/08/17 21:56:15 UTC

cvs commit: jakarta-jetspeed-2/portals-bridges/myfaces/src/java/org/apache/portals/bridges/myfaces RequestMap.java PortletExternalContextImpl.java FacesContextFactoryImpl.java RequestParameterMap.java RequestParameterValuesMap.java PortletViewHandlerImpl.java PortletFacesContextImpl.java InitParameterMap.java SessionMap.java ApplicationMap.java FacesPortlet.java

dlestrat    2004/08/17 12:56:15

  Added:       portals-bridges/myfaces/src/java/org/apache/portals/bridges/myfaces
                        RequestMap.java PortletExternalContextImpl.java
                        FacesContextFactoryImpl.java
                        RequestParameterMap.java
                        RequestParameterValuesMap.java
                        PortletViewHandlerImpl.java
                        PortletFacesContextImpl.java InitParameterMap.java
                        SessionMap.java ApplicationMap.java
                        FacesPortlet.java
  Log:
  MyFaces Bridge
  See http://nagoya.apache.org/jira/browse/JS2-107.
  
  Revision  Changes    Path
  1.1                  jakarta-jetspeed-2/portals-bridges/myfaces/src/java/org/apache/portals/bridges/myfaces/RequestMap.java
  
  Index: RequestMap.java
  ===================================================================
  /*
   * Copyright 2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.portals.bridges.myfaces;
  
  import java.util.Enumeration;
  
  import javax.portlet.PortletContext;
  import javax.portlet.PortletRequest;
  
  import net.sourceforge.myfaces.context.AbstractAttributeMap;
  
  
  /**
   * <p>{@link PortletRequest} attributes Map.</p>
   * 
   * @author <a href="dlestrat@apache.org">David Le Strat</a>
   */
  public class RequestMap extends AbstractAttributeMap
  {
  	/** Illegal argument exception message. */
  	final private static String ILLEGAL_ARGUMENT = "Only PortletContext supported";
  	/** The {@link PortletContext}. */
  	private final PortletRequest portletRequest;
  
      public RequestMap(Object request)
      {
          if (request instanceof PortletRequest)
          {
          	this.portletRequest = (PortletRequest) request;
          }
          else
          {
          	throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
          }
      }
  
      public Object getAttribute(String key)
      {
          if (null != this.portletRequest)
          {
          	return this.portletRequest.getAttribute(key);
          }
          else
          {
          	throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
          }
      }
  
      public void setAttribute(String key, Object value)
      {
      	if (null != this.portletRequest)
          {
      		this.portletRequest.setAttribute(key, value);
          }
      }
  
      public void removeAttribute(String key)
      {
      	if (null != this.portletRequest)
          {
      		this.portletRequest.removeAttribute(key);
          }
      }
  
      public Enumeration getAttributeNames()
      {
      	if (null != this.portletRequest)
          {
      		return this.portletRequest.getAttributeNames();
          }
      	else
          {
          	throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
          }
      }
  }
  
  
  
  1.1                  jakarta-jetspeed-2/portals-bridges/myfaces/src/java/org/apache/portals/bridges/myfaces/PortletExternalContextImpl.java
  
  Index: PortletExternalContextImpl.java
  ===================================================================
  /*
   * Copyright 2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.portals.bridges.myfaces;
  
  import java.io.IOException;
  import java.io.InputStream;
  import java.net.MalformedURLException;
  import java.net.URL;
  import java.security.Principal;
  import java.util.Enumeration;
  import java.util.Iterator;
  import java.util.Locale;
  import java.util.Map;
  import java.util.Set;
  
  import javax.faces.FacesException;
  import javax.faces.context.ExternalContext;
  
  import javax.portlet.PortletContext;
  import javax.portlet.PortletException;
  import javax.portlet.PortletRequest;
  import javax.portlet.PortletRequestDispatcher;
  import javax.portlet.PortletResponse;
  import javax.portlet.RenderRequest;
  import javax.portlet.RenderResponse;
  
  import net.sourceforge.myfaces.util.EnumerationIterator;
  
  import org.apache.commons.logging.LogFactory;
  import org.apache.commons.logging.Log;
  
  /**
   * <p>JSF 1.0 PRD2, 6.1.1</p>
   * 
   * @author <a href="dlestrat@apache.org">David Le Strat</a>
   */
  public class PortletExternalContextImpl extends ExternalContext
  {
  	private static final Log log = LogFactory.getLog(PortletExternalContextImpl.class);
  	
  	private static final String INIT_PARAMETER_MAP_ATTRIBUTE = InitParameterMap.class.getName();
      
      private PortletContext portletContext;
      private PortletRequest portletRequest;
      private PortletResponse portletResponse;
      private Map applicationMap;
      private Map sessionMap;
      private Map requestMap;
      private Map requestParameterMap;
      private Map requestParameterValuesMap;
      private Map requestHeaderMap;
      private Map requestHeaderValuesMap;
      private Map requestCookieMap;
      private Map initParameterMap;
      private String requestPathInfo;
      private String requestServletPath;
      
      public PortletExternalContextImpl(PortletContext portletContext,
      								  PortletRequest portletRequest,
      								  PortletResponse portletResponse)
      {
          this.portletContext = portletContext;
          this.portletRequest = portletRequest;
          this.portletResponse = portletResponse;
          this.applicationMap = null;
          this.sessionMap = null;
          this.requestMap = null;
          this.requestParameterMap = null;
          this.requestParameterValuesMap = null;
          this.requestHeaderMap = null;
          this.requestHeaderValuesMap = null;
          this.requestCookieMap = null;
          this.initParameterMap = null;
          this.requestPathInfo = null;
          this.requestServletPath = null;
      }
  
      public void release()
      {
          this.portletContext = null;
          this.portletRequest = null;
          this.portletResponse = null;
          this.applicationMap = null;
          this.sessionMap = null;
          this.requestMap = null;
          this.requestParameterMap = null;
          this.requestParameterValuesMap = null;
          this.requestHeaderMap = null;
          this.requestHeaderValuesMap = null;
          this.requestCookieMap = null;
          this.initParameterMap = null;
          this.requestPathInfo = null;
          this.requestServletPath = null;
      }
  
  
      public Object getSession(boolean create)
      {
          return this.portletRequest.getPortletSession(create);
      }
  
      public Object getContext()
      {
          return this.portletContext;
      }
  
      public Object getRequest()
      {
          return this.portletRequest;
      }
  
      public Object getResponse()
      {
          return this.portletResponse;
      }
  
      public Map getApplicationMap()
      {
          if (this.applicationMap == null)
          {
              this.applicationMap = new ApplicationMap(this.portletContext);
          }
          return this.applicationMap;
      }
  
      public Map getSessionMap()
      {
          if (this.sessionMap == null)
          {
              this.sessionMap = new SessionMap(this.portletRequest);
          }
          return this.sessionMap;
      }
  
      public Map getRequestMap()
      {
          if (this.requestMap == null)
          {
              this.requestMap = new RequestMap(this.portletRequest);
          }
          return this.requestMap;
      }
  
      public Map getRequestParameterMap()
      {
          if (this.requestParameterMap == null)
          {
              this.requestParameterMap = new RequestParameterMap(this.portletRequest);
          }
          return this.requestParameterMap;
      }
  
      public Map getRequestParameterValuesMap()
      {
          if (this.requestParameterValuesMap == null)
          {
              this.requestParameterValuesMap = new RequestParameterValuesMap(this.portletRequest);
          }
          return this.requestParameterValuesMap;
      }
  
      public Iterator getRequestParameterNames()
      {
          final Enumeration enum = this.portletRequest.getParameterNames();
          Iterator it = new Iterator()
          {
              public boolean hasNext() {
                  return enum.hasMoreElements();
              }
  
              public Object next() {
                  return enum.nextElement();
              }
  
              public void remove() {
                  throw new UnsupportedOperationException(this.getClass().getName() + " UnsupportedOperationException");
              }
          };
          return it;
      }
  
      public Map getRequestHeaderMap()
      {
          return null;
      }
  
      public Map getRequestHeaderValuesMap()
      {
          return null;
      }
  
      public Map getRequestCookieMap()
      {
          return null;
      }
  
      public Locale getRequestLocale()
      {
          return this.portletRequest.getLocale();
      }
  
      public String getRequestPathInfo()
      {
      	if (null == this.requestPathInfo)
      	{
          	this.requestPathInfo = (String) this.portletRequest.getAttribute("javax.servlet.include.path_info");
      	}
      	return  this.requestPathInfo;
      }
  
      public String getRequestContextPath()
      {
          return this.portletRequest.getContextPath();
      }
  
      public String getInitParameter(String s)
      {
          return this.portletContext.getInitParameter(s);
      }
  
      public Map getInitParameterMap()
      {
          if (this.initParameterMap == null)
          {
              if ((this.initParameterMap = (Map) this.portletContext.getAttribute(INIT_PARAMETER_MAP_ATTRIBUTE)) == null)
              {
                  this.initParameterMap = new InitParameterMap(this.portletContext);
                  this.portletContext.setAttribute(INIT_PARAMETER_MAP_ATTRIBUTE, this.initParameterMap);
              }
          }
          return this.initParameterMap;
      }
  
      public Set getResourcePaths(String s)
      {
          return this.portletContext.getResourcePaths(s);
      }
  
      public InputStream getResourceAsStream(String s)
      {
          return this.portletContext.getResourceAsStream(s);
      }
  
      public String encodeActionURL(String s)
      {
      	return this.portletResponse.encodeURL(s);
      }
  
      public String encodeResourceURL(String s)
      {
          return this.portletResponse.encodeURL(s);
      }
  
      public String encodeNamespace(String s)
      {
          return s;
      }
  
      public void dispatch(String requestURI) throws IOException, FacesException
      {
          if (!(this.portletResponse instanceof RenderResponse))
          {
          	throw new IllegalArgumentException("Only RenderResponse can be dispatched");
          }
          if (!(this.portletRequest instanceof RenderRequest))
          {
          	throw new IllegalArgumentException("Only RenderRequest can be dispatched");
          }
      	PortletRequestDispatcher portletRequestDispatcher
              = this.portletContext.getRequestDispatcher(requestURI);
          try
          {
          	portletRequestDispatcher.include((RenderRequest) this.portletRequest, (RenderResponse) this.portletResponse);
          }
          catch (PortletException e)
          {
          	if (e.getMessage() != null)
              {
                  throw new FacesException(e.getMessage(), e);
              }
              else
              {
                  throw new FacesException(e);
              }
          }
      }
  
      public String getRequestServletPath()
      {
          return (String) this.portletRequest.getAttribute(FacesPortlet.VIEW_ID);
      }
  
      public String getAuthType()
      {
          return this.portletRequest.getAuthType();
      }
  
      public String getRemoteUser()
      {
          return this.portletRequest.getRemoteUser();
      }
  
      public boolean isUserInRole(String role)
      {
          return this.portletRequest.isUserInRole(role);
      }
  
      public Principal getUserPrincipal()
      {
          return this.portletRequest.getUserPrincipal();
      }
  
      public void log(String message) {
          this.portletContext.log(message);
      }
  
      public void log(String message, Throwable t) {
      	this.portletContext.log(message, t);
      }
  
      public void redirect(String url) throws IOException
      {
      }
  
      public Iterator getRequestLocales()
      {
          return new EnumerationIterator(this.portletRequest.getLocales());
      }
  
      public URL getResource(String s) throws MalformedURLException
      {
          return this.portletContext.getResource(s);
      }
  }
  
  
  
  1.1                  jakarta-jetspeed-2/portals-bridges/myfaces/src/java/org/apache/portals/bridges/myfaces/FacesContextFactoryImpl.java
  
  Index: FacesContextFactoryImpl.java
  ===================================================================
  /*
   * Copyright 2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.portals.bridges.myfaces;
  
  import javax.faces.FacesException;
  import javax.faces.context.FacesContext;
  import javax.faces.context.FacesContextFactory;
  import javax.faces.lifecycle.Lifecycle;
  
  import javax.portlet.PortletContext;
  import javax.portlet.PortletRequest;
  import javax.portlet.PortletResponse;
  
  /**
   * <p>Loads the {@link PortletFacesContextImpl}</p>
   * @author <a href="dlestrat@apache.org">David Le Strat</a>
   */
  public class FacesContextFactoryImpl extends FacesContextFactory
  {
      public FacesContext getFacesContext(Object context,
                                          Object request,
                                          Object response,
                                          Lifecycle lifecycle)
      	throws FacesException
      {
          if (context instanceof PortletContext)
          {
              return new PortletFacesContextImpl((PortletContext)context,
                                                 (PortletRequest)request,
                                                 (PortletResponse)response);
          }
          else
          {
              throw new FacesException("Unsupported context type " + context.getClass().getName());
          }
      }
  }
  
  
  
  1.1                  jakarta-jetspeed-2/portals-bridges/myfaces/src/java/org/apache/portals/bridges/myfaces/RequestParameterMap.java
  
  Index: RequestParameterMap.java
  ===================================================================
  /*
   * Copyright 2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.portals.bridges.myfaces;
  
  import java.util.Enumeration;
  
  import javax.portlet.PortletRequest;
  
  import net.sourceforge.myfaces.context.AbstractAttributeMap;
  
  /**
   * <p>{@link PortletRequest} parameters as Map.</p>
   * 
   * @author <a href="dlestrat@apache.org">David Le Strat</a>
   */
  public class RequestParameterMap extends AbstractAttributeMap
  {
  	/** Illegal argument exception message. */
  	final private static String ILLEGAL_ARGUMENT = "Only PortletContext supported";
  	/** The {@link PortletRequest}. */
  	private final PortletRequest portletRequest;
  
      public RequestParameterMap(Object request)
      {
          if (request instanceof PortletRequest)
          {
          	this.portletRequest = (PortletRequest) request;
          }
          else
          {
          	throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
          }
      }
  
      public Object getAttribute(String key)
      {
          if (null != this.portletRequest)
          {
          	return this.portletRequest.getParameter(key);
          }
          else
          {
          	throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
          }
      }
  
      public void setAttribute(String key, Object value)
      {
          throw new UnsupportedOperationException("Cannot set PortletRequest Parameter");
      }
  
      public void removeAttribute(String key)
      {
          throw new UnsupportedOperationException("Cannot remove PortletRequest Parameter");
      }
  
      public Enumeration getAttributeNames()
      {
          if (null != this.portletRequest)
          {
          	return this.portletRequest.getParameterNames();
          }
          else
          {
          	throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
          }
      }
  }
  
  
  1.1                  jakarta-jetspeed-2/portals-bridges/myfaces/src/java/org/apache/portals/bridges/myfaces/RequestParameterValuesMap.java
  
  Index: RequestParameterValuesMap.java
  ===================================================================
  /*
   * Copyright 2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.portals.bridges.myfaces;
  
  import java.util.Enumeration;
  
  import javax.portlet.PortletRequest;
  
  import net.sourceforge.myfaces.context.AbstractAttributeMap;
  
  /**
   * <p>{@link PortletRequest} multi-value parameters as Map.</p>
   * 
   * @author <a href="dlestrat@apache.org">David Le Strat</a>
   */
  public class RequestParameterValuesMap extends AbstractAttributeMap
  {
  	/** Illegal argument exception message. */
  	final private static String ILLEGAL_ARGUMENT = "Only PortletContext supported";
  	/** The {@link PortletRequest}. */
  	private final PortletRequest portletRequest;
  
      public RequestParameterValuesMap(Object request)
      {
          if (request instanceof PortletRequest)
          {
          	this.portletRequest = (PortletRequest) request;
          }
          else
          {
          	throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
          }
      }
  
      public Object getAttribute(String key)
      {
          if (null != this.portletRequest)
          {
          	return this.portletRequest.getParameterValues(key);
          }
          else
          {
          	throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
          }
      }
  
      public void setAttribute(String key, Object value)
      {
          throw new UnsupportedOperationException("Cannot set PortletRequest ParameterValues");
      }
  
      public void removeAttribute(String key)
      {
          throw new UnsupportedOperationException("Cannot remove PortletRequest ParameterValues");
      }
  
      public Enumeration getAttributeNames()
      {
      	if (null != this.portletRequest)
          {
      		return this.portletRequest.getParameterNames();
          }
      	else
          {
          	throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
          }
      }
  }
  
  
  1.1                  jakarta-jetspeed-2/portals-bridges/myfaces/src/java/org/apache/portals/bridges/myfaces/PortletViewHandlerImpl.java
  
  Index: PortletViewHandlerImpl.java
  ===================================================================
  /*
   * Copyright 2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License"); you may not
   * use this file except in compliance with the License. You may obtain a copy of
   * the License at
   * 
   * http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   * License for the specific language governing permissions and limitations under
   * the License.
   */
  package org.apache.portals.bridges.myfaces;
  
  import java.io.IOException;
  import java.util.Locale;
  
  import javax.faces.FacesException;
  import javax.faces.application.ViewHandler;
  import javax.faces.component.UIViewRoot;
  import javax.faces.context.FacesContext;
  
  import javax.portlet.PortletURL;
  import javax.portlet.RenderResponse;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  /**
   * @author <a href="mailto:dlestrat@apache.org">David Le Strat</a>
   */
  public class PortletViewHandlerImpl extends ViewHandler
  {
      /** The Log instance for this class. */
      private static final Log log = LogFactory.getLog(PortletViewHandlerImpl.class);
  
      /** The ViewHandler. */
      private ViewHandler handler;
  
      /**
       * <p>Construct a new <code>ViewHandler</code> instance that delegates
       * non-portlet-specific behavior to the specified implementation.
       * 
       * @param handler The <code>ViewHandler</code> instance
       */
      public PortletViewHandlerImpl(ViewHandler handler)
      {
          if (log.isInfoEnabled())
          {
              log.info("Delegating to " + handler + "");
          }
          this.handler = handler;
      }
      
      public Locale calculateLocale(FacesContext facesContext)
      {
          return handler.calculateLocale(facesContext);
      }
  
      public String calculateRenderKitId(FacesContext facesContext)
      {
          return handler.calculateRenderKitId(facesContext);
      }
  
      public UIViewRoot createView(FacesContext facesContext, String viewId)
      {
          return handler.createView(facesContext, viewId);
      }
  
      public String getActionURL(FacesContext facesContext, String viewId)
      {
          Object response = facesContext.getExternalContext().getResponse();
          if (!(response instanceof RenderResponse)) {
              throw new IllegalStateException("Must be a RenderResponse");
          }
          RenderResponse renderResponse = (RenderResponse) response;
          PortletURL actionURL = renderResponse.createActionURL();
          return (actionURL.toString());
      }
      
      public String getResourceURL(FacesContext facesContext, String path)
      {
          return handler.getResourceURL(facesContext, path);
      }
      
      public void renderView(FacesContext facesContext, UIViewRoot viewToRender) throws IOException, FacesException
      {
          handler.renderView(facesContext, viewToRender);
      }
      
      public UIViewRoot restoreView(FacesContext facesContext, String viewId)
      {
          return handler.restoreView(facesContext, viewId);
      }
  
      public void writeState(FacesContext facesContext) throws IOException
      {
          handler.writeState(facesContext);
      }
  
  }
  
  
  
  1.1                  jakarta-jetspeed-2/portals-bridges/myfaces/src/java/org/apache/portals/bridges/myfaces/PortletFacesContextImpl.java
  
  Index: PortletFacesContextImpl.java
  ===================================================================
  /*
   * Copyright 2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.portals.bridges.myfaces;
  
  import java.util.ArrayList;
  import java.util.Collections;
  import java.util.Iterator;
  import java.util.List;
  import java.util.NoSuchElementException;
  
  import javax.faces.FactoryFinder;
  import javax.faces.application.Application;
  import javax.faces.application.ApplicationFactory;
  import javax.faces.application.FacesMessage;
  import javax.faces.component.UIViewRoot;
  import javax.faces.context.ExternalContext;
  import javax.faces.context.FacesContext;
  import javax.faces.context.ResponseStream;
  import javax.faces.context.ResponseWriter;
  import javax.faces.render.RenderKit;
  import javax.faces.render.RenderKitFactory;
  
  import javax.portlet.PortletContext;
  import javax.portlet.PortletRequest;
  import javax.portlet.PortletResponse;
  
  import net.sourceforge.myfaces.util.NullIterator;
  
  /**
   * TODO There should be a base class shared with ServletFacesContextImpl.
   * 
   * @see Also {@link net.sourceforge.myfaces.context.servlet.ServletFacesContextImpl}
   * @author <a href="dlestrat@apache.org">David Le Strat</a>
   *
   */
  public class PortletFacesContextImpl extends FacesContext
  {
  	//~ Static fields/initializers -----------------------------------------------------------------
  	protected static final Object NULL_DUMMY = new Object();
  
  	//~ Instance fields ----------------------------------------------------------------------------
      private List messageClientIds = null;
      private List messages = null;
      private Application application;
      private PortletExternalContextImpl externalContext;
      private ResponseStream responseStream = null;
      private ResponseWriter responseWriter = null;
      private FacesMessage.Severity maximumSeverity = FacesMessage.SEVERITY_INFO;
      private UIViewRoot viewRoot;
      private boolean renderResponse = false;
      private boolean responseComplete = false;
      private RenderKitFactory renderKitFactory;
  
      //~ Constructors -------------------------------------------------------------------------------
      public PortletFacesContextImpl(PortletContext portletContext,
                                     PortletRequest portletRequest,
                                     PortletResponse portletResponse)
      {
          this.application = ((ApplicationFactory)FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY))
                              .getApplication();
          this.renderKitFactory = (RenderKitFactory) FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
          this.externalContext = new PortletExternalContextImpl(portletContext,
                                                            	  portletRequest,
                                                                portletResponse);
          FacesContext.setCurrentInstance(this);  //protected method, therefore must be called from here
      }
  
      public ExternalContext getExternalContext()
      {
          return this.externalContext;
      }
  
      public FacesMessage.Severity getMaximumSeverity()
      {
          return this.maximumSeverity;
      }
  
      public Iterator getMessages()
      {
          return (this.messages != null) ? this.messages.iterator() : Collections.EMPTY_LIST.iterator();
      }
  
      public Application getApplication()
      {
          return this.application;
      }
  
      public Iterator getClientIdsWithMessages()
      {
          if (this.messages == null || this.messages.isEmpty())
          {
              return NullIterator.instance();
          }
  
          return new Iterator()
          {
          	private int next;
              boolean nextFound;
  
              public void remove()
              {
              	throw new UnsupportedOperationException(this.getClass().getName() + " UnsupportedOperationException");
              }
  
              public boolean hasNext()
              {
              	if (!nextFound)
                  {
                  	for (int len = messageClientIds.size(); next < len; next++)
                      {
                  		if (messageClientIds.get(next) != NULL_DUMMY)
                          {
                          	nextFound = true;
                              break;
                          }
                      }
                  }
                  return nextFound;
              }
  
              public Object next()
              {
              	if (hasNext())
                  {
              		nextFound = false;
                      return messageClientIds.get(next++);
                  }
              	throw new NoSuchElementException();
              }
          };
      }
  
      public Iterator getMessages(String clientId)
      {
          if (this.messages == null)
          {
              return NullIterator.instance();
          }
  
          List lst = new ArrayList();
          for (int i = 0; i < this.messages.size(); i++)
          {
              Object savedClientId = this.messageClientIds.get(i);
              if (clientId == null)
              {
                  if (savedClientId == NULL_DUMMY) lst.add(this.messages.get(i));
              }
              else
              {
                  if (clientId.equals(savedClientId)) lst.add(this.messages.get(i));
              }
          }
          return lst.iterator();
      }
  
      public RenderKit getRenderKit()
      {
      	if (getViewRoot() == null)
          {
              return null;
          }
  
          String renderKitId = getViewRoot().getRenderKitId();
         
          if (renderKitId == null)
          {
              return null;
          }
  
          return this.renderKitFactory.getRenderKit(this, renderKitId);
      }
  
      public boolean getRenderResponse()
      {
          return this.renderResponse;
      }
  
      public boolean getResponseComplete()
      {
          return this.responseComplete;
      }
  
      public void setResponseStream(ResponseStream responseStream)
      {
          if (responseStream == null)
          {
              throw new NullPointerException("responseStream");
          }
          this.responseStream = responseStream;
      }
  
      public ResponseStream getResponseStream()
      {
          return this.responseStream;
      }
  
      public void setResponseWriter(ResponseWriter responseWriter)
      {
          if (responseWriter == null)
          {
              throw new NullPointerException("responseWriter");
          }
          this.responseWriter = responseWriter;
      }
  
      public ResponseWriter getResponseWriter()
      {
          return this.responseWriter;
      }
  
      public void setViewRoot(UIViewRoot viewRoot)
      {
          if (viewRoot == null)
          {
              throw new NullPointerException("viewRoot");
          }
          this.viewRoot = viewRoot;
      }
  
      public UIViewRoot getViewRoot()
      {
          return this.viewRoot;
      }
  
      public void addMessage(String clientId, FacesMessage message)
      {
          if (message == null)
          {
              throw new NullPointerException("message");
          }
  
          if (this.messages == null)
          {
              this.messages = new ArrayList();
              this.messageClientIds = new ArrayList();
          }
          this.messages.add(message);
          this.messageClientIds.add((clientId != null) ? clientId : NULL_DUMMY);
          FacesMessage.Severity serSeverity =  message.getSeverity();
          if (serSeverity != null && serSeverity.compareTo(this.maximumSeverity) > 0)
          {
              this.maximumSeverity = message.getSeverity();
          }
      }
  
      public void release()
      {
          if (this.externalContext != null)
          {
              this.externalContext.release();
              this.externalContext = null;
          }
  
          this.messageClientIds = null;
          this.messages = null;
          this.application = null;
          this.responseStream = null;
          this.responseWriter = null;
          this.viewRoot = null;
  
          FacesContext.setCurrentInstance(null);
      }
  
      public void renderResponse()
      {
          this.renderResponse = true;
      }
  
      public void responseComplete()
      {
          this.responseComplete = true;
      }
  }
  
  
  
  1.1                  jakarta-jetspeed-2/portals-bridges/myfaces/src/java/org/apache/portals/bridges/myfaces/InitParameterMap.java
  
  Index: InitParameterMap.java
  ===================================================================
  /*
   * Copyright 2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.portals.bridges.myfaces;
  
  import java.util.Enumeration;
  
  import javax.portlet.PortletContext;
  
  import net.sourceforge.myfaces.context.AbstractAttributeMap;
  
  /**
   * <p>{@link PortletContext} init parameters as Map.</p>
   * 
   * @author <a href="dlestrat@apache.org">David Le Strat</a>
   */
  public class InitParameterMap extends AbstractAttributeMap
  {
  	/** Illegal argument exception message. */
  	final private static String ILLEGAL_ARGUMENT = "Only PortletContext supported";
  	/** The {@link PortletContext}. */
  	final private PortletContext portletContext;
  
      public InitParameterMap(Object context)
      {
          if (context instanceof PortletContext)
          {
          	this.portletContext = (PortletContext) context;
          }
          else
          {
          	throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
          }
      }
  
      public Object getAttribute(String key)
      {
          if (null != this.portletContext)
          {
          	return this.portletContext.getInitParameter(key);
          }
          else
          {
          	throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
          }
      }
  
      public void setAttribute(String key, Object value)
      {
          throw new UnsupportedOperationException("Cannot set PortletContext InitParameter");
      }
  
      public void removeAttribute(String key)
      {
          throw new UnsupportedOperationException("Cannot remove PortletContext InitParameter");
      }
  
      public Enumeration getAttributeNames()
      {
      	if (null != this.portletContext)
          {
      		return this.portletContext.getInitParameterNames();
          }
      	else
          {
          	throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
          }
      }
  }
  
  
  
  1.1                  jakarta-jetspeed-2/portals-bridges/myfaces/src/java/org/apache/portals/bridges/myfaces/SessionMap.java
  
  Index: SessionMap.java
  ===================================================================
  /*
   * Copyright 2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.portals.bridges.myfaces;
  
  import java.util.Enumeration;
  
  import javax.portlet.PortletRequest;
  import javax.portlet.PortletSession;
  
  import net.sourceforge.myfaces.context.AbstractAttributeMap;
  import net.sourceforge.myfaces.util.NullEnumeration;
  
  /**
   * HttpSession attibutes as Map.
   * 
   * @author Anton Koinov (latest modification by $Author: dlestrat $)<br>
   *         Refactored to support Portlets by <a href="dlestrat@apache.org">David Le Strat</a>
   */
  public class SessionMap extends AbstractAttributeMap
  {
  	/** Illegal argument exception message. */
  	final private static String ILLEGAL_ARGUMENT = "Only PortletContext supported";
  	/** The {@link PortletRequest}. */
  	private final PortletRequest portletRequest;
  
      public SessionMap(Object request)
      {
          if (request instanceof PortletRequest)
          {
          	this.portletRequest = (PortletRequest) request;
          }
          else
          {
          	throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
          }
      }
  
      protected Object getAttribute(String key)
      {
          if (null != this.portletRequest)
          {
          	PortletSession portletSession = this.portletRequest.getPortletSession(false);
          	return (portletSession == null) 
          		? null : portletSession.getAttribute(key.toString());
          }
          else
          {
          	throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
          }
      }
  
      protected void setAttribute(String key, Object value)
      {
      	if (null != this.portletRequest)
          {
      		this.portletRequest.getPortletSession(true).setAttribute(key, value);
          }
      }
  
      protected void removeAttribute(String key)
      {
      	if (null != this.portletRequest)
      	{
      		PortletSession portletSession = this.portletRequest.getPortletSession(false);;
      		if (null != portletSession)
      		{
      			portletSession.removeAttribute(key);
      		}
      	}
      }
  
      protected Enumeration getAttributeNames()
      {
      	if (null != this.portletRequest)
      	{
      		PortletSession portletSession = this.portletRequest.getPortletSession(false);;
      		return (portletSession == null)
              	? NullEnumeration.instance()
                  : portletSession.getAttributeNames();
      	}
      	else
          {
          	throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
          }
      }
  
  }
  
  
  1.1                  jakarta-jetspeed-2/portals-bridges/myfaces/src/java/org/apache/portals/bridges/myfaces/ApplicationMap.java
  
  Index: ApplicationMap.java
  ===================================================================
  /*
   * Copyright 2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.portals.bridges.myfaces;
  
  import java.util.Enumeration;
  
  import javax.portlet.PortletContext;
  
  import net.sourceforge.myfaces.context.servlet.AbstractAttributeMap;
  
  /**
   * <p>{@link PortletContext} attributes as a Map.</p>
   * 
   * @author <a href="dlestrat@apache.org">David Le Strat</a>
   */
  public class ApplicationMap extends AbstractAttributeMap
  {
      /** Illegal argument exception message. */
  	final private static String ILLEGAL_ARGUMENT = "Only PortletContext supported";
  	/** The {@link PortletContext}. */
  	final private PortletContext portletContext;
  
      public ApplicationMap(Object context)
      {
          if (context instanceof PortletContext)
          {
          	this.portletContext = (PortletContext) context;
          }
          else
          {
          	throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
          }
      }
  
      public Object getAttribute(String key)
      {
          if (null != this.portletContext)
          {
          	return this.portletContext.getAttribute(key);
          }
      	else
      	{
      		throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
      	}
      }
  
      public void setAttribute(String key, Object value)
      {
      	if (null != this.portletContext)
          {
      		this.portletContext.setAttribute(key, value);
          }
      }
  
      public void removeAttribute(String key)
      {
      	if (null != this.portletContext)
          {
      		this.portletContext.removeAttribute(key);
          }
      }
  
      public Enumeration getAttributeNames()
      {
      	if (null != this.portletContext)
          {
      		return this.portletContext.getAttributeNames();
          }
      	else
      	{
      		throw new IllegalArgumentException(ILLEGAL_ARGUMENT);
      	}
      }
  }
  
  
  
  1.1                  jakarta-jetspeed-2/portals-bridges/myfaces/src/java/org/apache/portals/bridges/myfaces/FacesPortlet.java
  
  Index: FacesPortlet.java
  ===================================================================
  /*
   * Copyright 2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.portals.bridges.myfaces;
  
  import java.io.IOException;
  
  import javax.faces.FacesException;
  import javax.faces.FactoryFinder;
  import javax.faces.application.Application;
  import javax.faces.component.UIViewRoot;
  import javax.faces.context.FacesContext;
  import javax.faces.context.FacesContextFactory;
  import javax.faces.lifecycle.Lifecycle;
  import javax.faces.lifecycle.LifecycleFactory;
  import javax.faces.render.RenderKitFactory;
  import javax.faces.webapp.FacesServlet;
  
  import javax.portlet.ActionRequest;
  import javax.portlet.ActionResponse;
  import javax.portlet.GenericPortlet;
  import javax.portlet.PortletConfig;
  import javax.portlet.PortletException;
  import javax.portlet.PortletRequest;
  import javax.portlet.PortletResponse;
  import javax.portlet.RenderRequest;
  import javax.portlet.RenderResponse;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  /**
   * <p>FacesPortlet utilizes Java Server Faces to create the user interface in a
   * portlet environment.</p>
   * 
   * @author <a href="mailto:dlestrat@yahoo.com">David Le Strat </a>
   */
  public final class FacesPortlet extends GenericPortlet
  {
  
      /** The Log instance for this class. */
      private static final Log log = LogFactory.getLog(FacesPortlet.class);
  
      /** The VIEW_ID used for externalContext.getRequestServletPath(). */
      public static final String VIEW_ID = "org.apache.portals.bridges.myfaces.VIEW_ID";
  
      /** Name of portlet preference for Action page. */
      public static final String PARAM_ACTION_PAGE = "ActionPage";
  
      /** Name of portlet preference for Custom page. */
      public static final String PARAM_CUSTOM_PAGE = "CustomPage";
  
      /** Name of portlet preference for Edit page. */
      public static final String PARAM_EDIT_PAGE = "EditPage";
  
      /** Name of portlet preference for Edit page */
      public static final String PARAM_HELP_PAGE = "HelpPage";
  
      /** Name of portlet preference for View page */
      public static final String PARAM_VIEW_PAGE = "ViewPage";
  
      /** Action request. */
      public static final String ACTION_REQUEST = "ACTION";
  
      /** View request. */
      public static final String VIEW_REQUEST = "VIEW";
  
      /** Custom request. */
      public static final String CUSTOM_REQUEST = "CUSTOM";
  
      /** Edit request. */
      public static final String EDIT_REQUEST = "EDIT";
  
      /** Help request. */
      public static final String HELP_REQUEST = "HELP";
  
      /** Default URL for the action page. */
      private String defaultActionPage = null;
  
      /** Default URL for the custom page. */
      private String defaultCustomPage = null;
  
      /** Default URL for the edit page. */
      private String defaultEditPage = null;
  
      /** Default URL for the help page. */
      private String defaultHelpPage = null;
  
      /** Default URL for the view page. */
      private String defaultViewPage = null;
  
      // ------------------------------------------------------ Manifest Constants
  
      /**
       * <p>
       * Context initialization parameter name for the lifecycle identifier of the
       * {@link Lifecycle}instance to be utilized.
       * </p>
       */
      private static final String LIFECYCLE_ID_ATTR = FacesServlet.LIFECYCLE_ID_ATTR;
  
      // ------------------------------------------------------ Instance Variables
  
      /**
       * <p>
       * The {@link Application}instance for this web application.
       * </p>
       */
      private Application application = null;
  
      /**
       * <p>
       * Factory for {@link FacesContext}instances.
       * </p>
       */
      private FacesContextFactory facesContextFactory = null;
  
      /**
       * <p>
       * The {@link Lifecycle}instance to use for request processing.
       * </p>
       */
      private Lifecycle lifecycle = null;
  
      /**
       * <p>
       * The <code>PortletConfig</code> instance for this portlet.
       * </p>
       */
      private PortletConfig portletConfig = null;
  
      // ---------------------------------------------------------- Public Methods
  
      /**
       * <p>Release all resources acquired at startup time.</p>
       */
      public void destroy()
      {
          if (log.isTraceEnabled())
          {
              log.trace("Begin FacesPortlet.destory() ");
          }
          application = null;
          facesContextFactory = null;
          lifecycle = null;
          portletConfig = null;
          if (log.isTraceEnabled())
          {
              log.trace("End FacesPortlet.destory() ");
          }
  
      }
  
      /**
       * <p>Acquire the factory instance we will require.</p>
       * 
       * @exception PortletException
       *                if, for any reason, the startp of this Faces application
       *                failed. This includes errors in the config file that is
       *                parsed before or during the processing of this
       *                <code>init()</code> method.
       */
      public void init(PortletConfig portletConfig) throws PortletException
      {
  
          if (log.isTraceEnabled())
          {
              log.trace("Begin FacesPortlet.init() ");
          }
  
          super.init(portletConfig);
  
          // Save our PortletConfig instance
          this.portletConfig = portletConfig;
          this.defaultViewPage = portletConfig.getInitParameter(PARAM_VIEW_PAGE);
          if (null == this.defaultViewPage)
          {
              // A Faces Portlet is required to have at least the
              // defaultViewPage
              // defined!
              throw new PortletException("Portlet " + portletConfig.getPortletName()
                      + " is incorrectly configured. No default View page is defined.");
          }
          if (null == this.defaultActionPage)
          {
              this.defaultActionPage = this.defaultViewPage;
          }
          if (null == this.defaultCustomPage)
          {
              this.defaultCustomPage = this.defaultViewPage;
          }
          if (null == this.defaultHelpPage)
          {
              this.defaultHelpPage = this.defaultViewPage;
          }
          if (null == this.defaultEditPage)
          {
              this.defaultEditPage = this.defaultViewPage;
          }
          if (log.isTraceEnabled())
          {
              log.trace("End FacesPortlet.init() ");
          }
      }
  
      public void doEdit(RenderRequest request, RenderResponse response) throws PortletException, IOException
      {
          process(request, response, defaultEditPage, FacesPortlet.EDIT_REQUEST);
      }
  
      public void doHelp(RenderRequest request, RenderResponse response) throws PortletException, IOException
      {
          process(request, response, defaultHelpPage, FacesPortlet.HELP_REQUEST);
      }
  
      public void doCustom(RenderRequest request, RenderResponse response) throws PortletException, IOException
      {
          process(request, response, defaultCustomPage, FacesPortlet.CUSTOM_REQUEST);
      }
  
      public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException
      {
          process(request, response, defaultViewPage, FacesPortlet.VIEW_REQUEST);
      }
  
      public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException
      {
          process(request, response, defaultActionPage, FacesPortlet.ACTION_REQUEST);
      }
  
      /**
       * <p>Gets the {@link FacesContextFactory}.</p>
       * 
       * @return The {@link FacesContextFactory}.
       * @throws PortletException Throws a {@link PortletException}.
       */
      public FacesContextFactory getFacesContextFactory() throws PortletException
      {
          if (facesContextFactory != null)
          {
              return facesContextFactory;
          }
          try
          {
              facesContextFactory = (FacesContextFactory) FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
              if (log.isTraceEnabled())
              {
                  log.trace("Retrieved facesContextFactory " + facesContextFactory);
              }
          }
          catch (FacesException e)
          {
              Throwable rootCause = e.getCause();
              if (rootCause == null)
              {
                  throw e;
              }
              else
              {
                  throw new PortletException(e.getMessage(), rootCause);
              }
          }
          return facesContextFactory;
      }
  
      /**
       * <p>Get the faces life cycle.</p>
       * 
       * @return The {@link Lifecycle}.
       * @throws PortletException Throws a {@link PortletException}.
       */
      public Lifecycle getLifecycle() throws PortletException
      {
          if (lifecycle != null)
          {
              return lifecycle;
          }
          try
          {
              LifecycleFactory lifecycleFactory = (LifecycleFactory) FactoryFinder
                      .getFactory(FactoryFinder.LIFECYCLE_FACTORY);
              if (log.isTraceEnabled())
              {
                  log.trace("Retrieved lifecycleFactory " + lifecycleFactory);
              }
              String lifecycleId = portletConfig.getPortletContext().getInitParameter(LIFECYCLE_ID_ATTR);
              if (log.isDebugEnabled())
              {
                  log.debug("lifecycleId " + lifecycleId);
              }
              if (lifecycleId == null)
              {
                  lifecycleId = LifecycleFactory.DEFAULT_LIFECYCLE;
              }
              lifecycle = lifecycleFactory.getLifecycle(lifecycleId);
              if (log.isTraceEnabled())
              {
                  log.trace("Retrieved lifecycle from lifecycleFactory " + lifecycle);
              }
          }
          catch (FacesException e)
          {
              Throwable rootCause = e.getCause();
              if (rootCause == null)
              {
                  throw e;
              }
              else
              {
                  throw new PortletException(e.getMessage(), rootCause);
              }
          }
          return lifecycle;
      }
  
      /**
       * <p>Processes the request.</p>
       * 
       * @param request The {@link PortletRequest}.
       * @param response The {@link PortletResponse}.
       * @param defaultPage The default page.
       * @param requestType The request type.
       * @throws PortletException Throws a {@link PortletException}.
       * @throws IOException Throws an {@link IOException}.
       */
      private void process(PortletRequest request, PortletResponse response, String defaultPage, String requestType)
              throws PortletException, IOException
      {
          boolean actionRequest = (request instanceof ActionRequest);
          boolean renderRequest = (request instanceof RenderRequest);
          if (actionRequest)
          {
              log.trace("Begin FacesPortlet.processAction()");
          }
  
          // Acquire the FacesContext instance for this request
          FacesContext context = getFacesContextFactory().getFacesContext(portletConfig.getPortletContext(), request,
                  response, getLifecycle());
  
          setDefaultView(context, defaultPage);
          if (log.isTraceEnabled())
          {
              log.trace("Begin Executing phases");
          }
  
          // Execute the pre-render request processing lifecycle for this request
          try
          {
              if (actionRequest)
              {
                  getLifecycle().execute(context);
                  if (log.isTraceEnabled())
                  {
                      log.trace("End Executing phases");
                  }
                  setDefaultView(context, defaultPage);
              }
              else if (renderRequest)
              {
                  getLifecycle().render(context);
                  if (log.isTraceEnabled())
                  {
                      log.trace("End executing RenderResponse phase ");
                  }
              }
              else
              {
                  throw new PortletException("Request must be of type ActionRequest or RenderRequest");
              }
          }
          catch (FacesException e)
          {
              Throwable t = ((FacesException) e).getCause();
              if (t == null)
              {
                  throw new PortletException(e.getMessage(), e);
              }
              else
              {
                  if (t instanceof PortletException)
                  {
                      throw ((PortletException) t);
                  }
                  else if (t instanceof IOException)
                  {
                      throw ((IOException) t);
                  }
                  else
                  {
                      throw new PortletException(t.getMessage(), t);
                  }
              }
          }
          finally
          {
              // Release the FacesContext instance for this request
              context.release();
          }
          if (log.isTraceEnabled())
          {
              log.trace("End FacesPortlet.process()");
          }
      }
  
      /**
       * <p>Set the view identifier to a default page.</p>
       * 
       * @param context The {@link FacesContext} for the current request.
       * @param defaultView The default view identifier.
       */
      private void setDefaultView(FacesContext facesContext, String defaultView)
      {
          // Need to be able to transport viewId between actionRequest and renderRequest.
          // If actionRequest, the view id is obtained from the navigation, we need to be able to keep that
          // value and not have it overwritten by the default view id.  Putting that value in the portletRequest does not
          // work. Need to use actionResponse.setRenderParameter...
          PortletRequest portletRequest = (PortletRequest) facesContext.getExternalContext().getRequest();
          if (portletRequest instanceof ActionRequest)
          {
              if ((null != facesContext.getViewRoot()) && (null != facesContext.getViewRoot().getViewId()))
              {
                  ((ActionResponse) facesContext.getExternalContext().getResponse()).setRenderParameter(FacesPortlet.VIEW_ID, facesContext.getViewRoot().getViewId());
              }
          }
          if ((portletRequest instanceof RenderRequest) && (null != portletRequest.getParameter(FacesPortlet.VIEW_ID)))
          {
              defaultView = portletRequest.getParameter(FacesPortlet.VIEW_ID);
          }
          if ((null != portletRequest.getAttribute(FacesPortlet.VIEW_ID)) && (!portletRequest.getAttribute(FacesPortlet.VIEW_ID).equals(defaultView)))
          {
              return;
          }
          if (facesContext.getViewRoot() == null)
          {
              facesContext.setViewRoot(new UIViewRoot());
              if (log.isDebugEnabled())
              {
                  log.debug("Created new ViewRoot" + facesContext.getViewRoot());
              }
          }
          if (null == facesContext.getViewRoot().getViewId())
          {
              facesContext.getViewRoot().setViewId(defaultView);
          }
          String viewId = facesContext.getViewRoot().getViewId().replaceAll(".jsp", ".jsf");
          portletRequest.setAttribute(FacesPortlet.VIEW_ID, viewId);
          if (log.isDebugEnabled())
          {
              log.debug("Set " + FacesPortlet.VIEW_ID + " to " + viewId);
          }
          facesContext.getViewRoot().setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
      }
  }
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org