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 2011/06/20 15:17:51 UTC

svn commit: r1137624 - in /myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago: internal/webapp/TobagoResponseXmlWriterImpl.java renderkit/TobagoRenderKit.java

Author: lofwyr
Date: Mon Jun 20 13:17:50 2011
New Revision: 1137624

URL: http://svn.apache.org/viewvc?rev=1137624&view=rev
Log:
TOBAGO-813: Possibility to render the output as XHTML
  - write not the content-type "application/xhtml+xml" in IE 6,7,8, but "text/html"
  - remove the "<?xml ?>" stuff we got from facelets, because it is at the wrong place and brakes the content detection of some browsers

Modified:
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/webapp/TobagoResponseXmlWriterImpl.java
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/TobagoRenderKit.java

Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/webapp/TobagoResponseXmlWriterImpl.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/webapp/TobagoResponseXmlWriterImpl.java?rev=1137624&r1=1137623&r2=1137624&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/webapp/TobagoResponseXmlWriterImpl.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/webapp/TobagoResponseXmlWriterImpl.java Mon Jun 20 13:17:50 2011
@@ -19,17 +19,25 @@ package org.apache.myfaces.tobago.intern
 
 import org.apache.myfaces.tobago.renderkit.html.HtmlElements;
 import org.apache.myfaces.tobago.util.XmlUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import javax.faces.context.ResponseWriter;
 import java.io.IOException;
 import java.io.Writer;
+import java.util.Arrays;
 
 public final class TobagoResponseXmlWriterImpl extends TobagoResponseWriterBase {
 
+  private static final Logger LOG = LoggerFactory.getLogger(TobagoResponseXmlWriterImpl.class);
+
   private static final String XHTML_DOCTYPE =
       "<!DOCTYPE html      PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\""
           + "     \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">";
 
+  public static final String XML_VERSION_1_0_ENCODING_UTF_8 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
+  public static final int XML_VERSION_1_0_ENCODING_UTF_8_LENGTH = XML_VERSION_1_0_ENCODING_UTF_8.length();
+
   public TobagoResponseXmlWriterImpl(
       Writer writer, String contentType, String characterEncoding) {
     super(writer, contentType, characterEncoding);
@@ -48,6 +56,19 @@ public final class TobagoResponseXmlWrit
     getWriter().write(XmlUtils.escape(text, offset, length, true));
   }
 
+  @Override
+  public void write(char[] cbuf, int off, int len) throws IOException {
+
+    // XXX Seems to be related to http://java.net/jira/browse/JAVASERVERFACES_SPEC_PUBLIC-696
+    if (cbuf.length == XML_VERSION_1_0_ENCODING_UTF_8_LENGTH
+    && Arrays.equals(cbuf, XML_VERSION_1_0_ENCODING_UTF_8.toCharArray())) {
+      if (LOG.isDebugEnabled()) {
+        LOG.debug("Filtering XML header: " + new String(cbuf));
+      }
+    } else {
+      super.write(cbuf, off, len);
+    }
+  }
 
   public ResponseWriter cloneWithWriter(final Writer originalWriter) {
     return new TobagoResponseXmlWriterImpl(

Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/TobagoRenderKit.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/TobagoRenderKit.java?rev=1137624&r1=1137623&r2=1137624&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/TobagoRenderKit.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/TobagoRenderKit.java Mon Jun 20 13:17:50 2011
@@ -19,10 +19,12 @@ package org.apache.myfaces.tobago.render
 
 import org.apache.myfaces.tobago.application.ProjectStage;
 import org.apache.myfaces.tobago.config.TobagoConfig;
+import org.apache.myfaces.tobago.context.Capability;
 import org.apache.myfaces.tobago.internal.webapp.DebugTobagoResponseWriterWrapper;
 import org.apache.myfaces.tobago.internal.webapp.TobagoResponseJsonWriterImpl;
 import org.apache.myfaces.tobago.internal.webapp.TobagoResponseWriterImpl;
 import org.apache.myfaces.tobago.internal.webapp.TobagoResponseXmlWriterImpl;
+import org.apache.myfaces.tobago.util.VariableResolverUtils;
 import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -99,15 +101,23 @@ public class TobagoRenderKit extends Ren
       LOG.warn("Content-Type '" + contentTypeList + "' not supported! Using text/html");
     }
 
+// XXX enable xhtml here, by hand:
+//    contentType = "application/xhtml+xml";
+
     boolean xml = false;
-    if ("application/xhtml".equals(contentType)
+    if ("application/xhtml+xml".equals(contentType)
+        || "application/xhtml".equals(contentType)
         || "application/xml".equals(contentType)
         || "text/xml".equals(contentType)) {
       xml = true;
     }
-    // XXX for XHTML 1.0 the content type must be set to "text/html" for IE6
-    // XXX so at this time we can't differ ...
-//    xml = true;
+
+    // content type xhtml is not supported in every browser... e. g. IE 6, 7, 8
+    if (!VariableResolverUtils.resolveClientProperties(FacesContext.getCurrentInstance())
+        .getUserAgent().hasCapability(Capability.CONTENT_TYPE_XHTML)) {
+      contentType = "text/html";
+    }
+
     TobagoResponseWriter responseWriter;
     if (xml) {
       responseWriter = new TobagoResponseXmlWriterImpl(writer, contentType, characterEncoding);