Author: fanningpj
Date: Thu Aug 2 20:04:49 2018
New Revision: 1837335
URL: http://svn.apache.org/viewvc?rev=1837335&view=rev
Log:
[github-120] rename some new xpwf abstract classes. This closes #120
Added:
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFAbstractFootnoteEndnote.java
(with props)
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFAbstractFootnotesEndnotes.java
(with props)
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFAbstractSDT.java
(with props)
Removed:
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/AbstractXWPFFootnoteEndnote.java
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/AbstractXWPFFootnotesEndnotes.java
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/AbstractXWPFSDT.java
Modified:
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/FootnoteEndnoteIdManager.java
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFEndnote.java
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFEndnotes.java
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFootnote.java
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFootnotes.java
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSDT.java
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSDTCell.java
poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFFootnotes.java
poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java
Modified:
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/FootnoteEndnoteIdManager.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/FootnoteEndnoteIdManager.java?rev=1837335&r1=1837334&r2=1837335&view=diff
==============================================================================
---
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/FootnoteEndnoteIdManager.java
(original)
+++
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/FootnoteEndnoteIdManager.java
Thu Aug 2 20:04:49 2018
@@ -41,10 +41,10 @@ public class FootnoteEndnoteIdManager {
public BigInteger nextId() {
List<BigInteger> ids = new ArrayList<BigInteger>();
- 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();
Added:
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFAbstractFootnoteEndnote.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFAbstractFootnoteEndnote.java?rev=1837335&view=auto
==============================================================================
---
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFAbstractFootnoteEndnote.java
(added)
+++
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFAbstractFootnoteEndnote.java
Thu Aug 2 20:04:49 2018
@@ -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}).
+ * <p>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}.</p>
+ * @since 4.0.0
+ */
+public abstract class XWPFAbstractFootnoteEndnote implements
Iterable<XWPFParagraph>, IBody {
+
+ private List<XWPFParagraph> paragraphs = new ArrayList<>();
+ private List<XWPFTable> tables = new ArrayList<>();
+ private List<XWPFPictureData> pictures = new ArrayList<>();
+ private List<IBodyElement> 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<XWPFParagraph> getParagraphs() {
+ return paragraphs;
+ }
+
+ /**
+ * Get an iterator over the {@link XWPFParagraph}s in the footnote.
+ * @return Iterator over the paragraph list.
+ */
+ public Iterator<XWPFParagraph> iterator() {
+ return paragraphs.iterator();
+ }
+
+ /**
+ * Get the list of {@link XWPFTable}s in the footnote.
+ * @return List of tables
+ */
+ public List<XWPFTable> getTables() {
+ return tables;
+ }
+
+ /**
+ * Gets the list of {@link XWPFPictureData}s in the footnote.
+ * @return List of pictures
+ */
+ public List<XWPFPictureData> getPictures() {
+ return pictures;
+ }
+
+ /**
+ * Gets the body elements ({@link IBodyElement}) of the footnote.
+ * @return List of body elements.
+ */
+ public List<IBodyElement> 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.
+ * <p>Use {@link XWPFDocument#createFootnote()} to create new
footnotes.</p>
+ * @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.
+ * <p>Footnote IDs are unique across all bottom-of-the-page and
+ * end note footnotes.</p>
+ *
+ * @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.
+ * <p>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)}.
+ * </p>
+ * <p>The first run of the first paragraph in a footnote should
+ * contain a {@link CTFtnEdnRef} object.</p>
+ *
+ * @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
Propchange:
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFAbstractFootnoteEndnote.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFAbstractFootnotesEndnotes.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFAbstractFootnotesEndnotes.java?rev=1837335&view=auto
==============================================================================
---
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFAbstractFootnotesEndnotes.java
(added)
+++
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFAbstractFootnotesEndnotes.java
Thu Aug 2 20:04:49 2018
@@ -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<XWPFAbstractFootnoteEndnote> 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
Propchange:
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFAbstractFootnotesEndnotes.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFAbstractSDT.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFAbstractSDT.java?rev=1837335&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFAbstractSDT.java
(added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFAbstractSDT.java
Thu Aug 2 20:04:49 2018
@@ -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
+ * <p>
+ * WARNING - APIs expected to change rapidly.
+ * <p>
+ * 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();
+ }
+}
Propchange:
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFAbstractSDT.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFEndnote.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFEndnote.java?rev=1837335&r1=1837334&r2=1837335&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFEndnote.java
(original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFEndnote.java Thu
Aug 2 20:04:49 2018
@@ -34,11 +34,11 @@ import org.openxmlformats.schemas.wordpr
* the footnote ID to create a reference to a footnote from within a
paragraph.</p>
* <p>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.</p>
* @since 4.0.0
*/
-public class XWPFEndnote extends AbstractXWPFFootnoteEndnote {
+public class XWPFEndnote extends XWPFAbstractFootnoteEndnote {
public XWPFEndnote() {}
@@ -48,7 +48,7 @@ public class XWPFEndnote extends Abstrac
}
@Internal
- public XWPFEndnote(CTFtnEdn note, AbstractXWPFFootnotesEndnotes footnotes)
{
+ public XWPFEndnote(CTFtnEdn note, XWPFAbstractFootnotesEndnotes footnotes)
{
super(note, footnotes);
}
@@ -57,7 +57,7 @@ public class XWPFEndnote extends Abstrac
* end note by adding a footnote reference if one is not found.
* <p>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))}.
* </p>
* <p>The first run of the first paragraph in a footnote should
* contain a {@link CTFtnEdnRef} object.</p>
Modified:
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFEndnotes.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFEndnotes.java?rev=1837335&r1=1837334&r2=1837335&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFEndnotes.java
(original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFEndnotes.java
Thu Aug 2 20:04:49 2018
@@ -44,7 +44,7 @@ import org.openxmlformats.schemas.wordpr
* 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 Abstra
*/
public List<XWPFEndnote> getEndnotesList() {
List<XWPFEndnote> resultList = new ArrayList<XWPFEndnote>();
- for (AbstractXWPFFootnoteEndnote note : listFootnote) {
+ for (XWPFAbstractFootnoteEndnote note : listFootnote) {
resultList.add((XWPFEndnote)note);
}
return resultList;
Modified:
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFootnote.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFootnote.java?rev=1837335&r1=1837334&r2=1837335&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFootnote.java
(original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFootnote.java
Thu Aug 2 20:04:49 2018
@@ -32,13 +32,13 @@ import org.openxmlformats.schemas.wordpr
* the footnote ID to create a reference to a footnote from within a
paragraph.</p>
* <p>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.</p>
*/
-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);
}
Modified:
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFootnotes.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFootnotes.java?rev=1837335&r1=1837334&r2=1837335&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFootnotes.java
(original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFootnotes.java
Thu Aug 2 20:04:49 2018
@@ -43,7 +43,7 @@ import org.openxmlformats.schemas.wordpr
* 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 Abstr
*/
public List<XWPFFootnote> getFootnotesList() {
List<XWPFFootnote> resultList = new ArrayList<XWPFFootnote>();
- for (AbstractXWPFFootnoteEndnote note : listFootnote) {
+ for (XWPFAbstractFootnoteEndnote note : listFootnote) {
resultList.add((XWPFFootnote)note);
}
return resultList;
Modified:
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java?rev=1837335&r1=1837334&r2=1837335&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java
(original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java
Thu Aug 2 20:04:49 2018
@@ -76,7 +76,7 @@ public class XWPFParagraph implements IB
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 IB
* @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");
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSDT.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSDT.java?rev=1837335&r1=1837334&r2=1837335&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSDT.java
(original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSDT.java Thu Aug
2 20:04:49 2018
@@ -25,7 +25,7 @@ import org.openxmlformats.schemas.wordpr
* <p>
* 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;
Modified:
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSDTCell.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSDTCell.java?rev=1837335&r1=1837334&r2=1837335&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSDTCell.java
(original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSDTCell.java Thu
Aug 2 20:04:49 2018
@@ -27,7 +27,7 @@ import org.openxmlformats.schemas.wordpr
* <p>
* 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) {
Modified:
poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFFootnotes.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFFootnotes.java?rev=1837335&r1=1837334&r2=1837335&view=diff
==============================================================================
---
poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFFootnotes.java
(original)
+++
poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFFootnotes.java
Thu Aug 2 20:04:49 2018
@@ -31,11 +31,11 @@ public class TestXWPFFootnotes extends T
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);
Modified:
poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java?rev=1837335&r1=1837334&r2=1837335&view=diff
==============================================================================
---
poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java
(original)
+++
poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java
Thu Aug 2 20:04:49 2018
@@ -40,8 +40,8 @@ public final class TestXWPFSDT {
XWPFDocument doc =
XWPFTestDataSamples.openSampleDocument("Bug54849.docx");
String tag = null;
String title = null;
- List<AbstractXWPFSDT> sdts = extractAllSDTs(doc);
- for (AbstractXWPFSDT sdt : sdts) {
+ List<XWPFAbstractSDT> 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<AbstractXWPFSDT> sdts = extractAllSDTs(doc);
+ List<XWPFAbstractSDT> 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<AbstractXWPFSDT> sdts = extractAllSDTs(doc);
+ List<XWPFAbstractSDT> 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<AbstractXWPFSDT> sdts = extractAllSDTs(doc);
+ List<XWPFAbstractSDT> sdts = extractAllSDTs(doc);
List<String> 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<AbstractXWPFSDT> sdts = extractAllSDTs(doc);
+ List<XWPFAbstractSDT> sdts = extractAllSDTs(doc);
assertEquals(1, sdts.size());
assertEquals("", sdts.get(0).getTag());
assertEquals("", sdts.get(0).getTitle());
}
- private List<AbstractXWPFSDT> extractAllSDTs(XWPFDocument doc) {
+ private List<XWPFAbstractSDT> extractAllSDTs(XWPFDocument doc) {
- List<AbstractXWPFSDT> sdts = new ArrayList<>();
+ List<XWPFAbstractSDT> sdts = new ArrayList<>();
List<XWPFHeader> headers = doc.getHeaderList();
for (XWPFHeader header : headers) {
@@ -172,8 +172,8 @@ public final class TestXWPFSDT {
return sdts;
}
- private List<AbstractXWPFSDT>
extractSDTsFromBodyElements(List<IBodyElement> elements) {
- List<AbstractXWPFSDT> sdts = new ArrayList<>();
+ private List<XWPFAbstractSDT>
extractSDTsFromBodyElements(List<IBodyElement> elements) {
+ List<XWPFAbstractSDT> 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<AbstractXWPFSDT> extractSDTsFromTable(XWPFTable table) {
+ private List<XWPFAbstractSDT> extractSDTsFromTable(XWPFTable table) {
- List<AbstractXWPFSDT> sdts = new ArrayList<>();
+ List<XWPFAbstractSDT> sdts = new ArrayList<>();
for (XWPFTableRow r : table.getRows()) {
for (ICell c : r.getTableICells()) {
if (c instanceof XWPFSDTCell) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]