From: Nick Burch Date: Fri, 6 May 2011 01:43:16 +0000 (+0000) Subject: Re-enable the XWPF test for adding paragraphs, and fix it up to work properly X-Git-Tag: REL_3_8_BETA3~42 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9a0997290ef1ed42a4a8f5dc1f14e02f5b0750a8;p=poi.git Re-enable the XWPF test for adding paragraphs, and fix it up to work properly git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1100022 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/ooxml/java/org/apache/poi/xwpf/package.html b/src/ooxml/java/org/apache/poi/xwpf/package.html new file mode 100644 index 0000000000..8c6c70d9e0 --- /dev/null +++ b/src/ooxml/java/org/apache/poi/xwpf/package.html @@ -0,0 +1,27 @@ + + + + +

This package contains classes for handling Microsoft .docx + Word Processing files, known in POI as XWPF (XML Word Processing + Format). +

+ + diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java index f0f314cf98..88c0675f19 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java @@ -649,7 +649,9 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody { * @return a new paragraph */ public XWPFParagraph createParagraph(){ - return new XWPFParagraph(ctDocument.getBody().addNewP(), this); + XWPFParagraph p = new XWPFParagraph(ctDocument.getBody().addNewP(), this); + paragraphs.add(p); + return p; } /** diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java b/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java index 27aa41d9cd..d931576902 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java @@ -24,7 +24,10 @@ import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.xwpf.usermodel.XWPFDocument; +import org.apache.poi.xwpf.usermodel.XWPFParagraph; import org.apache.poi.xwpf.usermodel.XWPFRelation; +import org.apache.xmlbeans.XmlCursor; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP; public final class TestXWPFDocument extends TestCase { @@ -95,20 +98,22 @@ public final class TestXWPFDocument extends TestCase { assertEquals("Apache POI", props.getExtendedProperties().getUnderlyingProperties().getApplication()); } -// public void testAddParagraph(){ -// XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx"); -// int pLength = doc.getParagraphs().length; -// XWPFParagraph p = doc.insertNewParagraph(3); -// assertTrue(p == doc.getParagraphs()[3]); -// assertTrue(++pLength == doc.getParagraphs().length); -// CTP ctp = p.getCTP(); -// XWPFParagraph newP = doc.getParagraph(ctp); -// assertSame(p, newP); -// XmlCursor cursor = doc.getDocument().getBody().getPArray(0).newCursor(); -// XWPFParagraph cP = doc.insertNewParagraph(cursor); -// assertSame(cP, doc.getParagraphs()[0]); -// assertTrue(++pLength == doc.getParagraphs().length); -// } + public void testAddParagraph(){ + XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx"); + assertEquals(3, doc.getParagraphs().size()); + + XWPFParagraph p = doc.createParagraph(); + assertEquals(p, doc.getParagraphs().get(3)); + assertEquals(4, doc.getParagraphs().size()); + + CTP ctp = p.getCTP(); + XWPFParagraph newP = doc.getParagraph(ctp); + assertSame(p, newP); + XmlCursor cursor = doc.getDocument().getBody().getPArray(0).newCursor(); + XWPFParagraph cP = doc.insertNewParagraph(cursor); + assertSame(cP, doc.getParagraphs().get(0)); + assertEquals(5, doc.getParagraphs().size()); + } public void testAddPicture(){ XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");