You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by so...@apache.org on 2009/05/14 12:21:53 UTC

svn commit: r774721 [2/2] - in /myfaces/trinidad/branches/1.2.11.3-branch: ./ trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/ trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/ trinidad-examples/ trinidad-examples/trinidad-de...

Modified: myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/dispatch/DispatchServletResponse.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/dispatch/DispatchServletResponse.java?rev=774721&r1=774720&r2=774721&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/dispatch/DispatchServletResponse.java (original)
+++ myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/dispatch/DispatchServletResponse.java Thu May 14 10:21:52 2009
@@ -18,9 +18,6 @@
  */
 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;
@@ -39,45 +36,21 @@
   public void setContentType(
     String contentTypeAndCharset)
   {
+    ContentTypeAndCharacterSet ct = new ContentTypeAndCharacterSet(contentTypeAndCharset);    
+
     // Ignore all calls to setContentType() if they come in the scope
     // of a Servlet include (generally a jsp:include).  The JSP
     // engine will ignore them, and in a .jspx, the default contentType
     // is text/xml!  So as a result, the absence of a contentType
     // in included jspx files was sometimes leading us to turn on
     // XHTML!
-    if ((_request.getAttribute("javax.servlet.include.request_uri") == null) &&
-        (contentTypeAndCharset != null))
+    if((_request.getAttribute("javax.servlet.include.request_uri")) == null &&  (ct.getContentType() != 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;
-          }
-        }
-      }
+      _request.setAttribute(DispatchResponseConfiguratorImpl.__CONTENT_TYPE_KEY, ct.getContentType());
     }
-    super.setContentType(contentTypeAndCharset);
+    
+    super.setContentType(ct.toString());
   }
 
    private final HttpServletRequest _request;
-
-
-  static private final Pattern _CONTENT_TYPE_PATTERN =
-                                  Pattern.compile("([^;]+)(?:;charset=(.*))?");
 }

