You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by mm...@apache.org on 2005/08/19 13:57:32 UTC
svn commit: r233466 -
/myfaces/impl/trunk/src/java/org/apache/myfaces/renderkit/html/HtmlRenderKitImpl.java
Author: mmarinschek
Date: Fri Aug 19 04:57:27 2005
New Revision: 233466
URL: http://svn.apache.org/viewcvs?rev=233466&view=rev
Log:
fix for MYFACES-376. Thanks to Jacob Hookom for pointing us to this problem and suggesting a way to fix this.
Modified:
myfaces/impl/trunk/src/java/org/apache/myfaces/renderkit/html/HtmlRenderKitImpl.java
Modified: myfaces/impl/trunk/src/java/org/apache/myfaces/renderkit/html/HtmlRenderKitImpl.java
URL: http://svn.apache.org/viewcvs/myfaces/impl/trunk/src/java/org/apache/myfaces/renderkit/html/HtmlRenderKitImpl.java?rev=233466&r1=233465&r2=233466&view=diff
==============================================================================
--- myfaces/impl/trunk/src/java/org/apache/myfaces/renderkit/html/HtmlRenderKitImpl.java (original)
+++ myfaces/impl/trunk/src/java/org/apache/myfaces/renderkit/html/HtmlRenderKitImpl.java Fri Aug 19 04:57:27 2005
@@ -20,14 +20,13 @@
import javax.faces.context.ResponseStream;
import javax.faces.context.ResponseWriter;
+import javax.faces.context.FacesContext;
import javax.faces.render.RenderKit;
import javax.faces.render.Renderer;
import javax.faces.render.ResponseStateManager;
import java.io.OutputStream;
import java.io.Writer;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.StringTokenizer;
+import java.util.*;
/**
@@ -38,6 +37,12 @@
extends RenderKit
{
private static final Log log = LogFactory.getLog(HtmlRenderKitImpl.class);
+ private static String HTML_CONTENT_TYPE = "text/html";
+ private static String XHTML_CONTENT_TYPE = "application/xhtml+xml";
+ private static String APPLICATION_XML_CONTENT_TYPE = "application/xml";
+ private static String TEXT_XML_CONTENT_TYPE = "text/xml";
+
+ private static String DEFAULT_CHAR_ENCODING = "ISO-8859-1";
//~ Instance fields ----------------------------------------------------------------------------
@@ -80,26 +85,92 @@
}
public ResponseWriter createResponseWriter(Writer writer,
- String contentTypeList,
+ String contentTypeListString,
String characterEncoding)
{
- if (contentTypeList == null)
+ FacesContext context = FacesContext.getCurrentInstance();
+
+ if (contentTypeListString == null)
+ {
+ contentTypeListString = (String)
+ context.getExternalContext().getRequestHeaderMap().get("Accept");
+
+ if(contentTypeListString == null)
+ {
+ if (log.isDebugEnabled())
+ log.debug("No content type list given, creating HtmlResponseWriterImpl with default content type.");
+
+ contentTypeListString = HTML_CONTENT_TYPE;
+ }
+ }
+
+ List contentTypeList = splitContentTypeListString(contentTypeListString);
+ String[] supportedContentTypeArray = new String[]{HTML_CONTENT_TYPE,
+ XHTML_CONTENT_TYPE,APPLICATION_XML_CONTENT_TYPE,TEXT_XML_CONTENT_TYPE};
+
+ String selectedContentType = null;
+
+ for (int i = 0; i < contentTypeList.size(); i++)
+ {
+ String contentType = (String) contentTypeList.get(i);
+
+ for (int j = 0; j < supportedContentTypeArray.length; j++)
+ {
+ String supportedContentType = supportedContentTypeArray[j].trim();
+
+ if (contentType.indexOf(supportedContentType) != -1)
+ {
+ if (contentType.indexOf(HTML_CONTENT_TYPE) != -1) {
+ selectedContentType = HTML_CONTENT_TYPE;
+ }
+ else if (contentType.indexOf(XHTML_CONTENT_TYPE) != -1 ||
+ contentType.indexOf(APPLICATION_XML_CONTENT_TYPE) != -1 ||
+ contentType.indexOf(TEXT_XML_CONTENT_TYPE) != -1) {
+ selectedContentType = XHTML_CONTENT_TYPE;
+ }
+ break;
+ }
+ }
+ if (selectedContentType!=null)
+ {
+ break;
+ }
+ }
+
+ if(selectedContentType==null)
+ {
+ throw new IllegalArgumentException("ContentTypeList does not contain a supported content type: " +
+ contentTypeListString);
+ }
+
+ if(characterEncoding==null)
{
- if (log.isInfoEnabled()) log.debug("No content type list given, creating HtmlResponseWriterImpl with default content type.");
- return new HtmlResponseWriterImpl(writer, null, characterEncoding);
+ characterEncoding = DEFAULT_CHAR_ENCODING;
}
- StringTokenizer st = new StringTokenizer(contentTypeList, ",");
+ return new HtmlResponseWriterImpl(writer, selectedContentType, characterEncoding);
+ }
+
+ private List splitContentTypeListString(String contentTypeListString)
+ {
+ List contentTypeList = new ArrayList();
+
+ StringTokenizer st = new StringTokenizer(contentTypeListString, ",");
while (st.hasMoreTokens())
{
String contentType = st.nextToken().trim();
- if (HtmlResponseWriterImpl.supportsContentType(contentType))
+
+ int semicolonIndex = contentType.indexOf(";");
+
+ if (semicolonIndex!=-1)
{
- return new HtmlResponseWriterImpl(writer, contentType, characterEncoding);
+ contentType = contentType.substring(0,semicolonIndex);
}
+
+ contentTypeList.add(contentType);
}
- throw new IllegalArgumentException("ContentTypeList does not contain a supported content type: " + contentTypeList);
+ return contentTypeList;
}
public ResponseStream createResponseStream(OutputStream outputstream)