You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2008/03/05 20:46:55 UTC

svn commit: r634001 - in /myfaces/tobago/trunk: core/src/main/java/org/apache/myfaces/tobago/util/ core/src/main/java/org/apache/myfaces/tobago/webapp/ theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/

Author: lofwyr
Date: Wed Mar  5 11:46:53 2008
New Revision: 634001

URL: http://svn.apache.org/viewvc?rev=634001&view=rev
Log:
TOBAGO-629: ensure content type meta header (for WebSphere)

Modified:
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/util/ResponseUtils.java
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriter.java
    myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/PageRenderer.java

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/util/ResponseUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/util/ResponseUtils.java?rev=634001&r1=634000&r2=634001&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/util/ResponseUtils.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/util/ResponseUtils.java Wed Mar  5 11:46:53 2008
@@ -17,8 +17,6 @@
  * limitations under the License.
  */
 
-import org.apache.myfaces.tobago.context.ClientProperties;
-
 import javax.faces.context.ExternalContext;
 import javax.faces.context.FacesContext;
 import javax.servlet.http.HttpServletResponse;
@@ -40,24 +38,11 @@
     }
   }
 
-  public static void ensureContentTypeHeader(FacesContext facesContext, String charset) {
+  public static void ensureContentTypeHeader(FacesContext facesContext, String contentType) {
     // TODO PortletRequest
     if (facesContext.getExternalContext().getResponse() instanceof HttpServletResponse) {
       HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
-      response.setContentType(generateContentType(facesContext, charset));
-    }
-  }
-
-  private static String generateContentType(FacesContext facesContext, String charset) {
-    StringBuilder sb = new StringBuilder("text/");
-    ClientProperties clientProperties
-        = ClientProperties.getInstance(facesContext.getViewRoot());
-    sb.append(clientProperties.getContentType());
-    if (charset == null) {
-      charset = "UTF-8";
+      response.setContentType(contentType);
     }
-    sb.append("; charset=");
-    sb.append(charset);
-    return sb.toString();
   }
 }

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriter.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriter.java?rev=634001&r1=634000&r2=634001&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriter.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriter.java Wed Mar  5 11:46:53 2008
@@ -17,10 +17,10 @@
  * limitations under the License.
  */
 
-import org.apache.myfaces.tobago.renderkit.html.StyleClasses;
-import org.apache.myfaces.tobago.renderkit.html.HtmlStyleMap;
 import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
 import org.apache.myfaces.tobago.renderkit.html.HtmlConstants;
+import org.apache.myfaces.tobago.renderkit.html.HtmlStyleMap;
+import org.apache.myfaces.tobago.renderkit.html.StyleClasses;
 
 import javax.faces.component.UIComponent;
 import javax.faces.context.ResponseWriter;
@@ -178,4 +178,21 @@
     writeText(null, property);
   }
 
+  public String getContentTypeWithCharSet() {
+    String contentType = getContentType();
+    if (contentType == null) {
+      contentType = "text/html";
+    }
+    String characterEncoding = getCharacterEncoding();
+    if (characterEncoding == null) {
+      characterEncoding = "UTF-8";
+    }
+
+    StringBuilder builder = new StringBuilder();
+    builder.append(contentType);
+    builder.append("; charset=");
+    builder.append(characterEncoding);
+    return builder.toString();
+
+  }
 }

Modified: myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/PageRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/PageRenderer.java?rev=634001&r1=634000&r2=634001&view=diff
==============================================================================
--- myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/PageRenderer.java (original)
+++ myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/PageRenderer.java Wed Mar  5 11:46:53 2008
@@ -24,7 +24,6 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_CHARSET;
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_DELAY;
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_DOCTYPE;
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_ENCTYPE;
@@ -162,8 +161,8 @@
     String viewId = facesContext.getViewRoot().getViewId();
     String formAction = viewHandler.getActionURL(facesContext, viewId);
     formAction = facesContext.getExternalContext().encodeActionURL(formAction);
-    String charset = (String) page.getAttributes().get(ATTR_CHARSET);
-    ResponseUtils.ensureContentTypeHeader(facesContext, charset);
+    String contentType = writer.getContentTypeWithCharSet();
+    ResponseUtils.ensureContentTypeHeader(facesContext, contentType);
 
     String title = (String) page.getAttributes().get(ATTR_LABEL);
 
@@ -182,13 +181,14 @@
     //if (debugMode) {
     writer.writeJavascript("var TbgHeadStart = new Date();");
     //}
+
     // meta
-    // TODO duplicate; see PageTag.doStartTag()
-//    writer.startElement(HtmlConstants.META, null);
-//    writer.writeAttribute("http-equiv", "Content-Type", null);
-//    writer.writeAttribute(
-//        "content", generateContentType(facesContext, charset), null);
-//    writer.endElement(HtmlConstants.META);
+    // this is needed, because websphere 6.0? ignores the setting of the content type on the response
+    writer.startElement(HtmlConstants.META, null);
+    writer.writeAttribute("http-equiv", "Content-Type", false);
+    writer.writeAttribute("content", contentType, false);
+    writer.endElement(HtmlConstants.META);
+
     // title
     writer.startElement(HtmlConstants.TITLE, null);
     writer.writeText(title != null ? title : "");