Modified: myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/ActionUploadRequestWrapper.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/ActionUploadRequestWrapper.java?rev=774721&r1=774720&r2=774721&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/ActionUploadRequestWrapper.java (original)
+++ myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/ActionUploadRequestWrapper.java Thu May 14 10:21:52 2009
@@ -1,178 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you 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.Map;
-
-import javax.faces.context.ExternalContext;
-
-import javax.portlet.ActionRequest;
-import javax.portlet.ActionResponse;
-
-import org.apache.myfaces.trinidad.logging.TrinidadLogger;
-import org.apache.myfaces.trinidadinternal.share.util.CaboHttpUtils;
-import org.apache.myfaces.trinidadinternal.webapp.wrappers.ActionRequestWrapper;
-
-public class ActionUploadRequestWrapper
-  extends ActionRequestWrapper
-{
-  public ActionUploadRequestWrapper(
-      ExternalContext ec,
-      Map<String, String[]> params)
-  {
-    super((ActionRequest)ec.getRequest());
-    _response = (ActionResponse)ec.getResponse();
-
-    @SuppressWarnings("unchecked")
-    Map<String, String[]> origionalMap = super.getParameterMap();
-
-    _extractedParams = new HashMap<String, String[]>(origionalMap);
-    _extractedParams.putAll(params);
-
-    _encoding = super.getCharacterEncoding();
-  }
-
-  /**
-   * Hide the content type so that no one tries to re-download the
-   * uploaded files.
-   */
-  @Override
-  public String getContentType()
-  {
-    return _WWW_FORM_URLENCODED_TYPE;
-  }
-
-  @Override
-  public String getCharacterEncoding()
-  {
-    return _encoding;
-  }
-
-
-  /**
-   * Trap calls to setCharacterEncoding() to decode parameters correctly
-   */
-  @Override
-  public void setCharacterEncoding(String encoding)
-    throws UnsupportedEncodingException
-  {
-    // If the encoding is already right, we can bail
-    if (encoding.equals(_encoding))
-      return;
-    
-    // Don't call super.setCharacterEncoding() - it's too late
-    // and we'll get a warning
-    _encoding = 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 (String[]) 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 String         _encoding;
-  private static final String _WWW_FORM_URLENCODED_TYPE =
-    "application/x-www-form-urlencoded";
-  private static final TrinidadLogger _LOG =
-     TrinidadLogger.createTrinidadLogger(ActionUploadRequestWrapper.class);
-}

Modified: myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/FileUploadConfiguratorImpl.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/FileUploadConfiguratorImpl.java?rev=774721&r1=774720&r2=774721&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/FileUploadConfiguratorImpl.java (original)
+++ myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/FileUploadConfiguratorImpl.java Thu May 14 10:21:52 2009
@@ -21,6 +21,9 @@
 
 import java.io.IOException;
 import java.io.InputStream;
+
+import java.lang.reflect.Proxy;
+
 import java.util.HashMap;
 import java.util.Map;
 
@@ -34,8 +37,10 @@
 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.ClassLoaderUtils;
 import org.apache.myfaces.trinidad.util.ExternalContextUtils;
 import org.apache.myfaces.trinidad.util.RequestStateMap;
+import org.apache.myfaces.trinidad.util.RequestType;
 import org.apache.myfaces.trinidadinternal.share.util.MultipartFormHandler;
 import org.apache.myfaces.trinidadinternal.share.util.MultipartFormItem;
 
@@ -226,22 +231,32 @@
   {
     if(!isApplied(externalContext))
     {
-      if(!ExternalContextUtils.isPortlet(externalContext))
-      {  
-        externalContext.setRequest(new UploadRequestWrapper(
-            (HttpServletRequest)externalContext.getRequest(),
-            addedParams));        
-      }
-      else if(ExternalContextUtils.isAction(externalContext))
+      RequestType type = ExternalContextUtils.getRequestType(externalContext);
+      
+      switch(type)
       {
-        /*
-         * 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.
-         */
-        externalContext.setRequest(new ActionUploadRequestWrapper(externalContext,
-           addedParams));
+        case SERVLET:
+          externalContext.setRequest(new UploadRequestWrapper(externalContext, addedParams));
+          break;
+        case RESOURCE:
+          externalContext.setRequest(new UploadResourceRequest(externalContext, addedParams));
+          break;
+        case ACTION:
+          //Portlet 2.0 should use the framework provided wrapper.  Portlet 1.0 needs to implement
+          //the interface.  Because we need to compile against Portlet 2.0, we implement the Portlet
+          //1.0 scenario using a Proxy.
+          Object req;
+          
+          if(_ENHANCED_PORTLET_SUPPORTED)
+          {
+            req = _getActionRequestWrapper(externalContext, addedParams);
+          }
+          else
+          {
+            req = _getActionRequestProxy(externalContext, addedParams);
+          }
+          
+          externalContext.setRequest(req);
       }
       apply(externalContext);        
     }
@@ -251,6 +266,32 @@
     return externalContext;
   }
   
+  static private Object _getActionRequestProxy(ExternalContext ec, Map<String, String[]> params)
+  {
+    try
+    {
+      Class<?> actionRequestClass = ClassLoaderUtils.loadClass("javax.portlet.ActionRequest");
+      return Proxy.newProxyInstance(ClassLoaderUtils.getContextClassLoader(), new Class<?>[]{actionRequestClass}, new UploadActionInvocationHandler(ec, params));
+    }
+    catch (ClassNotFoundException e)
+    {
+      throw new RuntimeException(e);
+    }
+  }
+  
+  static private Object _getActionRequestWrapper(ExternalContext ec, Map<String, String[]> params)
+  {
+    try
+    {
+      Class<?> wrapperClass = ClassLoaderUtils.loadClass("org.apache.myfaces.trinidadinternal.config.upload.UploadActionRequestWrapper");
+      return wrapperClass.getConstructor(ExternalContext.class, Map.class).newInstance(ec, params);
+    }
+    catch (Exception e)
+    {
+      throw new RuntimeException(e);
+    }
+  }
+  
   //This will ensure the property is removed on the next request
   @ExcludeFromManagedRequestScope
   static private class AppliedClass
@@ -302,6 +343,7 @@
   static private final String _APPLIED = FileUploadConfiguratorImpl.class.getName()+".APPLIED";
   static private final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(FileUploadConfiguratorImpl.class);
   static private final String _PARAMS = FileUploadConfiguratorImpl.class.getName()+".PARAMS";
+  static private final boolean _ENHANCED_PORTLET_SUPPORTED = ExternalContextUtils.isRequestTypeSupported(RequestType.RESOURCE);
   
   private long _maxAllowedBytes = 1L << 27;
 }

