[richfaces-svn-commits] JBoss Rich Faces SVN: r4964 - in trunk: extensions/portletbridge/portletbridge-impl and 7 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Fri Dec 21 19:30:11 EST 2007


Author: alexsmirnov
Date: 2007-12-21 19:30:11 -0500 (Fri, 21 Dec 2007)
New Revision: 4964

Added:
   trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/SeamExceptionHandlerImpl.java
   trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/PortletExternalContextImpl.java
   trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/RenderPortletExternalContextImpl.java
   trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/ServletExternalContextImpl.java
Removed:
   trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/PortletContextImpl.java
   trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/PortletRenderContextImpl.java
   trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/ServletContextImpl.java
Modified:
   trunk/extensions/pom.xml
   trunk/extensions/portletbridge/portletbridge-impl/pom.xml
   trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/ExceptionHandlerImpl.java
   trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/AbstractExternalContext.java
   trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/FacesContextFactoryImpl.java
   trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/lifecycle/PortalPhaseListener.java
   trunk/extensions/portletbridge/portletbridge-impl/src/test/java/org/ajax4jsf/portlet/context/ContextFactoryTest.java
   trunk/extensions/portletbridge/portletbridge-impl/src/test/java/org/ajax4jsf/portlet/context/FacesContextImplTest.java
   trunk/extensions/portletbridge/portletbridge-impl/src/test/java/org/ajax4jsf/portlet/context/PortletExternalContextTest.java
   trunk/framework/impl/src/main/java/org/ajax4jsf/resource/ResourceLifecycle.java
   trunk/samples/seamPortletEar/seamBooking/src/main/java/org/jboss/seam/example/booking/Booking.java
   trunk/samples/seamPortletEar/seamBooking/src/main/java/org/jboss/seam/example/booking/HotelBookingAction.java
   trunk/samples/seamPortletEar/seamBooking/src/main/java/org/jboss/seam/example/booking/User.java
   trunk/samples/seamPortletEar/seamBookingPortlet/src/main/webapp/WEB-INF/pages.xml
Log:
Continue to resolve Seam <-> portal incompabilites

Modified: trunk/extensions/pom.xml
===================================================================
--- trunk/extensions/pom.xml	2007-12-21 19:33:55 UTC (rev 4963)
+++ trunk/extensions/pom.xml	2007-12-22 00:30:11 UTC (rev 4964)
@@ -11,6 +11,6 @@
   <name>Richfaces extensions for a different environments</name>
   <packaging>pom</packaging>
   <modules>
-    <module>portletbridge</module>
+    <!-- module>portletbridge</module-->
   </modules>
 </project>
\ No newline at end of file

Modified: trunk/extensions/portletbridge/portletbridge-impl/pom.xml
===================================================================
--- trunk/extensions/portletbridge/portletbridge-impl/pom.xml	2007-12-21 19:33:55 UTC (rev 4963)
+++ trunk/extensions/portletbridge/portletbridge-impl/pom.xml	2007-12-22 00:30:11 UTC (rev 4964)
@@ -37,5 +37,18 @@
 			<classifier>tests</classifier>
 			<scope>test</scope>
 		</dependency>
+		<dependency>
+			<groupId>org.jboss.seam</groupId>
+			<artifactId>jboss-seam</artifactId>
+			<version>2.0.1-SNAPSHOT</version>
+			<optional>true</optional>
+		</dependency>
+		<dependency>
+			<groupId>javax.transaction</groupId>
+			<artifactId>jta</artifactId>
+			<version>1.0.1B</version>
+			<optional>true</optional>
+		</dependency>
+
 	</dependencies>
 </project>
\ No newline at end of file

Modified: trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/ExceptionHandlerImpl.java
===================================================================
--- trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/ExceptionHandlerImpl.java	2007-12-21 19:33:55 UTC (rev 4963)
+++ trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/ExceptionHandlerImpl.java	2007-12-22 00:30:11 UTC (rev 4964)
@@ -33,43 +33,7 @@
 {
    protected static final Log log = LogFactory.getLog(ExceptionHandlerImpl.class);
 
-   private static final String seamPages = "WEB-INF/pages.xml";
 
-   private Document getPagesDocument(String file)
-   {
-      Document document = null;
-      InputStream stream = getResourceAsStream(file);
-      if (stream == null)
-      {
-         log.info("no pages.xml file found: " + file);
-      }
-      else
-      {
-         log.debug("reading pages.xml file: " + file);
-         try
-         {
-            //get the dom from pages.xml
-            document = parse(stream);
-         }
-         catch (IOException ioe)
-         {
-            log.error("error reading pages.xml file:" + ioe);
-         }
-         catch (SAXException sax)
-         {
-            log.error("sax exception:" + sax);
-            Exception embed = sax.getException();
-            embed.printStackTrace();
-         }
-         catch (ParserConfigurationException pce)
-         {
-            log.error("parser configuration issue while reading pages.xml file:" + pce);
-         }
-
-      }
-      return document;
-   }
-
    /* (non-Javadoc)
    * @see org.ajax4jsf.portlet.ExceptionHandler#processActionException(javax.faces.context.FacesContext, org.ajax4jsf.portlet.application.PortletViewState, java.lang.Exception)
    */
@@ -86,100 +50,7 @@
    public void processRenderException(FacesContext context,
                                       PortletViewState windowState, Exception e) throws BridgeException
    {
-      Document seamPagesDoc = getPagesDocument(seamPages);
-
-      if (seamPagesDoc != null)
-      {
-         try
-         {
-            //TODO
-            context.getExternalContext().redirect(getExceptionViewId(seamPagesDoc, e));
-         }
-         catch (IOException e1)
-         {
-            e1.printStackTrace();
-         }
-         catch (XPathExpressionException e1)
-         {
-            e1.printStackTrace();
-         }
-
-      }
-      else
-      {
-         log.info("seam pages.xml not installed");
-      }
       throw new BridgeException("Error processing render lifecycle", e);
    }
 
-   private Document parse(InputStream stream) throws IOException, SAXException, ParserConfigurationException
-   {
-      DocumentBuilderFactory factory =
-         DocumentBuilderFactory.newInstance();
-
-      DocumentBuilder builder = factory.newDocumentBuilder();
-
-      return builder.parse(stream);
-   }
-
-   private String getExceptionViewId(Document document, Exception e) throws XPathExpressionException
-   {
-      XPathFactory xfactory = XPathFactory.newInstance();
-      XPath xpath = xfactory.newXPath();
-      NodeList nodes = document.getElementsByTagName("exception");
-      String redirectViewId = null;
-      boolean exceptionMatch = false;
-
-      //atleast one exception is defined in xml
-      if (nodes != null)
-      {
-         for (int i = 0; i < nodes.getLength(); i++)
-         {
-            Node node = nodes.item(i);
-            String className = xpath.evaluate("@class", node);
-            String loadedClassName = null;
-
-
-            if (className.length() > 0)
-            {
-               //compare exception class names
-               if (e.getClass().getName().equals(className))
-               {
-                  return xpath.evaluate("redirect/@view-id", node);
-               }
-            }
-            else
-            {
-               //no class was defined in attribute so check for general exception handler
-               redirectViewId = xpath.evaluate("redirect/@view-id", node);
-            }
-
-         }
-      }
-      return redirectViewId;
-   }
-
-   static InputStream getResourceAsStream(String resource)
-   {
-      ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
-      InputStream inputStream = null;
-      if (classLoader != null)
-      {
-         inputStream = classLoader.getResourceAsStream(resource);
-      }
-      return inputStream;
-   }
-
-   public static Class classForName(String name) throws ClassNotFoundException
-   {
-      try
-      {
-         return Thread.currentThread().getContextClassLoader().loadClass(name);
-      }
-      catch (Exception e)
-      {
-         return Class.forName(name);
-      }
-   }
-
 }

Added: trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/SeamExceptionHandlerImpl.java
===================================================================
--- trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/SeamExceptionHandlerImpl.java	                        (rev 0)
+++ trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/SeamExceptionHandlerImpl.java	2007-12-22 00:30:11 UTC (rev 4964)
@@ -0,0 +1,143 @@
+/**
+ *
+ */
+package org.ajax4jsf.portlet;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.faces.context.FacesContext;
+import javax.portlet.faces.BridgeException;
+import javax.servlet.ServletException;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.ajax4jsf.portlet.application.PortletViewState;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.seam.Seam;
+import org.jboss.seam.contexts.Contexts;
+import org.jboss.seam.contexts.FacesLifecycle;
+import org.jboss.seam.core.ConversationPropagation;
+import org.jboss.seam.core.Manager;
+import org.jboss.seam.exception.Exceptions;
+import org.jboss.seam.transaction.Transaction;
+import org.jboss.seam.transaction.UserTransaction;
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
+
+/**
+ * @author asmirnov
+ * @author <a href="mailto:whales at redhat.com">Wesley Hales</a>
+ */
+
+public class SeamExceptionHandlerImpl implements ExceptionHandler
+{
+   protected static final Log log = LogFactory.getLog(SeamExceptionHandlerImpl.class);
+
+
+   /* (non-Javadoc)
+   * @see org.ajax4jsf.portlet.ExceptionHandler#processActionException(javax.faces.context.FacesContext, org.ajax4jsf.portlet.application.PortletViewState, java.lang.Exception)
+   */
+   public void processActionException(FacesContext context,
+                                      PortletViewState windowState, Exception e) throws BridgeException
+   {
+      log.error("Error processing action lifecycle", e);
+      windowState.saveBeans(context);
+      windowState.saveMessages(context);
+      handleException(context, e);
+      windowState.setViewRoot(context.getViewRoot());
+   }
+
+   /* (non-Javadoc)
+    * @see org.ajax4jsf.portlet.ExceptionHandler#processRenderException(javax.faces.context.FacesContext, org.ajax4jsf.portlet.application.PortletViewState, java.lang.Exception)
+    */
+   public void processRenderException(FacesContext context,
+                                      PortletViewState windowState, Exception e) throws BridgeException
+   {
+      log.error("Error processing render lifecycle", e);
+      handleException(context, e);
+   }
+
+
+
+   public static Class classForName(String name) throws ClassNotFoundException
+   {
+      try
+      {
+         return Thread.currentThread().getContextClassLoader().loadClass(name);
+      }
+      catch (Exception e)
+      {
+         return Class.forName(name);
+      }
+   }
+   
+   private void handleException(FacesContext facesContext, Exception e) throws BridgeException {
+	      //if the event context was cleaned up, fish the conversation id 
+	      //directly out of the ServletRequest attributes, else get it from
+	      //the event context
+	      Manager manager = Contexts.isEventContextActive() ?
+	              (Manager) Contexts.getEventContext().get(Manager.class) :
+	              null;
+	      String conversationId = manager==null ? null : manager.getCurrentConversationId();
+	      
+	      //Initialize the temporary context objects
+	      FacesLifecycle.beginExceptionRecovery( facesContext.getExternalContext() );
+	      
+	      //If there is an existing long-running conversation on
+	      //the failed request, propagate it
+	      if (conversationId==null)
+	      {
+	          Manager.instance().initializeTemporaryConversation();
+	      }
+	      else
+	      {
+	          ConversationPropagation.instance().setConversationId(conversationId);
+	          Manager.instance().restoreConversation();
+	      }
+	      
+	      //Now do the exception handling
+	      try
+	      {
+	         rollbackTransactionIfNecessary();
+	         Exceptions.instance().handle(e);
+	      }
+	      catch (Exception ehe)
+	      {
+	         throw new BridgeException(ehe);
+	      }
+	      finally
+	      {
+	         //Finally, clean up the contexts
+	         try 
+	         {
+	            FacesLifecycle.endRequest( facesContext.getExternalContext() );
+	            log.debug("done running exception handlers");
+	         }
+	         catch (Exception ere)
+	         {
+	            log.error("could not destroy contexts", ere);
+	         }
+	      }
+
+   }
+
+   protected void rollbackTransactionIfNecessary()
+   {
+      try 
+      {
+         UserTransaction transaction = Transaction.instance();
+         if ( transaction.isActiveOrMarkedRollback() || transaction.isRolledBack() )
+         {
+            log.debug("killing transaction");
+            transaction.rollback();
+         }
+      }
+      catch (Exception te)
+      {
+         log.error("could not roll back transaction", te);
+      }
+   }
+}


