From: PJ Fanning Date: Thu, 2 Aug 2018 20:04:49 +0000 (+0000) Subject: [github-120] rename some new xpwf abstract classes. This closes #120 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9a6fde7673b477dc8cf4ea748b7df57274340b03;p=poi.git [github-120] rename some new xpwf abstract classes. This closes #120 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1837335 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/AbstractXWPFFootnoteEndnote.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/AbstractXWPFFootnoteEndnote.java deleted file mode 100644 index 606bf50a3b..0000000000 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/AbstractXWPFFootnoteEndnote.java +++ /dev/null @@ -1,515 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ -package org.apache.poi.xwpf.usermodel; - -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.apache.poi.ooxml.POIXMLDocumentPart; -import org.apache.poi.util.Internal; -import org.apache.xmlbeans.XmlCursor; -import org.apache.xmlbeans.XmlObject; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFtnEdn; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFtnEdnRef; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc; - -/** - * Base class for both bottom-of-the-page footnotes {@link XWPFFootnote} and end - * notes {@link XWPFEndnote}). - *

The only significant difference between footnotes and - * end notes is which part they go on. Footnotes are managed by the Footnotes part - * {@link XWPFFootnotes} and end notes are managed by the Endnotes part {@link XWPFEndnotes}.

- * @since 4.0.0 - */ -public abstract class AbstractXWPFFootnoteEndnote implements Iterable, IBody { - - private List paragraphs = new ArrayList<>(); - private List tables = new ArrayList<>(); - private List pictures = new ArrayList<>(); - private List bodyElements = new ArrayList<>(); - protected CTFtnEdn ctFtnEdn; - protected AbstractXWPFFootnotesEndnotes footnotes; - protected XWPFDocument document; - - public AbstractXWPFFootnoteEndnote() { - super(); - } - - @Internal - protected AbstractXWPFFootnoteEndnote(XWPFDocument document, CTFtnEdn body) { - ctFtnEdn = body; - this.document = document; - init(); - } - - @Internal - protected AbstractXWPFFootnoteEndnote(CTFtnEdn note, AbstractXWPFFootnotesEndnotes footnotes) { - this.footnotes = footnotes; - ctFtnEdn = note; - document = footnotes.getXWPFDocument(); - init(); - } - - protected void init() { - XmlCursor cursor = ctFtnEdn.newCursor(); - //copied from XWPFDocument...should centralize this code - //to avoid duplication - cursor.selectPath("./*"); - while (cursor.toNextSelection()) { - XmlObject o = cursor.getObject(); - if (o instanceof CTP) { - XWPFParagraph p = new XWPFParagraph((CTP) o, this); - bodyElements.add(p); - paragraphs.add(p); - } else if (o instanceof CTTbl) { - XWPFTable t = new XWPFTable((CTTbl) o, this); - bodyElements.add(t); - tables.add(t); - } else if (o instanceof CTSdtBlock) { - XWPFSDT c = new XWPFSDT((CTSdtBlock) o, this); - bodyElements.add(c); - } - - } - cursor.dispose(); - } - - /** - * Get the list of {@link XWPFParagraph}s in the footnote. - * @return List of paragraphs - */ - public List getParagraphs() { - return paragraphs; - } - - /** - * Get an iterator over the {@link XWPFParagraph}s in the footnote. - * @return Iterator over the paragraph list. - */ - public Iterator iterator() { - return paragraphs.iterator(); - } - - /** - * Get the list of {@link XWPFTable}s in the footnote. - * @return List of tables - */ - public List getTables() { - return tables; - } - - /** - * Gets the list of {@link XWPFPictureData}s in the footnote. - * @return List of pictures - */ - public List getPictures() { - return pictures; - } - - /** - * Gets the body elements ({@link IBodyElement}) of the footnote. - * @return List of body elements. - */ - public List getBodyElements() { - return bodyElements; - } - - /** - * Gets the underlying CTFtnEdn object for the footnote. - * @return CTFtnEdn object - */ - public CTFtnEdn getCTFtnEdn() { - return ctFtnEdn; - } - - /** - * Set the underlying CTFtnEdn for the footnote. - *

Use {@link XWPFDocument#createFootnote()} to create new footnotes.

- * @param footnote The CTFtnEdn object that will underly the footnote. - */ - public void setCTFtnEdn(CTFtnEdn footnote) { - ctFtnEdn = footnote; - } - - /** - * Gets the {@link XWPFTable} at the specified position from the footnote's table array. - * @param pos in table array - * @return The {@link XWPFTable} at position pos, or null if there is no table at position pos. - * @see org.apache.poi.xwpf.usermodel.IBody#getTableArray(int) - */ - public XWPFTable getTableArray(int pos) { - if (pos >= 0 && pos < tables.size()) { - return tables.get(pos); - } - return null; - } - - /** - * Inserts an existing {@link XWPFTable) into the arrays bodyElements and tables. - * - * @param pos Position, in the bodyElements array, to insert the table - * @param table {@link XWPFTable) to be inserted - * @see org.apache.poi.xwpf.usermodel.IBody#insertTable(int pos, XWPFTable table) - */ - public void insertTable(int pos, XWPFTable table) { - bodyElements.add(pos, table); - int i = 0; - for (CTTbl tbl : ctFtnEdn.getTblList()) { - if (tbl == table.getCTTbl()) { - break; - } - i++; - } - tables.add(i, table); - - } - - /** - * if there is a corresponding {@link XWPFTable} of the parameter - * ctTable in the tableList of this header - * the method will return this table, or null if there is no - * corresponding {@link XWPFTable}. - * - * @param ctTable - * @see org.apache.poi.xwpf.usermodel.IBody#getTable(CTTbl ctTable) - */ - public XWPFTable getTable(CTTbl ctTable) { - for (XWPFTable table : tables) { - if (table == null) - return null; - if (table.getCTTbl().equals(ctTable)) - return table; - } - return null; - } - - /** - * if there is a corresponding {@link XWPFParagraph} of the parameter p in the paragraphList of this header or footer - * the method will return that paragraph, otherwise the method will return null. - * - * @param p The CTP paragraph to find the corresponding {@link XWPFParagraph} for. - * @return The {@link XWPFParagraph} that corresponds to the CTP paragraph in the paragraph - * list of this footnote or null if no paragraph is found. - * @see org.apache.poi.xwpf.usermodel.IBody#getParagraph(CTP p) - */ - public XWPFParagraph getParagraph(CTP p) { - for (XWPFParagraph paragraph : paragraphs) { - if (paragraph.getCTP().equals(p)) - return paragraph; - } - return null; - } - - /** - * Returns the {@link XWPFParagraph} at position pos in footnote's paragraph array. - * @param pos Array position of the paragraph to get. - * @return the {@link XWPFParagraph} at position pos, or null if there is no paragraph at that position. - * - * @see org.apache.poi.xwpf.usermodel.IBody#getParagraphArray(int pos) - */ - public XWPFParagraph getParagraphArray(int pos) { - if(pos >=0 && pos < paragraphs.size()) { - return paragraphs.get(pos); - } - return null; - } - - /** - * get the {@link XWPFTableCell} that belongs to the CTTc cell. - * - * @param cell - * @return {@link XWPFTableCell} that corresponds to the CTTc cell, if there is one, otherwise null. - * @see org.apache.poi.xwpf.usermodel.IBody#getTableCell(CTTc cell) - */ - public XWPFTableCell getTableCell(CTTc cell) { - XmlCursor cursor = cell.newCursor(); - cursor.toParent(); - XmlObject o = cursor.getObject(); - if (!(o instanceof CTRow)) { - return null; - } - CTRow row = (CTRow) o; - cursor.toParent(); - o = cursor.getObject(); - cursor.dispose(); - if (!(o instanceof CTTbl)) { - return null; - } - CTTbl tbl = (CTTbl) o; - XWPFTable table = getTable(tbl); - if (table == null) { - return null; - } - XWPFTableRow tableRow = table.getRow(row); - if(tableRow == null){ - return null; - } - return tableRow.getTableCell(cell); - } - - /** - * Verifies that cursor is on the right position. - * - * @param cursor - * @return true if the cursor is within a CTFtnEdn element. - */ - private boolean isCursorInFtn(XmlCursor cursor) { - XmlCursor verify = cursor.newCursor(); - verify.toParent(); - if (verify.getObject() == this.ctFtnEdn) { - return true; - } - return false; - } - - /** - * The owning object for this footnote - * - * @return The {@link XWPFFootnotes} object that contains this footnote. - */ - public POIXMLDocumentPart getOwner() { - return footnotes; - } - - /** - * Insert a table constructed from OOXML table markup. - * @param cursor - * @return the inserted {@link XWPFTable} - * @see org.apache.poi.xwpf.usermodel.IBody#insertNewTbl(XmlCursor cursor) - */ - public XWPFTable insertNewTbl(XmlCursor cursor) { - if (isCursorInFtn(cursor)) { - String uri = CTTbl.type.getName().getNamespaceURI(); - String localPart = "tbl"; - cursor.beginElement(localPart, uri); - cursor.toParent(); - CTTbl t = (CTTbl) cursor.getObject(); - XWPFTable newT = new XWPFTable(t, this); - cursor.removeXmlContents(); - XmlObject o = null; - while (!(o instanceof CTTbl) && (cursor.toPrevSibling())) { - o = cursor.getObject(); - } - if (!(o instanceof CTTbl)) { - tables.add(0, newT); - } else { - int pos = tables.indexOf(getTable((CTTbl) o)) + 1; - tables.add(pos, newT); - } - int i = 0; - cursor = t.newCursor(); - while (cursor.toPrevSibling()) { - o = cursor.getObject(); - if (o instanceof CTP || o instanceof CTTbl) - i++; - } - bodyElements.add(i, newT); - XmlCursor c2 = t.newCursor(); - cursor.toCursor(c2); - cursor.toEndToken(); - c2.dispose(); - return newT; - } - return null; - } - - /** - * Add a new {@link XWPFParagraph} at position of the cursor. - * - * @param cursor - * @return The inserted {@link XWPFParagraph} - * @see org.apache.poi.xwpf.usermodel.IBody#insertNewParagraph(XmlCursor cursor) - */ - public XWPFParagraph insertNewParagraph(final XmlCursor cursor) { - if (isCursorInFtn(cursor)) { - String uri = CTP.type.getName().getNamespaceURI(); - String localPart = "p"; - cursor.beginElement(localPart, uri); - cursor.toParent(); - CTP p = (CTP) cursor.getObject(); - XWPFParagraph newP = new XWPFParagraph(p, this); - XmlObject o = null; - while (!(o instanceof CTP) && (cursor.toPrevSibling())) { - o = cursor.getObject(); - } - if ((!(o instanceof CTP)) || o == p) { - paragraphs.add(0, newP); - } else { - int pos = paragraphs.indexOf(getParagraph((CTP) o)) + 1; - paragraphs.add(pos, newP); - } - int i = 0; - XmlCursor p2 = p.newCursor(); - cursor.toCursor(p2); - p2.dispose(); - while (cursor.toPrevSibling()) { - o = cursor.getObject(); - if (o instanceof CTP || o instanceof CTTbl) - i++; - } - bodyElements.add(i, newP); - p2 = p.newCursor(); - cursor.toCursor(p2); - cursor.toEndToken(); - p2.dispose(); - return newP; - } - return null; - } - - /** - * Add a new {@link XWPFTable} to the end of the footnote. - * - * @param table CTTbl object from which to construct the {@link XWPFTable} - * @return The added {@link XWPFTable} - */ - public XWPFTable addNewTbl(CTTbl table) { - CTTbl newTable = ctFtnEdn.addNewTbl(); - newTable.set(table); - XWPFTable xTable = new XWPFTable(newTable, this); - tables.add(xTable); - return xTable; - } - - /** - * Add a new {@link XWPFParagraph} to the end of the footnote. - * - * @param paragraph CTP paragraph from which to construct the {@link XWPFParagraph} - * @return The added {@link XWPFParagraph} - */ - public XWPFParagraph addNewParagraph(CTP paragraph) { - CTP newPara = ctFtnEdn.addNewP(); - newPara.set(paragraph); - XWPFParagraph xPara = new XWPFParagraph(newPara, this); - paragraphs.add(xPara); - return xPara; - } - - /** - * Get the {@link XWPFDocument} the footnote is part of. - * @see org.apache.poi.xwpf.usermodel.IBody#getXWPFDocument() - */ - public XWPFDocument getXWPFDocument() { - return document; - } - - /** - * Get the Part to which the footnote belongs, which you need for adding relationships to other parts - * @return {@link POIXMLDocumentPart} that contains the footnote. - * - * @see org.apache.poi.xwpf.usermodel.IBody#getPart() - */ - public POIXMLDocumentPart getPart() { - return footnotes; - } - - /** - * Get the part type {@link BodyType} of the footnote. - * @return The {@link BodyType} value. - * - * @see org.apache.poi.xwpf.usermodel.IBody#getPartType() - */ - public BodyType getPartType() { - return BodyType.FOOTNOTE; - } - - /** - * Get the ID of the footnote. - *

Footnote IDs are unique across all bottom-of-the-page and - * end note footnotes.

- * - * @return Footnote ID - * @since 4.0.0 - */ - public BigInteger getId() { - return this.ctFtnEdn.getId(); - } - - /** - * Appends a new {@link XWPFParagraph} to this footnote. - * - * @return The new {@link XWPFParagraph} - * @since 4.0.0 - */ - public XWPFParagraph createParagraph() { - XWPFParagraph p = new XWPFParagraph(this.ctFtnEdn.addNewP(), this); - paragraphs.add(p); - bodyElements.add(p); - - // If the paragraph is the first paragraph in the footnote, - // ensure that it has a footnote reference run. - - if (p.equals(getParagraphs().get(0))) { - ensureFootnoteRef(p); - } - return p; - } - - /** - * Ensure that the specified paragraph has a reference marker for this - * footnote by adding a footnote reference if one is not found. - *

This method is for the first paragraph in the footnote, not - * paragraphs that will refer to the footnote. For references to - * the footnote, use {@link XWPFParagraph#addFootnoteReference(XWPFFootnote)}. - *

- *

The first run of the first paragraph in a footnote should - * contain a {@link CTFtnEdnRef} object.

- * - * @param p The {@link XWPFParagraph} to ensure - * @since 4.0.0 - */ - public abstract void ensureFootnoteRef(XWPFParagraph p); - - /** - * Appends a new {@link XWPFTable} to this footnote - * - * @return The new {@link XWPFTable} - * @since 4.0.0 - */ - public XWPFTable createTable() { - XWPFTable table = new XWPFTable(ctFtnEdn.addNewTbl(), this); - if (bodyElements.size() == 0) { - XWPFParagraph p = createParagraph(); - ensureFootnoteRef(p); - } - bodyElements.add(table); - tables.add(table); - return table; - } - - /** - * Appends a new {@link XWPFTable} to this footnote - * @param rows Number of rows to initialize the table with - * @param cols Number of columns to initialize the table with - * @return the new {@link XWPFTable} with the specified number of rows and columns - * @since 4.0.0 - */ - public XWPFTable createTable(int rows, int cols) { - XWPFTable table = new XWPFTable(ctFtnEdn.addNewTbl(), this, rows, cols); - bodyElements.add(table); - tables.add(table); - return table; - } - -} \ No newline at end of file diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/AbstractXWPFFootnotesEndnotes.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/AbstractXWPFFootnotesEndnotes.java deleted file mode 100644 index e0ed976f43..0000000000 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/AbstractXWPFFootnotesEndnotes.java +++ /dev/null @@ -1,90 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ -package org.apache.poi.xwpf.usermodel; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.poi.ooxml.POIXMLDocumentPart; -import org.apache.poi.openxml4j.opc.OPCPackage; -import org.apache.poi.openxml4j.opc.PackagePart; - -/** - * Base class for the Footnotes and Endnotes part implementations. - * @since 4.0.0 - */ -public abstract class AbstractXWPFFootnotesEndnotes extends POIXMLDocumentPart { - - protected XWPFDocument document; - protected List listFootnote = new ArrayList<>(); - private FootnoteEndnoteIdManager idManager; - - public AbstractXWPFFootnotesEndnotes(OPCPackage pkg) { - super(pkg); - } - - public AbstractXWPFFootnotesEndnotes(OPCPackage pkg, - String coreDocumentRel) { - super(pkg, coreDocumentRel); - } - - public AbstractXWPFFootnotesEndnotes() { - super(); - } - - public AbstractXWPFFootnotesEndnotes(PackagePart part) { - super(part); - } - - public AbstractXWPFFootnotesEndnotes(POIXMLDocumentPart parent, PackagePart part) { - super(parent, part); - } - - - public AbstractXWPFFootnoteEndnote getFootnoteById(int id) { - for (AbstractXWPFFootnoteEndnote note : listFootnote) { - if (note.getCTFtnEdn().getId().intValue() == id) - return note; - } - return null; - } - - /** - * @see org.apache.poi.xwpf.usermodel.IBody#getPart() - */ - public XWPFDocument getXWPFDocument() { - if (document != null) { - return document; - } else { - return (XWPFDocument) getParent(); - } - } - - public void setXWPFDocument(XWPFDocument doc) { - document = doc; - } - - public void setIdManager(FootnoteEndnoteIdManager footnoteIdManager) { - this.idManager = footnoteIdManager; - - } - - public FootnoteEndnoteIdManager getIdManager() { - return this.idManager; - } - -} \ No newline at end of file diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/AbstractXWPFSDT.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/AbstractXWPFSDT.java deleted file mode 100644 index bacabcbe84..0000000000 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/AbstractXWPFSDT.java +++ /dev/null @@ -1,107 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ -package org.apache.poi.xwpf.usermodel; - -import org.apache.poi.ooxml.POIXMLDocumentPart; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtPr; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTString; - -/** - * Experimental abstract class that is a base for XWPFSDT and XWPFSDTCell - *

- * WARNING - APIs expected to change rapidly. - *

- * These classes have so far been built only for read-only processing. - */ -public abstract class AbstractXWPFSDT implements ISDTContents { - private final String title; - private final String tag; - private final IBody part; - - public AbstractXWPFSDT(CTSdtPr pr, IBody part) { - if (pr == null) { - title = ""; - tag = ""; - } else { - CTString[] aliases = pr.getAliasArray(); - if (aliases != null && aliases.length > 0) { - title = aliases[0].getVal(); - } else { - title = ""; - } - CTString[] tags = pr.getTagArray(); - if (tags != null && tags.length > 0) { - tag = tags[0].getVal(); - } else { - tag = ""; - } - } - this.part = part; - - } - - /** - * @return first SDT Title - */ - public String getTitle() { - return title; - } - - /** - * @return first SDT Tag - */ - public String getTag() { - return tag; - } - - /** - * @return the content object - */ - public abstract ISDTContent getContent(); - - /** - * @return null - */ - public IBody getBody() { - return null; - } - - /** - * @return document part - */ - public POIXMLDocumentPart getPart() { - return part.getPart(); - } - - /** - * @return partType - */ - public BodyType getPartType() { - return BodyType.CONTENTCONTROL; - } - - /** - * @return element type - */ - public BodyElementType getElementType() { - return BodyElementType.CONTENTCONTROL; - } - - public XWPFDocument getDocument() { - return part.getXWPFDocument(); - } -} diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/FootnoteEndnoteIdManager.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/FootnoteEndnoteIdManager.java index 7fcefe2f79..2dc78b1d94 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/FootnoteEndnoteIdManager.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/FootnoteEndnoteIdManager.java @@ -41,10 +41,10 @@ public class FootnoteEndnoteIdManager { public BigInteger nextId() { List ids = new ArrayList(); - for (AbstractXWPFFootnoteEndnote note : document.getFootnotes()) { + for (XWPFAbstractFootnoteEndnote note : document.getFootnotes()) { ids.add(note.getId()); } - for (AbstractXWPFFootnoteEndnote note : document.getEndnotes()) { + for (XWPFAbstractFootnoteEndnote note : document.getEndnotes()) { ids.add(note.getId()); } int cand = ids.size(); diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFAbstractFootnoteEndnote.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFAbstractFootnoteEndnote.java new file mode 100644 index 0000000000..88998af955 --- /dev/null +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFAbstractFootnoteEndnote.java @@ -0,0 +1,515 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ +package org.apache.poi.xwpf.usermodel; + +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.apache.poi.ooxml.POIXMLDocumentPart; +import org.apache.poi.util.Internal; +import org.apache.xmlbeans.XmlCursor; +import org.apache.xmlbeans.XmlObject; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFtnEdn; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFtnEdnRef; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc; + +/** + * Base class for both bottom-of-the-page footnotes {@link XWPFFootnote} and end + * notes {@link XWPFEndnote}). + *

The only significant difference between footnotes and + * end notes is which part they go on. Footnotes are managed by the Footnotes part + * {@link XWPFFootnotes} and end notes are managed by the Endnotes part {@link XWPFEndnotes}.

+ * @since 4.0.0 + */ +public abstract class XWPFAbstractFootnoteEndnote implements Iterable, IBody { + + private List paragraphs = new ArrayList<>(); + private List tables = new ArrayList<>(); + private List pictures = new ArrayList<>(); + private List bodyElements = new ArrayList<>(); + protected CTFtnEdn ctFtnEdn; + protected XWPFAbstractFootnotesEndnotes footnotes; + protected XWPFDocument document; + + public XWPFAbstractFootnoteEndnote() { + super(); + } + + @Internal + protected XWPFAbstractFootnoteEndnote(XWPFDocument document, CTFtnEdn body) { + ctFtnEdn = body; + this.document = document; + init(); + } + + @Internal + protected XWPFAbstractFootnoteEndnote(CTFtnEdn note, XWPFAbstractFootnotesEndnotes footnotes) { + this.footnotes = footnotes; + ctFtnEdn = note; + document = footnotes.getXWPFDocument(); + init(); + } + + protected void init() { + XmlCursor cursor = ctFtnEdn.newCursor(); + //copied from XWPFDocument...should centralize this code + //to avoid duplication + cursor.selectPath("./*"); + while (cursor.toNextSelection()) { + XmlObject o = cursor.getObject(); + if (o instanceof CTP) { + XWPFParagraph p = new XWPFParagraph((CTP) o, this); + bodyElements.add(p); + paragraphs.add(p); + } else if (o instanceof CTTbl) { + XWPFTable t = new XWPFTable((CTTbl) o, this); + bodyElements.add(t); + tables.add(t); + } else if (o instanceof CTSdtBlock) { + XWPFSDT c = new XWPFSDT((CTSdtBlock) o, this); + bodyElements.add(c); + } + + } + cursor.dispose(); + } + + /** + * Get the list of {@link XWPFParagraph}s in the footnote. + * @return List of paragraphs + */ + public List getParagraphs() { + return paragraphs; + } + + /** + * Get an iterator over the {@link XWPFParagraph}s in the footnote. + * @return Iterator over the paragraph list. + */ + public Iterator iterator() { + return paragraphs.iterator(); + } + + /** + * Get the list of {@link XWPFTable}s in the footnote. + * @return List of tables + */ + public List getTables() { + return tables; + } + + /** + * Gets the list of {@link XWPFPictureData}s in the footnote. + * @return List of pictures + */ + public List getPictures() { + return pictures; + } + + /** + * Gets the body elements ({@link IBodyElement}) of the footnote. + * @return List of body elements. + */ + public List getBodyElements() { + return bodyElements; + } + + /** + * Gets the underlying CTFtnEdn object for the footnote. + * @return CTFtnEdn object + */ + public CTFtnEdn getCTFtnEdn() { + return ctFtnEdn; + } + + /** + * Set the underlying CTFtnEdn for the footnote. + *

Use {@link XWPFDocument#createFootnote()} to create new footnotes.

+ * @param footnote The CTFtnEdn object that will underly the footnote. + */ + public void setCTFtnEdn(CTFtnEdn footnote) { + ctFtnEdn = footnote; + } + + /** + * Gets the {@link XWPFTable} at the specified position from the footnote's table array. + * @param pos in table array + * @return The {@link XWPFTable} at position pos, or null if there is no table at position pos. + * @see org.apache.poi.xwpf.usermodel.IBody#getTableArray(int) + */ + public XWPFTable getTableArray(int pos) { + if (pos >= 0 && pos < tables.size()) { + return tables.get(pos); + } + return null; + } + + /** + * Inserts an existing {@link XWPFTable) into the arrays bodyElements and tables. + * + * @param pos Position, in the bodyElements array, to insert the table + * @param table {@link XWPFTable) to be inserted + * @see org.apache.poi.xwpf.usermodel.IBody#insertTable(int pos, XWPFTable table) + */ + public void insertTable(int pos, XWPFTable table) { + bodyElements.add(pos, table); + int i = 0; + for (CTTbl tbl : ctFtnEdn.getTblList()) { + if (tbl == table.getCTTbl()) { + break; + } + i++; + } + tables.add(i, table); + + } + + /** + * if there is a corresponding {@link XWPFTable} of the parameter + * ctTable in the tableList of this header + * the method will return this table, or null if there is no + * corresponding {@link XWPFTable}. + * + * @param ctTable + * @see org.apache.poi.xwpf.usermodel.IBody#getTable(CTTbl ctTable) + */ + public XWPFTable getTable(CTTbl ctTable) { + for (XWPFTable table : tables) { + if (table == null) + return null; + if (table.getCTTbl().equals(ctTable)) + return table; + } + return null; + } + + /** + * if there is a corresponding {@link XWPFParagraph} of the parameter p in the paragraphList of this header or footer + * the method will return that paragraph, otherwise the method will return null. + * + * @param p The CTP paragraph to find the corresponding {@link XWPFParagraph} for. + * @return The {@link XWPFParagraph} that corresponds to the CTP paragraph in the paragraph + * list of this footnote or null if no paragraph is found. + * @see org.apache.poi.xwpf.usermodel.IBody#getParagraph(CTP p) + */ + public XWPFParagraph getParagraph(CTP p) { + for (XWPFParagraph paragraph : paragraphs) { + if (paragraph.getCTP().equals(p)) + return paragraph; + } + return null; + } + + /** + * Returns the {@link XWPFParagraph} at position pos in footnote's paragraph array. + * @param pos Array position of the paragraph to get. + * @return the {@link XWPFParagraph} at position pos, or null if there is no paragraph at that position. + * + * @see org.apache.poi.xwpf.usermodel.IBody#getParagraphArray(int pos) + */ + public XWPFParagraph getParagraphArray(int pos) { + if(pos >=0 && pos < paragraphs.size()) { + return paragraphs.get(pos); + } + return null; + } + + /** + * get the {@link XWPFTableCell} that belongs to the CTTc cell. + * + * @param cell + * @return {@link XWPFTableCell} that corresponds to the CTTc cell, if there is one, otherwise null. + * @see org.apache.poi.xwpf.usermodel.IBody#getTableCell(CTTc cell) + */ + public XWPFTableCell getTableCell(CTTc cell) { + XmlCursor cursor = cell.newCursor(); + cursor.toParent(); + XmlObject o = cursor.getObject(); + if (!(o instanceof CTRow)) { + return null; + } + CTRow row = (CTRow) o; + cursor.toParent(); + o = cursor.getObject(); + cursor.dispose(); + if (!(o instanceof CTTbl)) { + return null; + } + CTTbl tbl = (CTTbl) o; + XWPFTable table = getTable(tbl); + if (table == null) { + return null; + } + XWPFTableRow tableRow = table.getRow(row); + if(tableRow == null){ + return null; + } + return tableRow.getTableCell(cell); + } + + /** + * Verifies that cursor is on the right position. + * + * @param cursor + * @return true if the cursor is within a CTFtnEdn element. + */ + private boolean isCursorInFtn(XmlCursor cursor) { + XmlCursor verify = cursor.newCursor(); + verify.toParent(); + if (verify.getObject() == this.ctFtnEdn) { + return true; + } + return false; + } + + /** + * The owning object for this footnote + * + * @return The {@link XWPFFootnotes} object that contains this footnote. + */ + public POIXMLDocumentPart getOwner() { + return footnotes; + } + + /** + * Insert a table constructed from OOXML table markup. + * @param cursor + * @return the inserted {@link XWPFTable} + * @see org.apache.poi.xwpf.usermodel.IBody#insertNewTbl(XmlCursor cursor) + */ + public XWPFTable insertNewTbl(XmlCursor cursor) { + if (isCursorInFtn(cursor)) { + String uri = CTTbl.type.getName().getNamespaceURI(); + String localPart = "tbl"; + cursor.beginElement(localPart, uri); + cursor.toParent(); + CTTbl t = (CTTbl) cursor.getObject(); + XWPFTable newT = new XWPFTable(t, this); + cursor.removeXmlContents(); + XmlObject o = null; + while (!(o instanceof CTTbl) && (cursor.toPrevSibling())) { + o = cursor.getObject(); + } + if (!(o instanceof CTTbl)) { + tables.add(0, newT); + } else { + int pos = tables.indexOf(getTable((CTTbl) o)) + 1; + tables.add(pos, newT); + } + int i = 0; + cursor = t.newCursor(); + while (cursor.toPrevSibling()) { + o = cursor.getObject(); + if (o instanceof CTP || o instanceof CTTbl) + i++; + } + bodyElements.add(i, newT); + XmlCursor c2 = t.newCursor(); + cursor.toCursor(c2); + cursor.toEndToken(); + c2.dispose(); + return newT; + } + return null; + } + + /** + * Add a new {@link XWPFParagraph} at position of the cursor. + * + * @param cursor + * @return The inserted {@link XWPFParagraph} + * @see org.apache.poi.xwpf.usermodel.IBody#insertNewParagraph(XmlCursor cursor) + */ + public XWPFParagraph insertNewParagraph(final XmlCursor cursor) { + if (isCursorInFtn(cursor)) { + String uri = CTP.type.getName().getNamespaceURI(); + String localPart = "p"; + cursor.beginElement(localPart, uri); + cursor.toParent(); + CTP p = (CTP) cursor.getObject(); + XWPFParagraph newP = new XWPFParagraph(p, this); + XmlObject o = null; + while (!(o instanceof CTP) && (cursor.toPrevSibling())) { + o = cursor.getObject(); + } + if ((!(o instanceof CTP)) || o == p) { + paragraphs.add(0, newP); + } else { + int pos = paragraphs.indexOf(getParagraph((CTP) o)) + 1; + paragraphs.add(pos, newP); + } + int i = 0; + XmlCursor p2 = p.newCursor(); + cursor.toCursor(p2); + p2.dispose(); + while (cursor.toPrevSibling()) { + o = cursor.getObject(); + if (o instanceof CTP || o instanceof CTTbl) + i++; + } + bodyElements.add(i, newP); + p2 = p.newCursor(); + cursor.toCursor(p2); + cursor.toEndToken(); + p2.dispose(); + return newP; + } + return null; + } + + /** + * Add a new {@link XWPFTable} to the end of the footnote. + * + * @param table CTTbl object from which to construct the {@link XWPFTable} + * @return The added {@link XWPFTable} + */ + public XWPFTable addNewTbl(CTTbl table) { + CTTbl newTable = ctFtnEdn.addNewTbl(); + newTable.set(table); + XWPFTable xTable = new XWPFTable(newTable, this); + tables.add(xTable); + return xTable; + } + + /** + * Add a new {@link XWPFParagraph} to the end of the footnote. + * + * @param paragraph CTP paragraph from which to construct the {@link XWPFParagraph} + * @return The added {@link XWPFParagraph} + */ + public XWPFParagraph addNewParagraph(CTP paragraph) { + CTP newPara = ctFtnEdn.addNewP(); + newPara.set(paragraph); + XWPFParagraph xPara = new XWPFParagraph(newPara, this); + paragraphs.add(xPara); + return xPara; + } + + /** + * Get the {@link XWPFDocument} the footnote is part of. + * @see org.apache.poi.xwpf.usermodel.IBody#getXWPFDocument() + */ + public XWPFDocument getXWPFDocument() { + return document; + } + + /** + * Get the Part to which the footnote belongs, which you need for adding relationships to other parts + * @return {@link POIXMLDocumentPart} that contains the footnote. + * + * @see org.apache.poi.xwpf.usermodel.IBody#getPart() + */ + public POIXMLDocumentPart getPart() { + return footnotes; + } + + /** + * Get the part type {@link BodyType} of the footnote. + * @return The {@link BodyType} value. + * + * @see org.apache.poi.xwpf.usermodel.IBody#getPartType() + */ + public BodyType getPartType() { + return BodyType.FOOTNOTE; + } + + /** + * Get the ID of the footnote. + *

Footnote IDs are unique across all bottom-of-the-page and + * end note footnotes.

+ * + * @return Footnote ID + * @since 4.0.0 + */ + public BigInteger getId() { + return this.ctFtnEdn.getId(); + } + + /** + * Appends a new {@link XWPFParagraph} to this footnote. + * + * @return The new {@link XWPFParagraph} + * @since 4.0.0 + */ + public XWPFParagraph createParagraph() { + XWPFParagraph p = new XWPFParagraph(this.ctFtnEdn.addNewP(), this); + paragraphs.add(p); + bodyElements.add(p); + + // If the paragraph is the first paragraph in the footnote, + // ensure that it has a footnote reference run. + + if (p.equals(getParagraphs().get(0))) { + ensureFootnoteRef(p); + } + return p; + } + + /** + * Ensure that the specified paragraph has a reference marker for this + * footnote by adding a footnote reference if one is not found. + *

This method is for the first paragraph in the footnote, not + * paragraphs that will refer to the footnote. For references to + * the footnote, use {@link XWPFParagraph#addFootnoteReference(XWPFFootnote)}. + *

+ *

The first run of the first paragraph in a footnote should + * contain a {@link CTFtnEdnRef} object.

+ * + * @param p The {@link XWPFParagraph} to ensure + * @since 4.0.0 + */ + public abstract void ensureFootnoteRef(XWPFParagraph p); + + /** + * Appends a new {@link XWPFTable} to this footnote + * + * @return The new {@link XWPFTable} + * @since 4.0.0 + */ + public XWPFTable createTable() { + XWPFTable table = new XWPFTable(ctFtnEdn.addNewTbl(), this); + if (bodyElements.size() == 0) { + XWPFParagraph p = createParagraph(); + ensureFootnoteRef(p); + } + bodyElements.add(table); + tables.add(table); + return table; + } + + /** + * Appends a new {@link XWPFTable} to this footnote + * @param rows Number of rows to initialize the table with + * @param cols Number of columns to initialize the table with + * @return the new {@link XWPFTable} with the specified number of rows and columns + * @since 4.0.0 + */ + public XWPFTable createTable(int rows, int cols) { + XWPFTable table = new XWPFTable(ctFtnEdn.addNewTbl(), this, rows, cols); + bodyElements.add(table); + tables.add(table); + return table; + } + +} \ No newline at end of file diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFAbstractFootnotesEndnotes.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFAbstractFootnotesEndnotes.java new file mode 100644 index 0000000000..d626350298 --- /dev/null +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFAbstractFootnotesEndnotes.java @@ -0,0 +1,90 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ +package org.apache.poi.xwpf.usermodel; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.poi.ooxml.POIXMLDocumentPart; +import org.apache.poi.openxml4j.opc.OPCPackage; +import org.apache.poi.openxml4j.opc.PackagePart; + +/** + * Base class for the Footnotes and Endnotes part implementations. + * @since 4.0.0 + */ +public abstract class XWPFAbstractFootnotesEndnotes extends POIXMLDocumentPart { + + protected XWPFDocument document; + protected List listFootnote = new ArrayList<>(); + private FootnoteEndnoteIdManager idManager; + + public XWPFAbstractFootnotesEndnotes(OPCPackage pkg) { + super(pkg); + } + + public XWPFAbstractFootnotesEndnotes(OPCPackage pkg, + String coreDocumentRel) { + super(pkg, coreDocumentRel); + } + + public XWPFAbstractFootnotesEndnotes() { + super(); + } + + public XWPFAbstractFootnotesEndnotes(PackagePart part) { + super(part); + } + + public XWPFAbstractFootnotesEndnotes(POIXMLDocumentPart parent, PackagePart part) { + super(parent, part); + } + + + public XWPFAbstractFootnoteEndnote getFootnoteById(int id) { + for (XWPFAbstractFootnoteEndnote note : listFootnote) { + if (note.getCTFtnEdn().getId().intValue() == id) + return note; + } + return null; + } + + /** + * @see org.apache.poi.xwpf.usermodel.IBody#getPart() + */ + public XWPFDocument getXWPFDocument() { + if (document != null) { + return document; + } else { + return (XWPFDocument) getParent(); + } + } + + public void setXWPFDocument(XWPFDocument doc) { + document = doc; + } + + public void setIdManager(FootnoteEndnoteIdManager footnoteIdManager) { + this.idManager = footnoteIdManager; + + } + + public FootnoteEndnoteIdManager getIdManager() { + return this.idManager; + } + +} \ No newline at end of file diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFAbstractSDT.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFAbstractSDT.java new file mode 100644 index 0000000000..93b2cdba8a --- /dev/null +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFAbstractSDT.java @@ -0,0 +1,107 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ +package org.apache.poi.xwpf.usermodel; + +import org.apache.poi.ooxml.POIXMLDocumentPart; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtPr; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTString; + +/** + * Experimental abstract class that is a base for XWPFSDT and XWPFSDTCell + *

+ * WARNING - APIs expected to change rapidly. + *

+ * These classes have so far been built only for read-only processing. + */ +public abstract class XWPFAbstractSDT implements ISDTContents { + private final String title; + private final String tag; + private final IBody part; + + public XWPFAbstractSDT(CTSdtPr pr, IBody part) { + if (pr == null) { + title = ""; + tag = ""; + } else { + CTString[] aliases = pr.getAliasArray(); + if (aliases != null && aliases.length > 0) { + title = aliases[0].getVal(); + } else { + title = ""; + } + CTString[] tags = pr.getTagArray(); + if (tags != null && tags.length > 0) { + tag = tags[0].getVal(); + } else { + tag = ""; + } + } + this.part = part; + + } + + /** + * @return first SDT Title + */ + public String getTitle() { + return title; + } + + /** + * @return first SDT Tag + */ + public String getTag() { + return tag; + } + + /** + * @return the content object + */ + public abstract ISDTContent getContent(); + + /** + * @return null + */ + public IBody getBody() { + return null; + } + + /** + * @return document part + */ + public POIXMLDocumentPart getPart() { + return part.getPart(); + } + + /** + * @return partType + */ + public BodyType getPartType() { + return BodyType.CONTENTCONTROL; + } + + /** + * @return element type + */ + public BodyElementType getElementType() { + return BodyElementType.CONTENTCONTROL; + } + + public XWPFDocument getDocument() { + return part.getXWPFDocument(); + } +} diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFEndnote.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFEndnote.java index 8f728788de..f18c1c118a 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFEndnote.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFEndnote.java @@ -34,11 +34,11 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR; * the footnote ID to create a reference to a footnote from within a paragraph.

*

To create a reference to a footnote within a paragraph you create a run * with a CTFtnEdnRef that specifies the ID of the target paragraph. - * The {@link XWPFParagraph#addFootnoteReference(AbstractXWPFFootnoteEndnote)} + * The {@link XWPFParagraph#addFootnoteReference(XWPFAbstractFootnoteEndnote)} * method does this for you.

* @since 4.0.0 */ -public class XWPFEndnote extends AbstractXWPFFootnoteEndnote { +public class XWPFEndnote extends XWPFAbstractFootnoteEndnote { public XWPFEndnote() {} @@ -48,7 +48,7 @@ public class XWPFEndnote extends AbstractXWPFFootnoteEndnote { } @Internal - public XWPFEndnote(CTFtnEdn note, AbstractXWPFFootnotesEndnotes footnotes) { + public XWPFEndnote(CTFtnEdn note, XWPFAbstractFootnotesEndnotes footnotes) { super(note, footnotes); } @@ -57,7 +57,7 @@ public class XWPFEndnote extends AbstractXWPFFootnoteEndnote { * end note by adding a footnote reference if one is not found. *

This method is for the first paragraph in the footnote, not * paragraphs that will refer to the footnote. For references to - * the footnote, use {@link XWPFParagraph#addFootnoteReference(AbstractXWPFFootnoteEndnote))}. + * the footnote, use {@link XWPFParagraph#addFootnoteReference(XWPFAbstractFootnoteEndnote))}. *

*

The first run of the first paragraph in a footnote should * contain a {@link CTFtnEdnRef} object.

diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFEndnotes.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFEndnotes.java index ebca459c05..deb76de2cb 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFEndnotes.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFEndnotes.java @@ -44,7 +44,7 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.STFtnEdn; * Managed end notes ({@link XWPFEndnote}). * @since 4.0.0 */ -public class XWPFEndnotes extends AbstractXWPFFootnotesEndnotes { +public class XWPFEndnotes extends XWPFAbstractFootnotesEndnotes { protected CTEndnotes ctEndnotes; @@ -183,7 +183,7 @@ public class XWPFEndnotes extends AbstractXWPFFootnotesEndnotes { */ public List getEndnotesList() { List resultList = new ArrayList(); - for (AbstractXWPFFootnoteEndnote note : listFootnote) { + for (XWPFAbstractFootnoteEndnote note : listFootnote) { resultList.add((XWPFEndnote)note); } return resultList; diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFootnote.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFootnote.java index d4afd64512..77459ecc87 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFootnote.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFootnote.java @@ -32,13 +32,13 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR; * the footnote ID to create a reference to a footnote from within a paragraph.

*

To create a reference to a footnote within a paragraph you create a run * with a CTFtnEdnRef that specifies the ID of the target paragraph. - * The {@link XWPFParagraph#addFootnoteReference(AbstractXWPFFootnoteEndnote)} + * The {@link XWPFParagraph#addFootnoteReference(XWPFAbstractFootnoteEndnote)} * method does this for you.

*/ -public class XWPFFootnote extends AbstractXWPFFootnoteEndnote { +public class XWPFFootnote extends XWPFAbstractFootnoteEndnote { @Internal - public XWPFFootnote(CTFtnEdn note, AbstractXWPFFootnotesEndnotes xFootnotes) { + public XWPFFootnote(CTFtnEdn note, XWPFAbstractFootnotesEndnotes xFootnotes) { super(note, xFootnotes); } diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFootnotes.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFootnotes.java index 4f3fa83b0d..144c692dcc 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFootnotes.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFootnotes.java @@ -43,7 +43,7 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.STFtnEdn; * Looks after the collection of Footnotes for a document. * Manages bottom-of-the-page footnotes ({@link XWPFFootnote}). */ -public class XWPFFootnotes extends AbstractXWPFFootnotesEndnotes { +public class XWPFFootnotes extends XWPFAbstractFootnotesEndnotes { protected CTFootnotes ctFootnotes; /** @@ -173,7 +173,7 @@ public class XWPFFootnotes extends AbstractXWPFFootnotesEndnotes { */ public List getFootnotesList() { List resultList = new ArrayList(); - for (AbstractXWPFFootnoteEndnote note : listFootnote) { + for (XWPFAbstractFootnoteEndnote note : listFootnote) { resultList.add((XWPFFootnote)note); } return resultList; 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 5080cec9f3..41ad4222fb 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java @@ -76,7 +76,7 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para if (o instanceof CTFtnEdnRef) { CTFtnEdnRef ftn = (CTFtnEdnRef) o; footnoteText.append(" [").append(ftn.getId()).append(": "); - AbstractXWPFFootnoteEndnote footnote = + XWPFAbstractFootnoteEndnote footnote = ftn.getDomNode().getLocalName().equals("footnoteReference") ? document.getFootnoteByID(ftn.getId().intValue()) : document.getEndnoteByID(ftn.getId().intValue()); @@ -1678,7 +1678,7 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para * @param footnote Footnote to which to add a reference. * @since 4.0.0 */ - public void addFootnoteReference(AbstractXWPFFootnoteEndnote footnote) { + public void addFootnoteReference(XWPFAbstractFootnoteEndnote footnote) { XWPFRun run = createRun(); CTR ctRun = run.getCTR(); ctRun.addNewRPr().addNewRStyle().setVal("FootnoteReference"); diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSDT.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSDT.java index 0f876357ce..82aa024623 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSDT.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSDT.java @@ -25,7 +25,7 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtRun; *

* WARNING - APIs expected to change rapidly */ -public class XWPFSDT extends AbstractXWPFSDT +public class XWPFSDT extends XWPFAbstractSDT implements IBodyElement, IRunBody, ISDTContents, IRunElement { private final ISDTContent content; diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSDTCell.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSDTCell.java index 438303c40b..5589287263 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSDTCell.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSDTCell.java @@ -27,7 +27,7 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtCell; *

* WARNING - APIs expected to change rapidly */ -public class XWPFSDTCell extends AbstractXWPFSDT implements ICell { +public class XWPFSDTCell extends XWPFAbstractSDT implements ICell { private final XWPFSDTContentCell cellContent; public XWPFSDTCell(CTSdtCell sdtCell, XWPFTableRow xwpfTableRow, IBody part) { diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFFootnotes.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFFootnotes.java index 39fb397442..1071f40c79 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFFootnotes.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFFootnotes.java @@ -31,11 +31,11 @@ public class TestXWPFFootnotes extends TestCase { public void testCreateFootnotes() throws IOException{ XWPFDocument docOut = new XWPFDocument(); - AbstractXWPFFootnotesEndnotes footnotes = docOut.createFootnotes(); + XWPFAbstractFootnotesEndnotes footnotes = docOut.createFootnotes(); assertNotNull(footnotes); - AbstractXWPFFootnotesEndnotes secondFootnotes = docOut.createFootnotes(); + XWPFAbstractFootnotesEndnotes secondFootnotes = docOut.createFootnotes(); assertSame(footnotes, secondFootnotes); diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java index 39a3ac6751..deac5c09ae 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java @@ -40,8 +40,8 @@ public final class TestXWPFSDT { XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug54849.docx"); String tag = null; String title = null; - List sdts = extractAllSDTs(doc); - for (AbstractXWPFSDT sdt : sdts) { + List sdts = extractAllSDTs(doc); + for (XWPFAbstractSDT sdt : sdts) { if (sdt.getContent().toString().equals("Rich_text")) { tag = "MyTag"; title = "MyTitle"; @@ -74,12 +74,12 @@ public final class TestXWPFSDT { }; XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug54849.docx"); - List sdts = extractAllSDTs(doc); + List sdts = extractAllSDTs(doc); assertEquals("number of sdts", contents.length, sdts.size()); for (int i = 0; i < contents.length; i++) { - AbstractXWPFSDT sdt = sdts.get(i); + XWPFAbstractSDT sdt = sdts.get(i); assertEquals(i + ": " + contents[i], contents[i], sdt.getContent().toString()); } } @@ -92,7 +92,7 @@ public final class TestXWPFSDT { //Bug54771a.docx and Bug54771b.docx test slightly //different recursion patterns. Keep both! XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug54771a.docx"); - List sdts = extractAllSDTs(doc); + List sdts = extractAllSDTs(doc); String text = sdts.get(0).getContent().getText(); assertEquals(2, sdts.size()); assertContains(text, "Test"); @@ -118,7 +118,7 @@ public final class TestXWPFSDT { @Test public void testNewLinesBetweenRuns() throws Exception { XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug55142.docx"); - List sdts = extractAllSDTs(doc); + List sdts = extractAllSDTs(doc); List targs = new ArrayList<>(); //these test newlines and tabs in paragraphs/body elements targs.add("Rich-text1 abcdefghi"); @@ -133,7 +133,7 @@ public final class TestXWPFSDT { targs.add("sdt_incell2 abcdefg"); for (int i = 0; i < sdts.size(); i++) { - AbstractXWPFSDT sdt = sdts.get(i); + XWPFAbstractSDT sdt = sdts.get(i); assertEquals(targs.get(i), targs.get(i), sdt.getContent().getText()); } } @@ -142,15 +142,15 @@ public final class TestXWPFSDT { public void test60341() throws IOException { //handle sdtbody without an sdtpr XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug60341.docx"); - List sdts = extractAllSDTs(doc); + List sdts = extractAllSDTs(doc); assertEquals(1, sdts.size()); assertEquals("", sdts.get(0).getTag()); assertEquals("", sdts.get(0).getTitle()); } - private List extractAllSDTs(XWPFDocument doc) { + private List extractAllSDTs(XWPFDocument doc) { - List sdts = new ArrayList<>(); + List sdts = new ArrayList<>(); List headers = doc.getHeaderList(); for (XWPFHeader header : headers) { @@ -172,8 +172,8 @@ public final class TestXWPFSDT { return sdts; } - private List extractSDTsFromBodyElements(List elements) { - List sdts = new ArrayList<>(); + private List extractSDTsFromBodyElements(List elements) { + List sdts = new ArrayList<>(); for (IBodyElement e : elements) { if (e instanceof XWPFSDT) { XWPFSDT sdt = (XWPFSDT) e; @@ -195,9 +195,9 @@ public final class TestXWPFSDT { return sdts; } - private List extractSDTsFromTable(XWPFTable table) { + private List extractSDTsFromTable(XWPFTable table) { - List sdts = new ArrayList<>(); + List sdts = new ArrayList<>(); for (XWPFTableRow r : table.getRows()) { for (ICell c : r.getTableICells()) { if (c instanceof XWPFSDTCell) {