Modified: myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadRequestWrapper.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadRequestWrapper.java?rev=774721&r1=774720&r2=774721&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadRequestWrapper.java (original)
+++ myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadRequestWrapper.java Thu May 14 10:21:52 2009
@@ -24,6 +24,10 @@
 import java.util.HashMap;
 import java.util.Map;
 
+import javax.faces.context.ExternalContext;
+
+import javax.portlet.ActionResponse;
+
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletRequestWrapper;
 
@@ -40,21 +44,19 @@
 @SuppressWarnings("deprecation")
 public class UploadRequestWrapper extends HttpServletRequestWrapper
 {
-  public UploadRequestWrapper(
-      HttpServletRequest request, 
-      Map<String, String[]> params)
+  public UploadRequestWrapper(ExternalContext ec, Map<String, String[]> params)
   {
-    super(request);
+    this((HttpServletRequest) ec.getRequest(), params);
     
-    @SuppressWarnings("unchecked")
-    // Merge in all the original parameters
-    Map<String, String[]> originalMap = super.getParameterMap();
-    
-    _extractedParams = new HashMap<String, String[]>(originalMap);
-    _extractedParams.putAll(params);
-    _encoding = super.getCharacterEncoding();
   }
   
+  public UploadRequestWrapper(HttpServletRequest req, Map<String, String[]> params)
+  {
+    super(req);
+    _manager = new UploadRequestManager(req, params);
+    
+  }
+
   /**
    * Hide the content type so that no one tries to re-download the
    * uploaded files.
@@ -62,13 +64,13 @@
   @Override
   public String getContentType()
   {
-    return _WWW_FORM_URLENCODED_TYPE;
+    return _manager.getContentType();
   }
 
   @Override
   public String getCharacterEncoding()
   {
-    return _encoding;
+    return _manager.getCharacterEncoding();
   }
 
   /**
@@ -78,52 +80,21 @@
   public void setCharacterEncoding(String encoding)
     throws UnsupportedEncodingException
   {
+    if (getCharacterEncoding().equals(encoding))
+    {
+      return;
+    }
+    
     // It is illegal to set the character encoding after parameters
     // have been retrieved.  This is an annoying restriction,
     // but we shouldn't break it
-    if (_parametersRetrieved)
+    if (_manager.isParameterRetrieved())
     {
       _LOG.warning("UNABLE_SET_REQUEST_CHARACTER", encoding);
       return;
     }
-
-    // If the encoding is already right, we can bail
-    if (encoding.equals(_encoding))
-      return;
-    
-    // Don't call super.setCharacterEncoding() - it's too late
-    // and we'll get a warning
-    _encoding = encoding;
-    if (_LOG.isFine())
-      _LOG.fine("Switching encoding of wrapper to " + encoding);
-
-    _extractedAndDecodedParams = 
-      new HashMap<String, String[]>(_extractedParams.size());
-      
-    byte[] buffer = new byte[256];
     
-    // FIXME: decodeRequestParameter() assumes the incoming
-    // character set is ISO-8859-1 - but this is not
-    // necessarily true!
-    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);
-    }
+    _manager.setCharacterEncoding(encoding);
 
     // Let the UploadedFiles know, so it can fix up filenames
     UploadedFiles.setCharacterEncoding(this, encoding);
@@ -132,62 +103,28 @@
   @Override
   public String getParameter(String param)
   {
-    String[] value = _getParameterValues(param);
-    if (value == null)
-      return null;
-
-    return value[0];
+    return _manager.getParameter(param);
   }
 
   @Override
   public Map<String, String[]> getParameterMap()
   {
-    Map<String, String[]> map = _getMap();
-    return Collections.unmodifiableMap(map);
+    return _manager.getParameterMap();
   }
 
   @Override
   public Enumeration<String> getParameterNames()
   {
-    return Collections.enumeration(_getMap().keySet());
+    return _manager.getParameterNames();
   }
 
   @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);
+    return _manager.getParameterValues(param);
   }
 
-  /**
-   * Get the correct map of parameters whether or not setCharacterEncoding()
-   * was called.
-   */
-  private Map<String, String[]> _getMap()
-  {
-    // Mark that parameters have been retrieved so we 
-    // can log a proper warning
-    _parametersRetrieved = true;
-    if (_extractedAndDecodedParams != null)
-      return _extractedAndDecodedParams;
-
-    return _extractedParams;
-  }
-
-  private Map<String, String[]> _extractedAndDecodedParams;
-  private Map<String, String[]> _extractedParams;
-  private String                _encoding;
-  private boolean               _parametersRetrieved;
-
-  private static final String _WWW_FORM_URLENCODED_TYPE =
-    "application/x-www-form-urlencoded";
-  private static final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(UploadRequestWrapper.class);
+  private UploadRequestManager _manager;
+  private static final TrinidadLogger _LOG =
+     TrinidadLogger.createTrinidadLogger(UploadRequestWrapper.class);
 }

