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/03/13 14:03:44 UTC

svn commit: r636751 - in /poi/trunk/src: documentation/content/xdocs/ scratchpad/src/org/apache/poi/hwpf/model/ scratchpad/src/org/apache/poi/hwpf/usermodel/ scratchpad/testcases/org/apache/poi/hwpf/data/ scratchpad/testcases/org/apache/poi/hwpf/usermo...

Author: nick
Date: Thu Mar 13 06:03:25 2008
New Revision: 636751

URL: http://svn.apache.org/viewvc?rev=636751&view=rev
Log:
Patch from Raghu from bug #44580 - Fix bug #28627, where hwpf Range.delete() didn't work properly

Added:
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/data/Bug28627.doc   (with props)
Modified:
    poi/trunk/src/documentation/content/xdocs/changes.xml
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.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=636751&r1=636750&r2=636751&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/changes.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/changes.xml Thu Mar 13 06:03:25 2008
@@ -36,6 +36,7 @@
 
 		<!-- Don't forget to update status.xml too! -->
         <release version="3.1-beta1" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="add">28627 / 44580 - Fix Range.delete() in HWPF</action>
            <action dev="POI-DEVELOPERS" type="add">44539 - Support for area references in formulas of rows >= 32768</action>
            <action dev="POI-DEVELOPERS" type="add">44536 - Improved support for detecting read-only recommended files</action>
            <action dev="POI-DEVELOPERS" type="fix">43901 - Correctly update the internal last cell number when adding and removing cells (previously sometimes off-by-one)</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=636751&r1=636750&r2=636751&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Thu Mar 13 06:03:25 2008
@@ -33,6 +33,7 @@
 	<!-- Don't forget to update changes.xml too! -->
     <changes>
         <release version="3.1-beta1" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="add">28627 / 44580 - Fix Range.delete() in HWPF</action>
            <action dev="POI-DEVELOPERS" type="add">44539 - Support for area references in formulas of rows >= 32768</action>
            <action dev="POI-DEVELOPERS" type="add">44536 - Improved support for detecting read-only recommended files</action>
            <action dev="POI-DEVELOPERS" type="fix">43901 - Correctly update the internal last cell number when adding and removing cells (previously sometimes off-by-one)</action>

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java?rev=636751&r1=636750&r2=636751&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java Thu Mar 13 06:03:25 2008
@@ -90,7 +90,19 @@
 
    public void adjustForDelete(int start, int length)
    {
+	   int myStart = getStart();
+	   int myEnd = getEnd();
+	   int end = start + length;
 
+	   /* do we have to delete from this text piece? */
+	   if (start <= myEnd && end >= myStart) {
+		   /* find where the deleted area overlaps with this text piece */
+		   int overlapStart = Math.max(myStart, start);
+		   int overlapEnd = Math.min(myEnd, end);
+		   ((StringBuffer)_buf).delete(overlapStart, overlapEnd);
+		   
+		   super.adjustForDelete(start, length);
+	   }
    }
 
    public int characterLength()

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java?rev=636751&r1=636750&r2=636751&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java Thu Mar 13 06:03:25 2008
@@ -494,6 +494,7 @@
     int numSections = _sections.size();
     int numRuns = _characters.size();
     int numParagraphs = _paragraphs.size();
+    int numTextPieces = _text.size();
 
     for (int x = _charStart; x < numRuns; x++)
     {
@@ -511,6 +512,12 @@
     {
       SEPX sepx = (SEPX)_sections.get(x);
       sepx.adjustForDelete(_start, _end - _start);
+    }
+    
+    for (int x = _textStart; x < numTextPieces; x++)
+    {
+    	TextPiece piece = (TextPiece)_text.get(x);
+    	piece.adjustForDelete(_start, _end - _start);
     }
   }
 

