You are viewing a plain text version of this content. The canonical link for it is here.
Posted to adffaces-commits@incubator.apache.org by jw...@apache.org on 2006/12/05 02:02:55 UTC

svn commit: r482451 [3/5] - in /incubator/adffaces/branches/jwaldman-portal/trinidad: trinidad-api/ trinidad-api/src/main/java/org/apache/myfaces/trinidad/config/ trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/ trinidad-api/src/main/jav...

Added: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/wrappers/PortletRequestWrapper.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/wrappers/PortletRequestWrapper.java?view=auto&rev=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/wrappers/PortletRequestWrapper.java (added)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/wrappers/PortletRequestWrapper.java Mon Dec  4 18:02:50 2006
@@ -0,0 +1,366 @@
+/*
+ * Copyright  2004-2006 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.myfaces.trinidad.webapp.wrappers;
+
+import java.security.Principal;
+import java.util.Enumeration;
+import java.util.Locale;
+import java.util.Map;
+
+import javax.portlet.PortalContext;
+import javax.portlet.PortletMode;
+import javax.portlet.PortletPreferences;
+import javax.portlet.PortletRequest;
+import javax.portlet.PortletSession;
+import javax.portlet.WindowState;
+
+/**
+ * TODO: Document this 
+ *
+ * @author Scott O'Bryan (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class PortletRequestWrapper implements PortletRequest
+{
+  public PortletRequestWrapper(PortletRequest request)
+  {
+    _req = request;
+  }
+  
+  private PortletRequest _req;
+
+  /**
+   * @param arg0
+   * @return
+   * @see javax.portlet.PortletRequest#getAttribute(java.lang.String)
+   */
+  public Object getAttribute(String arg0)
+  {
+    return _req.getAttribute(arg0);
+  }
+
+  /**
+   * @return
+   * @see javax.portlet.PortletRequest#getAttributeNames()
+   */
+  public Enumeration getAttributeNames()
+  {
+    return _req.getAttributeNames();
+  }
+
+  /**
+   * @return
+   * @see javax.portlet.PortletRequest#getAuthType()
+   */
+  public String getAuthType()
+  {
+    return _req.getAuthType();
+  }
+
+  /**
+   * @return
+   * @see javax.portlet.PortletRequest#getContextPath()
+   */
+  public String getContextPath()
+  {
+    return _req.getContextPath();
+  }
+
+  /**
+   * @return
+   * @see javax.portlet.PortletRequest#getLocale()
+   */
+  public Locale getLocale()
+  {
+    return _req.getLocale();
+  }
+
+  /**
+   * @return
+   * @see javax.portlet.PortletRequest#getLocales()
+   */
+  public Enumeration getLocales()
+  {
+    return _req.getLocales();
+  }
+
+  /**
+   * @param arg0
+   * @return
+   * @see javax.portlet.PortletRequest#getParameter(java.lang.String)
+   */
+  public String getParameter(String arg0)
+  {
+    return _req.getParameter(arg0);
+  }
+
+  /**
+   * @return
+   * @see javax.portlet.PortletRequest#getParameterMap()
+   */
+  public Map getParameterMap()
+  {
+    return _req.getParameterMap();
+  }
+
+  /**
+   * @return
+   * @see javax.portlet.PortletRequest#getParameterNames()
+   */
+  public Enumeration getParameterNames()
+  {
+    return _req.getParameterNames();
+  }
+
+  /**
+   * @param arg0
+   * @return
+   * @see javax.portlet.PortletRequest#getParameterValues(java.lang.String)
+   */
+  public String[] getParameterValues(String arg0)
+  {
+    return _req.getParameterValues(arg0);
+  }
+
+  /**
+   * @return
+   * @see javax.portlet.PortletRequest#getPortalContext()
+   */
+  public PortalContext getPortalContext()
+  {
+    return _req.getPortalContext();
+  }
+
+  /**
+   * @return
+   * @see javax.portlet.PortletRequest#getPortletMode()
+   */
+  public PortletMode getPortletMode()
+  {
+    return _req.getPortletMode();
+  }
+
+  /**
+   * @return
+   * @see javax.portlet.PortletRequest#getPortletSession()
+   */
+  public PortletSession getPortletSession()
+  {
+    return _req.getPortletSession();
+  }
+
+  /**
+   * @param arg0
+   * @return
+   * @see javax.portlet.PortletRequest#getPortletSession(boolean)
+   */
+  public PortletSession getPortletSession(boolean arg0)
+  {
+    return _req.getPortletSession(arg0);
+  }
+
+  /**
+   * @return
+   * @see javax.portlet.PortletRequest#getPreferences()
+   */
+  public PortletPreferences getPreferences()
+  {
+    return _req.getPreferences();
+  }
+
+  /**
+   * @param arg0
+   * @return
+   * @see javax.portlet.PortletRequest#getProperties(java.lang.String)
+   */
+  public Enumeration getProperties(String arg0)
+  {
+    return _req.getProperties(arg0);
+  }
+
+  /**
+   * @param arg0
+   * @return
+   * @see javax.portlet.PortletRequest#getProperty(java.lang.String)
+   */
+  public String getProperty(String arg0)
+  {
+    return _req.getProperty(arg0);
+  }
+
+  /**
+   * @return
+   * @see javax.portlet.PortletRequest#getPropertyNames()
+   */
+  public Enumeration getPropertyNames()
+  {
+    return _req.getPropertyNames();
+  }
+
+  /**
+   * @return
+   * @see javax.portlet.PortletRequest#getRemoteUser()
+   */
+  public String getRemoteUser()
+  {
+    return _req.getRemoteUser();
+  }
+
+  /**
+   * @return
+   * @see javax.portlet.PortletRequest#getRequestedSessionId()
+   */
+  public String getRequestedSessionId()
+  {
+    return _req.getRequestedSessionId();
+  }
+
+  /**
+   * @return
+   * @see javax.portlet.PortletRequest#getResponseContentType()
+   */
+  public String getResponseContentType()
+  {
+    return _req.getResponseContentType();
+  }
+
+  /**
+   * @return
+   * @see javax.portlet.PortletRequest#getResponseContentTypes()
+   */
+  public Enumeration getResponseContentTypes()
+  {
+    return _req.getResponseContentTypes();
+  }
+
+  /**
+   * @return
+   * @see javax.portlet.PortletRequest#getScheme()
+   */
+  public String getScheme()
+  {
+    return _req.getScheme();
+  }
+
+  /**
+   * @return
+   * @see javax.portlet.PortletRequest#getServerName()
+   */
+  public String getServerName()
+  {
+    return _req.getServerName();
+  }
+
+  /**
+   * @return
+   * @see javax.portlet.PortletRequest#getServerPort()
+   */
+  public int getServerPort()
+  {
+    return _req.getServerPort();
+  }
+
+  /**
+   * @return
+   * @see javax.portlet.PortletRequest#getUserPrincipal()
+   */
+  public Principal getUserPrincipal()
+  {
+    return _req.getUserPrincipal();
+  }
+
+  /**
+   * @return
+   * @see javax.portlet.PortletRequest#getWindowState()
+   */
+  public WindowState getWindowState()
+  {
+    return _req.getWindowState();
+  }
+
+  /**
+   * @param arg0
+   * @return
+   * @see javax.portlet.PortletRequest#isPortletModeAllowed(javax.portlet.PortletMode)
+   */
+  public boolean isPortletModeAllowed(PortletMode arg0)
+  {
+    return _req.isPortletModeAllowed(arg0);
+  }
+
+  /**
+   * @return
+   * @see javax.portlet.PortletRequest#isRequestedSessionIdValid()
+   */
+  public boolean isRequestedSessionIdValid()
+  {
+    return _req.isRequestedSessionIdValid();
+  }
+
+  /**
+   * @return
+   * @see javax.portlet.PortletRequest#isSecure()
+   */
+  public boolean isSecure()
+  {
+    return _req.isSecure();
+  }
+
+  /**
+   * @param arg0
+   * @return
+   * @see javax.portlet.PortletRequest#isUserInRole(java.lang.String)
+   */
+  public boolean isUserInRole(String arg0)
+  {
+    return _req.isUserInRole(arg0);
+  }
+
+  /**
+   * @param arg0
+   * @return
+   * @see javax.portlet.PortletRequest#isWindowStateAllowed(javax.portlet.WindowState)
+   */
+  public boolean isWindowStateAllowed(WindowState arg0)
+  {
+    return _req.isWindowStateAllowed(arg0);
+  }
+
+  /**
+   * @param arg0
+   * @see javax.portlet.PortletRequest#removeAttribute(java.lang.String)
+   */
+  public void removeAttribute(String arg0)
+  {
+    _req.removeAttribute(arg0);
+  }
+
+  /**
+   * @param arg0
+   * @param arg1
+   * @see javax.portlet.PortletRequest#setAttribute(java.lang.String, java.lang.Object)
+   */
+  public void setAttribute(String arg0, Object arg1)
+  {
+    _req.setAttribute(arg0, arg1);
+  }
+  
+  public PortletRequest getRequest()
+  {
+    return _req;
+  }
+}

