From: Nick Burch Date: Tue, 14 Sep 2010 11:34:33 +0000 (+0000) Subject: Add a getBodyElements() method to XWPF IBody, to make access to embedded paragraphs... X-Git-Tag: REL_3_7_BETA3~28 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=db4de8a4f38b5be6a3baddb63f45d89e8726e147;p=poi.git Add a getBodyElements() method to XWPF IBody, to make access to embedded paragraphs and tables easier, and a few tidy-ups git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@996849 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index b230d40b1e..a0fc2a0159 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + Add a getBodyElements() method to XWPF IBody, to make access to embedded paragraphs and tables easier More XSLFRelation entries for common .pptx file parts 49872 - avoid exception in XSSFFormulaEvaluator.evaluateInCell when evaluating shared formulas 49895 - avoid corruption of XSSFWorkbook after removing all merged cells from sheet diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/IBody.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/IBody.java index c42fde7d18..8f3aa9f7d0 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/IBody.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/IBody.java @@ -50,6 +50,13 @@ public interface IBody { * @return */ BodyType getPartType(); + + /** + * Returns an Iterator with paragraphs and tables, + * in the order that they occur in the text. + */ + public List getBodyElements(); + /** * Returns the paragraph(s) that holds * the text of the header or footer. 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 9f1acbbea7..bc773132ef 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java @@ -52,7 +52,6 @@ import org.apache.xmlbeans.XmlCursor; import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlObject; import org.apache.xmlbeans.XmlOptions; -import org.openxmlformats.schemas.drawingml.x2006.main.CTTableRow; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTComment; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDocument1; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFtnEdn; diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeaderFooter.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeaderFooter.java index fe24efcd34..5088eaee6f 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeaderFooter.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeaderFooter.java @@ -70,6 +70,10 @@ public abstract class XWPFHeaderFooter extends POIXMLDocumentPart implements IBo return headerFooter; } + public List getBodyElements(){ + return Collections.unmodifiableList(bodyElements); + } + /** * Returns the paragraph(s) that holds * the text of the header or footer. diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyle.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyle.java index 9de4eecdad..43fae3ac42 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyle.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyle.java @@ -129,6 +129,12 @@ public class XWPFStyle { return null; } + public String getName() { + if(ctStyle.isSetName()) + return ctStyle.getName().getVal(); + return null; + } + /** * compares the names of the Styles * @param compStyle diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTable.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTable.java index 79262b2ddd..4927f321b0 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTable.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTable.java @@ -46,7 +46,6 @@ public class XWPFTable implements IBodyElement{ protected List tableRows; protected List styleIDs; protected IBody part; - private XWPFDocument document; public XWPFTable(CTTbl table, IBody part, int row, int col) { this(table, part); diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java index 33adec4901..2497d801a9 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java @@ -74,6 +74,15 @@ public class XWPFTableCell implements IBody { return ctTc; } + /** + * returns an Iterator with paragraphs and tables + * @see org.apache.poi.xwpf.usermodel.IBody#getBodyElements() + * @return + */ + public List getBodyElements(){ + return Collections.unmodifiableList(bodyElements); + } + public void setParagraph(XWPFParagraph p) { if (ctTc.sizeOfPArray() == 0) { ctTc.addNewP(); 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 bf82b7ce9c..ac7e4f7a5c 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java @@ -236,6 +236,9 @@ public final class TestXWPFParagraph extends TestCase { assertEquals(0, paragraph.getCTP().sizeOfBookmarkEndArray()); CTBookmark ctBookmark = paragraph.getCTP().getBookmarkStartArray(0); assertEquals("poi", ctBookmark.getName()); + for(CTBookmark bookmark : paragraph.getCTP().getBookmarkStartList()) { + assertEquals("poi", bookmark.getName()); + } } public void testGetSetNumID() {