]> source.dussan.org Git - poi.git/commitdiff
47179 - Fix string encoding issues with HSMF chunks on non-windows platforms
authorNick Burch <nick@apache.org>
Sat, 16 May 2009 19:12:30 +0000 (19:12 +0000)
committerNick Burch <nick@apache.org>
Sat, 16 May 2009 19:12:30 +0000 (19:12 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@775508 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/changes.xml
src/documentation/content/xdocs/status.xml
src/scratchpad/src/org/apache/poi/hsmf/datatypes/StringChunk.java
src/scratchpad/testcases/org/apache/poi/hsmf/model/TestBlankFileRead.java

index 34b1327028e36047cd2d86c007462a934b877a28..c378bc5a42337abde82935faafba225e4e3e3e1b 100644 (file)
@@ -37,6 +37,7 @@
 
                <!-- Don't forget to update status.xml too! -->
         <release version="3.5-beta6" date="2009-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">47179 - Fix string encoding issues with HSMF chunks on non-windows platforms</action>
            <action dev="POI-DEVELOPERS" type="add">47183 - Attachment support for HSMF</action>
            <action dev="POI-DEVELOPERS" type="fix">47154 - Handle the cell format @ as the same as General</action>
            <action dev="POI-DEVELOPERS" type="fix">47048 - Fixed evaluation of defined names with the 'complex' flag set</action>
index bfbefcfab07d49e5822baa4340e469f44a509cc5..1a00c9ee03a189466d489b0bb3b0e0f7a4686fe3 100644 (file)
@@ -34,6 +34,7 @@
        <!-- Don't forget to update changes.xml too! -->
     <changes>
         <release version="3.5-beta6" date="2009-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">47179 - Fix string encoding issues with HSMF chunks on non-windows platforms</action>
            <action dev="POI-DEVELOPERS" type="add">47183 - Attachment support for HSMF</action>
            <action dev="POI-DEVELOPERS" type="fix">47154 - Handle the cell format @ as the same as General</action>
            <action dev="POI-DEVELOPERS" type="fix">47048 - Fixed evaluation of defined names with the 'complex' flag set</action>
index fe90bd68847e960d971c0e3bb71512034d4679af..ddeb1682962b8b7dbfe7ae25b33f5d9ab2de45b7 100644 (file)
@@ -18,6 +18,9 @@
 package org.apache.poi.hsmf.datatypes;
 
 import java.io.ByteArrayOutputStream;
+import java.io.UnsupportedEncodingException;
+
+import org.apache.poi.hsmf.datatypes.Types;
 
 /**
  * A Chunk made up of a single string.
@@ -61,7 +64,21 @@ public class StringChunk extends Chunk {
         * @see org.apache.poi.hsmf.Chunk.Chunk#setValue(java.io.ByteArrayOutputStream)
         */
        public void setValue(ByteArrayOutputStream value) {
-               this.value = value.toString().replaceAll("\0", "");
+               String tmpValue;
+               if (type == Types.NEW_STRING) {
+                       try {
+                               tmpValue = new String(value.toByteArray(), "UTF-16LE");
+                       } catch (UnsupportedEncodingException e) {
+                               throw new RuntimeException("Core encoding not found, JVM broken?", e);
+                       }
+               } else {
+                       try {
+                               tmpValue = new String(value.toByteArray(), "CP1252");
+                       } catch (UnsupportedEncodingException e) {
+                               throw new RuntimeException("Core encoding not found, JVM broken?", e);
+                       }
+               }
+               this.value = tmpValue.replace("\0", "");
        }
 
        public String toString() {
index 314cc506c4c1ef6c727012ded3852a0eb6083e30..5cb99cbf83dd53b028c21f234d8db4e820debc63 100644 (file)
@@ -68,7 +68,7 @@ public class TestBlankFileRead extends TestCase {
                String obtained = mapiMessage.getDisplayCC();
                String expected = "";
                
-               TestCase.assertEquals(obtained, expected);
+               TestCase.assertEquals(expected, obtained);
        }
        
        /**
@@ -80,7 +80,7 @@ public class TestBlankFileRead extends TestCase {
                String obtained = mapiMessage.getDisplayTo();
                String expected = "";
                
-               TestCase.assertEquals(obtained, expected);
+               TestCase.assertEquals(expected, obtained);
        }
        
        /**
@@ -107,7 +107,7 @@ public class TestBlankFileRead extends TestCase {
                String obtained = mapiMessage.getDisplayBCC();
                String expected = "";
                
-               TestCase.assertEquals(obtained, expected);
+               TestCase.assertEquals(expected, obtained);
        }