Added: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/wrappers/PortletResponseWrapper.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/wrappers/PortletResponseWrapper.java?view=auto&rev=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/wrappers/PortletResponseWrapper.java (added)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/wrappers/PortletResponseWrapper.java Mon Dec  4 18:02:50 2006
@@ -0,0 +1,70 @@
+/*
+ * Copyright  2004-2006 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.myfaces.trinidad.webapp.wrappers;
+
+import javax.portlet.PortletResponse;
+
+/**
+ * TODO: Document this 
+ *
+ * @author Scott O'Bryan (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class PortletResponseWrapper implements PortletResponse
+{
+  public PortletResponseWrapper(PortletResponse response)
+  {
+   _resp = response; 
+  }
+  
+  private PortletResponse _resp;
+  
+  public PortletResponse getResponse()
+  {
+    return _resp;
+  }
+
+  /**
+   * @param arg0
+   * @param arg1
+   * @see javax.portlet.PortletResponse#addProperty(java.lang.String, java.lang.String)
+   */
+  public void addProperty(String arg0, String arg1)
+  {
+    _resp.addProperty(arg0, arg1);
+  }
+
+  /**
+   * @param arg0
+   * @return
+   * @see javax.portlet.PortletResponse#encodeURL(java.lang.String)
+   */
+  public String encodeURL(String arg0)
+  {
+    return _resp.encodeURL(arg0);
+  }
+
+  /**
+   * @param arg0
+   * @param arg1
+   * @see javax.portlet.PortletResponse#setProperty(java.lang.String, java.lang.String)
+   */
+  public void setProperty(String arg0, String arg1)
+  {
+    _resp.setProperty(arg0, arg1);
+  }
+}

Added: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/wrappers/RenderRequestWrapper.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/wrappers/RenderRequestWrapper.java?view=auto&rev=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/wrappers/RenderRequestWrapper.java (added)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/wrappers/RenderRequestWrapper.java Mon Dec  4 18:02:50 2006
@@ -0,0 +1,45 @@
+/*
+ * Copyright  2004-2006 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.myfaces.trinidad.webapp.wrappers;
+
+import javax.portlet.RenderRequest;
+
+/**
+ * TODO: Document this 
+ *
+ * @author Scott O'Bryan (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class RenderRequestWrapper extends PortletRequestWrapper implements RenderRequest
+{
+  public RenderRequestWrapper(RenderRequest request)
+  {
+    super(request);
+    _req = request;
+  }
+  
+  private RenderRequest _req;
+
+  /* (non-Javadoc)
+   * @see org.apache.myfaces.trinidadinternal.webapp.wrappers.PortletRequestWrapper#getRequest()
+   */
+  @Override
+  public RenderRequest getRequest()
+  {
+    return _req;
+  }
+}

Added: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/wrappers/RenderResponseWrapper.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/wrappers/RenderResponseWrapper.java?view=auto&rev=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/wrappers/RenderResponseWrapper.java (added)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/wrappers/RenderResponseWrapper.java Mon Dec  4 18:02:50 2006
@@ -0,0 +1,179 @@
+/*
+ * Copyright  2004-2006 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.myfaces.trinidad.webapp.wrappers;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.util.Locale;
+
+import javax.portlet.PortletURL;
+import javax.portlet.RenderResponse;
+
+/**
+ * TODO: Document this 
+ *
+ * @author Scott O'Bryan (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class RenderResponseWrapper extends PortletResponseWrapper implements RenderResponse
+{
+  public RenderResponseWrapper(RenderResponse response)
+  {
+    super(response);
+    _resp = response;
+  }
+  
+  private RenderResponse _resp;
+
+  /* (non-Javadoc)
+   * @see javax.portlet.RenderResponse#createActionURL()
+   */
+  public PortletURL createActionURL()
+  {
+    return _resp.createActionURL();
+  }
+
+  /* (non-Javadoc)
+   * @see javax.portlet.RenderResponse#createRenderURL()
+   */
+  public PortletURL createRenderURL()
+  {
+    return _resp.createRenderURL();
+  }
+
+  /* (non-Javadoc)
+   * @see javax.portlet.RenderResponse#flushBuffer()
+   */
+  public void flushBuffer() throws IOException
+  {
+    _resp.flushBuffer();
+  }
+
+  /* (non-Javadoc)
+   * @see javax.portlet.RenderResponse#getBufferSize()
+   */
+  public int getBufferSize()
+  {
+    return _resp.getBufferSize();
+  }
+
+  /* (non-Javadoc)
+   * @see javax.portlet.RenderResponse#getCharacterEncoding()
+   */
+  public String getCharacterEncoding()
+  {
+    return _resp.getCharacterEncoding();
+  }
+
+  /* (non-Javadoc)
+   * @see javax.portlet.RenderResponse#getContentType()
+   */
+  public String getContentType()
+  {
+    return _resp.getContentType();
+  }
+
+  /* (non-Javadoc)
+   * @see javax.portlet.RenderResponse#getLocale()
+   */
+  public Locale getLocale()
+  {
+    return _resp.getLocale();
+  }
+
+  /* (non-Javadoc)
+   * @see javax.portlet.RenderResponse#getNamespace()
+   */
+  public String getNamespace()
+  {
+    return _resp.getNamespace();
+  }
+
+  /* (non-Javadoc)
+   * @see javax.portlet.RenderResponse#getPortletOutputStream()
+   */
+  public OutputStream getPortletOutputStream() throws IOException
+  {
+    return _resp.getPortletOutputStream();
+  }
+
+  /* (non-Javadoc)
+   * @see javax.portlet.RenderResponse#getWriter()
+   */
+  public PrintWriter getWriter() throws IOException
+  {
+    return _resp.getWriter();
+  }
+
+  /* (non-Javadoc)
+   * @see javax.portlet.RenderResponse#isCommitted()
+   */
+  public boolean isCommitted()
+  {
+    return _resp.isCommitted();
+  }
+
+  /* (non-Javadoc)
+   * @see javax.portlet.RenderResponse#reset()
+   */
+  public void reset()
+  {
+    _resp.reset();
+  }
+
+  /* (non-Javadoc)
+   * @see javax.portlet.RenderResponse#resetBuffer()
+   */
+  public void resetBuffer()
+  {
+    _resp.resetBuffer();
+  }
+
+  /* (non-Javadoc)
+   * @see javax.portlet.RenderResponse#setBufferSize(int)
+   */
+  public void setBufferSize(int arg0)
+  {
+    _resp.setBufferSize(arg0);
+  }
+
+  /* (non-Javadoc)
+   * @see javax.portlet.RenderResponse#setContentType(java.lang.String)
+   */
+  public void setContentType(String arg0)
+  {
+    _resp.setContentType(arg0);
+  }
+
+  /* (non-Javadoc)
+   * @see javax.portlet.RenderResponse#setTitle(java.lang.String)
+   */
+  public void setTitle(String arg0)
+  {
+    _resp.setTitle(arg0);
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.myfaces.trinidadinternal.webapp.wrappers.PortletResponseWrapper#getResponse()
+   */
+  @Override
+  public RenderResponse getResponse()
+  {
+    return _resp;
+  }
+}

Modified: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-demo/src/main/webapp/WEB-INF/trinidad-config.xml
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-demo/src/main/webapp/WEB-INF/trinidad-config.xml?view=diff&rev=482451&r1=482450&r2=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-demo/src/main/webapp/WEB-INF/trinidad-config.xml (original)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-demo/src/main/webapp/WEB-INF/trinidad-config.xml Mon Dec  4 18:02:50 2006
@@ -22,6 +22,8 @@
   <!-- you can use EL to get the skin. This allows the skin to change between
        requests. -->
   <skin-family>#{prefs.proxy.skinFamily}</skin-family>
+  
+  <output-mode>portlet</output-mode>
 
   <!--  Uncomment any of these to enable them -->
   <!-- accessibility-mode>inaccessible</accessibility-mode -->  

Modified: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-demo/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-demo/src/main/webapp/WEB-INF/web.xml?view=diff&rev=482451&r1=482450&r2=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-demo/src/main/webapp/WEB-INF/web.xml (original)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-demo/src/main/webapp/WEB-INF/web.xml Mon Dec  4 18:02:50 2006
@@ -79,6 +79,9 @@
     <param-name>org.apache.myfaces.trinidad.DIALOG_NAVIGATION_PREFIX</param-name>
     <param-value>userInputHere:</param-value>
   </context-param--> 
+  <listener>
+    <listener-class>org.apache.myfaces.trinidad.webapp.TrinidadListener</listener-class>
+  </listener>
 
   <filter>
     <filter-name>trinidad</filter-name>

