You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2011/11/30 20:27:11 UTC

svn commit: r1208717 - in /myfaces/shared/trunk_4.0.x/core/src/main: java/org/apache/myfaces/shared/config/ java/org/apache/myfaces/shared/renderkit/ java/org/apache/myfaces/shared/renderkit/html/ resources/META-INF/

Author: lu4242
Date: Wed Nov 30 19:27:10 2011
New Revision: 1208717

URL: http://svn.apache.org/viewvc?rev=1208717&view=rev
Log:
synch with impl shared

Added:
    myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/ContentTypeUtils.java
Modified:
    myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/config/MyfacesConfig.java
    myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRendererUtils.java
    myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlResponseWriterImpl.java
    myfaces/shared/trunk_4.0.x/core/src/main/resources/META-INF/myfaces-metadata.xml

Modified: myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/config/MyfacesConfig.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/config/MyfacesConfig.java?rev=1208717&r1=1208716&r2=1208717&view=diff
==============================================================================
--- myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/config/MyfacesConfig.java (original)
+++ myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/config/MyfacesConfig.java Wed Nov 30 19:27:10 2011
@@ -340,6 +340,16 @@ public class MyfacesConfig
     public final static String INIT_PARAM_STRICT_JSF_2_CC_EL_RESOLVER = "org.apache.myfaces.STRICT_JSF_2_CC_EL_RESOLVER";
     public final static boolean INIT_PARAM_STRICT_JSF_2_CC_EL_RESOLVER_DEFAULT = false;
     
+    /**
+     * Define the default content type that the default ResponseWriter generates, when no match can be derived from
+     * HTTP Accept Header.
+     */
+    @JSFWebConfigParam(since="2.0.11,2.1.5", expectedValues="text/html, application/xhtml+xml", 
+            defaultValue="text/html", group="render")
+    public final static String INIT_PARAM_DEFAULT_RESPONSE_WRITER_CONTENT_TYPE_MODE = 
+        "org.apache.myfaces.DEFAULT_RESPONSE_WRITER_CONTENT_TYPE_MODE";
+    public final static String INIT_PARAM_DEFAULT_RESPONSE_WRITER_CONTENT_TYPE_MODE_DEFAULT = "text/html";
+    
     private boolean _prettyHtml;
     private boolean _detectJavascript;
     private boolean _allowJavascript;
@@ -365,6 +375,7 @@ public class MyfacesConfig
     private boolean _debugPhaseListenerEnabled;
     private boolean _strictJsf2RefreshTargetAjax;
     private boolean _strictJsf2CCELResolver;
+    private String _defaultResponseWriterContentTypeMode;
 
     private static final boolean TOMAHAWK_AVAILABLE;
     private static final boolean MYFACES_IMPL_AVAILABLE;
@@ -459,6 +470,7 @@ public class MyfacesConfig
         setDebugPhaseListenerEnabled(INIT_PARAM_DEBUG_PHASE_LISTENER_DEFAULT);
         setStrictJsf2RefreshTargetAjax(INIT_PARAM_STRICT_JSF_2_REFRESH_TARGET_AJAX_DEFAULT);
         setStrictJsf2CCELResolver(INIT_PARAM_STRICT_JSF_2_CC_EL_RESOLVER_DEFAULT);
+        setDefaultResponseWriterContentTypeMode(INIT_PARAM_DEFAULT_RESPONSE_WRITER_CONTENT_TYPE_MODE_DEFAULT);
     }
 
     private static MyfacesConfig createAndInitializeMyFacesConfig(ExternalContext extCtx)
@@ -547,6 +559,10 @@ public class MyfacesConfig
         
         myfacesConfig.setStrictJsf2CCELResolver(WebConfigParamUtils.getBooleanInitParameter(extCtx, 
                 INIT_PARAM_STRICT_JSF_2_CC_EL_RESOLVER, INIT_PARAM_STRICT_JSF_2_CC_EL_RESOLVER_DEFAULT));