Modified: myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/xmlHttp/XmlHttpConfigurator.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/xmlHttp/XmlHttpConfigurator.java?rev=774721&r1=774720&r2=774721&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/xmlHttp/XmlHttpConfigurator.java (original)
+++ myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/xmlHttp/XmlHttpConfigurator.java Thu May 14 10:21:52 2009
@@ -23,6 +23,8 @@
 
 import java.lang.reflect.InvocationTargetException;
 
+import java.lang.reflect.Proxy;
+
 import javax.faces.FacesException;
 import javax.faces.context.ExternalContext;
 
@@ -33,18 +35,16 @@
 
 import javax.servlet.jsp.JspException;
 
+import org.apache.myfaces.trinidad.config.Configurator;
 import org.apache.myfaces.trinidad.logging.TrinidadLogger;
+import org.apache.myfaces.trinidad.util.ClassLoaderUtils;
+import org.apache.myfaces.trinidad.util.ExternalContextUtils;
+import org.apache.myfaces.trinidad.util.RequestType;
 import org.apache.myfaces.trinidadinternal.application.StateManagerImpl;
+import org.apache.myfaces.trinidadinternal.renderkit.core.CoreRenderKit;
 import org.apache.myfaces.trinidadinternal.renderkit.core.ppr.XmlResponseWriter;
 
