From beb8c490b0496306ef08d3a08f03977e14b2718f Mon Sep 17 00:00:00 2001
From: maximesinclair <maxime.sinclair@gmail.com>
Date: Fri, 13 Sep 2013 19:55:07 +0200
Subject: [PATCH] [BUGFIX] Text/plain outputs always in unicode

---
 .../java/net/sourceforge/plantuml/servlet/AsciiServlet.java | 2 +-
 .../net/sourceforge/plantuml/servlet/DiagramResponse.java   | 6 +++---
 .../java/net/sourceforge/plantuml/servlet/MapServlet.java   | 2 +-
 .../java/net/sourceforge/plantuml/servlet/AllTests.java     | 1 +
 .../java/net/sourceforge/plantuml/servlet/TestAsciiArt.java | 1 +
 src/test/java/net/sourceforge/plantuml/servlet/TestMap.java | 2 +-
 6 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/src/main/java/net/sourceforge/plantuml/servlet/AsciiServlet.java b/src/main/java/net/sourceforge/plantuml/servlet/AsciiServlet.java
index ca21cac..2c931c0 100644
--- a/src/main/java/net/sourceforge/plantuml/servlet/AsciiServlet.java
+++ b/src/main/java/net/sourceforge/plantuml/servlet/AsciiServlet.java
@@ -44,7 +44,7 @@ public class AsciiServlet extends UmlDiagramService {
 
     @Override
     public FileFormat getOutputFormat() {
-        return FileFormat.ATXT;
+        return FileFormat.UTXT;
     }
 
 }
diff --git a/src/main/java/net/sourceforge/plantuml/servlet/DiagramResponse.java b/src/main/java/net/sourceforge/plantuml/servlet/DiagramResponse.java
index 930b72f..223daf5 100644
--- a/src/main/java/net/sourceforge/plantuml/servlet/DiagramResponse.java
+++ b/src/main/java/net/sourceforge/plantuml/servlet/DiagramResponse.java
@@ -24,11 +24,11 @@
 package net.sourceforge.plantuml.servlet;
 
 import java.io.IOException;
+import java.io.PrintWriter;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
-import javax.servlet.ServletOutputStream;
 import javax.servlet.http.HttpServletResponse;
 
 import net.sourceforge.plantuml.FileFormat;
@@ -49,7 +49,7 @@ class DiagramResponse {
         Map<FileFormat, String> map = new HashMap<FileFormat, String>();
         map.put(FileFormat.PNG, "image/png");
         map.put(FileFormat.SVG, "image/svg+xml");
-        map.put(FileFormat.ATXT, "text/plain;charset=ISO-8859-1");
+        map.put(FileFormat.UTXT, "text/plain;charset=UTF-8");
         contentType = Collections.unmodifiableMap(map);
     }
 
@@ -76,7 +76,7 @@ class DiagramResponse {
         SourceStringReader reader = new SourceStringReader(uml);
         String map = reader.generateImage(new NullOutputStream(), new FileFormatOption(FileFormat.PNG));
         String[] mapLines = map.split("[\\r\\n]");
-        ServletOutputStream httpOut = response.getOutputStream();
+        PrintWriter httpOut = response.getWriter();
         for (int i=2; (i+1)<mapLines.length; i++) {
             httpOut.print(mapLines[i]);
         }
diff --git a/src/main/java/net/sourceforge/plantuml/servlet/MapServlet.java b/src/main/java/net/sourceforge/plantuml/servlet/MapServlet.java
index a506579..401f9c5 100644
--- a/src/main/java/net/sourceforge/plantuml/servlet/MapServlet.java
+++ b/src/main/java/net/sourceforge/plantuml/servlet/MapServlet.java
@@ -68,7 +68,7 @@ public class MapServlet extends HttpServlet {
     }
 
     public FileFormat getOutputFormat() {
-        return FileFormat.ATXT;
+        return FileFormat.UTXT;
     }
 
 }
diff --git a/src/test/java/net/sourceforge/plantuml/servlet/AllTests.java b/src/test/java/net/sourceforge/plantuml/servlet/AllTests.java
index e6db354..cfcda0e 100644
--- a/src/test/java/net/sourceforge/plantuml/servlet/AllTests.java
+++ b/src/test/java/net/sourceforge/plantuml/servlet/AllTests.java
@@ -14,6 +14,7 @@ public class AllTests extends TestSuite {
         suite.addTestSuite(TestSVG.class);
         suite.addTestSuite(TestProxy.class);
         suite.addTestSuite(TestMap.class);
+        suite.addTestSuite(TestCharset.class);
         // $JUnit-END$
         return suite;
     }
diff --git a/src/test/java/net/sourceforge/plantuml/servlet/TestAsciiArt.java b/src/test/java/net/sourceforge/plantuml/servlet/TestAsciiArt.java
index 4143ca6..ad66186 100644
--- a/src/test/java/net/sourceforge/plantuml/servlet/TestAsciiArt.java
+++ b/src/test/java/net/sourceforge/plantuml/servlet/TestAsciiArt.java
@@ -17,6 +17,7 @@ public class TestAsciiArt extends WebappTestCase {
         // Analyze response
         // Verifies the Content-Type header
         assertEquals("Response content type is not TEXT PLAIN", "text/plain", response.getContentType());
+        assertEquals("Response character set is not UTF-8", "UTF-8", response.getCharacterSet());
         // Get the content and verify its size
         String diagram = response.getText();
         int diagramLen = diagram.length();
diff --git a/src/test/java/net/sourceforge/plantuml/servlet/TestMap.java b/src/test/java/net/sourceforge/plantuml/servlet/TestMap.java
index af7612d..fda2bce 100644
--- a/src/test/java/net/sourceforge/plantuml/servlet/TestMap.java
+++ b/src/test/java/net/sourceforge/plantuml/servlet/TestMap.java
@@ -19,7 +19,7 @@ public class TestMap extends WebappTestCase {
         // Analyze response
         // Verifies the Content-Type header
         assertEquals("Response content type is not TEXT PLAIN", "text/plain", response.getContentType()); 
-        assertEquals("Response character set is not ISO-8859-1", "ISO-8859-1", response.getCharacterSet());
+        assertEquals("Response character set is not UTF-8", "UTF-8", response.getCharacterSet());
         // Get the content, check its first characters and verify its size
         String diagram = response.getText();
         assertTrue("Response content is not starting with <area", diagram.startsWith("<area"));