+        
+        myfacesConfig.setDefaultResponseWriterContentTypeMode(WebConfigParamUtils.getStringInitParameter(
+                extCtx, INIT_PARAM_DEFAULT_RESPONSE_WRITER_CONTENT_TYPE_MODE,
+                INIT_PARAM_DEFAULT_RESPONSE_WRITER_CONTENT_TYPE_MODE_DEFAULT));
 
         if (TOMAHAWK_AVAILABLE)
         {
@@ -1003,4 +1019,15 @@ public class MyfacesConfig
     {
         this._strictJsf2CCELResolver = strictJsf2CCELResolver;
     }
+
+    public String getDefaultResponseWriterContentTypeMode()
+    {
+        return _defaultResponseWriterContentTypeMode;
+    }
+
+    public void setDefaultResponseWriterContentTypeMode(
+            String defaultResponseWriterContentTypeMode)
+    {
+        this._defaultResponseWriterContentTypeMode = defaultResponseWriterContentTypeMode;
+    }
 }

Added: myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/ContentTypeUtils.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/ContentTypeUtils.java?rev=1208717&view=auto
==============================================================================
--- myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/ContentTypeUtils.java (added)
+++ myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/ContentTypeUtils.java Wed Nov 30 19:27:10 2011
@@ -0,0 +1,133 @@
+/*
+ * 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.shared.renderkit;
+
+import javax.faces.context.FacesContext;
+
+import org.apache.myfaces.shared.renderkit.html.HtmlRendererUtils;
+import org.apache.myfaces.shared.util.StringUtils;
+
+/**
+ * 
+ * @author Leonardo Uribe
+ *
+ */
+public class ContentTypeUtils
+{
+    public static final String HTML_CONTENT_TYPE = "text/html";
+    public static final String TEXT_ANY_CONTENT_TYPE = "text/*";
+    public static final String ANY_CONTENT_TYPE = "*/*";
+
+    public static final String[] HTML_ALLOWED_CONTENT_TYPES = {HTML_CONTENT_TYPE, ANY_CONTENT_TYPE, TEXT_ANY_CONTENT_TYPE};
+    
+    public static final String XHTML_CONTENT_TYPE = "application/xhtml+xml";
+    public static final String APPLICATION_XML_CONTENT_TYPE = "application/xml";
+    public static final String TEXT_XML_CONTENT_TYPE = "text/xml";
+    
+    public static final String[] XHTML_ALLOWED_CONTENT_TYPES = {XHTML_CONTENT_TYPE, APPLICATION_XML_CONTENT_TYPE, TEXT_XML_CONTENT_TYPE};
+    
+    public static final String[] AJAX_XHTML_ALLOWED_CONTENT_TYPES = {XHTML_CONTENT_TYPE};
+
+
+    /**
+     * Indicate if the passes content type match one of the options passed. 
+     */
+    public static boolean containsContentType(String contentType, String[] allowedContentTypes)
+    {
+        if (allowedContentTypes == null)
+        {
+            return false;
+        }
+        for (int i = 0; i < allowedContentTypes.length; i++)
+        {
+            if (allowedContentTypes[i].indexOf(contentType) != -1)
+            {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public static String chooseWriterContentType(String contentTypeListString, String[] htmlContentTypes, String[] xhtmlContentTypes)
+    {
+        String[] contentTypeList = splitContentTypeListString(contentTypeListString);
+        String[] supportedContentTypeArray = HtmlRendererUtils.getSupportedContentTypes();
+        String selectedContentType = null;
+        for (int i = 0; i < supportedContentTypeArray.length; i++)
+        {
+            String supportedContentType = supportedContentTypeArray[i].trim();
+
+            for (int j = 0; j < contentTypeList.length; j++)
+            {
+                String contentType = (String) contentTypeList[j];
+
+                if (contentType.indexOf(supportedContentType) != -1)
+                {
+                    if (containsContentType(contentType, htmlContentTypes))
+                    {
+                        selectedContentType = HTML_CONTENT_TYPE;
+                    }
+                    else if (containsContentType(contentType, xhtmlContentTypes))
+                    {
+                        selectedContentType = XHTML_CONTENT_TYPE;
+                    }
+                    break;
+                }
+            }
+            if (selectedContentType != null)
+            {
+                break;
+            }
+        }
+        return selectedContentType;
+    }
+    
+    public static String[] splitContentTypeListString(String contentTypeListString)
+    {
+        String[] splittedArray = StringUtils.splitShortString(contentTypeListString, ',');
+        for (int i = 0; i < splittedArray.length; i++)
+        {
+            int semicolonIndex = splittedArray[i].indexOf(";");
+            if (semicolonIndex != -1)
+            {
+                splittedArray[i] = splittedArray[i].substring(0,semicolonIndex);
+            }
+        }
+        return splittedArray;
+    }
+    
+    public static String getContentTypeFromAcceptHeader(FacesContext context)
+    {
+        String contentTypeListString = (String) context.getExternalContext()
+            .getRequestHeaderMap().get("Accept");
+        // There is a windows mobile IE client (6.12) sending
+        // "application/vnd.wap.mms-message;*/*"
+        // Note that the Accept header should be written as 
+        // "application/vnd.wap.mms-message,*/*" ,
+        // so this is bug of the client. Anyway, this is a workaround ...
+        if (contentTypeListString != null
+                && contentTypeListString
+                        .startsWith("application/vnd.wap.mms-message;*/*"))
+        {
+            contentTypeListString = "*/*";
+        }
+        return contentTypeListString;
+    }
+
+}

Modified: myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRendererUtils.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRendererUtils.java?rev=1208717&r1=1208716&r2=1208717&view=diff
==============================================================================
--- myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRendererUtils.java (original)
+++ myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRendererUtils.java Wed Nov 30 19:27:10 2011
@@ -1652,6 +1652,10 @@ public final class HtmlRendererUtils
             XHTML_CONTENT_TYPE, APPLICATION_XML_CONTENT_TYPE,
             TEXT_XML_CONTENT_TYPE, TEXT_ANY_CONTENT_TYPE, ANY_CONTENT_TYPE };
 
+    /**
+     * @deprecated use ContentTypeUtils instead
+     */
+    @Deprecated
     public static String selectContentType(String contentTypeListString)
     {
         if (contentTypeListString == null)

Modified: myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlResponseWriterImpl.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlResponseWriterImpl.java?rev=1208717&r1=1208716&r2=1208717&view=diff
==============================================================================
--- myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlResponseWriterImpl.java (original)
+++ myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlResponseWriterImpl.java Wed Nov 30 19:27:10 2011
@@ -30,6 +30,7 @@ import javax.faces.FacesException;
 import javax.faces.component.UIComponent;
 import javax.faces.context.ResponseWriter;
 
+import org.apache.myfaces.shared.renderkit.ContentTypeUtils;
 import org.apache.myfaces.shared.renderkit.RendererUtils;
 import org.apache.myfaces.shared.renderkit.html.util.UnicodeEncoder;
 import org.apache.myfaces.shared.util.CommentUtils;
@@ -50,8 +51,8 @@ public class HtmlResponseWriterImpl
     private static final String DEFAULT_CHARACTER_ENCODING = "ISO-8859-1";
     private static final String UTF8 = "UTF-8";
 
-    private static String APPLICATION_XML_CONTENT_TYPE = "application/xml";
-    private static String TEXT_XML_CONTENT_TYPE = "text/xml";
+    private static final String APPLICATION_XML_CONTENT_TYPE = "application/xml";
+    private static final String TEXT_XML_CONTENT_TYPE = "text/xml";
     
     //private boolean _writeDummyForm = false;
     //private Set _dummyFormParams = null;
@@ -73,6 +74,8 @@ public class HtmlResponseWriterImpl
     
     private String _contentType;
     
+    private String _writerContentTypeMode;
+    
     /**
      * This var prevents check if the contentType is for xhtml multiple times.
      */
@@ -96,7 +99,7 @@ public class HtmlResponseWriterImpl
 
     private boolean _cdataOpen;
 
-    private static final Set<String> s_emptyHtmlElements = new HashSet<String>();
+    private static final Set<String> S_EMPTY_HTML_ELEMENTS = new HashSet<String>();
 
     private static final String CDATA_START = "<![CDATA[ \n";
     private static final String CDATA_START_NO_LINE_RETURN = "<![CDATA[";
@@ -110,19 +113,19 @@ public class HtmlResponseWriterImpl
 
     static
     {
-        s_emptyHtmlElements.add("area");
-        s_emptyHtmlElements.add("br");
-        s_emptyHtmlElements.add("base");
-        s_emptyHtmlElements.add("basefont");
-        s_emptyHtmlElements.add("col");
-        s_emptyHtmlElements.add("frame");
-        s_emptyHtmlElements.add("hr");
-        s_emptyHtmlElements.add("img");
-        s_emptyHtmlElements.add("input");
-        s_emptyHtmlElements.add("isindex");
-        s_emptyHtmlElements.add("link");
-        s_emptyHtmlElements.add("meta");
-        s_emptyHtmlElements.add("param");
+        S_EMPTY_HTML_ELEMENTS.add("area");
+        S_EMPTY_HTML_ELEMENTS.add("br");
+        S_EMPTY_HTML_ELEMENTS.add("base");
+        S_EMPTY_HTML_ELEMENTS.add("basefont");
+        S_EMPTY_HTML_ELEMENTS.add("col");
+        S_EMPTY_HTML_ELEMENTS.add("frame");
+        S_EMPTY_HTML_ELEMENTS.add("hr");
+        S_EMPTY_HTML_ELEMENTS.add("img");
+        S_EMPTY_HTML_ELEMENTS.add("input");
+        S_EMPTY_HTML_ELEMENTS.add("isindex");
+        S_EMPTY_HTML_ELEMENTS.add("link");
+        S_EMPTY_HTML_ELEMENTS.add("meta");
+        S_EMPTY_HTML_ELEMENTS.add("param");
     }
 
     public HtmlResponseWriterImpl(Writer writer, String contentType, String characterEncoding)
@@ -131,7 +134,15 @@ public class HtmlResponseWriterImpl
     }
 
     public HtmlResponseWriterImpl(Writer writer, String contentType, String characterEncoding,
-             boolean wrapScriptContentWithXmlCommentTag)
+            boolean wrapScriptContentWithXmlCommentTag)
+    {
+        this(writer,contentType, characterEncoding, wrapScriptContentWithXmlCommentTag, 
+                contentType != null && HtmlRendererUtils.isXHTMLContentType(contentType) ? 
+                    ContentTypeUtils.XHTML_CONTENT_TYPE : ContentTypeUtils.HTML_CONTENT_TYPE);
+    }
+    
+    public HtmlResponseWriterImpl(Writer writer, String contentType, String characterEncoding,
+             boolean wrapScriptContentWithXmlCommentTag, String writerContentTypeMode)
     throws FacesException
     {
         _outputWriter = writer;
@@ -143,17 +154,25 @@ public class HtmlResponseWriterImpl
         _contentType = contentType;
         if (_contentType == null)
         {
-            if (log.isLoggable(Level.FINE)) log.fine("No content type given, using default content type " + DEFAULT_CONTENT_TYPE);
+            if (log.isLoggable(Level.FINE))
+            {
+                log.fine("No content type given, using default content type " + DEFAULT_CONTENT_TYPE);
+            }
             _contentType = DEFAULT_CONTENT_TYPE;
         }
-        _isXhtmlContentType = HtmlRendererUtils.isXHTMLContentType(_contentType);
+        _writerContentTypeMode = writerContentTypeMode;
+        _isXhtmlContentType = writerContentTypeMode.indexOf(ContentTypeUtils.XHTML_CONTENT_TYPE) != -1;
         
-        _useStraightXml = _contentType.indexOf(APPLICATION_XML_CONTENT_TYPE) != -1 ||
-                          _contentType.indexOf(TEXT_XML_CONTENT_TYPE) != -1;
+        _useStraightXml = _isXhtmlContentType && (_contentType.indexOf(APPLICATION_XML_CONTENT_TYPE) != -1 ||
+                          _contentType.indexOf(TEXT_XML_CONTENT_TYPE) != -1);
 
         if (characterEncoding == null)
         {
-            if (log.isLoggable(Level.FINE)) log.fine("No character encoding given, using default character encoding " + DEFAULT_CHARACTER_ENCODING);
+            if (log.isLoggable(Level.FINE))
+            {
+                log.fine("No character encoding given, using default character encoding " +
+                        DEFAULT_CHARACTER_ENCODING);
+            }
             _characterEncoding = DEFAULT_CHARACTER_ENCODING;
         }
         else
@@ -182,7 +201,9 @@ public class HtmlResponseWriterImpl
             String supportedContentType = supportedContentTypes[i];
 
             if(supportedContentType.indexOf(contentType)!=-1)
+            {
                 return true;
+            }
         }
         return false;
     }