Property changes on: trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/SeamExceptionHandlerImpl.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Date Revision Author

Modified: trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/AbstractExternalContext.java
===================================================================
--- trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/AbstractExternalContext.java	2007-12-21 19:33:55 UTC (rev 4963)
+++ trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/AbstractExternalContext.java	2007-12-22 00:30:11 UTC (rev 4964)
@@ -534,4 +534,20 @@
 	}
 
 	protected abstract String encodeURL(String actionUrl);
+
+	public String encodeResourceURL(String url) {
+		try {
+			PortalActionURL portalUrl = new PortalActionURL(url);
+			boolean inContext = portalUrl
+					.isInContext(getRequestContextPath());
+			// For resources in the portlet application context add namespace as URL parameter, to restore portlet session.
+			if (inContext) {
+				portalUrl.addParameter(NAMESPACE_PARAMETER, getNamespace());
+				url=portalUrl.toString();
+			}
+		} catch (MalformedURLException e) {
+			throw new FacesException(e);
+		}
+		return encodeURL(url);
+	}
 }
\ No newline at end of file

Modified: trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/FacesContextFactoryImpl.java
===================================================================
--- trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/FacesContextFactoryImpl.java	2007-12-21 19:33:55 UTC (rev 4963)
+++ trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/FacesContextFactoryImpl.java	2007-12-22 00:30:11 UTC (rev 4964)
@@ -92,7 +92,7 @@
 	 * Hold <code>FacesContextFactory</code> from default implementation.
 	 * 
 	 */
-	// private FacesContextFactory defaultFacesContextFactory;
+	private FacesContextFactory defaultFacesContextFactory;
 	private static final Log _log = LogFactory
 			.getLog(FacesContextFactoryImpl.class);
 
@@ -105,11 +105,11 @@
 	 * Factory from JSF implementation.
 	 * 
 	 */
