Return-Path: X-Original-To: apmail-poi-commits-archive@minotaur.apache.org Delivered-To: apmail-poi-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 464A47F19 for ; Tue, 9 Aug 2011 05:18:16 +0000 (UTC) Received: (qmail 58083 invoked by uid 500); 9 Aug 2011 05:18:12 -0000 Delivered-To: apmail-poi-commits-archive@poi.apache.org Received: (qmail 58033 invoked by uid 500); 9 Aug 2011 05:18:05 -0000 Mailing-List: contact commits-help@poi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@poi.apache.org Delivered-To: mailing list commits@poi.apache.org Received: (qmail 58018 invoked by uid 99); 9 Aug 2011 05:18:00 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 09 Aug 2011 05:18:00 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 09 Aug 2011 05:17:56 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 1069F238885D for ; Tue, 9 Aug 2011 05:17:36 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1155210 - in /poi/trunk/src/scratchpad: src/org/apache/poi/hwpf/HWPFDocument.java src/org/apache/poi/hwpf/model/SinglentonTextPiece.java src/org/apache/poi/hwpf/model/TextPiece.java testcases/org/apache/poi/hwpf/usermodel/TestBugs.java Date: Tue, 09 Aug 2011 05:17:35 -0000 To: commits@poi.apache.org From: sergey@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110809051736.1069F238885D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: sergey Date: Tue Aug 9 05:17:35 2011 New Revision: 1155210 URL: http://svn.apache.org/viewvc?rev=1155210&view=rev Log: backlink used doc's stringbuilder and singlenton TextPiece from TextPieceTable Added: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/SinglentonTextPiece.java Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java?rev=1155210&r1=1155209&r2=1155210&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java Tue Aug 9 05:17:35 2011 @@ -39,11 +39,11 @@ import org.apache.poi.hwpf.model.NoteTyp import org.apache.poi.hwpf.model.NotesTables; import org.apache.poi.hwpf.model.PAPBinTable; import org.apache.poi.hwpf.model.PicturesTable; -import org.apache.poi.hwpf.model.PieceDescriptor; import org.apache.poi.hwpf.model.RevisionMarkAuthorTable; import org.apache.poi.hwpf.model.SavedByTable; import org.apache.poi.hwpf.model.SectionTable; import org.apache.poi.hwpf.model.ShapesTable; +import org.apache.poi.hwpf.model.SinglentonTextPiece; import org.apache.poi.hwpf.model.StyleSheet; import org.apache.poi.hwpf.model.SubdocumentType; import org.apache.poi.hwpf.model.TextPiece; @@ -94,7 +94,8 @@ public final class HWPFDocument extends * structure*/ protected ComplexFileTable _cft; - protected final StringBuilder _text; + /** Contains text buffer linked directly to single-piece document text piece */ + protected StringBuilder _text; /** Holds the save history for this document. */ protected SavedByTable _sbt; @@ -284,9 +285,9 @@ public final class HWPFDocument extends { _cft = new ComplexFileTable(); _tpt = _cft.getTextPieceTable(); - _tpt.add( new TextPiece( 0, _text.length(), _text.toString() - .getBytes( "UTF-16LE" ), new PieceDescriptor( new byte[8], - 0 ) ) ); + final TextPiece textPiece = new SinglentonTextPiece( _text ); + _tpt.add( textPiece ); + _text = textPiece.getStringBuilder(); } // Read FSPA and Escher information Added: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/SinglentonTextPiece.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/SinglentonTextPiece.java?rev=1155210&view=auto ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/SinglentonTextPiece.java (added) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/SinglentonTextPiece.java Tue Aug 9 05:17:35 2011 @@ -0,0 +1,51 @@ +package org.apache.poi.hwpf.model; + +import java.io.IOException; + +import org.apache.poi.util.Internal; + +@Internal +public class SinglentonTextPiece extends TextPiece +{ + + public SinglentonTextPiece( StringBuilder buffer ) throws IOException + { + super( 0, buffer.length(), buffer.toString().getBytes( "UTF-16LE" ), + new PieceDescriptor( new byte[8], 0 ) ); + } + + @Override + public int bytesLength() + { + return getStringBuilder().length() * 2; + } + + @Override + public int characterLength() + { + return getStringBuilder().length(); + } + + @Override + public int getCP() + { + return 0; + } + + @Override + public int getEnd() + { + return characterLength(); + } + + @Override + public int getStart() + { + return 0; + } + + public String toString() + { + return "SinglentonTextPiece (" + characterLength() + " chars)"; + } +} 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=1155210&r1=1155209&r2=1155210&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 Tue Aug 9 05:17:35 2011 @@ -31,7 +31,7 @@ import org.apache.poi.util.Internal; * @author Ryan Ackley */ @Internal -public final class TextPiece extends PropertyNode +public class TextPiece extends PropertyNode { private boolean _usesUnicode; @@ -134,6 +134,7 @@ public final class TextPiece extends Pro * @param start Local start position, in characters * @param end Local end position, in characters */ + @Deprecated public String substring(int start, int end) { StringBuilder buf = (StringBuilder)_buf; @@ -157,6 +158,7 @@ public final class TextPiece extends Pro * @param start The start position for the delete, in characters * @param length The number of characters to delete */ + @Deprecated public void adjustForDelete(int start, int length) { int numChars = length; @@ -187,6 +189,7 @@ public final class TextPiece extends Pro /** * Returns the length, in characters */ + @Deprecated public int characterLength() { return (getEnd() - getStart()); 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=1155210&r1=1155209&r2=1155210&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 Tue Aug 9 05:17:35 2011 @@ -16,6 +16,8 @@ ==================================================================== */ package org.apache.poi.hwpf.usermodel; +import java.io.File; +import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.Arrays; @@ -473,4 +475,33 @@ public class TestBugs extends TestCase HWPFTestDataSamples.openSampleFileFromArchive( "Bug51524.zip" ); } + /** + * Bug 51604 - replace text fails for doc ( poi 3.8 beta release from + * download site ) + */ + public void test51604() + { + HWPFDocument document = HWPFTestDataSamples + .openSampleFile( "Bug51604.doc" ); + + Range range = document.getRange(); + int numParagraph = range.numParagraphs(); + int counter = 0; + 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(); + charRun.replaceText( text, "+" + ( ++counter ) ); + } + } + + document = HWPFTestDataSamples.writeOutAndReadBack( document ); + String text = document.getDocumentText(); + assertEquals( "+1+2+3+4+5+6+7+8+9+10+11+12", text ); + } + } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org For additional commands, e-mail: commits-help@poi.apache.org