@@ -191,6 +212,11 @@ public class HtmlResponseWriterImpl
     {
         return _contentType;
     }
+    
+    public String getWriterContentTypeMode()
+    {
+        return _writerContentTypeMode;
+    }
 
     public String getCharacterEncoding()
     {
@@ -251,7 +277,8 @@ public class HtmlResponseWriterImpl
     }
 
     @Override
-    public void startCDATA() throws IOException {
+    public void startCDATA() throws IOException
+    {
         if (!_cdataOpen)
         {
             write(CDATA_START_NO_LINE_RETURN);
@@ -260,7 +287,8 @@ public class HtmlResponseWriterImpl
     }
 
     @Override
-    public void endCDATA() throws IOException {
+    public void endCDATA() throws IOException
+    {
         if (_cdataOpen)
         {
             write(CDATA_END_NO_LINE_RETURN);
@@ -272,7 +300,7 @@ public class HtmlResponseWriterImpl
     {
         if (_startTagOpen)
         {
-            if (!_useStraightXml && s_emptyHtmlElements.contains(_startElementName.toLowerCase()))
+            if (!_useStraightXml && S_EMPTY_HTML_ELEMENTS.contains(_startElementName.toLowerCase()))
             {
                 _currentWriter.write(" />");
                 // make null, this will cause NullPointer in some invalid element nestings
@@ -366,13 +394,14 @@ public class HtmlResponseWriterImpl
         }
         else
         {
-            if (!_useStraightXml && s_emptyHtmlElements.contains(name.toLowerCase()))
+            if (!_useStraightXml && S_EMPTY_HTML_ELEMENTS.contains(name.toLowerCase()))
             {
            /*
            Should this be here?  It warns even when you have an x:htmlTag value="br", it should just close.
 
                 if (log.isWarnEnabled())
-                    log.warn("HTML nesting warning on closing " + name + ": This element must not contain nested elements or text in HTML");
+                    log.warn("HTML nesting warning on closing " + name + 
+                        ": This element must not contain nested elements or text in HTML");
                     */
             }
             else
@@ -410,17 +439,20 @@ public class HtmlResponseWriterImpl
             // simple CDATA without comments, but note we need to check
             // when we are using any valid notation (simple CDATA, commented CDATA, xml comment) 
             String trimmedContent = content.trim();
-            if (trimmedContent.startsWith(CommentUtils.CDATA_SIMPLE_START) && trimmedContent.endsWith(CommentUtils.CDATA_SIMPLE_END))
+            if (trimmedContent.startsWith(CommentUtils.CDATA_SIMPLE_START) && trimmedContent.endsWith(
+                    CommentUtils.CDATA_SIMPLE_END))
             {
                 _outputWriter.write(content);
                 return;
             }
-            else if (CommentUtils.isStartMatchWithCommentedCDATA(trimmedContent) && CommentUtils.isEndMatchWithCommentedCDATA(trimmedContent))
+            else if (CommentUtils.isStartMatchWithCommentedCDATA(trimmedContent) && 
+                    CommentUtils.isEndMatchWithCommentedCDATA(trimmedContent))
             {
                 _outputWriter.write(content);
                 return;
             }
-            else if (trimmedContent.startsWith(CommentUtils.COMMENT_SIMPLE_START) && trimmedContent.endsWith(CommentUtils.COMMENT_SIMPLE_END))
+            else if (trimmedContent.startsWith(CommentUtils.COMMENT_SIMPLE_START) && 
+                    trimmedContent.endsWith(CommentUtils.COMMENT_SIMPLE_END))
             {
                 //Use comment wrap is valid, but for xhtml it is preferred to use CDATA
                 _outputWriter.write(CDATA_START);
@@ -478,12 +510,14 @@ public class HtmlResponseWriterImpl
                 
                 return;
             }
-            else if (CommentUtils.isStartMatchWithCommentedCDATA(trimmedContent) && CommentUtils.isEndMatchWithCommentedCDATA(trimmedContent))
+            else if (CommentUtils.isStartMatchWithCommentedCDATA(trimmedContent) && 
+                    CommentUtils.isEndMatchWithCommentedCDATA(trimmedContent))
             {
                 _outputWriter.write(content);
                 return;
             }
-            else if (CommentUtils.isStartMatchWithInlineCommentedCDATA(trimmedContent) && CommentUtils.isEndMatchWithInlineCommentedCDATA(trimmedContent))
+            else if (CommentUtils.isStartMatchWithInlineCommentedCDATA(trimmedContent) && 
+                    CommentUtils.isEndMatchWithInlineCommentedCDATA(trimmedContent))
             {
                 _outputWriter.write(content);
                 return;
@@ -527,12 +561,14 @@ public class HtmlResponseWriterImpl
                     _outputWriter.write(content);
                     return;
                 }
-                else if (CommentUtils.isStartMatchWithCommentedCDATA(trimmedContent) && CommentUtils.isEndMatchWithCommentedCDATA(trimmedContent))
+                else if (CommentUtils.isStartMatchWithCommentedCDATA(trimmedContent) && 
+                        CommentUtils.isEndMatchWithCommentedCDATA(trimmedContent))
                 {
                     _outputWriter.write(content);
                     return;
                 }
-                else if (CommentUtils.isStartMatchWithInlineCommentedCDATA(trimmedContent) && CommentUtils.isEndMatchWithInlineCommentedCDATA(trimmedContent))
+                else if (CommentUtils.isStartMatchWithInlineCommentedCDATA(trimmedContent) && 
+                        CommentUtils.isEndMatchWithInlineCommentedCDATA(trimmedContent))
                 {
                     _outputWriter.write(content);
                     return;
@@ -597,7 +633,8 @@ public class HtmlResponseWriterImpl
         }
         if (!_startTagOpen)
         {
-            throw new IllegalStateException("Must be called before the start element is closed (attribute '" + name + "')");
+            throw new IllegalStateException("Must be called before the start element is closed (attribute '"
+                    + name + "')");
         }
 
         if (value instanceof Boolean)
@@ -618,7 +655,8 @@ public class HtmlResponseWriterImpl
             _currentWriter.write(' ');
             _currentWriter.write(name);
             _currentWriter.write("=\"");
-            _currentWriter.write(org.apache.myfaces.shared.renderkit.html.util.HTMLEncoder.encode(strValue, false, false, !UTF8.equals(_characterEncoding)));
+            _currentWriter.write(org.apache.myfaces.shared.renderkit.html.util.HTMLEncoder.encode(
+                    strValue, false, false, !UTF8.equals(_characterEncoding)));
             _currentWriter.write('"');
         }
     }
@@ -631,7 +669,8 @@ public class HtmlResponseWriterImpl
         }
         if (!_startTagOpen)
         {
-            throw new IllegalStateException("Must be called before the start element is closed (attribute '" + name + "')");
+            throw new IllegalStateException("Must be called before the start element is closed (attribute '"
+                    + name + "')");
         }
 
         String strValue = value.toString();
@@ -640,7 +679,8 @@ public class HtmlResponseWriterImpl
         _currentWriter.write("=\"");
         if (strValue.toLowerCase().startsWith("javascript:"))
         {
-            _currentWriter.write(org.apache.myfaces.shared.renderkit.html.util.HTMLEncoder.encode(strValue, false, false, !UTF8.equals(_characterEncoding)));
+            _currentWriter.write(org.apache.myfaces.shared.renderkit.html.util.HTMLEncoder.encode(
+                    strValue, false, false, !UTF8.equals(_characterEncoding)));
         }
         else
         {
@@ -672,7 +712,9 @@ public class HtmlResponseWriterImpl
             }
             */
             //_writer.write(strValue);
-            _currentWriter.write(org.apache.myfaces.shared.renderkit.html.util.HTMLEncoder.encodeURIAtributte(strValue, _characterEncoding));
+            _currentWriter.write(
+                    org.apache.myfaces.shared.renderkit.html.util.HTMLEncoder.encodeURIAtributte(
+                            strValue, _characterEncoding));
         }
         _currentWriter.write('"');
     }
@@ -704,12 +746,19 @@ public class HtmlResponseWriterImpl
         if (isScriptOrStyle())
         {
             // Don't bother encoding anything if chosen character encoding is UTF-8
-            if (UTF8.equals(_characterEncoding)) _currentWriter.write(strValue);
-            else _currentWriter.write(UnicodeEncoder.encode(strValue) );
+            if (UTF8.equals(_characterEncoding))
+            {
+                _currentWriter.write(strValue);
+            }
+            else
+            {
+                _currentWriter.write(UnicodeEncoder.encode(strValue));
+            }
         }
         else
         {
-            _currentWriter.write(org.apache.myfaces.shared.renderkit.html.util.HTMLEncoder.encode(strValue, false, false, !UTF8.equals(_characterEncoding)));
+            _currentWriter.write(org.apache.myfaces.shared.renderkit.html.util.HTMLEncoder.encode(
+                    strValue, false, false, !UTF8.equals(_characterEncoding)));
         }
     }
 
@@ -730,18 +779,26 @@ public class HtmlResponseWriterImpl
         {
             String strValue = new String(cbuf, off, len);
             // Don't bother encoding anything if chosen character encoding is UTF-8
-            if (UTF8.equals(_characterEncoding)) _currentWriter.write(strValue);
-            else _currentWriter.write(UnicodeEncoder.encode(strValue) );
+            if (UTF8.equals(_characterEncoding))
+            {
+                _currentWriter.write(strValue);
+            }
+            else
+            {
+                _currentWriter.write(UnicodeEncoder.encode(strValue));
+            }
         }
         else if (isTextarea())
         {
             // For textareas we must *not* map successive spaces to &nbsp or Newlines to <br/>
-            org.apache.myfaces.shared.renderkit.html.util.HTMLEncoder.encode(cbuf, off, len, false, false, !UTF8.equals(_characterEncoding), _currentWriter);
+            org.apache.myfaces.shared.renderkit.html.util.HTMLEncoder.encode(
+                    cbuf, off, len, false, false, !UTF8.equals(_characterEncoding), _currentWriter);
         }
         else
         {
             // We map successive spaces to &nbsp; and Newlines to <br/>
-            org.apache.myfaces.shared.renderkit.html.util.HTMLEncoder.encode(cbuf, off, len, true, true, !UTF8.equals(_characterEncoding), _currentWriter);
+            org.apache.myfaces.shared.renderkit.html.util.HTMLEncoder.encode(
+                    cbuf, off, len, true, true, !UTF8.equals(_characterEncoding), _currentWriter);
         }
     }
 
@@ -820,7 +877,8 @@ public class HtmlResponseWriterImpl
     public ResponseWriter cloneWithWriter(Writer writer)
     {
         HtmlResponseWriterImpl newWriter
-                = new HtmlResponseWriterImpl(writer, getContentType(), getCharacterEncoding(), _wrapScriptContentWithXmlCommentTag);
+                = new HtmlResponseWriterImpl(writer, getContentType(), getCharacterEncoding(), 
+                        _wrapScriptContentWithXmlCommentTag, _writerContentTypeMode);
         //newWriter._writeDummyForm = _writeDummyForm;
         //newWriter._dummyFormParams = _dummyFormParams;
         return newWriter;
@@ -840,8 +898,14 @@ public class HtmlResponseWriterImpl
         closeStartTagIfNecessary();
         String strValue = new String(cbuf, off, len);
         // Don't bother encoding anything if chosen character encoding is UTF-8
-        if (UTF8.equals(_characterEncoding)) _currentWriter.write(strValue);
-        else _currentWriter.write(UnicodeEncoder.encode(strValue) );
+        if (UTF8.equals(_characterEncoding))
+        {
+            _currentWriter.write(strValue);
+        }
+        else
+        {
+            _currentWriter.write(UnicodeEncoder.encode(strValue));
+        }
     }
 
     public void write(int c) throws IOException
@@ -855,8 +919,14 @@ public class HtmlResponseWriterImpl
         closeStartTagIfNecessary();
         String strValue = new String(cbuf);
         // Don't bother encoding anything if chosen character encoding is UTF-8
-        if (UTF8.equals(_characterEncoding)) _currentWriter.write(strValue);
-        else _currentWriter.write(UnicodeEncoder.encode(strValue) );
+        if (UTF8.equals(_characterEncoding))
+        {
+            _currentWriter.write(strValue);
+        }
+        else
+        {
+            _currentWriter.write(UnicodeEncoder.encode(strValue));
+        }
     }
 
     public void write(String str) throws IOException