-	public FacesContextFactoryImpl(/* FacesContextFactory defaultFactory */) {
+	public FacesContextFactoryImpl(FacesContextFactory defaultFactory) {
 		super();
-		// if (this.defaultFacesContextFactory == null) {
-		// this.defaultFacesContextFactory = defaultFactory;
-		// }
+		 if (this.defaultFacesContextFactory == null) {
+		 this.defaultFacesContextFactory = defaultFactory;
+		 }
 		if (_log.isDebugEnabled()) {
 			_log.debug("Portal - specific FacesContextFactory has initialised");
 		}
@@ -137,7 +137,7 @@
 		if ((context instanceof PortletContext)
 				&& (request instanceof ActionRequest)
 				&& (response instanceof ActionResponse)) {
-			externalContext = new PortletContextImpl((PortletContext) context,
+			externalContext = new PortletExternalContextImpl((PortletContext) context,
 					(PortletRequest) request, (PortletResponse) response);
 			if (_log.isDebugEnabled()) {
 				_log
@@ -146,7 +146,7 @@
 		} else if ((context instanceof PortletContext)
 				&& (request instanceof RenderRequest)
 				&& (response instanceof RenderResponse)) {
-			externalContext = new PortletRenderContextImpl((PortletContext) context,
+			externalContext = new RenderPortletExternalContextImpl((PortletContext) context,
 					(PortletRequest) request, (PortletResponse) response);
 			if (_log.isDebugEnabled()) {
 				_log
@@ -155,7 +155,8 @@
 		} else if ((context instanceof ServletContext)
 				&& (request instanceof HttpServletRequest)
 				&& (response instanceof HttpServletResponse)) {
-			externalContext = new ServletContextImpl((ServletContext) context,
+			// TODO - if request don't contain namespace parameter, create default context instance.
+			externalContext = new ServletExternalContextImpl((ServletContext) context,
 					(HttpServletRequest) request,
 					(HttpServletResponse) response);
 			if (_log.isDebugEnabled()) {

Deleted: trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/PortletContextImpl.java
===================================================================
--- trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/PortletContextImpl.java	2007-12-21 19:33:55 UTC (rev 4963)
+++ trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/PortletContextImpl.java	2007-12-22 00:30:11 UTC (rev 4964)
@@ -1,365 +0,0 @@
-/**
- * 
- */
-package org.ajax4jsf.portlet.context;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLDecoder;
-import java.net.URLEncoder;
-import java.security.Principal;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Set;
-import java.util.regex.Pattern;
-
-import javax.faces.application.ViewHandler;
-import javax.faces.context.ExternalContext;
-import javax.faces.context.FacesContext;
-import javax.faces.context.FacesContextFactory;
-import javax.portlet.ActionRequest;
-import javax.portlet.ActionResponse;
-import javax.portlet.PortletContext;
-import javax.portlet.PortletException;
-import javax.portlet.PortletRequest;
-import javax.portlet.PortletRequestDispatcher;
-import javax.portlet.PortletResponse;
-import javax.portlet.PortletSession;
-import javax.portlet.RenderRequest;
-import javax.portlet.RenderResponse;
-import javax.portlet.PortletURL;
-import javax.portlet.faces.Bridge;
-
-import org.ajax4jsf.webapp.WebXml;
-
-/**
- * Version of the {@link ExternalContext} for a Portlet request.
- * {@link FacesContextFactory} will create instance of this class for a portal
- * <code>action</code> phase.
- * 
- * @author asmirnov
- * 
- */
-public class PortletContextImpl extends AbstractExternalContext {
-
-	public static final String ACTION_URL_DO_NOTHITG = "/ajax4jsfPortletBridge/actionUrl/do/nothitg";
-	private String namespace;
-
-	public PortletContextImpl(PortletContext context, PortletRequest request,
-			PortletResponse response) {
-		super(context, request, response);
-		WebXml webXml = (WebXml) context.getAttribute(WebXml.CONTEXT_ATTRIBUTE);
-		if (null != webXml) {
-			_servletPath = webXml.getFacesServletPrefix();
-		}
-		ArrayList excludedAttributes = Collections.list(request
-				.getAttributeNames());
-		request.setAttribute(EXCLUDED_PARAMETERS_ATTRIBUTE, excludedAttributes);
-	}
-
-	public void setResponseCharacterEncoding(String encoding) {
-		// Do nothing
-	}
-
-	public String getResponseCharacterEncoding() {
-		return null;
-	}
-
-	public String getResponseContentType() {
-		return null;
-	}
-
-	public void setRequestCharacterEncoding(String encoding)
-			throws UnsupportedEncodingException {
-		try {
-			ActionRequest actionRequest = (ActionRequest) getPortletRequest();
-			actionRequest.setCharacterEncoding(encoding);
-		} catch (IllegalStateException e) {
-			// TODO: handle exception
-		}
-	}
-
-	public String getRequestCharacterEncoding() {
-		ActionRequest actionRequest = (ActionRequest) getPortletRequest();
-		return actionRequest.getCharacterEncoding();
-	}
-
-	public String getRequestContentType() {
-		return null;
-	}
-
-	protected PortletContext getPortletContext() {
-		return (PortletContext) getContext();
-	}
-
-	protected PortletRequest getPortletRequest() {
-		return (PortletRequest) getRequest();
-	}
-
-	protected PortletResponse getPortletResponse() {
-		return (PortletResponse) getResponse();
-	}
-
-	public String getInitParameter(String name) {
-		return getPortletContext().getInitParameter(name);
-	}
-
-	protected String getNamespace() {
-		if (null == namespace) {
-			namespace = (String) getRequestParameter(AbstractExternalContext.NAMESPACE_PARAMETER);
-			if (null == namespace) {
-				throw new IllegalStateException(
-						"Can not determine portlet namespace");
-			}
-		}
-		return namespace;
-	}
-
-	public URL getResource(String path) throws MalformedURLException {
-		return getPortletContext().getResource(path);
-	}
-
-	public InputStream getResourceAsStream(String path) {
-		return getPortletContext().getResourceAsStream(path);
-	}
-
-	public Set getResourcePaths(String path) {
-		return getPortletContext().getResourcePaths(path);
-	}
-
-	protected Enumeration enumerateRequestParameterNames() {
-		return getPortletRequest().getParameterNames();
-	}
-
-	protected Object getContextAttribute(String name) {
-		return getPortletContext().getAttribute(name);
-	}
-
-	protected Enumeration getContextAttributeNames() {
-		return getPortletContext().getAttributeNames();
-	}
-
-	protected Enumeration getInitParametersNames() {
-		return getPortletContext().getInitParameterNames();
-	}
-
-	protected Object getRequestAttribute(String name) {
-		return getPortletRequest().getAttribute(name);
-	}
-
-	protected Enumeration getRequestAttributeNames() {
-		return getPortletRequest().getAttributeNames();
-	}
-
-	public Map getRequestParameterValuesMap() {
-		return getPortletRequest().getParameterMap();
-	}
-
-	protected Object getRequestParameterValues(String name) {
-		return getPortletRequest().getParameterValues(name);
-	}
-
-	protected Object getRequestHeader(String name) {
-		return getPortletRequest().getProperty(name);
-	}
-
-	protected Enumeration getRequestHeaderNames() {
-		return getPortletRequest().getPropertyNames();
-	}
-
-	protected String[] getRequestHeaderValues(String name) {
-		Enumeration properties = getPortletRequest().getProperties(name);
-		List values = new ArrayList();
-		while (properties.hasMoreElements()) {
-			Object value = (Object) properties.nextElement();
-			values.add(value);
-		}
-		return (String[]) values.toArray(EMPTY_STRING_ARRAY);
-	}
-
-	protected Object getRequestParameter(String name) {
-		return getPortletRequest().getParameter(name);
-	}
-
-	protected Object getSessionAttribute(String name) {
-		return getPortletRequest().getPortletSession(true).getAttribute(name,
-				PortletSession.PORTLET_SCOPE);
-	}
-
-	protected Enumeration getSessionAttributeNames() {
-		return getPortletRequest().getPortletSession(true).getAttributeNames(
-				PortletSession.PORTLET_SCOPE);
-	}
-
-	protected void removeContextAttribute(String name) {
-		getPortletContext().removeAttribute(name);
-	}
-
-	protected void removeRequestAttribute(String name) {
-		getPortletRequest().removeAttribute(name);
-	}
-
-	protected void removeSessionAttribute(String name) {
-		getPortletRequest().getPortletSession(true).removeAttribute(name,
-				PortletSession.PORTLET_SCOPE);
-	}
-
-	protected void setContextAttribute(String name, Object value) {
-		getPortletContext().setAttribute(name, value);
-	}
-
-	protected void setRequestAttribute(String name, Object value) {
-		getPortletRequest().setAttribute(name, value);
-	}
-
-	protected void setSessionAttribute(String name, Object value) {
-		getPortletRequest().getPortletSession(true).setAttribute(name, value,
-				PortletSession.PORTLET_SCOPE);
-	}
-
-	public void dispatch(String path) throws IOException {
-		if (null == path) {
-			throw new NullPointerException("Path to new view is null");
-		}
-		throw new IllegalStateException(
-				"Dispatch to new view not at render phase");
-	}
-
-	private static final Pattern absoluteUrl = Pattern.compile("");
-	private static final Pattern directLink = Pattern.compile("");
-	private static final Pattern viewIdParam = Pattern.compile("");
-
-	/**
-	 * @param parameters
-	 * @return
-	 */
-	@Override
-	protected String createActionUrl(Map<String, String> parameters) {
-		String dummyActionURL = getRequestContextPath() + ACTION_URL_DO_NOTHITG;
-		try {
-			PortalActionURL actionUrl = new PortalActionURL(dummyActionURL);
-			for (Iterator<Map.Entry<String, String>> param = parameters
-					.entrySet().iterator(); param.hasNext();) {
-				Map.Entry<String, String> parameter = param.next();
-				actionUrl
-						.addParameter(parameter.getKey(), parameter.getValue());
-			}
-			return actionUrl.toString();
-		} catch (MalformedURLException e) {
-
-		}
-		return dummyActionURL;
-	}
-
-	public String encodeResourceURL(String url) {
-		return encodeURL(url);
-	}
-
-	/**
-	 * @param url
-	 * @return
-	 */
-	protected String encodeURL(String url) {
-		return getPortletResponse().encodeURL(url);
-	}
-
-	public String getAuthType() {
-		return getPortletRequest().getAuthType();
-	}
-
-	public String getRemoteUser() {
-		return getPortletRequest().getRemoteUser();
-	}
-
-	public String getRequestContextPath() {
-		return getPortletRequest().getContextPath();
-	}
-
-	public Locale getRequestLocale() {
-		return getPortletRequest().getLocale();
-	}
-
-	public Iterator getRequestLocales() {
-		return new EnumerationIterator(getPortletRequest().getLocales());
-	}
-
-	private String _pathInfo = null;
-
-	public String getRequestPathInfo() {
-		String pathInfo = (String) getRequestParameter(VIEW_ID_PARAMETER);
-		if (null == pathInfo) {
-			pathInfo = (String) getRequestAttribute(VIEW_ID_PARAMETER);
-		}
-		return pathInfo;
-	}
-
-	private String _servletPath = null;
-
-	public String getRequestServletPath() {
-		return _servletPath;
-	}
-
-	public Object getSession(boolean create) {
-		return getPortletRequest().getPortletSession();
-	}
-
-	public Principal getUserPrincipal() {
-		return getPortletRequest().getUserPrincipal();
-	}
-
-	public boolean isUserInRole(String role) {
-		return getPortletRequest().isUserInRole(role);
-	}
-
-	public void log(String message) {
-		getPortletContext().log(message);
-	}
-
-	public void log(String message, Throwable exception) {
-		getPortletContext().log(message, exception);
-	}
-
-	public void redirect(String url) throws IOException {
-		if (null == url || url.length() < 0) {
-			throw new NullPointerException("Path to redirect is null");
-		}
-		PortalActionURL actionURL = new PortalActionURL(url);
-		if (url.startsWith("#")
-				|| (!actionURL.isInContext(getRequestContextPath()))
-				|| "true".equalsIgnoreCase(actionURL
-						.getParameter(Bridge.DIRECT_LINK))) {
-			((ActionResponse) getResponse()).sendRedirect(url);
-		} else {
-			internalRedirect(actionURL);
-		}
-	}
-
-	/**
-	 * @param actionURL
-	 */
-	protected void internalRedirect(PortalActionURL actionURL) {
-		// Detect ViewId from URL and create new view for them.
-		String viewId = actionURL.getParameter(VIEW_ID_PARAMETER);
-		if (null != viewId) {
-			try {
-				viewId = URLDecoder.decode(viewId, "UTF8");
-				FacesContext facesContext = FacesContext.getCurrentInstance();
-				ViewHandler viewHandler = facesContext.getApplication()
-						.getViewHandler();
-				facesContext.setViewRoot(viewHandler.createView(facesContext,
-						viewId));
-				setHasNavigationRedirect(true);
-			} catch (UnsupportedEncodingException e) {
-				// Do nothing - UTF-8 encoding is a default.
-			}
-		}
-	}
-}

Copied: trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/PortletExternalContextImpl.java (from rev 4938, trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/PortletContextImpl.java)
===================================================================
--- trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/PortletExternalContextImpl.java	                        (rev 0)
+++ trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/PortletExternalContextImpl.java	2007-12-22 00:30:11 UTC (rev 4964)
@@ -0,0 +1,361 @@
+/**
+ * 
+ */
+package org.ajax4jsf.portlet.context;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
+import java.security.Principal;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Pattern;
+
+import javax.faces.application.ViewHandler;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.faces.context.FacesContextFactory;
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletContext;
+import javax.portlet.PortletException;
+import javax.portlet.PortletRequest;
+import javax.portlet.PortletRequestDispatcher;
+import javax.portlet.PortletResponse;
+import javax.portlet.PortletSession;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.PortletURL;
+import javax.portlet.faces.Bridge;
+
+import org.ajax4jsf.webapp.WebXml;
+
+/**
+ * Version of the {@link ExternalContext} for a Portlet request.
+ * {@link FacesContextFactory} will create instance of this class for a portal
+ * <code>action</code> phase.
+ * 
+ * @author asmirnov
+ * 
+ */
+public class PortletExternalContextImpl extends AbstractExternalContext {
+
+	public static final String ACTION_URL_DO_NOTHITG = "/ajax4jsfPortletBridge/actionUrl/do/nothitg";
+	private String namespace;
+
+	public PortletExternalContextImpl(PortletContext context, PortletRequest request,
+			PortletResponse response) {
+		super(context, request, response);
+		WebXml webXml = (WebXml) context.getAttribute(WebXml.CONTEXT_ATTRIBUTE);
+		if (null != webXml) {
+			_servletPath = webXml.getFacesServletPrefix();
+		}
+		ArrayList excludedAttributes = Collections.list(request
+				.getAttributeNames());
+		request.setAttribute(EXCLUDED_PARAMETERS_ATTRIBUTE, excludedAttributes);
+	}
+
+	public void setResponseCharacterEncoding(String encoding) {
+		// Do nothing
+	}
+
+	public String getResponseCharacterEncoding() {
+		return null;
+	}
+
+	public String getResponseContentType() {
+		return null;
+	}
+
+	public void setRequestCharacterEncoding(String encoding)
+			throws UnsupportedEncodingException {
+		try {
+			ActionRequest actionRequest = (ActionRequest) getPortletRequest();
+			actionRequest.setCharacterEncoding(encoding);
+		} catch (IllegalStateException e) {
+			// TODO: handle exception
+		}
+	}
+
+	public String getRequestCharacterEncoding() {
+		ActionRequest actionRequest = (ActionRequest) getPortletRequest();
+		return actionRequest.getCharacterEncoding();
+	}
+
+	public String getRequestContentType() {
+		return null;
+	}
+
+	protected PortletContext getPortletContext() {
+		return (PortletContext) getContext();
+	}
+
+	protected PortletRequest getPortletRequest() {
+		return (PortletRequest) getRequest();
+	}
+
+	protected PortletResponse getPortletResponse() {
+		return (PortletResponse) getResponse();
+	}
+
+	public String getInitParameter(String name) {
+		return getPortletContext().getInitParameter(name);
+	}
+
+	protected String getNamespace() {
+		if (null == namespace) {
+			namespace = (String) getRequestParameter(AbstractExternalContext.NAMESPACE_PARAMETER);
+			if (null == namespace) {
+				throw new IllegalStateException(
+						"Can not determine portlet namespace");
+			}
+		}
+		return namespace;
+	}
+
+	public URL getResource(String path) throws MalformedURLException {
+		return getPortletContext().getResource(path);
+	}
+
+	public InputStream getResourceAsStream(String path) {
+		return getPortletContext().getResourceAsStream(path);
+	}
+
+	public Set getResourcePaths(String path) {
+		return getPortletContext().getResourcePaths(path);
+	}
+
+	protected Enumeration enumerateRequestParameterNames() {
+		return getPortletRequest().getParameterNames();
+	}
+
+	protected Object getContextAttribute(String name) {
+		return getPortletContext().getAttribute(name);
+	}
+
+	protected Enumeration getContextAttributeNames() {
+		return getPortletContext().getAttributeNames();
+	}
+
+	protected Enumeration getInitParametersNames() {
+		return getPortletContext().getInitParameterNames();
+	}
+
+	protected Object getRequestAttribute(String name) {
+		return getPortletRequest().getAttribute(name);
+	}
+
+	protected Enumeration getRequestAttributeNames() {
+		return getPortletRequest().getAttributeNames();
+	}
+
+	public Map getRequestParameterValuesMap() {
+		return getPortletRequest().getParameterMap();
+	}
+
+	protected Object getRequestParameterValues(String name) {
+		return getPortletRequest().getParameterValues(name);
+	}
+
+	protected Object getRequestHeader(String name) {
+		return getPortletRequest().getProperty(name);
+	}
+
+	protected Enumeration getRequestHeaderNames() {
+		return getPortletRequest().getPropertyNames();
+	}
+
+	protected String[] getRequestHeaderValues(String name) {
+		Enumeration properties = getPortletRequest().getProperties(name);
+		List values = new ArrayList();
+		while (properties.hasMoreElements()) {
+			Object value = (Object) properties.nextElement();
+			values.add(value);
+		}
+		return (String[]) values.toArray(EMPTY_STRING_ARRAY);
+	}
+
+	protected Object getRequestParameter(String name) {
+		return getPortletRequest().getParameter(name);
+	}
+
+	protected Object getSessionAttribute(String name) {
+		return getPortletRequest().getPortletSession(true).getAttribute(name,
+				PortletSession.PORTLET_SCOPE);
+	}
+
+	protected Enumeration getSessionAttributeNames() {
+		return getPortletRequest().getPortletSession(true).getAttributeNames(
+				PortletSession.PORTLET_SCOPE);
+	}
+
+	protected void removeContextAttribute(String name) {
+		getPortletContext().removeAttribute(name);
+	}
+
+	protected void removeRequestAttribute(String name) {
+		getPortletRequest().removeAttribute(name);
+	}
+
+	protected void removeSessionAttribute(String name) {
+		getPortletRequest().getPortletSession(true).removeAttribute(name,
+				PortletSession.PORTLET_SCOPE);
+	}
+
+	protected void setContextAttribute(String name, Object value) {
+		getPortletContext().setAttribute(name, value);
+	}
+
+	protected void setRequestAttribute(String name, Object value) {
+		getPortletRequest().setAttribute(name, value);
+	}
+
+	protected void setSessionAttribute(String name, Object value) {
+		getPortletRequest().getPortletSession(true).setAttribute(name, value,
+				PortletSession.PORTLET_SCOPE);
+	}
+
+	public void dispatch(String path) throws IOException {
+		if (null == path) {
+			throw new NullPointerException("Path to new view is null");
+		}
+		throw new IllegalStateException(
+				"Dispatch to new view not at render phase");
+	}
+
+	private static final Pattern absoluteUrl = Pattern.compile("");
+	private static final Pattern directLink = Pattern.compile("");
+	private static final Pattern viewIdParam = Pattern.compile("");
+
+	/**
+	 * @param parameters
+	 * @return
+	 */
+	@Override
+	protected String createActionUrl(Map<String, String> parameters) {
+		String dummyActionURL = getRequestContextPath() + ACTION_URL_DO_NOTHITG;
+		try {
+			PortalActionURL actionUrl = new PortalActionURL(dummyActionURL);
+			for (Iterator<Map.Entry<String, String>> param = parameters
+					.entrySet().iterator(); param.hasNext();) {
+				Map.Entry<String, String> parameter = param.next();
+				actionUrl
+						.addParameter(parameter.getKey(), parameter.getValue());
+			}
+			return actionUrl.toString();
+		} catch (MalformedURLException e) {
+
+		}
+		return dummyActionURL;
+	}
+
+	/**
+	 * @param url
+	 * @return
+	 */
+	protected String encodeURL(String url) {
+		return getPortletResponse().encodeURL(url);
+	}
+
+	public String getAuthType() {
+		return getPortletRequest().getAuthType();
+	}
+
+	public String getRemoteUser() {
+		return getPortletRequest().getRemoteUser();
+	}
+
+	public String getRequestContextPath() {
+		return getPortletRequest().getContextPath();
+	}
+
+	public Locale getRequestLocale() {
+		return getPortletRequest().getLocale();
+	}
+
+	public Iterator getRequestLocales() {
+		return new EnumerationIterator(getPortletRequest().getLocales());
+	}
+
+	private String _pathInfo = null;
+
+	public String getRequestPathInfo() {
+		String pathInfo = (String) getRequestParameter(VIEW_ID_PARAMETER);
+		if (null == pathInfo) {
+			pathInfo = (String) getRequestAttribute(VIEW_ID_PARAMETER);
+		}
+		return pathInfo;
+	}
+
+	private String _servletPath = null;
+
+	public String getRequestServletPath() {
+		return _servletPath;
+	}
+
+	public Object getSession(boolean create) {
+		return getPortletRequest().getPortletSession();
+	}
+
+	public Principal getUserPrincipal() {
+		return getPortletRequest().getUserPrincipal();
+	}
+
+	public boolean isUserInRole(String role) {
+		return getPortletRequest().isUserInRole(role);
+	}
+
+	public void log(String message) {
+		getPortletContext().log(message);
+	}
+
+	public void log(String message, Throwable exception) {
+		getPortletContext().log(message, exception);
+	}
+
+	public void redirect(String url) throws IOException {
+		if (null == url || url.length() < 0) {
+			throw new NullPointerException("Path to redirect is null");
+		}
+		PortalActionURL actionURL = new PortalActionURL(url);
+		if (url.startsWith("#")
+				|| (!actionURL.isInContext(getRequestContextPath()))
+				|| "true".equalsIgnoreCase(actionURL
+						.getParameter(Bridge.DIRECT_LINK))) {
+			((ActionResponse) getResponse()).sendRedirect(url);
+		} else {
+			internalRedirect(actionURL);
+		}
+	}
+
+	/**
+	 * @param actionURL
+	 */
+	protected void internalRedirect(PortalActionURL actionURL) {
+		// Detect ViewId from URL and create new view for them.
+		String viewId = actionURL.getParameter(VIEW_ID_PARAMETER);
+		if (null != viewId) {
+			try {
+				viewId = URLDecoder.decode(viewId, "UTF8");
+				FacesContext facesContext = FacesContext.getCurrentInstance();
+				ViewHandler viewHandler = facesContext.getApplication()
+						.getViewHandler();
+				facesContext.setViewRoot(viewHandler.createView(facesContext,
+						viewId));
+				setHasNavigationRedirect(true);
+			} catch (UnsupportedEncodingException e) {
+				// Do nothing - UTF-8 encoding is a default.
+			}
+		}
+	}
+}

Deleted: trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/PortletRenderContextImpl.java
===================================================================
--- trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/PortletRenderContextImpl.java	2007-12-21 19:33:55 UTC (rev 4963)
+++ trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/PortletRenderContextImpl.java	2007-12-22 00:30:11 UTC (rev 4964)
@@ -1,184 +0,0 @@
-/**
- * 
- */
-package org.ajax4jsf.portlet.context;
-
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.regex.Pattern;
-
-import javax.faces.FacesException;
-import javax.faces.render.ResponseStateManager;
-import javax.portlet.ActionRequest;
-import javax.portlet.ActionResponse;
-import javax.portlet.PortletConfig;
-import javax.portlet.PortletContext;
-import javax.portlet.PortletException;
-import javax.portlet.PortletRequest;
-import javax.portlet.PortletRequestDispatcher;
-import javax.portlet.PortletResponse;
-import javax.portlet.PortletURL;
-import javax.portlet.RenderRequest;
-import javax.portlet.RenderResponse;
-import javax.portlet.faces.Bridge;
-
-import org.ajax4jsf.portlet.application.PortletViewState;
-
-/**
- * @author asmirnov
- * 
- */
-public class PortletRenderContextImpl extends PortletContextImpl {
-
-	public String getResponseCharacterEncoding() {
-		RenderResponse renderResponse = (RenderResponse) getPortletResponse();
-		return renderResponse.getCharacterEncoding();
-	}
-
-	public String getResponseContentType() {
-		RenderResponse renderResponse = (RenderResponse) getPortletResponse();
-		return renderResponse.getContentType();
-	}
-
-	public void setRequestCharacterEncoding(String encoding)
-			throws UnsupportedEncodingException {
-		// Do nothing.
-	}
-
-	public String getRequestCharacterEncoding() {
-		return null;
-	}
-
-	protected String getNamespace() {
-		return ((RenderResponse) getPortletResponse()).getNamespace();
-	}
-
-	private Map<String, String[]> _requestParameters;
-
-	public PortletRenderContextImpl(PortletContext context,
-			PortletRequest request, PortletResponse response) {
-		super(context, request, response);
-	}
-
-	protected Object getRequestParameter(String name) {
-		Object[] values = (Object[]) getRequestParameterValues(name);
-		if (null != values) {
-			return values[0];
-		} else {
-			return null;
-		}
-	}
-
-	protected Enumeration enumerateRequestParameterNames() {
-		Map<String, String[]> requestParameters = getSavedRequestParameters();
-		if (null != requestParameters) {
-			return Collections.enumeration(requestParameters.keySet());
-		} else {
-			return Collections.enumeration(Collections.EMPTY_LIST);
-		}
-	}
-
-	@Override
-	public void redirect(String url) throws IOException {
-		if (null == url) {
-			throw new NullPointerException("Path to redirect is null");
-		}
-		PortalActionURL actionURL = new PortalActionURL(url);
-      if((!actionURL.isInContext(getRequestContextPath()) && null == actionURL.getParameter(VIEW_ID_PARAMETER)) || "true".equalsIgnoreCase(actionURL.getParameter(Bridge.DIRECT_LINK))){
-//			dispatch(url);
-
-//         throw new IllegalStateException(
-//			"Redirect to new url not at action phase");
-		} else {
-		// HACK - if page is in the context, just treat it as navigation case
-			internalRedirect(actionURL);
-		}
-	}
-
-	@Override
-	protected String createActionUrl(Map<String, String> parameters) {
-		RenderResponse renderResponse = (RenderResponse) getPortletResponse();
-		PortletURL portletURL = renderResponse.createActionURL();
-		portletURL.setParameter(AbstractExternalContext.NAMESPACE_PARAMETER,
-				renderResponse.getNamespace());
-		for (Iterator<Entry<String, String>> param = parameters.entrySet()
-				.iterator(); param.hasNext();) {
-			Entry<String, String> parameter = param.next();
-			portletURL.setParameter(parameter.getKey(), parameter.getValue());
-		}
-      return portletURL.toString();
-	}
-
-	public void dispatch(String path) throws IOException {
-		if (null == path) {
-			throw new NullPointerException("Path to new view is null");
-		}
-      PortletRequestDispatcher dispatcher = getPortletContext()
-				.getRequestDispatcher(path);
-		if (null == dispatcher) {
-			throw new IllegalStateException(
-					"Dispatcher for render request is not created");
-		}
-		try {
-			RenderRequest renderRequest = (RenderRequest) getPortletRequest();
-			RenderResponse portletResponse = (RenderResponse) getPortletResponse();
-			dispatcher.include(renderRequest, portletResponse);
-		} catch (PortletException e) {
-			throw new FacesException(e);
-		}
-	}
-
-	/**
-	 * @return
-	 */
-	@SuppressWarnings("unchecked")
-	private Map<String, String[]> getSavedRequestParameters() {
-		if (null == _requestParameters) {
-			// Get parameters ( all or a View state only ) restored as requered
-			// in the JSR 301 PLT 5.1
-			Object preserveRequestAttr = Boolean.FALSE;
-			PortletConfig portletConfig = (PortletConfig) getRequestAttribute(PORTLET_CONFIG_ATTRIBUTE);
-			if (null != portletConfig) {
-				String portletPreserveParamName = Bridge.PORTLET_ATTR_PREFIX
-						+ portletConfig.getPortletName()
-						+ Bridge.PRESERVE_ACTION_PARAM_ATTR_SUFFIX;
-				preserveRequestAttr = getContextAttribute(portletPreserveParamName);
-			}
-			Map<String, String[]> parameters = (Map<String, String[]>) getRequestAttribute(PortletViewState.REQUEST_PARAMETERS_ATTRIBUTE);
-			if (Boolean.TRUE.equals(preserveRequestAttr)) {
-				_requestParameters = parameters;
-			} else if (null != parameters) {
-				_requestParameters = new HashMap<String, String[]>();
-				String[] viewState = parameters
-						.get(ResponseStateManager.VIEW_STATE_PARAM);
-				if (null != viewState) {
-					_requestParameters.put(
-							ResponseStateManager.VIEW_STATE_PARAM, viewState);
-
-				}
-				String[] conversationId = parameters.get(CONVERSATION_ID_PARAMETER);
-				if(null != conversationId){
-					_requestParameters.put(CONVERSATION_ID_PARAMETER, conversationId);
-				}
-			}
-		}
-		return _requestParameters;
-	}
-
-	protected Object getRequestParameterValues(String name) {
-		Map<String, String[]> requestParameters = getSavedRequestParameters();
-		if (null != requestParameters) {
-			return requestParameters.get(name);
-		} else {
-			return null;
-		}
-	}
-
-}

Copied: trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/RenderPortletExternalContextImpl.java (from rev 4944, trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/PortletRenderContextImpl.java)
===================================================================
--- trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/RenderPortletExternalContextImpl.java	                        (rev 0)
+++ trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/RenderPortletExternalContextImpl.java	2007-12-22 00:30:11 UTC (rev 4964)
@@ -0,0 +1,184 @@
+/**
+ * 
+ */
+package org.ajax4jsf.portlet.context;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.regex.Pattern;
+
+import javax.faces.FacesException;
+import javax.faces.render.ResponseStateManager;
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletContext;
+import javax.portlet.PortletException;
+import javax.portlet.PortletRequest;
+import javax.portlet.PortletRequestDispatcher;
+import javax.portlet.PortletResponse;
+import javax.portlet.PortletURL;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.faces.Bridge;
+
+import org.ajax4jsf.portlet.application.PortletViewState;
+
+/**
+ * @author asmirnov
+ * 
+ */
+public class RenderPortletExternalContextImpl extends PortletExternalContextImpl {
+
+	public String getResponseCharacterEncoding() {
+		RenderResponse renderResponse = (RenderResponse) getPortletResponse();
+		return renderResponse.getCharacterEncoding();
+	}
+
+	public String getResponseContentType() {
+		RenderResponse renderResponse = (RenderResponse) getPortletResponse();
+		return renderResponse.getContentType();
+	}
+
+	public void setRequestCharacterEncoding(String encoding)
+			throws UnsupportedEncodingException {
+		// Do nothing.
+	}
+
+	public String getRequestCharacterEncoding() {
+		return null;
+	}
+
+	protected String getNamespace() {
+		return ((RenderResponse) getPortletResponse()).getNamespace();
+	}
+
+	private Map<String, String[]> _requestParameters;
+
+	public RenderPortletExternalContextImpl(PortletContext context,
+			PortletRequest request, PortletResponse response) {
+		super(context, request, response);
+	}
+
+	protected Object getRequestParameter(String name) {
+		Object[] values = (Object[]) getRequestParameterValues(name);
+		if (null != values) {
+			return values[0];
+		} else {
+			return null;
+		}
+	}
+
+	protected Enumeration enumerateRequestParameterNames() {
+		Map<String, String[]> requestParameters = getSavedRequestParameters();
+		if (null != requestParameters) {
+			return Collections.enumeration(requestParameters.keySet());
+		} else {
+			return Collections.enumeration(Collections.EMPTY_LIST);
+		}
+	}
+
+	@Override
+	public void redirect(String url) throws IOException {
+		if (null == url) {
+			throw new NullPointerException("Path to redirect is null");
+		}
+		PortalActionURL actionURL = new PortalActionURL(url);
+      if((!actionURL.isInContext(getRequestContextPath()) && null == actionURL.getParameter(VIEW_ID_PARAMETER)) || "true".equalsIgnoreCase(actionURL.getParameter(Bridge.DIRECT_LINK))){
+//			dispatch(url);
+
+//         throw new IllegalStateException(
+//			"Redirect to new url not at action phase");
+		} else {
+		// HACK - if page is in the context, just treat it as navigation case
+			internalRedirect(actionURL);
+		}
+	}
+
+	@Override
+	protected String createActionUrl(Map<String, String> parameters) {
+		RenderResponse renderResponse = (RenderResponse) getPortletResponse();
+		PortletURL portletURL = renderResponse.createActionURL();
+		portletURL.setParameter(AbstractExternalContext.NAMESPACE_PARAMETER,
+				renderResponse.getNamespace());
+		for (Iterator<Entry<String, String>> param = parameters.entrySet()
+				.iterator(); param.hasNext();) {
+			Entry<String, String> parameter = param.next();
+			portletURL.setParameter(parameter.getKey(), parameter.getValue());
+		}
+      return portletURL.toString();
+	}
+
+	public void dispatch(String path) throws IOException {
+		if (null == path) {
+			throw new NullPointerException("Path to new view is null");
+		}
+      PortletRequestDispatcher dispatcher = getPortletContext()
+				.getRequestDispatcher(path);
+		if (null == dispatcher) {
+			throw new IllegalStateException(
+					"Dispatcher for render request is not created");
+		}
+		try {
+			RenderRequest renderRequest = (RenderRequest) getPortletRequest();
+			RenderResponse portletResponse = (RenderResponse) getPortletResponse();
+			dispatcher.include(renderRequest, portletResponse);
+		} catch (PortletException e) {
+			throw new FacesException(e);
+		}
+	}
+
+	/**
+	 * @return
+	 */
+	@SuppressWarnings("unchecked")
+	private Map<String, String[]> getSavedRequestParameters() {
+		if (null == _requestParameters) {
+			// Get parameters ( all or a View state only ) restored as requered
+			// in the JSR 301 PLT 5.1
+			Object preserveRequestAttr = Boolean.FALSE;
+			PortletConfig portletConfig = (PortletConfig) getRequestAttribute(PORTLET_CONFIG_ATTRIBUTE);
+			if (null != portletConfig) {
+				String portletPreserveParamName = Bridge.PORTLET_ATTR_PREFIX
+						+ portletConfig.getPortletName()
+						+ Bridge.PRESERVE_ACTION_PARAM_ATTR_SUFFIX;
+				preserveRequestAttr = getContextAttribute(portletPreserveParamName);
+			}
+			Map<String, String[]> parameters = (Map<String, String[]>) getRequestAttribute(PortletViewState.REQUEST_PARAMETERS_ATTRIBUTE);
+			if (Boolean.TRUE.equals(preserveRequestAttr)) {
+				_requestParameters = parameters;
+			} else if (null != parameters) {
+				_requestParameters = new HashMap<String, String[]>();
+				String[] viewState = parameters
+						.get(ResponseStateManager.VIEW_STATE_PARAM);
+				if (null != viewState) {
+					_requestParameters.put(
+							ResponseStateManager.VIEW_STATE_PARAM, viewState);
+
+				}
+				String[] conversationId = parameters.get(CONVERSATION_ID_PARAMETER);
+				if(null != conversationId){
+					_requestParameters.put(CONVERSATION_ID_PARAMETER, conversationId);
+				}
+			}
+		}
+		return _requestParameters;
+	}
+
+	protected Object getRequestParameterValues(String name) {
+		Map<String, String[]> requestParameters = getSavedRequestParameters();
+		if (null != requestParameters) {
+			return requestParameters.get(name);
+		} else {
+			return null;
+		}
+	}
+
+}

Deleted: trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/ServletContextImpl.java
===================================================================
--- trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/ServletContextImpl.java	2007-12-21 19:33:55 UTC (rev 4963)
+++ trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/ServletContextImpl.java	2007-12-22 00:30:11 UTC (rev 4964)
@@ -1,386 +0,0 @@
-/**
- * 
- */
-package org.ajax4jsf.portlet.context;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.security.Principal;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.Iterator;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Set;
-import java.util.Map.Entry;
-
-import javax.faces.FacesException;
-import javax.faces.context.FacesContext;
-import javax.portlet.PortletSession;
-import javax.portlet.PortletSessionUtil;
-import javax.servlet.RequestDispatcher;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.http.HttpSession;
-
-import org.ajax4jsf.context.AjaxContext;
-import org.ajax4jsf.portlet.AjaxPortletBridge;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * @author asmirnov
- * 
- */
-public class ServletContextImpl extends AbstractExternalContext {
-
-	private static final Log _log = LogFactory.getLog(ServletContextImpl.class);
-
-	private String namespace;
-
-	/**
-	 * @param context
-	 * @param request
-	 * @param response
-	 */
-	public ServletContextImpl(ServletContext context,
-			HttpServletRequest request, HttpServletResponse response) {
-		super(context, request, response);
-		ArrayList excludedAttributes = Collections.list(request.getAttributeNames());
-		request.setAttribute(EXCLUDED_PARAMETERS_ATTRIBUTE, excludedAttributes);
-	}
-
-	public void setResponseCharacterEncoding(String encoding) {
-
-		getHttpResponse().setCharacterEncoding(encoding);
-	}
-
-	public String getResponseCharacterEncoding() {
-		return getHttpResponse().getCharacterEncoding();
-	}
-
-	public String getResponseContentType() {
-		return getHttpResponse().getContentType();
-	}
-
-	public void setRequestCharacterEncoding(String encoding)
-			throws UnsupportedEncodingException {
-		getHttpRequest().setCharacterEncoding(encoding);
-	}
-
-	public String getRequestCharacterEncoding() {
-		return getHttpRequest().getCharacterEncoding();
-	}
-
-	public String getRequestContentType() {
-		return getHttpRequest().getContentType();
-	}
-
-	private HttpServletRequest getHttpRequest() {
-		return (HttpServletRequest) getRequest();
-	}
-
-	private ServletContext getServletContext() {
-		return (ServletContext) getContext();
-	}
-
-	private HttpServletResponse getHttpResponse() {
-		return (HttpServletResponse) getResponse();
-	}
-
-	protected String getNamespace() {
-		if (null == namespace) {
-			Object requestParameter = getRequestParameter(NAMESPACE_PARAMETER);
-			if (null != requestParameter) {
-				namespace = (String) requestParameter;
-				if (_log.isDebugEnabled()) {
-					_log.debug("Namespace for a portlet instance is "
-							+ namespace);
-				}
-			} else {
-				throw new FacesException(
-						"AJAX call to portlet without namespace parameter");
-			}
-		}
-		return namespace;
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see javax.faces.context.ExternalContext#getInitParameter(java.lang.String)
-	 */
-	public String getInitParameter(String name) {
-		return getServletContext().getInitParameter(name);
-	}
-
-	protected Enumeration getInitParametersNames() {
-		return getServletContext().getInitParameterNames();
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see javax.faces.context.ExternalContext#getResource(java.lang.String)
-	 */
-	public URL getResource(String path) throws MalformedURLException {
-		return getServletContext().getResource(path);
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see javax.faces.context.ExternalContext#getResourceAsStream(java.lang.String)
-	 */
-	public InputStream getResourceAsStream(String path) {
-		return getServletContext().getResourceAsStream(path);
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see javax.faces.context.ExternalContext#getResourcePaths(java.lang.String)
-	 */
-	public Set getResourcePaths(String path) {
-		return getServletContext().getResourcePaths(path);
-	}
-
-	protected Object getContextAttribute(String name) {
-		return getServletContext().getAttribute(name);
-	}
-
-	protected Enumeration getContextAttributeNames() {
-		return getServletContext().getAttributeNames();
-	}
-
-	protected void setContextAttribute(String name, Object value) {
-		getServletContext().setAttribute(name, value);
-	}
-
-	public String getAuthType() {
-		return getHttpRequest().getAuthType();
-	}
-
-	public String getRemoteUser() {
-		Principal userPrincipal = getUserPrincipal();
-		if( null != userPrincipal){
-			return userPrincipal.getName();
-		}
-		return getHttpRequest().getRemoteUser();
-	}
-
-	public String getRequestContextPath() {
-		return getHttpRequest().getContextPath();
-	}
-
-	public String getRequestPathInfo() {
-		return getHttpRequest().getPathInfo();
-	}
-
-	public String getRequestServletPath() {
-		return getHttpRequest().getServletPath();
-	}
-
-	protected Enumeration enumerateRequestParameterNames() {
-		return getHttpRequest().getParameterNames();
-	}
-
-	protected Object getRequestAttribute(String name) {
-		return getHttpRequest().getAttribute(name);
-	}
-
-	protected Enumeration getRequestAttributeNames() {
-		return getHttpRequest().getAttributeNames();
-	}
-
-	protected Object getRequestParameterValues(String name) {
-		return getHttpRequest().getParameterValues(name);
-	}
-
-	protected Object getRequestHeader(String name) {
-		return getHttpRequest().getHeader(name);
-	}
-
-	protected Enumeration getRequestHeaderNames() {
-		return getHttpRequest().getHeaderNames();
-	}
-
-	protected String[] getRequestHeaderValues(String name) {
-		Enumeration values = getHttpRequest().getHeaders(name);
-		ArrayList valuesList = new ArrayList();
-		while (values.hasMoreElements()) {
-			valuesList.add(values.nextElement());
-		}
-		return (String[]) valuesList.toArray(EMPTY_STRING_ARRAY);
-	}
-
-	protected Object getRequestParameter(String name) {
-		return getHttpRequest().getParameter(name);
-	}
-
-	private String sessionPrefix;
-
-	private String getSessionPrefix() {
-		if (sessionPrefix == null) {
-			HttpSession session = getHttpRequest().getSession(false);
-			String namespase = getNamespace();
-			if (null == namespase || null == session) {
-				throw new FacesException(
-						"JSF request called without portlet namespace parameter");
-			}
-			Enumeration attributeNames = session.getAttributeNames();
-			while (attributeNames.hasMoreElements() && null == sessionPrefix) {
-				String name = (String) attributeNames.nextElement();
-				Object attribute = session.getAttribute(name);
-				if (PortletSessionUtil.decodeScope(name) == PortletSession.PORTLET_SCOPE
-						&& PortletSessionUtil.decodeAttributeName(name).equals(
-								NAMESPACE_PARAMETER)
-						&& namespase.equals(attribute)) {
-					sessionPrefix = name.substring(0, name.length()
-							- NAMESPACE_PARAMETER.length());
-					if (_log.isDebugEnabled()) {
-						_log
-								.debug("Prefix for a PORTLET_SCOPE session attributes: "
-										+ sessionPrefix);
-					}
-				}
-			}
-			if (null == sessionPrefix) {
-				throw new FacesException(
-						"Prefix for attributes in portlet session scope not found");
-			}
-		}
-		return sessionPrefix;
-	}
-
-	protected Object getSessionAttribute(String name) {
-		return getHttpRequest().getSession(true).getAttribute(
-				getSessionPrefix() + name);
-	}
-
-	protected Enumeration getSessionAttributeNames() {
-		return new SessionAttributesNames(getHttpRequest().getSession(true)
-				.getAttributeNames(), getSessionPrefix());
-	}
-
-	protected void removeSessionAttribute(String name) {
-		getHttpRequest().getSession(true).removeAttribute(
-				getSessionPrefix() + name);
-	}
-
-	protected void setSessionAttribute(String name, Object value) {
-		getHttpRequest().getSession(true).setAttribute(
-				getSessionPrefix() + name, value);
-	}
-
-	protected void removeContextAttribute(String name) {
-		getHttpRequest().getSession(true).removeAttribute(name);
-	}
-
-	protected void removeRequestAttribute(String name) {
-		getHttpRequest().removeAttribute(name);
-	}
-
-	protected void setRequestAttribute(String name, Object value) {
-		getHttpRequest().setAttribute(name, value);
-	}
-
-	public void dispatch(String path) throws IOException {
-		RequestDispatcher requestDispatcher = getHttpRequest()
-				.getRequestDispatcher(path);
-		if (requestDispatcher == null) {
-			(getHttpResponse()).sendError(HttpServletResponse.SC_NOT_FOUND);
-			return;
-		}
-		try {
-			requestDispatcher.forward(getHttpRequest(), getHttpResponse());
-		} catch (IOException ioe) {
-			throw ioe;
-		} catch (ServletException se) {
-			throw new FacesException(se);
-		}
-
-	}
-
-	@Override
-	protected String createActionUrl(Map<String, String> parameters) {
-		String url = getHttpRequest().getParameter(ACTION__PARAMETER);
-		if(null == url){
-			throw new FacesException("No portal action url availible");
-		}
-		PortalActionURL portalUrl;
-		try {
-			portalUrl = new PortalActionURL(url);
-		} catch (MalformedURLException e) {
-			throw new FacesException("Malformed Portal Action URL "+url);
-		}
-		for (Entry<String, String> parameterEntry : parameters.entrySet()) {
-			portalUrl.addParameter(parameterEntry.getKey(), parameterEntry.getValue());
-		}
-		return portalUrl.toString();
-	}
-
-	public String encodeResourceURL(String url) {
-		return encodeURL(url);
-	}
-
-	/**
-	 * @param url
-	 * @return
-	 */
-	protected String encodeURL(String url) {
-		return getHttpResponse().encodeURL(url);
-	}
-
-	public Locale getRequestLocale() {
-		return getHttpRequest().getLocale();
-	}
-
-	public Iterator getRequestLocales() {
-		return new EnumerationIterator(getHttpRequest().getLocales());
-	}
-
-	public Object getSession(boolean create) {
-		HttpSession session = getHttpRequest().getSession(create);
-		if (null != session) {
-			session = new ServletSessionWrapper(session, getSessionPrefix());
-		}
-		return session;
-	}
-
-	public Principal getUserPrincipal() {
-        Principal userPrincipal = getHttpRequest().getUserPrincipal();
-		HttpSession httpSession = getHttpRequest().getSession(false);
-		if(null != httpSession){
-			Principal portalPrincipal = (Principal) httpSession.getAttribute(PORTAL_USER_PRINCIPAL);
-			if(null != portalPrincipal){
-				userPrincipal = portalPrincipal;
-			}
-		}
-		return userPrincipal;
-	}
-
-	public boolean isUserInRole(String role) {
-		return getHttpRequest().isUserInRole(role);
-	}
-
-	public void log(String message) {
-		getServletContext().log(message);
-	}
-
-	public void log(String message, Throwable exception) {
-		getServletContext().log(message, exception);
-	}
-
-	public void redirect(String url) throws IOException {
-		getHttpResponse().sendRedirect(url);
-		FacesContext.getCurrentInstance().responseComplete();
-	}
-
-}

Copied: trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/ServletExternalContextImpl.java (from rev 4938, trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/ServletContextImpl.java)
===================================================================
--- trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/ServletExternalContextImpl.java	                        (rev 0)
+++ trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/context/ServletExternalContextImpl.java	2007-12-22 00:30:11 UTC (rev 4964)
@@ -0,0 +1,382 @@
+/**
+ * 
+ */
+package org.ajax4jsf.portlet.context;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.security.Principal;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import javax.faces.FacesException;
+import javax.faces.context.FacesContext;
+import javax.portlet.PortletSession;
+import javax.portlet.PortletSessionUtil;
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import org.ajax4jsf.context.AjaxContext;
+import org.ajax4jsf.portlet.AjaxPortletBridge;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * @author asmirnov
+ * 
+ */
+public class ServletExternalContextImpl extends AbstractExternalContext {
+
+	private static final Log _log = LogFactory.getLog(ServletExternalContextImpl.class);
+
+	private String namespace;
+
+	/**
+	 * @param context
+	 * @param request
+	 * @param response
+	 */
+	public ServletExternalContextImpl(ServletContext context,
+			HttpServletRequest request, HttpServletResponse response) {
+		super(context, request, response);
+		ArrayList excludedAttributes = Collections.list(request.getAttributeNames());
+		request.setAttribute(EXCLUDED_PARAMETERS_ATTRIBUTE, excludedAttributes);
+	}
+
+	public void setResponseCharacterEncoding(String encoding) {
+
+		getHttpResponse().setCharacterEncoding(encoding);
+	}
+
+	public String getResponseCharacterEncoding() {
+		return getHttpResponse().getCharacterEncoding();
+	}
+
+	public String getResponseContentType() {
+		return getHttpResponse().getContentType();
+	}
+
+	public void setRequestCharacterEncoding(String encoding)
+			throws UnsupportedEncodingException {
+		getHttpRequest().setCharacterEncoding(encoding);
+	}
+
+	public String getRequestCharacterEncoding() {
+		return getHttpRequest().getCharacterEncoding();
+	}
+
+	public String getRequestContentType() {
+		return getHttpRequest().getContentType();
+	}
+
+	private HttpServletRequest getHttpRequest() {
+		return (HttpServletRequest) getRequest();
+	}
+
+	private ServletContext getServletContext() {
+		return (ServletContext) getContext();
+	}
+
+	private HttpServletResponse getHttpResponse() {
+		return (HttpServletResponse) getResponse();
+	}
+
+	protected String getNamespace() {
+		if (null == namespace) {
+			Object requestParameter = getRequestParameter(NAMESPACE_PARAMETER);
+			if (null != requestParameter) {
+				namespace = (String) requestParameter;
+				if (_log.isDebugEnabled()) {
+					_log.debug("Namespace for a portlet instance is "
+							+ namespace);
+				}
+			} else {
+				throw new FacesException(
+						"AJAX call to portlet without namespace parameter");
+			}
+		}
+		return namespace;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see javax.faces.context.ExternalContext#getInitParameter(java.lang.String)
+	 */
+	public String getInitParameter(String name) {
+		return getServletContext().getInitParameter(name);
+	}
+
+	protected Enumeration getInitParametersNames() {
+		return getServletContext().getInitParameterNames();
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see javax.faces.context.ExternalContext#getResource(java.lang.String)
+	 */
+	public URL getResource(String path) throws MalformedURLException {
+		return getServletContext().getResource(path);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see javax.faces.context.ExternalContext#getResourceAsStream(java.lang.String)
+	 */
+	public InputStream getResourceAsStream(String path) {
+		return getServletContext().getResourceAsStream(path);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see javax.faces.context.ExternalContext#getResourcePaths(java.lang.String)
+	 */
+	public Set getResourcePaths(String path) {
+		return getServletContext().getResourcePaths(path);
+	}
+
+	protected Object getContextAttribute(String name) {
+		return getServletContext().getAttribute(name);
+	}
+
+	protected Enumeration getContextAttributeNames() {
+		return getServletContext().getAttributeNames();
+	}
+
+	protected void setContextAttribute(String name, Object value) {
+		getServletContext().setAttribute(name, value);
+	}
+
+	public String getAuthType() {
+		return getHttpRequest().getAuthType();
+	}
+
+	public String getRemoteUser() {
+		Principal userPrincipal = getUserPrincipal();
+		if( null != userPrincipal){
+			return userPrincipal.getName();
+		}
+		return getHttpRequest().getRemoteUser();
+	}
+
+	public String getRequestContextPath() {
+		return getHttpRequest().getContextPath();
+	}
+
+	public String getRequestPathInfo() {
+		return getHttpRequest().getPathInfo();
+	}
+
+	public String getRequestServletPath() {
+		return getHttpRequest().getServletPath();
+	}
+
+	protected Enumeration enumerateRequestParameterNames() {
+		return getHttpRequest().getParameterNames();
+	}
+
+	protected Object getRequestAttribute(String name) {
+		return getHttpRequest().getAttribute(name);
+	}
+
+	protected Enumeration getRequestAttributeNames() {
+		return getHttpRequest().getAttributeNames();
+	}
+
+	protected Object getRequestParameterValues(String name) {
+		return getHttpRequest().getParameterValues(name);
+	}
+
+	protected Object getRequestHeader(String name) {
+		return getHttpRequest().getHeader(name);
+	}
+
+	protected Enumeration getRequestHeaderNames() {
+		return getHttpRequest().getHeaderNames();
+	}
+
+	protected String[] getRequestHeaderValues(String name) {
+		Enumeration values = getHttpRequest().getHeaders(name);
+		ArrayList valuesList = new ArrayList();
+		while (values.hasMoreElements()) {
+			valuesList.add(values.nextElement());
+		}
+		return (String[]) valuesList.toArray(EMPTY_STRING_ARRAY);
+	}
+
+	protected Object getRequestParameter(String name) {
+		return getHttpRequest().getParameter(name);
+	}
+
+	private String sessionPrefix;
+
+	private String getSessionPrefix() {
+		if (sessionPrefix == null) {
+			HttpSession session = getHttpRequest().getSession(false);
+			String namespase = getNamespace();
+			if (null == namespase || null == session) {
+				throw new FacesException(
+						"JSF request called without portlet namespace parameter");
+			}
+			Enumeration attributeNames = session.getAttributeNames();
+			while (attributeNames.hasMoreElements() && null == sessionPrefix) {
+				String name = (String) attributeNames.nextElement();
+				Object attribute = session.getAttribute(name);
+				if (PortletSessionUtil.decodeScope(name) == PortletSession.PORTLET_SCOPE
+						&& PortletSessionUtil.decodeAttributeName(name).equals(
+								NAMESPACE_PARAMETER)
+						&& namespase.equals(attribute)) {
+					sessionPrefix = name.substring(0, name.length()
+							- NAMESPACE_PARAMETER.length());
+					if (_log.isDebugEnabled()) {
+						_log
+								.debug("Prefix for a PORTLET_SCOPE session attributes: "
+										+ sessionPrefix);
+					}
+				}
+			}
+			if (null == sessionPrefix) {
+				throw new FacesException(
+						"Prefix for attributes in portlet session scope not found");
+			}
+		}
+		return sessionPrefix;
+	}
+
+	protected Object getSessionAttribute(String name) {
+		return getHttpRequest().getSession(true).getAttribute(
+				getSessionPrefix() + name);
+	}
+
+	protected Enumeration getSessionAttributeNames() {
+		return new SessionAttributesNames(getHttpRequest().getSession(true)
+				.getAttributeNames(), getSessionPrefix());
+	}
+
+	protected void removeSessionAttribute(String name) {
+		getHttpRequest().getSession(true).removeAttribute(
+				getSessionPrefix() + name);
+	}
+
+	protected void setSessionAttribute(String name, Object value) {
+		getHttpRequest().getSession(true).setAttribute(
+				getSessionPrefix() + name, value);
+	}
+
+	protected void removeContextAttribute(String name) {
+		getHttpRequest().getSession(true).removeAttribute(name);
+	}
+
+	protected void removeRequestAttribute(String name) {
+		getHttpRequest().removeAttribute(name);
+	}
+
+	protected void setRequestAttribute(String name, Object value) {
+		getHttpRequest().setAttribute(name, value);
+	}
+
+	public void dispatch(String path) throws IOException {
+		RequestDispatcher requestDispatcher = getHttpRequest()
+				.getRequestDispatcher(path);
+		if (requestDispatcher == null) {
+			(getHttpResponse()).sendError(HttpServletResponse.SC_NOT_FOUND);
+			return;
+		}
+		try {
+			requestDispatcher.forward(getHttpRequest(), getHttpResponse());
+		} catch (IOException ioe) {
+			throw ioe;
+		} catch (ServletException se) {
+			throw new FacesException(se);
+		}
+
+	}
+
+	@Override
+	protected String createActionUrl(Map<String, String> parameters) {
+		String url = getHttpRequest().getParameter(ACTION__PARAMETER);
+		if(null == url){
+			throw new FacesException("No portal action url availible");
+		}
+		PortalActionURL portalUrl;
+		try {
+			portalUrl = new PortalActionURL(url);
+		} catch (MalformedURLException e) {
+			throw new FacesException("Malformed Portal Action URL "+url);
+		}
+		for (Entry<String, String> parameterEntry : parameters.entrySet()) {
+			portalUrl.addParameter(parameterEntry.getKey(), parameterEntry.getValue());
+		}
+		return portalUrl.toString();
+	}
+
+	/**
+	 * @param url
+	 * @return
+	 */
+	protected String encodeURL(String url) {
+		return getHttpResponse().encodeURL(url);
+	}
+
+	public Locale getRequestLocale() {
+		return getHttpRequest().getLocale();
+	}
+
+	public Iterator getRequestLocales() {
+		return new EnumerationIterator(getHttpRequest().getLocales());
+	}
+
+	public Object getSession(boolean create) {
+		HttpSession session = getHttpRequest().getSession(create);
+		if (null != session) {
+			session = new ServletSessionWrapper(session, getSessionPrefix());
+		}
+		return session;
+	}
+
+	public Principal getUserPrincipal() {
+        Principal userPrincipal = getHttpRequest().getUserPrincipal();
+		HttpSession httpSession = getHttpRequest().getSession(false);
+		if(null != httpSession){
+			Principal portalPrincipal = (Principal) httpSession.getAttribute(PORTAL_USER_PRINCIPAL);
+			if(null != portalPrincipal){
+				userPrincipal = portalPrincipal;
+			}
+		}
+		return userPrincipal;
+	}
+
+	public boolean isUserInRole(String role) {
+		return getHttpRequest().isUserInRole(role);
+	}
+
+	public void log(String message) {
+		getServletContext().log(message);
+	}
+
+	public void log(String message, Throwable exception) {
+		getServletContext().log(message, exception);
+	}
+
+	public void redirect(String url) throws IOException {
+		getHttpResponse().sendRedirect(url);
+		FacesContext.getCurrentInstance().responseComplete();
+	}
+
+}

Modified: trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/lifecycle/PortalPhaseListener.java
===================================================================
--- trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/lifecycle/PortalPhaseListener.java	2007-12-21 19:33:55 UTC (rev 4963)
+++ trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/lifecycle/PortalPhaseListener.java	2007-12-22 00:30:11 UTC (rev 4964)
@@ -38,8 +38,33 @@
 		if (phaseId.equals(PhaseId.RESTORE_VIEW)) {
 			Object portletPhase = context.getExternalContext().getRequestMap()
 					.get(Bridge.PORTLET_LIFECYCLE_PHASE);
-			if (null == portletPhase) {
-				// For a servlet phase, put all portlet-related parameters back to ajaxContext.
+			if (Bridge.PortletPhase.RenderPhase.equals(portletPhase)) {
+				context.renderResponse();
+			}
+		} else if (phaseId.equals(PhaseId.INVOKE_APPLICATION)
+				|| (!phaseId.equals(PhaseId.RENDER_RESPONSE) && context
+						.getRenderResponse())) {
+			// save request scope variables and Faces Messages.
+			PortletViewState windowState = PortletStateHolder.getInstance(
+					context).getWindowState(context);
+			windowState.saveRequest(context);
+		}
+
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see javax.faces.event.PhaseListener#beforePhase(javax.faces.event.PhaseEvent)
+	 */
+	public void beforePhase(PhaseEvent event) {
+		PhaseId phaseId = event.getPhaseId();
+		FacesContext context = event.getFacesContext();
+		Object portletPhase = context.getExternalContext().getRequestMap().get(
+				Bridge.PORTLET_LIFECYCLE_PHASE);
+		if (null == portletPhase && phaseId.equals(PhaseId.RENDER_RESPONSE)) {
+				// For a servlet phase, put all portlet-related parameters
+				// back to ajaxContext.
 				Map<String, String> requestParameters = context
 						.getExternalContext().getRequestParameterMap();
 
@@ -69,37 +94,12 @@
 								AbstractExternalContext.PORTLET_NAME_PARAMETER,
 								requestParameters
 										.get(AbstractExternalContext.PORTLET_NAME_PARAMETER));
-
-			} else if (Bridge.PortletPhase.RenderPhase.equals(portletPhase)) {
-				context.renderResponse();
-			}
-		}
-
+			} 
 	}
 
 	/*
 	 * (non-Javadoc)
 	 * 
-	 * @see javax.faces.event.PhaseListener#beforePhase(javax.faces.event.PhaseEvent)
-	 */
-	public void beforePhase(PhaseEvent event) {
-		PhaseId phaseId = event.getPhaseId();
-		FacesContext context = event.getFacesContext();
-		if (phaseId.equals(PhaseId.RENDER_RESPONSE)) {
-			Object portletPhase = context.getExternalContext().getRequestMap()
-					.get(Bridge.PORTLET_LIFECYCLE_PHASE);
-			if (null == portletPhase) {
-				// save request scope variables and Faces Messages.
-				PortletViewState windowState = PortletStateHolder.getInstance(
-						context).getWindowState(context);
-				windowState.saveRequest(context);
-			}
-		}
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
 	 * @see javax.faces.event.PhaseListener#getPhaseId()
 	 */
 	public PhaseId getPhaseId() {

Modified: trunk/extensions/portletbridge/portletbridge-impl/src/test/java/org/ajax4jsf/portlet/context/ContextFactoryTest.java
===================================================================
--- trunk/extensions/portletbridge/portletbridge-impl/src/test/java/org/ajax4jsf/portlet/context/ContextFactoryTest.java	2007-12-21 19:33:55 UTC (rev 4963)
+++ trunk/extensions/portletbridge/portletbridge-impl/src/test/java/org/ajax4jsf/portlet/context/ContextFactoryTest.java	2007-12-22 00:30:11 UTC (rev 4964)
@@ -47,11 +47,11 @@
          * {@link org.ajax4jsf.portlet.context.FacesContextFactoryImpl#FacesContextFactoryImpl(javax.faces.context.FacesContextFactory)}.
          */
     public void testFacesContextFactoryImpl() {
-	FacesContextFactoryImpl factory = new FacesContextFactoryImpl();
+	FacesContextFactoryImpl factory = new FacesContextFactoryImpl(facesContextFactory);
 	FacesContext context = factory.getFacesContext(servletContext, request,
 		response, lifecycle);
 	assertTrue((context instanceof FacesContextImpl));
-	assertTrue((context.getExternalContext() instanceof ServletContextImpl));
+	assertTrue((context.getExternalContext() instanceof AbstractExternalContext));
     }
 
     /**
@@ -59,7 +59,7 @@
          * {@link org.ajax4jsf.portlet.context.FacesContextFactoryImpl#getFacesContext(java.lang.Object, java.lang.Object, java.lang.Object, javax.faces.lifecycle.Lifecycle)}.
          */
     public void testGetFacesContextPortlet() {
-	FacesContextFactoryImpl factory = new FacesContextFactoryImpl();
+	FacesContextFactoryImpl factory = new FacesContextFactoryImpl(facesContextFactory);
 	MockPortletContext portletContext = new MockPortletContext();
 	MockActionRequest portletRequest = new MockActionRequest();
 	MockActionResponse portletResponse = new MockActionResponse();
@@ -71,7 +71,7 @@
     }
 
     public void testIllegalEnvironment() throws Exception {
-	FacesContextFactoryImpl factory = new FacesContextFactoryImpl();
+	FacesContextFactoryImpl factory = new FacesContextFactoryImpl(facesContextFactory);
 	try {
 	    FacesContext context = factory.getFacesContext(null, request,
 		    response, lifecycle);

Modified: trunk/extensions/portletbridge/portletbridge-impl/src/test/java/org/ajax4jsf/portlet/context/FacesContextImplTest.java
===================================================================
--- trunk/extensions/portletbridge/portletbridge-impl/src/test/java/org/ajax4jsf/portlet/context/FacesContextImplTest.java	2007-12-21 19:33:55 UTC (rev 4963)
+++ trunk/extensions/portletbridge/portletbridge-impl/src/test/java/org/ajax4jsf/portlet/context/FacesContextImplTest.java	2007-12-22 00:30:11 UTC (rev 4964)
@@ -17,7 +17,7 @@
 public class FacesContextImplTest extends AbstractAjax4JsfTestCase {
     private static final String ID0 = "_id0";
     protected FacesContextImpl portalFacesContext;
-    protected ServletContextImpl servletContextImpl;
+    protected AbstractExternalContext servletContextImpl;
 
     /**
      * @param arg0
@@ -31,7 +31,7 @@
      */
     public void setUp() throws Exception {
 	super.setUp();
-	servletContextImpl = new ServletContextImpl(servletContext,request,response);
+	servletContextImpl = new ServletExternalContextImpl(servletContext,request,response);
 	portalFacesContext = new FacesContextImpl(servletContextImpl,lifecycle);
 	
     }

Modified: trunk/extensions/portletbridge/portletbridge-impl/src/test/java/org/ajax4jsf/portlet/context/PortletExternalContextTest.java
===================================================================
--- trunk/extensions/portletbridge/portletbridge-impl/src/test/java/org/ajax4jsf/portlet/context/PortletExternalContextTest.java	2007-12-21 19:33:55 UTC (rev 4963)
+++ trunk/extensions/portletbridge/portletbridge-impl/src/test/java/org/ajax4jsf/portlet/context/PortletExternalContextTest.java	2007-12-22 00:30:11 UTC (rev 4964)
@@ -37,7 +37,7 @@
 	portletContext=new MockPortletContext();
 	portletRequest = new MockActionRequest();
 	portletResponse = new MockActionResponse();
-	portletContextImpl = new PortletContextImpl(portletContext,portletRequest,portletResponse);
+	portletContextImpl = new PortletExternalContextImpl(portletContext,portletRequest,portletResponse);
 	portalFacesContext = new FacesContextImpl(portletContextImpl,lifecycle);
 	portalFacesContext.setViewRoot(facesContext.getViewRoot());
     }
@@ -55,7 +55,7 @@
     }
 
     /**
-     * Test method for {@link org.ajax4jsf.portlet.context.PortletContextImpl#getRequestParameterValuesMap()}.
+     * Test method for {@link org.ajax4jsf.portlet.context.PortletExternalContextImpl#getRequestParameterValuesMap()}.
      */
     public final void testGetRequestParameterValuesMap() {
 	Map requestParameterValuesMap = portalFacesContext.getExternalContext().getRequestParameterValuesMap();
@@ -66,7 +66,7 @@
     }
 
     /**
-     * Test method for {@link org.ajax4jsf.portlet.context.PortletContextImpl#getInitParameter(java.lang.String)}.
+     * Test method for {@link org.ajax4jsf.portlet.context.PortletExternalContextImpl#getInitParameter(java.lang.String)}.
      */
     public final void testGetInitParameterString() {
 	assertNull(portalFacesContext.getExternalContext().getInitParameter("blabla"));
@@ -74,14 +74,14 @@
     }
 
     /**
-     * Test method for {@link org.ajax4jsf.portlet.context.PortletContextImpl#getRequestLocales()}.
+     * Test method for {@link org.ajax4jsf.portlet.context.PortletExternalContextImpl#getRequestLocales()}.
      */
     public final void testGetRequestLocales() {
 //	fail("Not yet implemented");
     }
 
     /**
-     * Test method for {@link org.ajax4jsf.portlet.context.PortletContextImpl#getSession(boolean)}.
+     * Test method for {@link org.ajax4jsf.portlet.context.PortletExternalContextImpl#getSession(boolean)}.
      */
     public final void testGetSessionBoolean() {
 //	fail("Not yet implemented");

Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/resource/ResourceLifecycle.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/resource/ResourceLifecycle.java	2007-12-21 19:33:55 UTC (rev 4963)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/resource/ResourceLifecycle.java	2007-12-22 00:30:11 UTC (rev 4964)
@@ -133,7 +133,11 @@
 				// create "dummy" viewRoot, to avoid problems in phase
 				// listeners.
 				UIViewRoot root = new UIViewRoot();
-				root.setViewId(resource.getKey());
+				String key = resource.getKey();
+				if(null != key && !key.startsWith("/")){
+					key="/"+key;
+				}
+				root.setViewId(key);
 				root.setLocale(Locale.getDefault());
 				root.setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
 				facesContext.setViewRoot(root);

Modified: trunk/samples/seamPortletEar/seamBooking/src/main/java/org/jboss/seam/example/booking/Booking.java
===================================================================
--- trunk/samples/seamPortletEar/seamBooking/src/main/java/org/jboss/seam/example/booking/Booking.java	2007-12-21 19:33:55 UTC (rev 4963)
+++ trunk/samples/seamPortletEar/seamBooking/src/main/java/org/jboss/seam/example/booking/Booking.java	2007-12-22 00:30:11 UTC (rev 4964)
@@ -87,7 +87,7 @@
       this.hotel = hotel;
    }
    
-   @ManyToOne @NotNull
+//   @ManyToOne @NotNull
    public User getUser()
    {
       return user;

Modified: trunk/samples/seamPortletEar/seamBooking/src/main/java/org/jboss/seam/example/booking/HotelBookingAction.java
===================================================================
--- trunk/samples/seamPortletEar/seamBooking/src/main/java/org/jboss/seam/example/booking/HotelBookingAction.java	2007-12-21 19:33:55 UTC (rev 4963)
+++ trunk/samples/seamPortletEar/seamBooking/src/main/java/org/jboss/seam/example/booking/HotelBookingAction.java	2007-12-22 00:30:11 UTC (rev 4964)
@@ -51,7 +51,7 @@
    
    private boolean bookingValid;
    
-//   @Begin
+   @Begin
    public void selectHotel(Hotel selectedHotel)
    {
       hotel = em.merge(selectedHotel);
@@ -91,7 +91,7 @@
       return bookingValid;
    }
    
-//   @End
+   @End
    public void confirm()
    {
       em.persist(booking);
@@ -100,7 +100,7 @@
       events.raiseTransactionSuccessEvent("bookingConfirmed");
    }
    
-//   @End
+   @End
    public void cancel() {}
    
    @Remove

Modified: trunk/samples/seamPortletEar/seamBooking/src/main/java/org/jboss/seam/example/booking/User.java
===================================================================
--- trunk/samples/seamPortletEar/seamBooking/src/main/java/org/jboss/seam/example/booking/User.java	2007-12-21 19:33:55 UTC (rev 4963)
+++ trunk/samples/seamPortletEar/seamBooking/src/main/java/org/jboss/seam/example/booking/User.java	2007-12-22 00:30:11 UTC (rev 4964)
@@ -4,7 +4,10 @@
 import static org.jboss.seam.ScopeType.SESSION;
 
 import java.io.Serializable;
+import java.security.Principal;
 
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
 import javax.persistence.Entity;
 import javax.persistence.Id;
 import javax.persistence.Table;
@@ -15,10 +18,8 @@
 import org.jboss.seam.annotations.Name;
 import org.jboss.seam.annotations.Scope;
 
- at Entity
 @Name("user")
 @Scope(SESSION)
- at Table(name="Customer")
 public class User implements Serializable
 {
    private String username;
@@ -34,19 +35,23 @@
    
    public User() {}
 
-   @NotNull
-   @Length(max=100)
    public String getName()
    {
-      return name;
+      if (name == null) {
+		ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
+		Principal userPrincipal = externalContext.getUserPrincipal();
+		if(null != userPrincipal){
+			name = userPrincipal.getName();
+			username = userPrincipal.toString();
+		}
+	}
+	return name;
    }
    public void setName(String name)
    {
       this.name = name;
    }
    
-   @NotNull
-   @Length(min=5, max=15)
    public String getPassword()
    {
       return password;
@@ -56,9 +61,6 @@
       this.password = password;
    }
    
-   @Id
-   @Length(min=4, max=15)
-   @Pattern(regex="^\\w*$", message="not a valid username")
    public String getUsername()
    {
       return username;

Modified: trunk/samples/seamPortletEar/seamBookingPortlet/src/main/webapp/WEB-INF/pages.xml
===================================================================
--- trunk/samples/seamPortletEar/seamBookingPortlet/src/main/webapp/WEB-INF/pages.xml	2007-12-21 19:33:55 UTC (rev 4963)
+++ trunk/samples/seamPortletEar/seamBookingPortlet/src/main/webapp/WEB-INF/pages.xml	2007-12-22 00:30:11 UTC (rev 4964)
@@ -56,7 +56,7 @@
     </page>
     
 	<page view-id="/hotel.xhtml" 
-	      conversation-required="false" 
+	      conversation-required="true" 
 	      login-required="true">
           
         <description>View hotel: #{hotel.name}</description>
@@ -68,7 +68,7 @@
     </page>
 
 	<page view-id="/book.xhtml" 
-	      conversation-required="false" 
+	      conversation-required="true" 
 	      login-required="true">
           
         <description>Book hotel: #{hotel.name}</description>
@@ -82,7 +82,7 @@
     </page>
 
 	<page view-id="/confirm.xhtml" 
-	      conversation-required="false" 
+	      conversation-required="true" 
 	      login-required="true">
           
         <description>Confirm booking: #{booking.description}</description>




More information about the richfaces-svn-commits mailing list