[github-195] Rework getParagraph functions for XWPF. Thanks to Marius Volhart. This closes #195

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1883424 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2020-11-14 16:39:44 +00:00
parent 6bcdd5af58
commit b8cb440ce4
5 changed files with 14 additions and 47 deletions

View File

@ -71,13 +71,11 @@ public interface IBody {
public List<XWPFTable> getTables();
/**
* if there is a corresponding {@link XWPFParagraph} of the parameter ctTable in the paragraphList of this header or footer
* the method will return this paragraph
* if there is no corresponding {@link XWPFParagraph} the method will return null
* Returns the paragraph corresponding to the provided {@link CTP}.
*
* @param p is instance of CTP and is searching for an XWPFParagraph
* @return null if there is no XWPFParagraph with an corresponding CTPparagraph in the paragraphList of this header or footer
* XWPFParagraph with the correspondig CTP p
* @return The paragraph corresponding to the {@link CTP}, or {@code null} if there is no corresponding paragraph in
* this body.
*/
public XWPFParagraph getParagraph(CTP p);

View File

@ -90,7 +90,7 @@ public abstract class XWPFAbstractFootnoteEndnote implements Iterable<XWPFParag
XWPFSDT c = new XWPFSDT((CTSdtBlock) o, this);
bodyElements.add(c);
}
}
cursor.dispose();
}
@ -182,7 +182,7 @@ public abstract class XWPFAbstractFootnoteEndnote implements Iterable<XWPFParag
i++;
}
tables.add(i, table);
}
/**
@ -204,15 +204,7 @@ public abstract class XWPFAbstractFootnoteEndnote implements Iterable<XWPFParag
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)
*/
@Override
public XWPFParagraph getParagraph(CTP p) {
for (XWPFParagraph paragraph : paragraphs) {
if (paragraph.getCTP().equals(p))
@ -456,10 +448,10 @@ public abstract class XWPFAbstractFootnoteEndnote implements Iterable<XWPFParag
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);
}
@ -512,4 +504,4 @@ public abstract class XWPFAbstractFootnoteEndnote implements Iterable<XWPFParag
return table;
}
}
}

View File

@ -1546,17 +1546,11 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
return styles;
}
/**
* get the paragraph with the CTP class p
*
* @param p
* @return the paragraph with the CTP class p
*/
@Override
public XWPFParagraph getParagraph(CTP p) {
for (int i = 0; i < getParagraphs().size(); i++) {
if (getParagraphs().get(i).getCTP() == p) {
return getParagraphs().get(i);
for (XWPFParagraph paragraph : paragraphs) {
if (paragraph.getCTP() == p) {
return paragraph;
}
}
return null;

View File

@ -180,22 +180,13 @@ public abstract class XWPFHeaderFooter extends POIXMLDocumentPart implements IBo
return null;
}
/**
* if there is a corresponding {@link XWPFParagraph} of the parameter ctTable in the paragraphList of this header or footer
* the method will return this paragraph
* if there is no corresponding {@link XWPFParagraph} the method will return null
*
* @param p is instance of CTP and is searching for an XWPFParagraph
* @return null if there is no XWPFParagraph with an corresponding CTPparagraph in the paragraphList of this header or footer
* XWPFParagraph with the correspondig CTP p
*/
@Override
public XWPFParagraph getParagraph(CTP p) {
for (XWPFParagraph paragraph : paragraphs) {
if (paragraph.getCTP().equals(p))
return paragraph;
}
return null;
}
/**

View File

@ -175,15 +175,7 @@ public class XWPFTableCell implements IBody, ICell {
bodyElements.remove(removedParagraph);
}
/**
* if there is a corresponding {@link XWPFParagraph} of the parameter ctTable in the paragraphList of this table
* the method will return this paragraph
* if there is no corresponding {@link XWPFParagraph} the method will return null
*
* @param p is instance of CTP and is searching for an XWPFParagraph
* @return null if there is no XWPFParagraph with an corresponding CTPparagraph in the paragraphList of this table
* XWPFParagraph with the correspondig CTP p
*/
@Override
public XWPFParagraph getParagraph(CTP p) {
for (XWPFParagraph paragraph : paragraphs) {
if (p.equals(paragraph.getCTP())) {