]> source.dussan.org Git - poi.git/commitdiff
String Continue records support (with test), from bug #41064
authorNick Burch <nick@apache.org>
Tue, 4 Dec 2007 16:55:56 +0000 (16:55 +0000)
committerNick Burch <nick@apache.org>
Tue, 4 Dec 2007 16:55:56 +0000 (16:55 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@600995 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/changes.xml
src/documentation/content/xdocs/status.xml
src/java/org/apache/poi/hssf/record/RecordFactory.java
src/java/org/apache/poi/hssf/record/StringRecord.java
src/java/org/apache/poi/util/StringUtil.java
src/testcases/org/apache/poi/hssf/data/StringContinueRecords.xls [new file with mode: 0644]
src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java

index 829fb4d18a0d0a4efe505de0c0e666243feecab2..ef6511128ee1addb04a50f31e537ae49c5a34533 100644 (file)
@@ -36,6 +36,7 @@
 
                <!-- Don't forget to update status.xml too! -->
         <release version="3.0.2-FINAL" date="2007-??-??">
+            <action dev="POI-DEVELOPERS" type="add">41064 - [PATCH] Support for String continue records</action>
             <action dev="POI-DEVELOPERS" type="add">27511 - [PATCH] Support for data validation, via DVRecord and DVALRecord</action>
             <action dev="POI-DEVELOPERS" type="fix">43877 and 39512 - Fix for handling mixed OBJ and CONTINUE records.</action>
             <action dev="POI-DEVELOPERS" type="fix">43807 - Throw an IllegalArgumentException if asked to create a merged region with invalid columns or rows, rather than writing out a corrupt file</action>
index 18a30501714de3a4560a8d444621e1bed67fd967..d09ccb87cc35bc5f90eeaf276117694fde80955f 100644 (file)
@@ -33,6 +33,7 @@
        <!-- Don't forget to update changes.xml too! -->
     <changes>
         <release version="3.0.2-FINAL" date="2007-??-??">
+            <action dev="POI-DEVELOPERS" type="add">41064 - [PATCH] Support for String continue records</action>
             <action dev="POI-DEVELOPERS" type="add">27511 - [PATCH] Support for data validation, via DVRecord and DVALRecord</action>
             <action dev="POI-DEVELOPERS" type="fix">43877 - Fix for handling mixed OBJ and CONTINUE records</action>
             <action dev="POI-DEVELOPERS" type="fix">39512 - Fix for handling mixed OBJ and CONTINUE records</action>
index 984291cdb0be7c09d9a7ee1bfe8126ce8178e25d..cf705a316d2a8bca396c356e14f3e587cd60be56 100644 (file)
@@ -147,6 +147,9 @@ public class RecordFactory
                         } else if (record.getSid() == ContinueRecord.sid &&
                                    (lastRecord instanceof DrawingGroupRecord)) {
                             ((DrawingGroupRecord)lastRecord).processContinueRecord(((ContinueRecord)record).getData());
+                        } else if (record.getSid() == ContinueRecord.sid &&
+                                               (lastRecord instanceof StringRecord)) {
+                               ((StringRecord)lastRecord).processContinueRecord(((ContinueRecord)record).getData());
                         } else if (record.getSid() == ContinueRecord.sid) {
                           if (lastRecord instanceof UnknownRecord) {
                             //Gracefully handle records that we dont know about,
index a880d7235b1e4d7fb7c59fea7861622b95fc25fb..b3a42aaba4eeb5853a428b19fb3a136a25270619 100644 (file)
@@ -83,6 +83,14 @@ public class StringRecord
             field_3_string = StringUtil.getFromCompressedUnicode(data, 0, field_1_string_length);
         }
     }
+    
+    public void processContinueRecord(byte[] data) {
+       if(isUnCompressedUnicode()) {
+               field_3_string += StringUtil.getFromUnicodeLE(data, 0, field_1_string_length - field_3_string.length());
+       } else {
+               field_3_string += StringUtil.getFromCompressedUnicode(data, 0, field_1_string_length - field_3_string.length());
+       }
+    }
 
     public boolean isInValueSection()
     {
index 9dd8e4838ec4a73aa1902f5e7afc607d5d7eaa6d..673b5246e147c9de21ca6be0951e22ee360eaacd 100644 (file)
@@ -161,7 +161,8 @@ public class StringUtil {
                final int offset,
                final int len) {
                try {
-                       return new String(string, offset, len, "ISO-8859-1");
+                       int len_to_use = Math.min(len, string.length - offset);
+                       return new String(string, offset, len_to_use, "ISO-8859-1");
                } catch (UnsupportedEncodingException e) {
                        throw new InternalError(); /* unreachable */
                }
diff --git a/src/testcases/org/apache/poi/hssf/data/StringContinueRecords.xls b/src/testcases/org/apache/poi/hssf/data/StringContinueRecords.xls
new file mode 100644 (file)
index 0000000..f2ada9e
Binary files /dev/null and b/src/testcases/org/apache/poi/hssf/data/StringContinueRecords.xls differ
index 027495a1b086168d91efeb9281782c6964519bb3..0aef5c765a1a52add6604cd386fdef4531593310 100644 (file)
@@ -68,6 +68,19 @@ public class TestExcelExtractor extends TestCase {
                );
        }
        
+       public void testwithContinueRecords() throws Exception {
+               String path = System.getProperty("HSSF.testdata.path");
+               FileInputStream fin = new FileInputStream(path + File.separator + "StringContinueRecords.xls");
+               
+               ExcelExtractor extractor = new ExcelExtractor(new POIFSFileSystem(fin));
+               
+               extractor.getText();
+               
+               // Has masses of text
+               // Until we fixed bug #41064, this would've
+               //   failed by now
+               assertTrue(extractor.getText().length() > 40960);
+       }
        
        public void testStringConcat() throws Exception {
                String path = System.getProperty("HSSF.testdata.path");