From 77f5742c75dcd9d1130cc87f69f1bfc28814eb91 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Tue, 14 Sep 2010 11:34:33 +0000 Subject: [PATCH] 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 --- src/documentation/content/xdocs/status.xml | 1 + src/ooxml/java/org/apache/poi/xwpf/usermodel/IBody.java | 7 +++++++ .../java/org/apache/poi/xwpf/usermodel/XWPFDocument.java | 1 - .../org/apache/poi/xwpf/usermodel/XWPFHeaderFooter.java | 4 ++++ .../java/org/apache/poi/xwpf/usermodel/XWPFStyle.java | 6 ++++++ .../java/org/apache/poi/xwpf/usermodel/XWPFTable.java | 1 - .../org/apache/poi/xwpf/usermodel/XWPFTableCell.java | 9 +++++++++ .../org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java | 3 +++ 8 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index b230d40b1..a0fc2a015 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 c42fde7d1..8f3aa9f7d 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 9f1acbbea..bc773132e 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 fe24efcd3..5088eaee6 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 9de4eecda..43fae3ac4 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 79262b2dd..4927f321b 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 33adec490..2497d801a 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 bf82b7ce9..ac7e4f7a5 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() {