Modified: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/pom.xml
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/pom.xml?view=diff&rev=482451&r1=482450&r2=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/pom.xml (original)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/pom.xml Mon Dec  4 18:02:50 2006
@@ -169,6 +169,13 @@
     </dependency>
 
     <dependency>
+      <groupId>portlet-api</groupId>
+      <artifactId>portlet-api</artifactId>
+      <version>1.0</version>
+      <scope>provided</scope>
+    </dependency>
+
+    <dependency>
       <groupId>org.apache.myfaces.trinidad</groupId>
       <artifactId>trinidad-build</artifactId>
     </dependency>

Added: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/ConfigParser.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/ConfigParser.java?view=auto&rev=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/ConfigParser.java (added)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/ConfigParser.java Mon Dec  4 18:02:50 2006
@@ -0,0 +1,260 @@
+/*
+ * Copyright  2004-2006 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.myfaces.trinidadinternal.config;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Locale;
+import java.util.Map;
+import java.util.TimeZone;
+
+import javax.faces.context.ExternalContext;
+import javax.faces.el.ValueBinding;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.apache.myfaces.trinidad.bean.PropertyKey;
+import org.apache.myfaces.trinidad.logging.TrinidadLogger;
+import org.apache.myfaces.trinidad.util.ClassLoaderUtils;
+import org.apache.myfaces.trinidad.webapp.UploadedFileProcessor;
+import org.apache.myfaces.trinidadinternal.config.upload.UploadedFileProcessorImpl;
+import org.apache.myfaces.trinidadinternal.context.RequestContextBean;
+import org.apache.myfaces.trinidadinternal.util.nls.LocaleUtils;
+import org.xml.sax.Attributes;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.DefaultHandler;
+
+
+
+/**
+ *
+ */
+public class ConfigParser
+{
+  /**
+   *
+   */
+  static public RequestContextBean parseConfigFile(
+    ExternalContext externalContext)
+  {
+    RequestContextBean bean = new RequestContextBean();
+
+    InputStream in = externalContext.getResourceAsStream(_CONFIG_FILE);
+    if (in != null)
+    {
+      try
+      {
+        InputSource input = new InputSource();
+        input.setByteStream(in);
+        input.setPublicId(_CONFIG_FILE);
+
+        SAXParserFactory factory = SAXParserFactory.newInstance();
+        factory.setNamespaceAware(true);
+        XMLReader reader = factory.newSAXParser().getXMLReader();
+
+        reader.setContentHandler(new Handler(bean,externalContext));
+        reader.parse(input);
+      }
+      catch (IOException ioe)
+      {
+        _LOG.warning(ioe);
+      }
+      catch (ParserConfigurationException pce)
+      {
+        _LOG.warning(pce);
+      }
+      catch (SAXException saxe)
+      {
+        _LOG.warning(saxe);
+      }
+      finally
+      {
+        try
+        {
+          in.close();
+        }
+        catch (IOException ioe)
+        {
+          // Ignore
+          ;
+        }
+      }
+    }
+
+    String className = (String)
+      bean.getProperty(RequestContextBean.UPLOADED_FILE_PROCESSOR_KEY);
+    if (className != null)
+    {
+      className = className.trim();
+
+      try
+      {
+        Class<?> clazz = ClassLoaderUtils.loadClass(className);
+        bean.setProperty(RequestContextBean.UPLOADED_FILE_PROCESSOR_KEY,
+                         clazz.newInstance());
+      }
+      catch (Exception e)
+      {
+        _LOG.severe("Could not instantiate UploadedFileProcessor", e);
+        bean.setProperty(RequestContextBean.UPLOADED_FILE_PROCESSOR_KEY,
+                         new UploadedFileProcessorImpl());
+      }
+    }
+    else
+    {
+      bean.setProperty(RequestContextBean.UPLOADED_FILE_PROCESSOR_KEY,
+                       new UploadedFileProcessorImpl());
+    }
+
+    UploadedFileProcessor ufp = (UploadedFileProcessor)
+      bean.getProperty(RequestContextBean.UPLOADED_FILE_PROCESSOR_KEY);
+
+    ufp.init(externalContext);
+
+    if (_LOG.isInfo())
+    {
+      Object debug = bean.getProperty(RequestContextBean.DEBUG_OUTPUT_KEY);
+      if (Boolean.TRUE.equals(debug))
+        _LOG.info("Trinidad is running in debug mode. "+
+                  "Do not use in a production environment. See:"+_CONFIG_FILE);
+    }
+    return bean;
+  }
+
+  static private class Handler extends DefaultHandler
+  {
+    public Handler(RequestContextBean bean, ExternalContext context)
+    {
+        _applicationMap = context.getApplicationMap();
+        _bean = bean;
+    }
+
+    @Override
+    public void startElement(String uri,
+                             String localName,
+                             String qName,
+                             Attributes atts)
+    {
+      _currentText = "";
+    }
+
+    @Override
+    public void characters(char[] ch, int start, int length)
+    {
+      if (_currentText != null)
+        _currentText = _currentText + new String(ch, start, length);
+    }
+
+    @Override
+    public void endElement(String uri,
+                           String localName,
+                           String qName)
+    {
+      if ((_currentText != null) && !"".equals(_currentText))
+      {
+        PropertyKey key = _bean.getType().findKey(localName);
+        if (key == null)
+        {
+          if (_LOG.isWarning())
+            _LOG.warning("Element {0} is not understood", qName);
+        }
+        else
+        {
+          if (_currentText.startsWith("#{") &&
+              _currentText.endsWith("}"))
+          {
+            if (!key.getSupportsBinding())
+            {
+              if (_LOG.isWarning())
+                _LOG.warning("Element {0} does not support EL expressions.",
+                             qName);
+            }
+            else
+            {
+              ValueBinding binding =
+                LazyValueBinding.createValueBinding(_currentText);
+              _bean.setValueBinding(key, binding);
+            }
+          }
+          else
+          {
+            Object value;
+
+            if (key.getType() == Character.class)
+            {
+              value = _currentText.charAt(0);
+            }
+            else if (key.getType() == Integer.class)
+            {
+              value = _getIntegerValue(_currentText, qName);
+            }
+            else if (key.getType() == Boolean.class)
+            {
+              value = ("true".equalsIgnoreCase(_currentText)
+                       ? Boolean.TRUE : Boolean.FALSE);
+            }
+            else if (key.getType() == TimeZone.class)
+            {
+              value = TimeZone.getTimeZone(_currentText);
+            }
+            else if (key.getType() == Locale.class)
+            {
+              value = LocaleUtils.getLocaleForIANAString(_currentText);
+            }
+            else
+            {
+              value = _currentText;
+            }
+            if (key == RequestContextBean.REMOTE_DEVICE_REPOSITORY_URI){
+                _applicationMap.put("remote-device-repository-uri",value);
+            }
+            _bean.setProperty(key, value);
+          }
+        }
+      }
+
+      _currentText = null;
+    }
+
+  private static Integer _getIntegerValue(String text, String qName)
+  {
+    Integer value = null;
+    try
+    {
+      value = Integer.valueOf(text);
+    }
+    catch (NumberFormatException nfe)
+    {
+      if (_LOG.isWarning())
+      {
+        _LOG.warning("Element {0} only accepts integer values",
+                     qName);
+      }
+    }
+    return value;
+  }
+
+
+    private RequestContextBean _bean;
+    private String              _currentText;
+    private Map                _applicationMap;
+  }
+
+  static private final String _CONFIG_FILE = "/WEB-INF/trinidad-config.xml";
+  static private final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(ConfigParser.class);
+}

