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/09/18 15:59:54 UTC

svn commit: r289920 - /myfaces/impl/trunk/src/java/org/apache/myfaces/renderkit/html/HtmlRenderKitImpl.java

Author: mmarinschek
Date: Sun Sep 18 06:59:50 2005
New Revision: 289920

URL: http://svn.apache.org/viewcvs?rev=289920&view=rev
Log:
better script support

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=289920&r1=289919&r2=289920&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 Sun Sep 18 06:59:50 2005
@@ -20,7 +20,6 @@
 
 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;
@@ -38,17 +37,6 @@
     extends RenderKit
 {
     private static final Log log = LogFactory.getLog(HtmlRenderKitImpl.class);
-    private static String HTML_CONTENT_TYPE = "text/html";
-    private static String FORM_SUBMIT_APPLICATION_WWW_FORM_URLENCODED_CONTENT_TYPE ="application/x-www-form-urlencoded";
-    private static String FORM_SUBMIT_MULTIPART_FORM_DATA_CONTENT_TYPE="multipart/form-data";
-    private static String ANY_CONTENT_TYPE ="*/*";
-
-    //todo: enable these as soon as myfaces supports proper text/xml
-    /*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 ----------------------------------------------------------------------------
 
@@ -114,97 +102,14 @@
                                                String contentTypeListString,
                                                String characterEncoding)
     {
-        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,
-                /*todo: enable these as soon as MyFaces supports proper text/xml markup
-                XHTML_CONTENT_TYPE,APPLICATION_XML_CONTENT_TYPE,TEXT_XML_CONTENT_TYPE,*/
-                FORM_SUBMIT_APPLICATION_WWW_FORM_URLENCODED_CONTENT_TYPE,
-                FORM_SUBMIT_MULTIPART_FORM_DATA_CONTENT_TYPE,
-                ANY_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 ||
-                                contentType.indexOf(FORM_SUBMIT_APPLICATION_WWW_FORM_URLENCODED_CONTENT_TYPE) != -1 ||
-                                contentType.indexOf(FORM_SUBMIT_MULTIPART_FORM_DATA_CONTENT_TYPE) != -1 ||
-                                contentType.indexOf(ANY_CONTENT_TYPE)!=-1) {
-                            selectedContentType = HTML_CONTENT_TYPE;
-                        }
-                        /* todo: enable this as soon as MyFaces supports proper text/xml markup
-                        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);
-        }
+        String selectedContentType = HtmlRendererUtils.selectContentType(contentTypeListString);
 
         if(characterEncoding==null)
         {
-            characterEncoding = DEFAULT_CHAR_ENCODING;
+            characterEncoding = HtmlRendererUtils.DEFAULT_CHAR_ENCODING;
         }
 
         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();
-
-            int semicolonIndex = contentType.indexOf(";");
-
-            if (semicolonIndex!=-1)
-            {
-                contentType = contentType.substring(0,semicolonIndex);
-            }
-
-            contentTypeList.add(contentType);
-        }
-
-        return contentTypeList;
     }
 
     public ResponseStream createResponseStream(OutputStream outputStream)