@@ -867,8 +937,14 @@ public class HtmlResponseWriterImpl
         if (str.length() > 0)
         {
             // Don't bother encoding anything if chosen character encoding is UTF-8
-            if (UTF8.equals(_characterEncoding)) _currentWriter.write(str);
-            else _currentWriter.write(UnicodeEncoder.encode(str) );
+            if (UTF8.equals(_characterEncoding))
+            {
+                _currentWriter.write(str);
+            }
+            else
+            {
+                _currentWriter.write(UnicodeEncoder.encode(str));
+            }
         }
     }
 
@@ -877,8 +953,14 @@ public class HtmlResponseWriterImpl
         closeStartTagIfNecessary();
         String strValue = str.substring(off, off+len);
         // Don't bother encoding anything if chosen character encoding is UTF-8
-        if (UTF8.equals(_characterEncoding)) _currentWriter.write(strValue);
-        else _currentWriter.write(UnicodeEncoder.encode(strValue) );
+        if (UTF8.equals(_characterEncoding))
+        {
+            _currentWriter.write(strValue);
+        }
+        else
+        {
+            _currentWriter.write(UnicodeEncoder.encode(strValue));
+        }
     }
     
     /**

Modified: myfaces/shared/trunk_4.0.x/core/src/main/resources/META-INF/myfaces-metadata.xml
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk_4.0.x/core/src/main/resources/META-INF/myfaces-metadata.xml?rev=1208717&r1=1208716&r2=1208717&view=diff
==============================================================================
--- myfaces/shared/trunk_4.0.x/core/src/main/resources/META-INF/myfaces-metadata.xml (original)
+++ myfaces/shared/trunk_4.0.x/core/src/main/resources/META-INF/myfaces-metadata.xml Wed Nov 30 19:27:10 2011
@@ -8104,6 +8104,19 @@ To ensure strict compatibility with the 
       <group>EL</group>
     </webConfigParam>
     <webConfigParam>
+      <name>org.apache.myfaces.DEFAULT_RESPONSE_WRITER_CONTENT_TYPE_MODE</name>
+      <fieldName>INIT_PARAM_DEFAULT_RESPONSE_WRITER_CONTENT_TYPE_MODE</fieldName>
+      <desc>Define the default content type that the default ResponseWriter generates, when no match can be derived from
+HTTP Accept Header</desc>
+      <longDesc>Define the default content type that the default ResponseWriter generates, when no match can be derived from
+HTTP Accept Header.</longDesc>
+      <defaultValue>text/html</defaultValue>
+      <expectedValues>text/html, application/xhtml+xml</expectedValues>
+      <sourceClassName>org.apache.myfaces.shared.config.MyfacesConfig</sourceClassName>
+      <since>2.0.11,2.1.5</since>
+      <group>render</group>
+    </webConfigParam>
+    <webConfigParam>
       <name>org.apache.myfaces.FLASH_SCOPE_DISABLED</name>
       <fieldName>FLASH_SCOPE_DISABLED_PARAM</fieldName>
       <desc>Defines whether flash scope is disabled, preventing add the Flash cookie to the response</desc>