You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by se...@apache.org on 2011/08/11 15:55:36 UTC

svn commit: r1156616 - in /poi/trunk/src/scratchpad: src/org/apache/poi/hwpf/model/FileInformationBlock.java src/org/apache/poi/hwpf/usermodel/Range.java testcases/org/apache/poi/hwpf/usermodel/TestBugs.java

Author: sergey
Date: Thu Aug 11 13:55:35 2011
New Revision: 1156616

URL: http://svn.apache.org/viewvc?rev=1156616&view=rev
Log:
fix document parts boundaries modifications on text changes (in FIB)

Modified:
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java?rev=1156616&r1=1156615&r2=1156616&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java Thu Aug 11 13:55:35 2011
@@ -544,6 +544,12 @@ public final class FileInformationBlock 
 
     public void setSubdocumentTextStreamLength( SubdocumentType type, int length )
     {
+        if ( length < 0 )
+            throw new IllegalArgumentException(
+                    "Subdocument length can't be less than 0 (passed value is "
+                            + length + "). " + "If there is no subdocument "
+                            + "length must be set to zero." );
+
         _longHandler.setLong( type.getFibLongFieldIndex(), length );
     }
 
@@ -977,4 +983,3 @@ public final class FileInformationBlock 
 //    }
 
 }
-

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=1156616&r1=1156615&r2=1156616&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 Aug 11 13:55:35 2011
@@ -1078,11 +1078,13 @@ public class Range { // TODO -instantiab
             currentEnd += currentLength;
 
             // do we need to shift this part?
-            if ( _start < currentEnd )
-            {
-                fib.setSubdocumentTextStreamLength( type, currentLength
-                        + adjustment );
-            }
+            if ( _start > currentEnd )
+                continue;
+
+            fib.setSubdocumentTextStreamLength( type, currentLength
+                    + adjustment );
+
+            break;
         }
     }
 

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java?rev=1156616&r1=1156615&r2=1156616&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java Thu Aug 11 13:55:35 2011
@@ -26,6 +26,11 @@ import org.apache.poi.util.LittleEndian;
 
 import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
+
+import org.apache.poi.hwpf.model.SubdocumentType;
+
+import org.apache.poi.hwpf.model.FileInformationBlock;
+
 import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.poi.POIDataSamples;
 import org.apache.poi.hwpf.HWPFDocument;
@@ -513,8 +518,8 @@ public class TestBugs extends TestCase
     }
 
     /**
-     * Bug 51604 - replace text fails for doc ( poi 3.8 beta release from
-     * download site )
+     * [RESOLVED FIXED] Bug 51604 - replace text fails for doc ( poi 3.8 beta
+     * release from download site )
      */
     public void test51604()
     {
@@ -541,4 +546,44 @@ public class TestBugs extends TestCase
         assertEquals( "+1+2+3+4+5+6+7+8+9+10+11+12", text );
     }
 
+    /**
+     * [RESOLVED FIXED] Bug 51604 - replace text fails for doc ( poi 3.8 beta
+     * release from download site )
+     */
+    public void test51604p2()
+    {
+        HWPFDocument doc = HWPFTestDataSamples
+                .openSampleFile( "Bug51604.doc" );
+
+        Range range = doc.getRange();
+        int numParagraph = range.numParagraphs();
+        for ( int i = 0; i < numParagraph; i++ )
+        {
+            Paragraph paragraph = range.getParagraph( i );
+            int numCharRuns = paragraph.numCharacterRuns();
+            for ( int j = 0; j < numCharRuns; j++ )
+            {
+                CharacterRun charRun = paragraph.getCharacterRun( j );
+                String text = charRun.text();
+                if ( text.contains( "Header" ) )
+                    charRun.replaceText( text, "added" );
+            }
+        }
+
+        doc = HWPFTestDataSamples.writeOutAndReadBack( doc );
+        final FileInformationBlock fileInformationBlock = doc
+                .getFileInformationBlock();
+
+        int totalLength = 0;
+        for ( SubdocumentType type : SubdocumentType.values() )
+        {
+            final int partLength = fileInformationBlock
+                    .getSubdocumentTextStreamLength( type );
+            assert ( partLength >= 0 );
+
+            totalLength += partLength;
+        }
+
+        assertEquals( doc.getText().length(), totalLength );
+    }
 }



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