Author: hlship
Date: Fri Oct 17 11:13:47 2008
New Revision: 705690

URL: http://svn.apache.org/viewvc?rev=705690&view=rev
Log:
TAP5-23: TextStreamResponse needs a charset
TAP5-268: UTF8 characters are not supported in the autocomplete mixin

Modified:
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/ContentType.java
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MarkupWriterFactoryImpl.java
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/util/TextStreamResponse.java
    
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/ContentTypeTest.java
    
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/services/iTunes.xml

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/ContentType.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/ContentType.java?rev=705690&r1=705689&r2=705690&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/ContentType.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/ContentType.java
 Fri Oct 17 11:13:47 2008
@@ -133,6 +133,14 @@
     }
 
     /**
+     * @return the character set (the  "charset" parameter) or null.
+     */
+    public String getCharset()
+    {
+        return getParameter(InternalConstants.CHARSET_CONTENT_TYPE_PARAMETER);
+    }
+
+    /**
      * @param key the name of the content type parameter
      * @return the value of the content type parameter
      */
@@ -212,5 +220,4 @@
     {
         return unparse();
     }
-
 }

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MarkupWriterFactoryImpl.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MarkupWriterFactoryImpl.java?rev=705690&r1=705689&r2=705690&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MarkupWriterFactoryImpl.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MarkupWriterFactoryImpl.java
 Fri Oct 17 11:13:47 2008
@@ -19,7 +19,6 @@
 import org.apache.tapestry5.dom.DefaultMarkupModel;
 import org.apache.tapestry5.dom.MarkupModel;
 import org.apache.tapestry5.dom.XMLMarkupModel;
-import org.apache.tapestry5.internal.InternalConstants;
 import org.apache.tapestry5.internal.structure.Page;
 import org.apache.tapestry5.services.MarkupWriterFactory;
 
@@ -48,7 +47,7 @@
         // The charset parameter sets the encoding attribute of the XML 
declaration, if
         // not null and if using the XML model.
 
-        return new MarkupWriterImpl(model, 
contentType.getParameter(InternalConstants.CHARSET_CONTENT_TYPE_PARAMETER));
+        return new MarkupWriterImpl(model, contentType.getCharset());
     }
 
     public MarkupWriter newMarkupWriter(String pageName)
@@ -59,5 +58,4 @@
 
         return newMarkupWriter(contentType);
     }
-
 }

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/util/TextStreamResponse.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/util/TextStreamResponse.java?rev=705690&r1=705689&r2=705690&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/util/TextStreamResponse.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/util/TextStreamResponse.java
 Fri Oct 17 11:13:47 2008
@@ -1,4 +1,4 @@
-// Copyright 2007 The Apache Software Foundation
+// Copyright 2007, 2008 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -14,9 +14,9 @@
 
 package org.apache.tapestry5.util;
 
+import org.apache.tapestry5.ContentType;
 import org.apache.tapestry5.StreamResponse;
-import static org.apache.tapestry5.ioc.internal.util.Defense.notBlank;
-import static org.apache.tapestry5.ioc.internal.util.Defense.notNull;
+import org.apache.tapestry5.ioc.internal.util.Defense;
 import org.apache.tapestry5.services.Response;
 
 import java.io.ByteArrayInputStream;
@@ -25,12 +25,36 @@
 
 public class TextStreamResponse implements StreamResponse
 {
-    private final String contentType, text;
+    private final ContentType contentType;
 
+    private final String text;
+
+    /**
+     * Constructor that defaults the character set to "utf-8".
+     */
     public TextStreamResponse(String contentType, String text)
     {
-        notBlank(contentType, "contentType");
-        notNull(text, "text");
+        this(contentType, "UTF-8", text);
+    }
+
+    /**
+     * Constructor allowing the content type and character set to the 
specified.
+     *
+     * @param contentType type of content, often "text/xml"
+     * @param charset     character set of output, usually "UTF-8"
+     * @param text        text to be streamed in the response
+     * @see org.apache.tapestry5.SymbolConstants#CHARSET
+     */
+    public TextStreamResponse(String contentType, String charset, String text)
+    {
+        this(new ContentType(Defense.notBlank(contentType, "contentType"),
+                             Defense.notBlank(charset, "charset")), text);
+    }
+
+    public TextStreamResponse(ContentType contentType, String text)
+    {
+        Defense.notNull(contentType, "contentType");
+        Defense.notNull(text, "text");
 
         this.contentType = contentType;
         this.text = text;
@@ -38,17 +62,28 @@
 
     public String getContentType()
     {
-        return contentType;
+        return contentType.toString();
     }
 
+    /**
+     * Converts the text to a byte array (as per the character set, which is 
usually "UTF-8"), and returns a stream for
+     * that byte array.
+     *
+     * @return the text as a byte array stram
+     * @throws IOException
+     */
     public InputStream getStream() throws IOException
     {
-        return new ByteArrayInputStream(text.getBytes());
+        byte[] textBytes = text.getBytes(contentType.getCharset());
+
+        return new ByteArrayInputStream(textBytes);
     }
 
+    /**
+     * Does nothing; subclasses may override.
+     */
     public void prepareResponse(Response response)
     {
-        // No-op by default.
-    }
 
+    }
 }

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/ContentTypeTest.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/ContentTypeTest.java?rev=705690&r1=705689&r2=705690&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/ContentTypeTest.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/ContentTypeTest.java
 Fri Oct 17 11:13:47 2008
@@ -70,8 +70,7 @@
 
         assertEquals(parameterNames.get(0), "charset");
 
-        String charset = contentType.getParameter("charset");
-        assertEquals(charset, "utf-8");
+        assertEquals(contentType.getCharset(), "utf-8");
 
         String nonexistant = contentType.getParameter("nonexistant");
         assertTrue(nonexistant == null);

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/services/iTunes.xml
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/services/iTunes.xml?rev=705690&r1=705689&r2=705690&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/services/iTunes.xml
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/services/iTunes.xml
 Fri Oct 17 11:13:47 2008
@@ -46104,7 +46104,7 @@
                <key>1943</key>
                <dict>
                        <key>Track ID</key><integer>1943</integer>
-                       <key>Name</key><string>Give It Away</string>
+                       <key>Name</key><string>Give It Away: Mü</string>
                        <key>Artist</key><string>Zero 7</string>
                        <key>Album Artist</key><string>Zero 7</string>
                        <key>Album</key><string>Simple Things</string>


Reply via email to