myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfreed...@apache.org
Subject svn commit: r811171 - /myfaces/portlet-bridge/core/trunk/impl/src/main/java/org/apache/myfaces/portlet/faces/util/map/PortletRequestHeaders.java
Date Thu, 03 Sep 2009 23:30:46 GMT
Author: mfreedman
Date: Thu Sep  3 23:30:46 2009
New Revision: 811171

URL: http://svn.apache.org/viewvc?rev=811171&view=rev
Log:
Updated HeaderMap impls to always construct/use the portlet defined values for the content-type/accept
headers as they commonly don't match what some portlet containers show through in the operation
that gets the headers/properties.

Modified:
    myfaces/portlet-bridge/core/trunk/impl/src/main/java/org/apache/myfaces/portlet/faces/util/map/PortletRequestHeaders.java

Modified: myfaces/portlet-bridge/core/trunk/impl/src/main/java/org/apache/myfaces/portlet/faces/util/map/PortletRequestHeaders.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/core/trunk/impl/src/main/java/org/apache/myfaces/portlet/faces/util/map/PortletRequestHeaders.java?rev=811171&r1=811170&r2=811171&view=diff
==============================================================================
--- myfaces/portlet-bridge/core/trunk/impl/src/main/java/org/apache/myfaces/portlet/faces/util/map/PortletRequestHeaders.java
(original)
+++ myfaces/portlet-bridge/core/trunk/impl/src/main/java/org/apache/myfaces/portlet/faces/util/map/PortletRequestHeaders.java
Thu Sep  3 23:30:46 2009
@@ -98,156 +98,169 @@
         addProperty(name, values.nextElement());
       }
     }
-    
+
     StringBuilder property = null;
 
-    // if they don't already exist, now add in the the required (HTTP)
-    // headers to ensure compatibility with servlets
-    if (!containsHeader(mHeaderNames, "ACCEPT"))
+    // can't assume portlet container overrides these headers to reflect portlet constraints
-- so do so
+    ensurePortletAcceptHeader();
+    ensurePortletAcceptLanguage();
+
+
+    if ((Bridge.PortletPhase) mPortletRequest.getAttribute(Bridge.PORTLET_LIFECYCLE_PHASE)
==
+        Bridge.PortletPhase.ACTION_PHASE)
     {
-      Enumeration<String> contentTypes = mPortletRequest.getResponseContentTypes();
-      property = new StringBuilder(64);
-      
-      boolean addComma = false;
-      while (contentTypes.hasMoreElements())
-      {
-        String type = contentTypes.nextElement();
-        if (type != null)
-        {
-          if (addComma)
-          {
-            property = property.append(',');
-          }
-          else
-          {
-            addComma = true;
-          }
-          
-          property = property.append(type);
-        }
-      }
+      ensurePortletContentType();
+      ensurePortletContentLength();
+    }
+    // Technically don't need this test here but I will forget to change this code when
+    // JSR 286 is supported and there are more phases.
+    else if ((Bridge.PortletPhase) mPortletRequest.getAttribute(Bridge.PORTLET_LIFECYCLE_PHASE)
==
+             Bridge.PortletPhase.RENDER_PHASE)
+    {
+      // its the RENDER_PHASE -- spec says we must remove the CONTENT_TYPE if
+      // came in the request -- so it matches null return from
+      // EC.getRequestContentType/CharacterSetEncoding
+      mHeaders.remove("CONTENT-TYPE");
+      mHeaderNames.remove("CONTENT-TYPE");
+    }
+
+    return true;
+  }
 
-      if (addComma)
+  private boolean containsHeader(List<String> headerNames, String key)
+  {
+    for (String name : headerNames)
+    {
+      if (key.toUpperCase().equals(name.toUpperCase()))
       {
-        addProperty("ACCEPT", property.toString());
+        return true;
       }
     }
+    
+    return false;
+  }
+  
+  private void ensurePortletAcceptHeader()
+  {
+    // Make sure its not there
+    mHeaders.remove("ACCEPT");
+    mHeaderNames.remove("ACCEPT");
+    
+    Enumeration<String> contentTypes =
+      mPortletRequest.getResponseContentTypes();
+    StringBuilder property = new StringBuilder(64);
 
-    if (!containsHeader(mHeaderNames, "ACCEPT-LANGUAGE"))
+    boolean addComma = false;
+    while (contentTypes.hasMoreElements())
     {
-      Enumeration<Locale> locales = mPortletRequest.getLocales();
-      if (property == null)
+      String type = contentTypes.nextElement();
+      if (type != null)
       {
-        property = new StringBuilder(64);
-      }
-      else
-      {
-        property.setLength(0);
-      }
-      
-      boolean addComma = false;
-      while (locales.hasMoreElements())
-      {
-        Locale l = locales.nextElement();
-        if (l != null)
+        if (addComma)
         {
-          if (addComma)
-          {
-            property = property.append(',');
-          }
-          else
-          {
-            addComma = true;
-          }
-          
-          String s = l.getLanguage();
-          // only add if language not empty
-          if (s.length() > 0)
-          {
-            property = property.append(s);
-            s = l.getCountry();
-            if (s.length() > 0)
-            {
-              property = property.append('-');
-              property = property.append(s);
-            }
-          }
+          property = property.append(',');
+        }
+        else
+        {
+          addComma = true;
         }
-      }
 
-      if (addComma)
-      {
-        addProperty("ACCEPT-LANGUAGE", property.toString());
+        property = property.append(type);
       }
     }
 
-    if ((Bridge.PortletPhase) mPortletRequest.getAttribute(Bridge.PORTLET_LIFECYCLE_PHASE)
== Bridge.PortletPhase.ACTION_PHASE)
+    if (addComma)
     {
+      addProperty("ACCEPT", property.toString());
+    }
+  }
 
