poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r951498 - in /poi/trunk: src/documentation/content/xdocs/ src/scratchpad/src/org/apache/poi/hwpf/usermodel/ src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/ test-data/document/
Date Fri, 04 Jun 2010 17:19:31 GMT
Author: nick
Date: Fri Jun  4 17:19:31 2010
New Revision: 951498

URL: http://svn.apache.org/viewvc?rev=951498&view=rev
Log:
Apply with tweaks the patch from bug #45269 - improve replaceText on HWPF ranges

Added:
    poi/trunk/test-data/document/Bug45269.doc   (with props)
Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeReplacement.java

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=951498&r1=951497&r2=951498&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Fri Jun  4 17:19:31 2010
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.7-SNAPSHOT" date="2010-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">45269 - improve replaceText on HWPF
ranges</action>
            <action dev="POI-DEVELOPERS" type="fix">47815 - correct documentation on
what happens when you request a String from a non-string Formula cell</action>
            <action dev="POI-DEVELOPERS" type="fix">49386 - avoid NPE when extracting
OOXML file properties which are dates</action>
            <action dev="POI-DEVELOPERS" type="fix">49377 - only call DecimalFormat.setRoundingMode
on Java 1.6 - it's needed to match excel's rendering of numbers</action>

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=951498&r1=951497&r2=951498&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 Fri Jun  4 17:19:31
2010
@@ -745,8 +745,9 @@ public class Range { // TODO -instantiab
 
 		subRange.insertBefore(pValue);
 
-		if (subRange.getEndOffset() != previousEndOffset)
-			_end += (subRange.getEndOffset() - previousEndOffset);
+		if (subRange.getEndOffset() != previousEndOffset) {
+			adjustForInsert(subRange.getEndOffset() - previousEndOffset);
+		}
 
 		// re-create the sub-range so we can delete it
 		subRange = new Range((absPlaceHolderIndex + pValue.length()), (absPlaceHolderIndex

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=951498&r1=951497&r2=951498&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 Fri
Jun  4 17:19:31 2010
@@ -161,4 +161,41 @@ public final class TestProblems extends 
 		HWPFDocument doc2 = writeOutAndRead(doc);
 		assertEquals("Nick Burch", doc2.getSummaryInformation().getAuthor());
 	}
+	
+	/**
+	 * Test for reading paragraphs from Range after replacing some 
+	 * text in this Range.
+	 * Bug #45269
+	 */
+	public void testReadParagraphsAfterReplaceText()throws Exception{
+    HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug45269.doc");
+    Range range = doc.getRange();
+    
+    String toFind = "campo1";
+    String longer = " foi porraaaaa ";
+    String shorter = " foi ";
+    
+    //check replace with longer text
+    for (int x = 0; x < range.numParagraphs(); x++) {
+      Paragraph para = range.getParagraph(x);
+      int offset = para.text().indexOf(toFind);
+      if (offset >= 0) {
+          para.replaceText(toFind, longer, offset);
+          assertEquals(offset, para.text().indexOf(longer));
+      }
+    }
+    
+  	doc = HWPFTestDataSamples.openSampleFile("Bug45269.doc");
+   range = doc.getRange();
+    
+    //check replace with shorter text
+    for (int x = 0; x < range.numParagraphs(); x++) {
+      Paragraph para = range.getParagraph(x);
+      int offset = para.text().indexOf(toFind);
+      if (offset >= 0) {
+          para.replaceText(toFind, shorter, offset);
+          assertEquals(offset, para.text().indexOf(shorter));
+      }
+    }
+	}
 }

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeReplacement.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeReplacement.java?rev=951498&r1=951497&r2=951498&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeReplacement.java
(original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeReplacement.java
Fri Jun  4 17:19:31 2010
@@ -85,12 +85,16 @@ public final class TestRangeReplacement 
 
 		HWPFDocument daDoc = HWPFTestDataSamples.openSampleFile(illustrativeDocFile);
 
+		// Has one section
 		Range range = daDoc.getRange();
 		assertEquals(1, range.numSections());
 
+		// The first section has 5 paragraphs
 		Section section = range.getSection(0);
 		assertEquals(5, section.numParagraphs());
 
+		
+		// Change some text
 		Paragraph para = section.getParagraph(2);
 
 		String text = para.text();
@@ -101,12 +105,14 @@ public final class TestRangeReplacement 
 
 		para.replaceText(searchText, replacementText, offset);
 
+		// Ensure we still have one section, 5 paragraphs
 		assertEquals(1, range.numSections());
 		section = range.getSection(0);
 
-		assertEquals(4, section.numParagraphs());
+		assertEquals(5, section.numParagraphs());
 		para = section.getParagraph(2);
 
+		// Ensure the text is what we should now have
 		text = para.text();
 		assertEquals(expectedText2, text);
 	}

Added: poi/trunk/test-data/document/Bug45269.doc
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/document/Bug45269.doc?rev=951498&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/document/Bug45269.doc
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



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


Mime
View raw message