Added: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/data/Bug28627.doc
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/data/Bug28627.doc?rev=636751&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/data/Bug28627.doc
------------------------------------------------------------------------------
    svn:mime-type = application/msword

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java?rev=636751&r1=636750&r2=636751&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java Thu Mar 13 06:03:25 2008
@@ -16,19 +16,14 @@
 */
 package org.apache.poi.hwpf.usermodel;
 
-import java.io.ByteArrayOutputStream;
+import java.io.File;
 import java.io.FileInputStream;
-import java.util.Iterator;
-import java.util.List;
+import java.io.FileOutputStream;
+
+import junit.framework.TestCase;
 
 import org.apache.poi.hwpf.HWPFDocument;
 import org.apache.poi.hwpf.model.StyleSheet;
-import org.apache.poi.hwpf.model.TextPiece;
-import org.apache.poi.hwpf.usermodel.Paragraph;
-import org.apache.poi.hwpf.usermodel.Range;
-import org.apache.poi.util.LittleEndian;
-
-import junit.framework.TestCase;
 
 /**
  * Test various problem documents
@@ -36,16 +31,18 @@
  * @author Nick Burch (nick at torchbox dot com)
  */
 public class TestProblems extends TestCase {
+
 	private String dirname = System.getProperty("HWPF.testdata.path");
 	
     protected void setUp() throws Exception {
-    }			
-    
+    }
+
     /**
      * ListEntry passed no ListTable
      */
     public void testListEntryNoListTable() throws Exception {
-    	HWPFDocument doc = new HWPFDocument(new FileInputStream(dirname + "/ListEntryNoListTable.doc"));
+    	HWPFDocument doc = new HWPFDocument(new FileInputStream(
+    			new File(dirname, "ListEntryNoListTable.doc")));
     	
     	Range r = doc.getRange();
     	StyleSheet styleSheet = doc.getStyleSheet();
@@ -62,7 +59,8 @@
 	 * AIOOB for TableSprmUncompressor.unCompressTAPOperation
 	 */
 	public void testSprmAIOOB() throws Exception {
-    	HWPFDocument doc = new HWPFDocument(new FileInputStream(dirname + "/AIOOB-Tap.doc"));
+    	HWPFDocument doc = new HWPFDocument(new FileInputStream(
+    			new File(dirname, "AIOOB-Tap.doc")));
     	
     	Range r = doc.getRange();
     	StyleSheet styleSheet = doc.getStyleSheet();
@@ -79,7 +77,8 @@
 	 * Test for TableCell not skipping the last paragraph
 	 */
 	public void testTableCellLastParagraph() throws Exception {
-    	HWPFDocument doc = new HWPFDocument(new FileInputStream(dirname + "/Bug44292.doc"));
+    	HWPFDocument doc = new HWPFDocument(new FileInputStream(
+    			new File(dirname, "Bug44292.doc")));
 		Range r = doc.getRange();
 			
 		//get the table
@@ -103,5 +102,40 @@
 		cell = row.getCell(2);
 		// Last cell should have one paragraph
 		assertEquals(1, cell.numParagraphs());
+	}
+
+	public void testRangeDelete() throws Exception {
+    	HWPFDocument doc = new HWPFDocument(new FileInputStream(
+    			new File(dirname, "Bug28627.doc")));
+
+    	Range range = doc.getRange();
+		int numParagraphs = range.numParagraphs();
+		
+		int totalLength = 0, deletedLength = 0;
+		
+		for (int i = 0; i < numParagraphs; i++) {
+			Paragraph para = range.getParagraph(i);
+			String text = para.text();
+
+			totalLength += text.length();
+			if (text.indexOf("{delete me}") > -1) {
+				para.delete();
+				deletedLength = text.length();
+			}
+		}
+		
+		// check the text length after deletion
+		int newLength = 0;
+    	range = doc.getRange();
+		numParagraphs = range.numParagraphs();
+		
+		for (int i = 0; i < numParagraphs; i++) {
+			Paragraph para = range.getParagraph(i);
+			String text = para.text();
+
+			newLength += text.length();			
+		}
+		
+		assertEquals(newLength, totalLength - deletedLength);
 	}
 }



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