-      if (!containsHeader(mHeaderNames, "CONTENT-TYPE"))
-      {
-        String contentType = ((ActionRequest) mPortletRequest).getContentType();
-        String charset = ((ActionRequest) mPortletRequest).getCharacterEncoding();
+  private void ensurePortletAcceptLanguage()
+  {
+    // Make sure its not there
+    mHeaders.remove("ACCEPT-LANGUAGE");
+    mHeaderNames.remove("ACCEPT-LANGUAGE");
+    
+    StringBuilder property = new StringBuilder(64);
+    Enumeration<Locale> locales = mPortletRequest.getLocales();
 
-        if (contentType != null)
+    boolean addComma = false;
+    while (locales.hasMoreElements())
+    {
+      Locale l = locales.nextElement();
+      if (l != null)
+      {
+        if (addComma)
         {
-          if (property == null)
-          {
-            property = new StringBuilder(64);
-          }
-          else
-          {
-            property.setLength(0);
-          }
-
-          property = property.append(contentType);
-          if (charset != null)
-          {
-            property = property.append("; charset=");
-            property = property.append(charset);
-          }
-          addProperty("CONTENT-TYPE", property.toString());
+          property = property.append(',');
+        }
+        else
+        {
+          addComma = true;
         }
-      }
-
-      if (!containsHeader(mHeaderNames, "CONTENT-LENGTH"))
-      {
-        int contentLength = ((ActionRequest) mPortletRequest).getContentLength();
 
-        if (contentLength != -1)
+        String s = l.getLanguage();
+        // only add if language not empty
+        if (s.length() > 0)
         {
-          addProperty("CONTENT-LENGTH", String.valueOf(contentLength));
+          property = property.append(s);
+          s = l.getCountry();
+          if (s.length() > 0)
+          {
+            property = property.append('-');
+            property = property.append(s);
+          }
         }
       }
-
     }
-    // Technically don't need this test here but I will forget to change this code when
-    // JSR 286 is supported and there are more phases.
-    else if ((Bridge.PortletPhase) mPortletRequest.getAttribute(Bridge.PORTLET_LIFECYCLE_PHASE)
== Bridge.PortletPhase.RENDER_PHASE)
+
+    if (addComma)
     {
-      // its the RENDER_PHASE -- spec says we must remove the CONTENT_TYPE if 
-      // came in the request -- so it matches null return from
-      // EC.getRequestContentType/CharacterSetEncoding
-      mHeaders.remove("CONTENT-TYPE");
-      mHeaderNames.remove("CONTENT-TYPE");
+      addProperty("ACCEPT-LANGUAGE", property.toString());
     }
-
-    return true;
   }
-
-  private boolean containsHeader(List<String> headerNames, String key)
+  
+  private void ensurePortletContentType()
   {
-    for (String name : headerNames)
+    // Make sure its not there
+    mHeaders.remove("CONTENT-TYPE");
+    mHeaderNames.remove("CONTENT-TYPE");
+    
+    StringBuilder property = new StringBuilder(64);
+    String contentType =
+      ((ActionRequest) mPortletRequest).getContentType();
+    String charset =
+      ((ActionRequest) mPortletRequest).getCharacterEncoding();
+
+    if (contentType != null)
     {
-      if (key.toUpperCase().equals(name.toUpperCase()))
+      property = property.append(contentType);
+      if (charset != null)
       {
-        return true;
+        property = property.append("; charset=");
+        property = property.append(charset);
       }
+      
+      addProperty("CONTENT-TYPE", property.toString());
     }
+  }
+
+  private void ensurePortletContentLength()
+  {
+    // Make sure its not there
+    mHeaders.remove("CONTENT-LENGTH");
+    mHeaderNames.remove("CONTENT-LENGTH");
     
-    return false;
+    int contentLength =
+      ((ActionRequest) mPortletRequest).getContentLength();
+
+    if (contentLength != -1)
+    {
+      addProperty("CONTENT-LENGTH", String.valueOf(contentLength));
+    }
   }
 
+
   protected final void addProperty(String name, String value)
   {
     if (mHeaders == Collections.EMPTY_MAP)



Mime
View raw message