You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2008/12/09 20:36:53 UTC

svn commit: r724848 - in /poi/trunk/src: documentation/content/xdocs/ java/org/apache/poi/hssf/record/ java/org/apache/poi/hssf/usermodel/ testcases/org/apache/poi/hssf/usermodel/

Author: nick
Date: Tue Dec  9 11:36:53 2008
New Revision: 724848

URL: http://svn.apache.org/viewvc?rev=724848&view=rev
Log:
Fix bug #46368 - HSSFRichTextRun and strings longer than 32768 characters

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/UnicodeString.java
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFRichTextString.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.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=724848&r1=724847&r2=724848&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/changes.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/changes.xml Tue Dec  9 11:36:53 2008
@@ -37,6 +37,7 @@
 
 		<!-- Don't forget to update status.xml too! -->
         <release version="3.5-beta5" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">46368 - Fix HSSFRichTextRun and strings longer than 32768 characters</action>
            <action dev="POI-DEVELOPERS" type="add">Support sheet-level names</action>
            <action dev="POI-DEVELOPERS" type="fix">Fixed XSSFCell to properly handle cell references with column numbers up to XFD</action>
            <action dev="POI-DEVELOPERS" type="fix">44914 - Fixed warning message "WARN. Unread n bytes of record 0xNN"</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=724848&r1=724847&r2=724848&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Tue Dec  9 11:36:53 2008
@@ -34,6 +34,7 @@
 	<!-- Don't forget to update changes.xml too! -->
     <changes>
         <release version="3.5-beta5" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">46368 - Fix HSSFRichTextRun and strings longer than 32768 characters</action>
            <action dev="POI-DEVELOPERS" type="add">Support sheet-level names</action>
            <action dev="POI-DEVELOPERS" type="fix">Fixed XSSFCell to properly handle cell references with column numbers up to XFD</action>
            <action dev="POI-DEVELOPERS" type="fix">44914 - Fixed warning message "WARN. Unread n bytes of record 0xNN"</action>

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/UnicodeString.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/UnicodeString.java?rev=724848&r1=724847&r2=724848&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/UnicodeString.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/UnicodeString.java Tue Dec  9 11:36:53 2008
@@ -202,9 +202,9 @@
 
         boolean isCompressed = ((field_2_optionflags & 1) == 0);
         if (isCompressed) {
-            field_3_string = in.readCompressedUnicode(field_1_charCount);
+            field_3_string = in.readCompressedUnicode(getCharCount());
         } else {
-            field_3_string = in.readUnicodeLEString(field_1_charCount);
+            field_3_string = in.readUnicodeLEString(getCharCount());
         }
  
 
@@ -226,15 +226,25 @@
 
 
     /**
-     * get the number of characters in the string
-     *
+     * get the number of characters in the string,
+     *  as an un-wrapped int
      *
      * @return number of characters
-     *
      */
+    public int getCharCount() {
+    	if(field_1_charCount < 0) {
+    		return field_1_charCount + 65536;
+    	}
+        return field_1_charCount;
+    }
 
-    public short getCharCount()
-    {
+    /**
+     * get the number of characters in the string,
+     * wrapped as needed to fit within a short
+     *
+     * @return number of characters
+     */
+    public short getCharCountShort() {
         return field_1_charCount;
     }
 

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFRichTextString.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFRichTextString.java?rev=724848&r1=724847&r2=724848&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFRichTextString.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFRichTextString.java Tue Dec  9 11:36:53 2008
@@ -198,8 +198,7 @@
     /**
      * @return  the number of characters in the text.
      */
-    public int length()
-    {
+    public int length() {
         return string.getCharCount();
     }
 

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java?rev=724848&r1=724847&r2=724848&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java Tue Dec  9 11:36:53 2008
@@ -35,6 +35,9 @@
 import org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate;
 import org.apache.poi.hssf.record.formula.DeletedArea3DPtg;
 import org.apache.poi.hssf.record.formula.Ptg;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.RichTextString;
+import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.util.TempFile;
 
@@ -1540,4 +1543,36 @@
         HSSFWorkbook wb = openSample("45290.xls");
         assertEquals(1, wb.getNumberOfSheets());
     }
+    
+    /**
+     * HSSFRichTextString.length() returns negative for really
+     *  long strings
+     */
+    public void test46368() {
+        HSSFWorkbook wb = new HSSFWorkbook();
+    	HSSFSheet s = wb.createSheet();
+    	HSSFRow r = s.createRow(0);
+    	for(int i=0; i<15; i++) {
+    		int len = 32760 + i;
+    		HSSFCell c = r.createCell(i);
+    		
+    		StringBuffer sb = new StringBuffer();
+    		for(int j=0; j<len; j++) {
+    			sb.append("x");
+    		}
+    		HSSFRichTextString rtr = new HSSFRichTextString(sb.toString());
+    		assertEquals(len, rtr.length());
+    		c.setCellValue(rtr);
+    	}
+    	
+    	// Save and reload
+    	wb = writeOutAndReadBack(wb);
+    	s = wb.getSheetAt(0);
+    	r = s.getRow(0);
+    	for(int i=0; i<15; i++) {
+    		int len = 32760 + i;
+    		HSSFCell c = r.getCell(i);
+    		assertEquals(len, c.getRichStringCellValue().length());
+    	}
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org