From ed0b8046308f8c9515a716250be0aa2c3dc747ab Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Tue, 3 May 2011 05:50:25 +0000 Subject: [PATCH] Fix bug #51111 - Correct XWPFParagraph tracking of new runs git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1098920 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/status.xml | 1 + .../org/apache/poi/xwpf/usermodel/XWPFParagraph.java | 4 +++- .../apache/poi/xwpf/usermodel/TestXWPFParagraph.java | 10 ++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 6280db36ad..b81681a103 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 51111 - Correct XWPFParagraph tracking of new runs 51115 - Handle DataFormatter escaping of "." in the same way as "-" and "/" 51100 - Fix IOUtils issue for NPOIFS reading from an InputStream where every block is full 50956 - Correct XSSF cell style cloning between workbooks diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java index 2833695e92..a4cccccabe 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java @@ -260,7 +260,9 @@ public class XWPFParagraph implements IBodyElement{ * @return a new text run */ public XWPFRun createRun() { - return new XWPFRun(paragraph.addNewR(), this); + XWPFRun run = new XWPFRun(paragraph.addNewR(), this); + runs.add(run); + return run; } /** diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java index 6bf3c03ff0..0fa1b92ba0 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java @@ -252,6 +252,16 @@ public final class TestXWPFParagraph extends TestCase { assertEquals("10", p.getNumID().toString()); } + public void testAddingRuns() throws Exception { + XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx"); + + XWPFParagraph p = doc.getParagraphs().get(0); + assertEquals(2, p.getRuns().size()); + + XWPFRun r = p.createRun(); + assertEquals(3, p.getRuns().size()); + } + public void testPictures() throws Exception { XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("VariousPictures.docx"); assertEquals(7, doc.getParagraphs().size()); -- 2.39.5