Author: nick
Date: Tue Dec  4 08:55:56 2007
New Revision: 600995

URL: http://svn.apache.org/viewvc?rev=600995&view=rev
Log:
String Continue records support (with test), from bug #41064

Added:
    poi/trunk/src/testcases/org/apache/poi/hssf/data/StringContinueRecords.xls  
 (with props)
Modified:
    poi/trunk/src/documentation/content/xdocs/changes.xml
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/java/org/apache/poi/hssf/record/RecordFactory.java
    poi/trunk/src/java/org/apache/poi/hssf/record/StringRecord.java
    poi/trunk/src/java/org/apache/poi/util/StringUtil.java
    
poi/trunk/src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java

Modified: poi/trunk/src/documentation/content/xdocs/changes.xml
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/changes.xml?rev=600995&r1=600994&r2=600995&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/changes.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/changes.xml Tue Dec  4 08:55:56 
2007
@@ -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>

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=600995&r1=600994&r2=600995&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Tue Dec  4 08:55:56 
2007
@@ -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>

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/RecordFactory.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/RecordFactory.java?rev=600995&r1=600994&r2=600995&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/RecordFactory.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/RecordFactory.java Tue Dec  4 
08:55:56 2007
@@ -147,6 +147,9 @@
                         } 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,

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/StringRecord.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/StringRecord.java?rev=600995&r1=600994&r2=600995&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/StringRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/StringRecord.java Tue Dec  4 
08:55:56 2007
@@ -83,6 +83,14 @@
             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()
     {

Modified: poi/trunk/src/java/org/apache/poi/util/StringUtil.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/util/StringUtil.java?rev=600995&r1=600994&r2=600995&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/util/StringUtil.java (original)
+++ poi/trunk/src/java/org/apache/poi/util/StringUtil.java Tue Dec  4 08:55:56 
2007
@@ -161,7 +161,8 @@
                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 */
                }

Added: 
poi/trunk/src/testcases/org/apache/poi/hssf/data/StringContinueRecords.xls
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/data/StringContinueRecords.xls?rev=600995&view=auto
==============================================================================
Binary file - no diff available.

Propchange: 
poi/trunk/src/testcases/org/apache/poi/hssf/data/StringContinueRecords.xls
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: 
poi/trunk/src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java?rev=600995&r1=600994&r2=600995&view=diff
==============================================================================
--- 
poi/trunk/src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java 
(original)
+++ 
poi/trunk/src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java 
Tue Dec  4 08:55:56 2007
@@ -68,6 +68,19 @@
                );
        }
        
+       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");



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to