Added: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/GlobalConfiguratorImpl.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/GlobalConfiguratorImpl.java?view=auto&rev=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/GlobalConfiguratorImpl.java (added)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/GlobalConfiguratorImpl.java Mon Dec  4 18:02:50 2006
@@ -0,0 +1,299 @@
+/* Copyright  2003-2006 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.myfaces.trinidadinternal.config;
+
+import java.util.List;
+
+import javax.faces.context.ExternalContext;
+
+import org.apache.myfaces.trinidad.config.Configurator;
+import org.apache.myfaces.trinidad.config.GlobalConfigurator;
+import org.apache.myfaces.trinidad.context.RequestContext;
+import org.apache.myfaces.trinidad.context.RequestContextFactory;
+import org.apache.myfaces.trinidad.logging.TrinidadLogger;
+import org.apache.myfaces.trinidad.skin.SkinFactory;
+import org.apache.myfaces.trinidad.util.ClassLoaderUtils;
+import org.apache.myfaces.trinidadinternal.context.RequestContextFactoryImpl;
+import org.apache.myfaces.trinidadinternal.context.TrinidadPhaseListener;
+import org.apache.myfaces.trinidadinternal.skin.SkinFactoryImpl;
+import org.apache.myfaces.trinidadinternal.skin.SkinUtils;
+
+/**
+ * This is the implementation of the Trinidad GlobalConfigurator.
+ * 
+ * @see org.apache.myfaces.trinidad.config.GlobalConfigurator
+ * @author Scott O'Bryan (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class GlobalConfiguratorImpl extends GlobalConfigurator
+{
+  /**
+   * Returns <code>true</code> is {@link #beginRequest(ExternalContext)} has been called and
+   * {@link #endRequest(ExternalContext)} has not. It will return <code>false</code> under all
+   * other circumstances.
+   * 
+   * @param ec
+   *          the current externalContext
+   * @return a boolean saying whether a particular request has begun but has not ended.
+   */
+  public static boolean isRequestBegun(final ExternalContext ec)
+  {
+    return Boolean.TRUE.equals(ec.getSessionMap().get(_IN_REQUEST));
+  }
+
+  /**
+   * Default constructor
+   */
+  public GlobalConfiguratorImpl()
+  {
+    _services = ClassLoaderUtils.getServices(GlobalConfigurator.class.getName());
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see org.apache.myfaces.trinidad.config.Configurator#beginRequest(javax.faces.context.ExternalContext)
+   */
+  @SuppressWarnings("unchecked")
+  public void beginRequest(final ExternalContext externalContext)
+  {
+    _checkInitialized();
+    _attachRequestContext(externalContext);
+
+    // By contract, Configurators beginRequest is only called once per physical request.
+    // The globalConfigurator may be called multiple times, however, so we need to enforce
+    // the contract.
+    if (!isRequestBegun(externalContext))
+    {
+      externalContext.getSessionMap().put(_IN_REQUEST, Boolean.TRUE);
+
+      // If request map is present, we don't have a new request
+      // Launch Configurator Services
+      for (final Configurator config : _services)
+      {
+        config.beginRequest(externalContext);
+      }
+    }
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see org.apache.myfaces.trinidad.config.Configurator#destroy()
+   */
+  public void destroy()
+  {
+    _checkInitialized();
+    for (final Configurator config : _services)
+    {
+      try
+      {
+        config.destroy();
+      }
+      catch (final Throwable t)
+      {
+        // we always want to continue to destroy things, so log errors and continue
+        _LOG.severe(t);
+      }
+      finally
+      {
+        _initialized = false;
+      }
+    }
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see org.apache.myfaces.trinidad.config.Configurator#endRequest(javax.faces.context.ExternalContext)
+   */
+  public void endRequest(final ExternalContext externalContext)
+  {
+    _checkInitialized();
+
+    if (isRequestBegun(externalContext))
+    {
+      for (final Configurator config : _services)
+      {
+        config.endRequest(externalContext);
+      }
+      externalContext.getSessionMap().remove(_IN_REQUEST);
+    }
+
+    final RequestContext context = RequestContext.getCurrentInstance();
+
+    if (context != null)
+    {
+      context.release();
+      assert RequestContext.getCurrentInstance() == null;
+    }
+
+    externalContext.getSessionMap().remove(_PERSISTANT_ATTRIBUTES);
+  }
+
+  public ExternalContext getExternalContext(ExternalContext externalContext)
+  {
+    _checkInitialized();
+    // Wrap ExternalContexts
+    for (final Configurator config : _services)
+    {
+      externalContext = config.getExternalContext(externalContext);
+    }
+
+    return externalContext;
+  }
+
+  /**
+   * Gets the maximum number of bytes that MultipartFormItem.writeFile() will be allowed to write.
+   */
+  public long getMaximumAllowedBytes()
+  {
+    return _maxAllowedBytes;
+  }
+
+  /*
+   * @see org.apache.myfaces.trinidad.config.Configurator#init(javax.faces.context.ExternalContext)
+   */
+  public void init(final ExternalContext externalContext)
+  {
+    // Create a new RequestContextFactory is needed
+    if (RequestContextFactory.getFactory() == null)
+    {
+      RequestContextFactory.setFactory(new RequestContextFactoryImpl());
+    }
+
+    // Create a new SkinFactory if needed.
+    if (SkinFactory.getFactory() == null)
+    {
+      SkinFactory.setFactory(new SkinFactoryImpl());
+    }
+
+    if (!_initialized)
+    {
+      // register the base skins
+      SkinUtils.registerBaseSkins();
+
+      for (final Configurator config : _services)
+      {
+        config.init(externalContext);
+      }
+
+      // after the 'services' filters are initialized, then register
+      // the skin extensions found in trinidad-skins.xml. This
+      // gives a chance to the 'services' filters to create more base
+      // skins that the skins in trinidad-skins.xml can extend.
+      SkinUtils.registerSkinExtensions(externalContext);
+      _initialized = true;
+    }
+  }
+
+  @Override
+  public boolean isInitialized()
+  {
+    return _initialized;
+  }
+
+  /**
+   * Sets the maximum number of bytes that MultipartFormItem.writeFile() will be allowed to write.
+   * This value may be set immediately before or between calls to MultipartFormItem.writeFile(). If
+   * any call to writeFile() exceeds this value, an EOFException will be thrown.
+   * <p>
+   * 
+   * @param maxAllowedBytes
+   *          the maximum number of bytes that MultipartFormItem.writeFile() will be allowed to
+   *          write. Defaults to 128MB.
+   * @see org.apache.myfaces.trinidadinternal.share.util.MultipartFormItem#writeFile
+   */
+  public void setMaximumAllowedBytes(final long maxAllowedBytes)
+  {
+    _maxAllowedBytes = Math.max(0L, maxAllowedBytes);
+  }
+
+  /**
+   * @param externalContext
+   * @return
+   */
+  @SuppressWarnings("unchecked")
+  private void _attachRequestContext(final ExternalContext externalContext)
+  {
+    // If someone didn't release the RequestContext on an earlier request,
+    // then it'd still be around, and trying to create a new one
+    // would trigger an exception. We don't want to take down
+    // this thread for all eternity, so clean up after poorly-behaved code.
+    RequestContext context = RequestContext.getCurrentInstance();
+    if (context != null)
+    {
+      if (_LOG.isWarning())
+      {
+        _LOG.warning("RequestContext had not been properly released on earlier " + "request.");
+      }
+      context.release();
+    }
+
+    // See if we've got a cached RequestContext instance; if so,
+    // reattach it
+    final Object cachedRequestContext = externalContext.getRequestMap().get(
+        TrinidadPhaseListener.CACHED_REQUEST_CONTEXT);
+
+    // Catch both the null scenario and the
+    // RequestContext-from-a-different-classloader scenario
+    if (cachedRequestContext instanceof RequestContext)
+    {
+      context = (RequestContext) cachedRequestContext;
+      context.attach();
+    }
+    else
+    {
+      final RequestContextFactory factory = RequestContextFactory.getFactory();
+      assert factory != null;
+      context = factory.createContext(externalContext);
+      externalContext.getRequestMap().put(TrinidadPhaseListener.CACHED_REQUEST_CONTEXT, context);
+    }
+
+    assert RequestContext.getCurrentInstance() == context;
+  }
+
+  private void _checkInitialized()
+  {
+    if (!isInitialized())
+    {
+      throw new IllegalStateException("Configurator not initialized!");
+    }
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see org.apache.myfaces.trinidad.config.GlobalConfigurator#getPersistantRequestMap(javax.faces.context.ExternalContext)
+   */
+
+  private boolean                     _initialized           = false;
+
+  private long                        _maxAllowedBytes;
+
+  private List<Configurator>          _services              = null;
+
+  static private final String         _IN_REQUEST            = GlobalConfiguratorImpl.class
+                                                                 .getName()
+                                                                 + ".IN_REQUEST";
+
+  static private final TrinidadLogger _LOG                   = TrinidadLogger
+                                                                 .createTrinidadLogger(GlobalConfiguratorImpl.class);
+
+  static private final String         _PERSISTANT_ATTRIBUTES = GlobalConfiguratorImpl.class
+                                                                 .getName()
+                                                                 + ".PERSISTANT_ATTRIBUTES";
+}

Added: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/LazyValueBinding.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/LazyValueBinding.java?view=auto&rev=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/LazyValueBinding.java (added)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/LazyValueBinding.java Mon Dec  4 18:02:50 2006
@@ -0,0 +1,126 @@
+/*
+ * Copyright  2004-2006 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.myfaces.trinidadinternal.config;
+
+import javax.faces.FactoryFinder;
+import javax.faces.application.Application;
+import javax.faces.application.ApplicationFactory;
+import javax.faces.context.FacesContext;
+import javax.faces.el.ReferenceSyntaxException;
+import javax.faces.el.ValueBinding;
+
+import org.apache.myfaces.trinidad.logging.TrinidadLogger;
+
+/**
+ * A ValueBinding class that lazily parses the underlying EL expression
+ * (in case the Application object is not yet available).  Unfortunately,
+ * this implementation means that errors in the syntax of the EL
+ * expression won't get detected until use.
+ *
+ * @author The Oracle ADF Faces Team
+ */
+class LazyValueBinding extends ValueBinding
+{
+  /**
+   * Create a ValueBinding;  if the Application is not yet
+   * available, delay actual parsing until later.
+   */
+  static public ValueBinding createValueBinding(String expression)
+  {
+    ApplicationFactory factory = (ApplicationFactory)
+      FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
+    if (factory != null)
+    {
+      Application application = factory.getApplication();
+      if (application != null)
+      {
+        try
+        {
+          return application.createValueBinding(expression);
+        }
+        catch (NullPointerException npe)
+        {
+          ;
+          // In the Sun RI, JSF 1.0 and 1.1, creating a ValueBinding
+          // when there isn't a FacesContext results in a NullPointerException.
+          // Work around this bug.
+        }
+      }
+    }
+
+    return new LazyValueBinding(expression);
+  }
+
+  private LazyValueBinding(String expression)
+  {
+    _expression = expression;
+  }
+
+  @Override
+  public Object getValue(FacesContext context)
+  {
+    return _getValueBinding().getValue(context);
+  }
+
+  @Override
+  public void setValue(FacesContext context, Object value)
+  {
+    _getValueBinding().setValue(context, value);
+  }
+
+  @Override
+  public boolean isReadOnly(FacesContext context)
+  {
+    return _getValueBinding().isReadOnly(context);
+  }
+
+  @Override
+  public Class<?> getType(FacesContext context)
+  {
+    return _getValueBinding().getType(context);
+  }
+
+  @Override
+  public String getExpressionString()
+  {
+    return _expression;
+  }
+
+  private ValueBinding _getValueBinding()
+  {
+    if (_binding == null)
+    {
+      ApplicationFactory factory = (ApplicationFactory)
+        FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
+      Application application = factory.getApplication();
+      try
+      {
+        _binding = application.createValueBinding(_expression);
+      }
+      catch (ReferenceSyntaxException rse)
+      {
+        _LOG.warning(rse);
+      }
+    }
+
+    return _binding;
+  }
+
+  private final String       _expression;
+  private       ValueBinding _binding;
+
+  static private final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(LazyValueBinding.class);
+}

Added: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/dispatch/DispatchRenderResponse.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/dispatch/DispatchRenderResponse.java?view=auto&rev=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/dispatch/DispatchRenderResponse.java (added)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/dispatch/DispatchRenderResponse.java Mon Dec  4 18:02:50 2006
@@ -0,0 +1,74 @@
+/*
+ * Copyright  2004-2006 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.myfaces.trinidadinternal.config.dispatch;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.faces.context.ExternalContext;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+
+import org.apache.myfaces.trinidad.webapp.wrappers.RenderResponseWrapper;
+
+@SuppressWarnings("deprecation")
+class DispatchRenderResponse extends RenderResponseWrapper
+{
+  public DispatchRenderResponse(ExternalContext ec)
+  {
+    super((RenderResponse)ec.getResponse());
+     _request = (RenderRequest)ec.getRequest();
+  }
+
+  @Override
+  public void setContentType(
+    String contentTypeAndCharset)
+  {
+    if(contentTypeAndCharset != null)
+    {
+      Matcher matcher = _CONTENT_TYPE_PATTERN.matcher(contentTypeAndCharset);
+      if (matcher.matches())
+      {
+        String contentType = matcher.group(1);
+        String charset = (matcher.groupCount() > 1) ? matcher.group(2) : null; 
+        
+        // capture the content type on the request
+        _request.setAttribute(DispatchResponseConfiguratorImpl._CONTENT_TYPE_KEY, contentType);
+  
+        // TODO: use Agent APIs when available
+        if ("application/xhtml+xml".equals(contentType))
+        {
+          //TODO: Is this still needed in IE7??
+          String userAgent = _request.getProperty("User-agent");          
+          if (userAgent != null && userAgent.indexOf("compatible; MSIE") != -1)
+          {
+            // IE must serve XHTML as text/html
+            contentTypeAndCharset = "text/html";
+  
+            if (charset != null)
+              contentTypeAndCharset += ";charset=" + charset;
+          }
+        }
+      }
+    }
+    super.setContentType(contentTypeAndCharset);
+  }
+  
+  private final RenderRequest _request;
+                                   
+  static private final Pattern _CONTENT_TYPE_PATTERN = 
+                                  Pattern.compile("([^;]+)(?:;charset=(.*))?");
+}

Added: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/dispatch/DispatchResponseConfiguratorImpl.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/dispatch/DispatchResponseConfiguratorImpl.java?view=auto&rev=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/dispatch/DispatchResponseConfiguratorImpl.java (added)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/dispatch/DispatchResponseConfiguratorImpl.java Mon Dec  4 18:02:50 2006
@@ -0,0 +1,219 @@
+/*
+ * Copyright  2004-2006 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.myfaces.trinidadinternal.config.dispatch;
+
+import java.io.IOException;
+import java.util.Map;
+
+import javax.faces.FacesException;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.portlet.PortletContext;
+import javax.portlet.PortletException;
+import javax.portlet.PortletRequestDispatcher;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.servlet.ServletResponse;
+
+import org.apache.myfaces.trinidad.config.GenericConfigurator;
+import org.apache.myfaces.trinidad.util.ExternalContextUtils;
+import org.apache.myfaces.trinidad.webapp.wrappers.PortletContextWrapper;
+import org.apache.myfaces.trinidadinternal.context.ExternalContextDecorator;
+
+/**
+ * TODO: Document this 
+ *
+ * @author Scott O'Bryan (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class DispatchResponseConfiguratorImpl extends GenericConfigurator
+{
+
+  /* (non-Javadoc)
+   * @see org.apache.myfaces.trinidad.config.GenericConfigurator#getExternalContext(javax.faces.context.ExternalContext)
+   */
+  @Override
+  public ExternalContext getExternalContext(ExternalContext externalContext)
+  {
+    if(!isApplied(externalContext))
+    {
+      if(ExternalContextUtils.isPortlet(externalContext))
+      {
+        if(!ExternalContextUtils.isAction(externalContext))
+        {
+          apply(externalContext);
+          return new PortletExternalContext(externalContext);
+        }
+      }
+      else
+      {
+        apply(externalContext);
+        return new ServletExternalContext(externalContext);
+      }
+    }
+     
+      
+    //return the origional
+    return externalContext;
+  }
+  
+  @SuppressWarnings("unchecked")
+  static public String getContentType(
+    FacesContext context)
+  {
+    Map<String, Object> requestMap = context.getExternalContext().getRequestMap();
+    return (String) requestMap.get(_CONTENT_TYPE_KEY);
+  }
+  
+  private class ServletExternalContext extends ExternalContextDecorator
+  {
+    public ServletExternalContext(ExternalContext ec)
+    {
+      _ec = ec;
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.myfaces.trinidadinternal.context.ExternalContextDecorator#getRequest()
+     */
+    @Override
+    public Object getResponse()
+    {
+      if(_response == null)
+      {
+        _response = new DispatchServletResponse(_ec);
+      }
+      
+      return _response;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.myfaces.trinidadinternal.context.ExternalContextDecorator#getExternalContext()
+     */
+    @Override
+    protected ExternalContext getExternalContext()
+    {
+      return _ec;
+    }
+    
+    private ServletResponse  _response;
+    private ExternalContext _ec;
+  }
+
+  private class PortletExternalContext extends ExternalContextDecorator
+  {
+    public PortletExternalContext(ExternalContext ec)
+    {
+      _ec = ec;
+    }
+  
+    /* (non-Javadoc)
+     * @see org.apache.myfaces.trinidadinternal.context.ExternalContextDecorator#getContext()
+     */
+    @Override
+    public Object getContext()
+    {
+      return _getPortletContext();
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.myfaces.trinidadinternal.context.ExternalContextDecorator#getResponse()
+     */
+    @Override
+    public Object getResponse()
+    {
+      return _getRenderResponse();
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.myfaces.trinidadinternal.context.ExternalContextDecorator#dispatch(java.lang.String)
+     */
+    @Override
+    public void dispatch(String path) throws IOException
+    {
+      final PortletRequestDispatcher requestDispatcher = ((PortletContext)getContext()).getRequestDispatcher(path); 
+      try
+      {
+        requestDispatcher.include((RenderRequest)getRequest(), (RenderResponse)getResponse());
+      }
+      catch (final PortletException e)
+      {
+        if (e.getMessage() != null)
+        {
+          throw new FacesException(e.getMessage(), e);
+        }
+        else
+        {
+          throw new FacesException(e);
+        }
+      }   
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.myfaces.trinidadinternal.context.ExternalContextDecorator#getExternalContext()
+     */
+    @Override
+    protected ExternalContext getExternalContext()
+    {
+      return _ec;
+    }
+
+    private PortletContext _getPortletContext()
+    {
+      if(_context == null)
+      {
+        _context = new PortletContextWrapper((PortletContext)_ec.getContext());
+      }
+      return _context;     
+    }
+    
+    private RenderResponse _getRenderResponse()
+    {
+      if(_response == null)
+      {
+        _response = new DispatchRenderResponse(_ec);
+      }
+      return _response;
+    }
+    
+    private ExternalContext _ec;
+    private RenderResponse _response;
+    private PortletContext _context;
+  }
+  
+  /**
+   * Returns <code>true</code> if the request wrapper has been applied.
+   * 
+   * @param context
+   * @return
+   */
+  static public boolean isApplied(ExternalContext context)
+  {
+    return (context.getRequestMap().get(_APPLIED)!=null);
+  }
+  
+  /**
+   * 
+   */
+  @SuppressWarnings("unchecked")
+  static public void apply(ExternalContext context)
+  {
+    context.getRequestMap().put(_APPLIED, Boolean.TRUE);
+  }
+  
+  static private final String _APPLIED = DispatchResponseConfiguratorImpl.class.getName()+".APPLIED";
+  static final String _CONTENT_TYPE_KEY = DispatchResponseConfiguratorImpl.class.getName() + ".CONTENT_TYPE";
+}

Added: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/dispatch/DispatchServletResponse.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/dispatch/DispatchServletResponse.java?view=auto&rev=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/dispatch/DispatchServletResponse.java (added)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/dispatch/DispatchServletResponse.java Mon Dec  4 18:02:50 2006
@@ -0,0 +1,73 @@
+/*
+ * Copyright  2004-2006 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.myfaces.trinidadinternal.config.dispatch;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.faces.context.ExternalContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpServletResponseWrapper;
+
+@SuppressWarnings("deprecation")
+public class DispatchServletResponse extends HttpServletResponseWrapper
+{
+  public DispatchServletResponse(ExternalContext ec)
+  {
+    super((HttpServletResponse)ec.getResponse());
+    _request = (HttpServletRequest)ec.getRequest();
+  }
+
+  @Override
+  public void setContentType(
+    String contentTypeAndCharset)
+  {
+    if(contentTypeAndCharset != null)
+    {
+      Matcher matcher = _CONTENT_TYPE_PATTERN.matcher(contentTypeAndCharset);
+      if (matcher.matches())
+      {
+        String contentType = matcher.group(1);
+        String charset = (matcher.groupCount() > 1) ? matcher.group(2) : null; 
+        
+        // capture the content type on the request
+        _request.setAttribute(DispatchResponseConfiguratorImpl._CONTENT_TYPE_KEY, contentType);
+  
+        // TODO: use Agent APIs when available
+        if ("application/xhtml+xml".equals(contentType))
+        {
+          String userAgent = _request.getHeader("User-agent");
+          if (userAgent.indexOf("compatible; MSIE") != -1)
+          {
+            // IE must serve XHTML as text/html
+            contentTypeAndCharset = "text/html";
+  
+            if (charset != null)
+              contentTypeAndCharset += ";charset=" + charset;
+          }
+        }
+      }
+    }
+    super.setContentType(contentTypeAndCharset);
+  }
+  
+   private final HttpServletRequest _request;
+ 
+                                  
+  static private final Pattern _CONTENT_TYPE_PATTERN = 
+                                  Pattern.compile("([^;]+)(?:;charset=(.*))?");
+}

Added: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/FileUploadConfiguratorImpl.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/FileUploadConfiguratorImpl.java?view=auto&rev=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/FileUploadConfiguratorImpl.java (added)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/FileUploadConfiguratorImpl.java Mon Dec  4 18:02:50 2006
@@ -0,0 +1,273 @@
+/*
+ * Copyright  2004-2006 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.myfaces.trinidadinternal.config.upload;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.faces.context.ExternalContext;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.myfaces.trinidad.config.GenericConfigurator;
+import org.apache.myfaces.trinidad.context.RequestContext;
+import org.apache.myfaces.trinidad.logging.TrinidadLogger;
+import org.apache.myfaces.trinidad.model.UploadedFile;
+import org.apache.myfaces.trinidad.util.ExternalContextUtils;
+import org.apache.myfaces.trinidadinternal.share.util.MultipartFormHandler;
+import org.apache.myfaces.trinidadinternal.share.util.MultipartFormItem;
+
+/**
+ * This configurator will handle the FileUploads for Trinidad.
+ *
+ * @author Scott O'Bryan (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class FileUploadConfiguratorImpl extends GenericConfigurator
+{
+  
+  /**
+   * Returns the added parameters
+   * 
+   * @param externalContext
+   * @return
+   */
+  static public Map<String, String[]> getAddedParameters(ExternalContext externalContext)
+  {
+    @SuppressWarnings("unchecked")
+    Map<String, String[]> map = (Map<String, String[]>) externalContext.getRequestMap().get(_PARAMS);
+    
+    return map;
+  }
+  
+  /**
+   * Returns <code>true</code> if the request wrapper has been applied.
+   * 
+   * @param context
+   * @return
+   */
+  static public boolean isApplied(ExternalContext context)
+  {
+    return (context.getRequestMap().get(_APPLIED)!=null);
+  }
+  
+  /**
+   * 
+   */
+  @SuppressWarnings("unchecked")
+  static public void apply(ExternalContext context)
+  {
+    context.getRequestMap().put(_APPLIED, Boolean.TRUE);
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.myfaces.trinidad.config.GenericConfigurator#beginRequest(javax.faces.context.ExternalContext)
+   */
+  @Override
+  @SuppressWarnings("unchecked")
+  public void beginRequest(ExternalContext externalContext)
+  {
+    /*
+     * Note: This class does not do a dispose on the file uploads.  The
+     * reason for this is that in a portal environment, multiple render-requests
+     * may depend on the same set of files being available to the view layer.
+     * Instead the files will be automatically cleaned up when the portlet
+     * generated the next request.  If we need to clean up sooner then we should
+     * clean up on the end-request.
+     */
+    //Process MultipartForm if need be
+    if (MultipartFormHandler.isMultipartRequest(externalContext) && 
+       (externalContext.getRequest() instanceof HttpServletRequest || 
+          ExternalContextUtils.isPortlet(externalContext)))
+    {
+      try
+      {
+        final MultipartFormHandler mfh = new MultipartFormHandler(externalContext);
+
+        // TODO: How is this set?
+        mfh.setMaximumAllowedBytes(_maxAllowedBytes);
+        mfh.setCharacterEncoding(ExternalContextUtils.getCharacterEncoding(externalContext));
+
+        final HashMap<String, String[]> parameters = new HashMap<String, String[]>();
+        MultipartFormItem item;
+        final UploadedFiles files = new UploadedFiles(externalContext); 
+        while ((item = mfh.getNextPart()) != null)
+        {
+          final String name = item.getName();
+          String value = null;
+          // No filename - it's not a file uploaded field
+          if (item.getFilename() == null)
+          {
+            value = item.getValue();
+            final Object oldValue = parameters.get(name);
+            if (oldValue == null)
+            {
+              parameters.put(name, new String[]{value});
+            }
+            else
+            {
+              final String[] oldArray = (String[]) oldValue;
+              final String[] newArray = new String[oldArray.length + 1];
+              System.arraycopy(oldArray, 0, newArray, 1, oldArray.length);
+              newArray[0] = value;
+              parameters.put(name, newArray);
+            }
+          }
+          // Upload a file
+          else if (item.getFilename().length() > 0)
+          {
+            _doUploadFile(RequestContext.getCurrentInstance(), externalContext, files, item);
+          }
+        }
+        externalContext.getRequestMap().put(_PARAMS, parameters);
+      }
+      catch (Throwable t)
+      {
+        if(_LOG.isSevere())
+        {
+          _LOG.severe(t);
+        }
+      }
+    }
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.myfaces.trinidad.config.GenericConfigurator#getExternalContext(javax.faces.context.ExternalContext)
+   */
+  @Override
+  public ExternalContext getExternalContext(ExternalContext externalContext)
+  {
+    //Wrap only if there are parameters present
+    Map<String, String[]> addedParams = getAddedParameters(externalContext);
+    
+    if(addedParams != null)
+    {
+      @SuppressWarnings("unchecked")
+      Map<String, String[]> parameters = new HashMap<String, String[]>(externalContext.getRequestParameterValuesMap());
+      parameters.putAll(addedParams);
+
+      return _getExternalContextWrapper(externalContext, addedParams);
+    }
+    
+    return externalContext;
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.myfaces.trinidad.config.GenericConfigurator#init(javax.faces.context.ExternalContext)
+   */
+  @Override
+  public void init(ExternalContext externalContext)
+  {
+    super.init(externalContext);
+    //TODO initialize _maxAllowedBytes
+  }
+  
+  private void _doUploadFile(
+      final RequestContext   context,
+      final ExternalContext  externalContext,
+      final UploadedFiles     files,
+      final MultipartFormItem item) throws IOException
+  {
+    final UploadedFile temp = new TempUploadedFile(item);
+
+    final UploadedFile file =
+      context.getUploadedFileProcessor().processFile(externalContext, temp);
+
+    if (file != null)
+    {
+      // Store the file.
+      files.__put(item.getName(), file);
+
+      if (_LOG.isFine())
+      {
+        _LOG.fine("Uploaded file " + file.getFilename() + "(" +
+            file.getLength() + " bytes) for ID " + item.getName());
+      }
+    }
+  }
+  
+  static private ExternalContext _getExternalContextWrapper(ExternalContext externalContext, Map<String, String[]> addedParams)
+  {
+    if(!isApplied(externalContext))
+    {
+      if(!ExternalContextUtils.isPortlet(externalContext))
+      {
+        return new ServletUploadedExternalContext(externalContext, addedParams);
+      }
+      else if(ExternalContextUtils.isAction(externalContext))
+      {
+        /*
+         * We only need to do this if we have an action request.  Why?
+         * Because durring the ActionRequest, the wrapper will set the
+         * RenderParameters.  This is a cool thing because subsequent
+         * render requests will retain these parameters for us.
+         */
+        return new PortletUploadedExternalContext(externalContext, addedParams);
+      }
+    }
+    
+    //If we don't have any wrapped params or we have a render portal request,
+    //return the origional external context
+    return externalContext;
+  }
+
+  static private class TempUploadedFile implements UploadedFile
+  {
+    public TempUploadedFile(MultipartFormItem item)
+    {
+      _item = item;
+      assert(item.getValue() == null);
+    }
+
+    public String getFilename()
+    {
+      return _item.getFilename();
+    }
+
+    public String getContentType()
+    {
+      return _item.getContentType();
+    }
+
+    public long getLength()
+    {
+      // The length is not known yet.
+      return -1L;
+    }
+
+    public Object getOpaqueData()
+    {
+      return null;
+    }
+
+    public InputStream getInputStream() throws IOException
+    {
+      return _item.getInputStream();
+    }
+
+    public void dispose()
+    {
+      throw new UnsupportedOperationException();
+    }
+
+    private MultipartFormItem _item;
+  }
+  static private final String _APPLIED = FileUploadConfiguratorImpl.class.getName()+".APPLIED";
+  static private final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(FileUploadConfiguratorImpl.class);
+  static public final String _PARAMS = FileUploadConfiguratorImpl.class.getName()+".PARAMS";
+  private long _maxAllowedBytes = 1L << 27;
+}

Added: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/PortletUploadedExternalContext.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/PortletUploadedExternalContext.java?view=auto&rev=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/PortletUploadedExternalContext.java (added)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/PortletUploadedExternalContext.java Mon Dec  4 18:02:50 2006
@@ -0,0 +1,258 @@
+/*
+ * Copyright  2004-2006 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.myfaces.trinidadinternal.config.upload;
+
+import java.io.UnsupportedEncodingException;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.faces.context.ExternalContext;
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletRequest;
+
+import org.apache.myfaces.trinidad.context.external.PortletRequestParameterMap;
+import org.apache.myfaces.trinidad.context.external.PortletRequestParameterValuesMap;
+import org.apache.myfaces.trinidad.logging.TrinidadLogger;
+import org.apache.myfaces.trinidad.webapp.wrappers.ActionRequestWrapper;
+import org.apache.myfaces.trinidadinternal.context.ExternalContextDecorator;
+import org.apache.myfaces.trinidadinternal.share.util.CaboHttpUtils;
+
+/**
+ * TODO: Document this 
+ *
+ * @author Scott O'Bryan (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+class PortletUploadedExternalContext extends ExternalContextDecorator
+{
+  PortletUploadedExternalContext(ExternalContext externalContext, Map<String, String[]> extractedParams)
+  {
+    _externalContext = externalContext;
+    FileUploadConfiguratorImpl.apply(externalContext);
+    
+    @SuppressWarnings("unchecked")
+    Map<String, String[]> params = new HashMap<String, String[]>(externalContext.getRequestParameterValuesMap());
+    params.putAll(extractedParams);
+    
+    _wrappedRequest  = new PortletUploadRequestWrapper((ActionRequest)_externalContext.getRequest(), (ActionResponse)_externalContext.getResponse(), params);
+  }
+  
+  /* (non-Javadoc)
+   * @see org.apache.myfaces.trinidadinternal.context.ExternalContextDecorator#getRequest()
+   */
+  @Override
+  public Object getRequest()
+  {
+    return _wrappedRequest;
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.myfaces.trinidadinternal.context.ExternalContextDecorator#getRequestParameterMap()
+   */
+  @Override
+  public Map<String, String> getRequestParameterMap()
+  {
+    if(_requestParameterMap == null)
+    {
+      _requestParameterMap = new PortletRequestParameterMap(_wrappedRequest);
+    }        
+    return _requestParameterMap;
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.myfaces.trinidadinternal.context.ExternalContextDecorator#getRequestParameterNames()
+   */
+  @Override
+  public Iterator<String> getRequestParameterNames()
+  {
+    if(_requestParameterNames == null)
+    {
+      if(_requestParameterMap != null)
+      {        
+        _requestParameterNames = _requestParameterMap.keySet().iterator();
+      }
+      else
+      {
+        _requestParameterNames = getRequestParameterValuesMap().keySet().iterator();
+      }
+    }  
+    return _requestParameterNames;
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.myfaces.trinidadinternal.context.ExternalContextDecorator#getRequestParameterValuesMap()
+   */
+  @Override
+  public Map <String, String[]>getRequestParameterValuesMap()
+  {
+    if(_requestParameterValuesMap == null)
+    {
+      _requestParameterValuesMap = new PortletRequestParameterValuesMap(_wrappedRequest);
+    }
+    return _requestParameterValuesMap;
+  }
+
+  private ExternalContext _externalContext;
+  private PortletRequest _wrappedRequest;  
+  private Map<String, String>   _requestParameterMap;
+  private Map<String, String[]> _requestParameterValuesMap;
+  private Iterator<String>      _requestParameterNames;
+
+  /* (non-Javadoc)
+   * @see org.apache.myfaces.trinidadinternal.context.ExternalContextDecorator#getExternalContext()
+   */
+  @Override
+  protected ExternalContext getExternalContext()
+  {
+    return _externalContext;
+  }
+  
+  private class PortletUploadRequestWrapper extends ActionRequestWrapper
+  {
+    public PortletUploadRequestWrapper(
+        ActionRequest request,
+        ActionResponse response,
+        Map<String, String[]> params)
+    {
+      super(request);
+      _response = response;
+      
+      @SuppressWarnings("unchecked") 
+      Map<String, String[]> origionalMap = super.getParameterMap();
+      
+      _extractedParams = new HashMap<String, String[]>(origionalMap);
+      _extractedParams.putAll(params);
+      
+      //add these params to the render request
+      response.setRenderParameters(_extractedParams);
+    }
+    
+    /**
+     * Hide the content type so that no one tries to re-download the
+     * uploaded files.
+     */
+    @Override
+    public String getContentType()
+    {
+      return _WWW_FORM_URLENCODED_TYPE;
+    }
+
+    /**
+     * Trap calls to setCharacterEncoding() to decode parameters correctly
+     */
+    @Override
+    public void setCharacterEncoding(String encoding)
+      throws UnsupportedEncodingException
+    {
+      super.setCharacterEncoding(encoding);
+      if (_LOG.isFine())
+        _LOG.fine("Switching encoding of wrapper to " + encoding);
+
+      _extractedAndDecodedParams = 
+        new HashMap<String, String[]>(_extractedParams.size());
+        
+      byte[] buffer = new byte[256];
+      
+      for(Map.Entry<String, String[]> entry : _extractedParams.entrySet())
+      {
+        String key = entry.getKey();
+        key = CaboHttpUtils.decodeRequestParameter(key, encoding, buffer);
+
+        String[] oldValue = entry.getValue();
+        int length = oldValue.length;
+        String[] newValue = new String[length];
+        for (int i = 0; i < length; i++)
+        {
+          newValue[i] = CaboHttpUtils.decodeRequestParameter(oldValue[i],
+                                                             encoding,
+                                                             buffer);
+          if (_LOG.isFinest())
+            _LOG.finest("Parameter " + key + ":" + newValue[i]);
+        }
+
+        _extractedAndDecodedParams.put(key, newValue);
+        _response.setRenderParameters(_extractedAndDecodedParams);
+      }
+
+      // Let the UploadedFiles know, so it can fix up filenames
+      UploadedFiles.setCharacterEncoding(this, encoding);
+    }
+
+    @Override
+    public String getParameter(String param)
+    {
+      String[] value = _getParameterValues(param);
+      if (value == null)
+        return null;
+
+      return value[0];
+    }
+
+    @Override
+    public Map<String, String[]> getParameterMap()
+    {
+      Map<String, String[]> map = _getMap();
+      return Collections.unmodifiableMap(map);
+    }
+
+    @Override
+    public Enumeration<String> getParameterNames()
+    {
+      return Collections.enumeration(_getMap().keySet());
+    }
+
+    @Override
+    public String[] getParameterValues(String param)
+    {
+      String[] value = _getParameterValues(param);
+      if (value == null)
+        return null;
+
+      return value.clone();
+    }
+
+    private String[] _getParameterValues(String param)
+    {
+      return _getMap().get(param);
+    }
+
+    /**
+     * Get the correct map of parameters whether or not setCharacterEncoding()
+     * was called.
+     */
+    private Map<String, String[]> _getMap()
+    {
+      if (_extractedAndDecodedParams != null)
+        return _extractedAndDecodedParams;
+
+      return _extractedParams;
+    }
+
+    private Map<String, String[]> _extractedAndDecodedParams;
+    private Map<String, String[]> _extractedParams;
+    private ActionResponse _response;
+
+    private static final String _WWW_FORM_URLENCODED_TYPE =
+      "application/x-www-form-urlencoded";
+  }
+  
+  private static final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(PortletUploadedExternalContext.class);
+}

Added: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/ServletUploadedExternalContext.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/ServletUploadedExternalContext.java?view=auto&rev=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/ServletUploadedExternalContext.java (added)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/ServletUploadedExternalContext.java Mon Dec  4 18:02:50 2006
@@ -0,0 +1,119 @@
+/*
+ * Copyright  2004-2006 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.myfaces.trinidadinternal.config.upload;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.faces.context.ExternalContext;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.myfaces.trinidad.context.external.ServletRequestParameterMap;
+import org.apache.myfaces.trinidad.context.external.ServletRequestParameterValuesMap;
+import org.apache.myfaces.trinidadinternal.context.ExternalContextDecorator;
+
+/**
+ * TODO: Document this 
+ *
+ * @author Scott O'Bryan (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+class ServletUploadedExternalContext extends ExternalContextDecorator
+{ 
+  ServletUploadedExternalContext(ExternalContext externalContext, Map<String, String[]> extractedParams)
+  {
+    _externalContext = externalContext;
+    FileUploadConfiguratorImpl.apply(externalContext);
+    
+    @SuppressWarnings("unchecked")
+    Map<String, String[]> params = new HashMap<String, String[]>(externalContext.getRequestParameterValuesMap());
+    params.putAll(extractedParams);
+    
+    _wrappedRequest  = new UploadRequestWrapper((HttpServletRequest)_externalContext.getRequest(), params);
+  }
+  
+  /* (non-Javadoc)
+   * @see org.apache.myfaces.trinidadinternal.context.ExternalContextDecorator#getRequest()
+   */
+  @Override
+  public Object getRequest()
+  {
+    return _wrappedRequest;
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.myfaces.trinidadinternal.context.ExternalContextDecorator#getRequestParameterMap()
+   */
+  @Override
+  public Map<String, String> getRequestParameterMap()
+  {
+    if(_requestParameterMap == null)
+    {
+      _requestParameterMap = new ServletRequestParameterMap(_wrappedRequest);
+    }        
+    return _requestParameterMap;
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.myfaces.trinidadinternal.context.ExternalContextDecorator#getRequestParameterNames()
+   */
+  @Override
+  public Iterator<String> getRequestParameterNames()
+  {
+    if(_requestParameterNames == null)
+    {
+      if(_requestParameterMap != null)
+      {        
+        _requestParameterNames = _requestParameterMap.keySet().iterator();
+      }
+      else
+      {
+        _requestParameterNames = getRequestParameterValuesMap().keySet().iterator();
+      }
+    }  
+    return _requestParameterNames;
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.myfaces.trinidadinternal.context.ExternalContextDecorator#getRequestParameterValuesMap()
+   */
+  @Override
+  public Map <String, String[]>getRequestParameterValuesMap()
+  {
+    if(_requestParameterValuesMap == null)
+    {
+      _requestParameterValuesMap = new ServletRequestParameterValuesMap(_wrappedRequest);
+    }
+    return _requestParameterValuesMap;
+  }
+
+  private ExternalContext _externalContext;
+  private HttpServletRequest _wrappedRequest;  
+  private Map<String, String>   _requestParameterMap;
+  private Map<String, String[]> _requestParameterValuesMap;
+  private Iterator<String>      _requestParameterNames;
+
+  /* (non-Javadoc)
+   * @see org.apache.myfaces.trinidadinternal.context.ExternalContextDecorator#getExternalContext()
+   */
+  @Override
+  protected ExternalContext getExternalContext()
+  {
+    return _externalContext;
+  }
+}

Added: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadRequestWrapper.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadRequestWrapper.java?view=auto&rev=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadRequestWrapper.java (added)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadRequestWrapper.java Mon Dec  4 18:02:50 2006
@@ -0,0 +1,145 @@
+package org.apache.myfaces.trinidadinternal.config.upload;
+
+import java.io.UnsupportedEncodingException;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
+
+import org.apache.myfaces.trinidad.logging.TrinidadLogger;
+import org.apache.myfaces.trinidadinternal.share.util.CaboHttpUtils;
+
+/**
+ * Request wrapper class that hooks in parameters identified in
+ * the servlet request.
+ *
+ * @todo Stop going String -> bytes -> String;  change MultipartFormHandler
+ *  to simply extract byte arrays, and do all the type conversion here.
+ * @author The Oracle ADF Faces Team
+ */
+@SuppressWarnings("deprecation")
+public class UploadRequestWrapper extends HttpServletRequestWrapper
+{
+  public UploadRequestWrapper(
+      HttpServletRequest request, 
+      Map<String, String[]> params)
+  {
+    super(request);
+    
+    @SuppressWarnings("unchecked")
+    Map<String, String[]> origionalMap = super.getParameterMap();
+    
+    _extractedParams = new HashMap<String, String[]>(origionalMap);
+    _extractedParams.putAll(params);
+  }
+  
+  /**
+   * Hide the content type so that no one tries to re-download the
+   * uploaded files.
+   */
+  @Override
+  public String getContentType()
+  {
+    return _WWW_FORM_URLENCODED_TYPE;
+  }
+
+  /**
+   * Trap calls to setCharacterEncoding() to decode parameters correctly
+   */
+  @Override
+  public void setCharacterEncoding(String encoding)
+    throws UnsupportedEncodingException
+  {
+    super.setCharacterEncoding(encoding);
+    if (_LOG.isFine())
+      _LOG.fine("Switching encoding of wrapper to " + encoding);
+
+    _extractedAndDecodedParams = 
+      new HashMap<String, String[]>(_extractedParams.size());
+      
+    byte[] buffer = new byte[256];
+    
+    for(Map.Entry<String, String[]> entry : _extractedParams.entrySet())
+    {
+      String key = entry.getKey();
+      key = CaboHttpUtils.decodeRequestParameter(key, encoding, buffer);
+
+      String[] oldValue = entry.getValue();
+      int length = oldValue.length;
+      String[] newValue = new String[length];
+      for (int i = 0; i < length; i++)
+      {
+        newValue[i] = CaboHttpUtils.decodeRequestParameter(oldValue[i],
+                                                           encoding,
+                                                           buffer);
+        if (_LOG.isFinest())
+          _LOG.finest("Parameter " + key + ":" + newValue[i]);
+      }
+
+      _extractedAndDecodedParams.put(key, newValue);
+    }
+
+    // Let the UploadedFiles know, so it can fix up filenames
+    UploadedFiles.setCharacterEncoding(this, encoding);
+  }
+
+  @Override
+  public String getParameter(String param)
+  {
+    String[] value = _getParameterValues(param);
+    if (value == null)
+      return null;
+
+    return value[0];
+  }
+
+  @Override
+  public Map<String, String[]> getParameterMap()
+  {
+    Map<String, String[]> map = _getMap();
+    return Collections.unmodifiableMap(map);
+  }
+
+  @Override
+  public Enumeration<String> getParameterNames()
+  {
+    return Collections.enumeration(_getMap().keySet());
+  }
+
+  @Override
+  public String[] getParameterValues(String param)
+  {
+    String[] value = _getParameterValues(param);
+    if (value == null)
+      return null;
+
+    return value.clone();
+  }
+
+  private String[] _getParameterValues(String param)
+  {
+    return _getMap().get(param);
+  }
+
+  /**
+   * Get the correct map of parameters whether or not setCharacterEncoding()
+   * was called.
+   */
+  private Map<String, String[]> _getMap()
+  {
+    if (_extractedAndDecodedParams != null)
+      return _extractedAndDecodedParams;
+
+    return _extractedParams;
+  }
+
+  private Map<String, String[]> _extractedAndDecodedParams;
+  private Map<String, String[]> _extractedParams;
+
+  private static final String _WWW_FORM_URLENCODED_TYPE =
+    "application/x-www-form-urlencoded";
+  private static final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(UploadRequestWrapper.class);
+}