-/**
- * Though a configurator in spirit, at this point it purely exposes
- * Servlet functionality, and is only used to wrap the servlet response.
- * 
- * TODO: support portlets, and make this a true configurator.
- */
-public class XmlHttpConfigurator
-  /*extends Configurator*/
+public class XmlHttpConfigurator extends Configurator
 {
   public XmlHttpConfigurator()
   {
@@ -54,18 +54,34 @@
   {
     return new XmlHttpServletRequest(request);
   }
-
-  public static void beginRequest(ExternalContext externalContext)
-  {
-    StateManagerImpl.reuseRequestTokenForResponse(externalContext);
-    Object response = externalContext.getResponse();
-    if (response instanceof ServletResponse)
-    {
-      externalContext.setResponse(
-         new XmlHttpServletResponse((ServletResponse) response));
+  
+  @Override
+  public ExternalContext getExternalContext(ExternalContext externalContext)
+  {
+    if(CoreRenderKit.isPartialRequest(externalContext))
+    {    
+      StateManagerImpl.reuseRequestTokenForResponse(externalContext);
+      
+      RequestType type = ExternalContextUtils.getRequestType(externalContext);
+      
+      switch(type)
+      {
+        case SERVLET:
+          if(ExternalContextUtils.isHttpServletRequest(externalContext))
+          {
+            externalContext.setResponse(new XmlHttpServletResponse(externalContext));
+          }
+          break;
+        case RESOURCE:
+          externalContext = new XmlHttpPortletExternalContext(externalContext);
+          externalContext.setResponse(new XmlHttpResourceResponse(externalContext));
+      }
     }
+    
+    return externalContext;
   }
-
+  
+  
   /**
    * Sends a <redirect> element to the server
    */
@@ -159,7 +175,6 @@
 
   static private int _ERROR_COUNT = 0;
 
-
   static private final TrinidadLogger _LOG =
     TrinidadLogger.createTrinidadLogger(XmlHttpConfigurator.class);
 }

Modified: myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/xmlHttp/XmlHttpServletResponse.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/xmlHttp/XmlHttpServletResponse.java?rev=774721&r1=774720&r2=774721&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/xmlHttp/XmlHttpServletResponse.java (original)
+++ myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/xmlHttp/XmlHttpServletResponse.java Thu May 14 10:21:52 2009
@@ -21,6 +21,8 @@
 import java.io.IOException;
 import java.io.PrintWriter;
 
+import javax.faces.context.ExternalContext;
+
 import javax.servlet.ServletOutputStream;
 import javax.servlet.ServletResponse;
 import javax.servlet.http.HttpServletResponse;
@@ -32,9 +34,9 @@
 @SuppressWarnings("deprecation")
 final class XmlHttpServletResponse extends HttpServletResponseWrapper
 {
-  XmlHttpServletResponse(ServletResponse response)
+  XmlHttpServletResponse(ExternalContext ec)
   {
-    super((HttpServletResponse)response);
+    super((HttpServletResponse)ec.getResponse());
     
     _contentType = "text/xml;charset=utf-8";
     

Modified: myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/RequestContextImpl.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/RequestContextImpl.java?rev=774721&r1=774720&r2=774721&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/RequestContextImpl.java (original)
+++ myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/RequestContextImpl.java Thu May 14 10:21:52 2009
@@ -76,9 +76,6 @@
 import org.apache.myfaces.trinidadinternal.util.nls.LocaleUtils;
 import org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl;
 
-import sun.reflect.generics.reflectiveObjects.NotImplementedException;
-
-
 /**
  */
 public class RequestContextImpl extends RequestContext
@@ -898,7 +895,7 @@
     public void addRenderedPartialTarget(String id)
     {
       // not valid outside of rendering
-      throw new NotImplementedException();
+      throw new UnsupportedOperationException();
     }
 
     public boolean isPartialTarget(String clientId)
@@ -939,7 +936,7 @@
     public VisitContext getVisitContext()
     {
       // not valid outside of rendering
-      throw new NotImplementedException();
+      throw new UnsupportedOperationException();
     }
 
     private FacesContext _facesContext;

Modified: myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/TrinidadPhaseListener.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/TrinidadPhaseListener.java?rev=774721&r1=774720&r2=774721&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/TrinidadPhaseListener.java (original)
+++ myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/TrinidadPhaseListener.java Thu May 14 10:21:52 2009
@@ -83,18 +83,6 @@
       ExternalContext ec = context.getExternalContext();
       // Assume it's not a postback request
       ec.getRequestMap().put(_POSTBACK_KEY, Boolean.FALSE);
-
-      // And initialize XmlHttp.  We wait until beforePhase()
-      // of RESTORE_VIEW, instead of doing this in the filter,
-      // so that we don't get a request parameter before ViewHandler.initView()
-      // has been called:  doing that leads to big problems.  Note
-      // that with the 1.2_03 RI, this will still be too early,
-      // as it called initView() after beforePhase()
-      if (CoreRenderKit.isPartialRequest(ec))
-      {
-        XmlHttpConfigurator.beginRequest(ec);
-      }
-      
     }
     // If we've reached "apply request values", this is definitely a
     // postback (the ViewHandler should have reached the same conclusion too,

Modified: myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreRenderingContext.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreRenderingContext.java?rev=774721&r1=774720&r2=774721&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreRenderingContext.java (original)
+++ myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreRenderingContext.java Thu May 14 10:21:52 2009
@@ -43,6 +43,8 @@
 import org.apache.myfaces.trinidad.skin.Skin;
 import org.apache.myfaces.trinidad.skin.SkinFactory;
 import org.apache.myfaces.trinidad.style.Styles;
+import org.apache.myfaces.trinidad.util.ExternalContextUtils;
+import org.apache.myfaces.trinidad.util.RequestType;
 import org.apache.myfaces.trinidadinternal.agent.AgentUtil;
 import org.apache.myfaces.trinidadinternal.agent.TrinidadAgent;
 import org.apache.myfaces.trinidadinternal.agent.TrinidadAgentImpl;
@@ -656,7 +658,15 @@
     }
     else if (CoreRenderKit.OUTPUT_MODE_PORTLET.equals(outputMode))
     {
-      return AgentUtil.mergeCapabilities(agent, _PORTLET_CAPABILITIES);
+      if(ExternalContextUtils.isRequestTypeSupported(RequestType.RESOURCE))
+      {
+        //Set things up for the Portlet 2.0 container.
+        return AgentUtil.mergeCapabilities(agent, _ENHANCED_PORTLET_CAPABILITIES);
+      }
+      else
+      { 
+        return AgentUtil.mergeCapabilities(agent, _PORTLET_CAPABILITIES);
+      }
     }
     else
     {
@@ -802,6 +812,9 @@
 
   static private final Map<Object, Object> _PORTLET_CAPABILITIES =
     new HashMap<Object, Object>();
+  
+  static private final Map<Object, Object> _ENHANCED_PORTLET_CAPABILITIES =
+    new HashMap<Object, Object>();
 
   static
   {
@@ -835,6 +848,9 @@
                             Boolean.FALSE);
     _PORTLET_CAPABILITIES.put(TrinidadAgent.CAP_MULTIPLE_WINDOWS,
                             Boolean.FALSE);
+    
+    _ENHANCED_PORTLET_CAPABILITIES.put(TrinidadAgent.CAP_MULTIPLE_WINDOWS,
+                              Boolean.FALSE);
   }
 
   static private final TrinidadLogger _LOG =

Modified: myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/FormRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/FormRenderer.java?rev=774721&r1=774720&r2=774721&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/FormRenderer.java (original)
+++ myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/FormRenderer.java Thu May 14 10:21:52 2009
@@ -29,6 +29,7 @@
 import javax.faces.component.ActionSource;
 import javax.faces.component.UIComponent;
 import javax.faces.component.UIForm;
+import javax.faces.context.ExternalContext;
 import javax.faces.context.FacesContext;
 import javax.faces.context.ResponseWriter;
 import javax.faces.convert.Converter;
@@ -47,6 +48,8 @@
 import org.apache.myfaces.trinidad.context.FormData;
 import org.apache.myfaces.trinidad.context.PartialPageContext;
 import org.apache.myfaces.trinidad.context.RenderingContext;
+import org.apache.myfaces.trinidad.util.ExternalContextUtils;
+import org.apache.myfaces.trinidad.util.RequestType;
 import org.apache.myfaces.trinidadinternal.renderkit.core.CoreResponseStateManager;
 import org.apache.myfaces.trinidadinternal.renderkit.uix.SubformRenderer;
 
@@ -168,6 +171,7 @@
     FacesBean           bean) throws IOException
   {
     ResponseWriter rw = context.getResponseWriter();
+    ExternalContext ec = context.getExternalContext();
 
     String formName = arc.getFormData().getName();
     
@@ -241,6 +245,15 @@
     String action =
       context.getApplication().getViewHandler().getActionURL(context, viewId);
     renderEncodedActionURI(context, "action", action);
+    
+    RequestType type = ExternalContextUtils.getRequestType(ec);
+    
+    //Always add expando to portlet form
+    if(type.isPortlet())
+    {
+      renderEncodedResourceURI(context, "_trinPPRAction", action);
+    }
+    
     if (supportsTarget(arc))
     {
       rw.writeAttribute("target", getTargetFrame(bean), "targetFrame");

Modified: myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/webapp/wrappers/PortletContextWrapper.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/webapp/wrappers/PortletContextWrapper.java?rev=774721&r1=774720&r2=774721&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/webapp/wrappers/PortletContextWrapper.java (original)
+++ myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/webapp/wrappers/PortletContextWrapper.java Thu May 14 10:21:52 2009
@@ -27,12 +27,15 @@
 import javax.portlet.PortletContext;
 import javax.portlet.PortletRequestDispatcher;
 
-/**
- * TODO: Document this
- *
- * @version $Revision$ $Date$
- */
+import org.apache.myfaces.trinidad.util.ExternalContextUtils;
+import org.apache.myfaces.trinidad.util.RequestType;
 
+ /**
+  * Wrapper for the native PortletContext object.  Unlike the other Portlet Wrapper classes in
+  * this package, this class may be used for both Portlet 1.0 and 2.0 containers.
+  *
+  * @version $Revision$ $Date$
+  */
 public class PortletContextWrapper implements PortletContext
 {
   public PortletContextWrapper(PortletContext context)
@@ -56,7 +59,7 @@
    * @return
    * @see javax.portlet.PortletContext#getAttributeNames()
    */
-  public Enumeration<?> getAttributeNames()
+  public Enumeration<String> getAttributeNames()
   {
     return _context.getAttributeNames();
   }
@@ -75,7 +78,7 @@
    * @return
    * @see javax.portlet.PortletContext#getInitParameterNames()
    */
-  public Enumeration<?> getInitParameterNames()
+  public Enumeration<String> getInitParameterNames()
   {
     return _context.getInitParameterNames();
   }
@@ -115,7 +118,7 @@
    */
   public PortletRequestDispatcher getNamedDispatcher(String arg0)
   {
-    return new PortletRequestDispatcherWrapper(_context.getNamedDispatcher(arg0));
+    return _context.getNamedDispatcher(arg0);
   }
 
   /**
@@ -144,7 +147,7 @@
    */
   public PortletRequestDispatcher getRequestDispatcher(String arg0)
   {
-    return new PortletRequestDispatcherWrapper(_context.getRequestDispatcher(arg0));
+    return _context.getRequestDispatcher(arg0);
   }
 
   /**
@@ -227,4 +230,20 @@
   {
     _context.setAttribute(arg0, arg1);
   }
+
+  /**
+   * Portlet 2.0 only functionality.  These wrappers are not intended for Portlet 2.0.  Marked
+   * final in order to prevent overloading.
+   */
+  public Enumeration<String> getContainerRuntimeOptions()
+  {
+    if(!_PORTLET_2_CONTAINER)
+    {
+      throw new UnsupportedOperationException("This method is only supported in Portlet 2.0 containers");
+    }
+    
+    return _context.getContainerRuntimeOptions();
+  } 
+  
+  private static final boolean _PORTLET_2_CONTAINER = ExternalContextUtils.isRequestTypeSupported(RequestType.RESOURCE);
 }

Modified: myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/RequestQueue.js
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/RequestQueue.js?rev=774721&r1=774720&r2=774721&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/RequestQueue.js (original)
+++ myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/RequestQueue.js Thu May 14 10:21:52 2009
@@ -134,11 +134,18 @@
   headerParams
   )
 {
+  //this retrieves the action url for PPR.  Generally this will be the action property on
+  //actionForm, however in the case of a Portal 2.0 environment, this could be a special
+  //expando property encoded as a ResourceUrl.  As such, if the expando is available, use it
+  //for PPR
+  var pprURL = actionForm.getAttribute("_trinPPRAction");
+  var action = pprURL?pprURL:actionForm.action;
+  
   if (this._isMultipartForm(actionForm))
   {
     // TODO: log a warning if we're dropping any headers?  Or
     // come up with a hack to send "headers" via a multipart request?
-    this.sendMultipartRequest(context, method, actionForm.action, actionForm, params);
+    this.sendMultipartRequest(context, method, action, actionForm, params);
   }
   else
   {
@@ -148,7 +155,7 @@
     if(_agent.isIE && window.external)
       window.external.AutoCompleteSaveForm(actionForm);
 
-    this.sendRequest(context, method, actionForm.action, content, headerParams);
+    this.sendRequest(context, method, action, content, headerParams);
   }
 }
 

Modified: myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/resources/META-INF/services/org.apache.myfaces.trinidad.config.Configurator
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/resources/META-INF/services/org.apache.myfaces.trinidad.config.Configurator?rev=774721&r1=774720&r2=774721&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/resources/META-INF/services/org.apache.myfaces.trinidad.config.Configurator (original)
+++ myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/resources/META-INF/services/org.apache.myfaces.trinidad.config.Configurator Thu May 14 10:21:52 2009
@@ -1,3 +1,4 @@
 org.apache.myfaces.trinidadinternal.config.upload.FileUploadConfiguratorImpl
 org.apache.myfaces.trinidadinternal.config.dispatch.DispatchResponseConfiguratorImpl
+org.apache.myfaces.trinidadinternal.config.xmlHttp.XmlHttpConfigurator
 org.apache.myfaces.trinidadinternal.config.CheckSerializationConfigurator