Fix and update JavaDoc entries, and correct areas with wildy inconsistent whitespace / style to the surrounding code

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1492802 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2013-06-13 18:29:08 +00:00
parent 19ade4ae64
commit d323b0054c
2 changed files with 337 additions and 343 deletions

View File

@ -26,108 +26,103 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc;
/** /**
* <p> * <p>An IBody represents the different parts of the document which
* 8 Jan 2010 * can contain collections of Paragraphs and Tables. It provides a
* common way to work with these and their contents.</p>
* <p>Typically, this is something like a XWPFDocument, or one of
* the parts in it like XWPFHeader, XWPFFooter, XWPFTableCell
* </p> * </p>
* <p>
* // This Interface represents an object, which is able to have a collection of paragraphs and tables
* this can be XWFPDocument, XWPFHeader, XWPFFooter, XWPFTableCell
* </p>
* @author Philipp Epp
*
*/ */
public interface IBody { public interface IBody {
/** /**
* returns the Part, to which the body belongs, which you need for adding relationship to other parts * returns the Part, to which the body belongs, which you need for adding relationship to other parts
* Actually it is needed of the class XWPFTableCell. Because you have to know to which part the tableCell * Actually it is needed of the class XWPFTableCell. Because you have to know to which part the tableCell
* belongs. * belongs.
* @return the Part, to which the body belongs * @return the Part, to which the body belongs
*/ */
POIXMLDocumentPart getPart(); public POIXMLDocumentPart getPart();
/**
* get the PartType of the body, for example
* DOCUMENT, HEADER, FOOTER, FOOTNOTE,
* @return the PartType of the body
*/
BodyType getPartType();
/**
* Returns an Iterator with paragraphs and tables,
* in the order that they occur in the text.
*/
public List<IBodyElement> getBodyElements();
/** /**
* Returns the paragraph(s) that holds * get the PartType of the body, for example
* the text of the header or footer. * DOCUMENT, HEADER, FOOTER, FOOTNOTE,
*/ * @return the PartType of the body
*/
public BodyType getPartType();
/**
* Returns an Iterator with paragraphs and tables,
* in the order that they occur in the text.
*/
public List<IBodyElement> getBodyElements();
/**
* Returns the paragraph(s) that holds
* the text of the header or footer.
*/
public List<XWPFParagraph> getParagraphs(); public List<XWPFParagraph> getParagraphs();
/** /**
* Return the table(s) that holds the text * Return the table(s) that holds the text
* of the IBodyPart, for complex cases * of the IBodyPart, for complex cases
* where a paragraph isn't used. * where a paragraph isn't used.
*/ */
public List<XWPFTable> getTables(); 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
* @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
*/
public XWPFParagraph getParagraph(CTP p);
/**
* if there is a corresponding {@link XWPFTable} of the parameter ctTable in the tableList of this header
* the method will return this table
* if there is no corresponding {@link XWPFTable} the method will return null
* @param ctTable
*/
public XWPFTable getTable(CTTbl ctTable);
/**
* Returns the paragraph that of position pos
*/
public XWPFParagraph getParagraphArray(int pos);
/**
* Returns the table at position pos
*/
public XWPFTable getTableArray(int pos);
/**
*inserts a new paragraph at position of the cursor
* @param cursor
*/
public XWPFParagraph insertNewParagraph(XmlCursor cursor);
/**
* inserts a new Table at the cursor position.
* @param cursor
*/
public XWPFTable insertNewTbl(XmlCursor cursor);
/** /**
* inserts a new Table at position pos * if there is a corresponding {@link XWPFParagraph} of the parameter ctTable in the paragraphList of this header or footer
* @param pos * the method will return this paragraph
* @param table * if there is no corresponding {@link XWPFParagraph} the method will return null
*/ * @param p is instance of CTP and is searching for an XWPFParagraph
void insertTable(int pos, XWPFTable table); * @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
*/
public XWPFParagraph getParagraph(CTP p);
/** /**
* returns the TableCell to which the Table belongs * if there is a corresponding {@link XWPFTable} of the parameter ctTable in the tableList of this header
* @param cell * the method will return this table
*/ * if there is no corresponding {@link XWPFTable} the method will return null
XWPFTableCell getTableCell(CTTc cell); * @param ctTable
*/
public XWPFTable getTable(CTTbl ctTable);
/**
* Returns the paragraph that of position pos
*/
public XWPFParagraph getParagraphArray(int pos);
/**
* Returns the table at position pos
*/
public XWPFTable getTableArray(int pos);
/**
*inserts a new paragraph at position of the cursor
* @param cursor
*/
public XWPFParagraph insertNewParagraph(XmlCursor cursor);
/**
* inserts a new Table at the cursor position.
* @param cursor
*/
public XWPFTable insertNewTbl(XmlCursor cursor);
/**
* inserts a new Table at position pos
* @param pos
* @param table
*/
void insertTable(int pos, XWPFTable table);
/**
* returns the TableCell to which the Table belongs
* @param cell
*/
public XWPFTableCell getTableCell(CTTc cell);
/** /**
* Return XWPFDocument * Return XWPFDocument
*/ */
public XWPFDocument getXWPFDocument(); public XWPFDocument getXWPFDocument();
} }

View File

@ -74,18 +74,18 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.STDocProtect;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.StylesDocument; import org.openxmlformats.schemas.wordprocessingml.x2006.main.StylesDocument;
/** /**
* Experimental class to do low level processing * <p>High(ish) level class for working with .docx files.</p>
* of docx files. *
* * <p>This class tries to hide some of the complexity
* If you're using these low level classes, then you * of the underlying file format, but as it's not a
* will almost certainly need to refer to the OOXML * mature and stable API yet, certain parts of the
* specifications from * XML structure come through. You'll therefore almost
* certainly need to refer to the OOXML specifications
* from
* http://www.ecma-international.org/publications/standards/Ecma-376.htm * http://www.ecma-international.org/publications/standards/Ecma-376.htm
* * at some point in your use.</p>
* WARNING - APIs expected to change rapidly
*/ */
public class XWPFDocument extends POIXMLDocument implements Document, IBody { public class XWPFDocument extends POIXMLDocument implements Document, IBody {
private CTDocument1 ctDocument; private CTDocument1 ctDocument;
private XWPFSettings settings; private XWPFSettings settings;
/** /**
@ -110,31 +110,31 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
private XWPFHeaderFooterPolicy headerFooterPolicy; private XWPFHeaderFooterPolicy headerFooterPolicy;
public XWPFDocument(OPCPackage pkg) throws IOException { public XWPFDocument(OPCPackage pkg) throws IOException {
super(pkg); super(pkg);
//build a tree of POIXMLDocumentParts, this document being the root //build a tree of POIXMLDocumentParts, this document being the root
load(XWPFFactory.getInstance()); load(XWPFFactory.getInstance());
} }
public XWPFDocument(InputStream is) throws IOException { public XWPFDocument(InputStream is) throws IOException {
super(PackageHelper.open(is)); super(PackageHelper.open(is));
//build a tree of POIXMLDocumentParts, this workbook being the root //build a tree of POIXMLDocumentParts, this workbook being the root
load(XWPFFactory.getInstance()); load(XWPFFactory.getInstance());
} }
public XWPFDocument(){ public XWPFDocument(){
super(newPackage()); super(newPackage());
onDocumentCreate(); onDocumentCreate();
} }
@Override @Override
protected void onDocumentRead() throws IOException { protected void onDocumentRead() throws IOException {
try { try {
DocumentDocument doc = DocumentDocument.Factory.parse(getPackagePart().getInputStream()); DocumentDocument doc = DocumentDocument.Factory.parse(getPackagePart().getInputStream());
ctDocument = doc.getDocument(); ctDocument = doc.getDocument();
initFootnotes(); initFootnotes();
// parse the document with cursor and add // parse the document with cursor and add
// the XmlObject to its lists // the XmlObject to its lists
@ -212,46 +212,46 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
} }
private void initHyperlinks(){ private void initHyperlinks(){
// Get the hyperlinks // Get the hyperlinks
// TODO: make me optional/separated in private function // TODO: make me optional/separated in private function
try { try {
Iterator<PackageRelationship> relIter = Iterator<PackageRelationship> relIter =
getPackagePart().getRelationshipsByType(XWPFRelation.HYPERLINK.getRelation()).iterator(); getPackagePart().getRelationshipsByType(XWPFRelation.HYPERLINK.getRelation()).iterator();
while(relIter.hasNext()) { while(relIter.hasNext()) {
PackageRelationship rel = relIter.next(); PackageRelationship rel = relIter.next();
hyperlinks.add(new XWPFHyperlink(rel.getId(), rel.getTargetURI().toString())); hyperlinks.add(new XWPFHyperlink(rel.getId(), rel.getTargetURI().toString()));
} }
} catch (InvalidFormatException e){ } catch (InvalidFormatException e){
throw new POIXMLException(e); throw new POIXMLException(e);
} }
} }
private void initFootnotes() throws XmlException, IOException { private void initFootnotes() throws XmlException, IOException {
for(POIXMLDocumentPart p : getRelations()){ for(POIXMLDocumentPart p : getRelations()){
String relation = p.getPackageRelationship().getRelationshipType(); String relation = p.getPackageRelationship().getRelationshipType();
if (relation.equals(XWPFRelation.FOOTNOTE.getRelation())) { if (relation.equals(XWPFRelation.FOOTNOTE.getRelation())) {
FootnotesDocument footnotesDocument = FootnotesDocument.Factory.parse(p.getPackagePart().getInputStream()); FootnotesDocument footnotesDocument = FootnotesDocument.Factory.parse(p.getPackagePart().getInputStream());
this.footnotes = (XWPFFootnotes)p; this.footnotes = (XWPFFootnotes)p;
this.footnotes.onDocumentRead(); this.footnotes.onDocumentRead();
for(CTFtnEdn ctFtnEdn : footnotesDocument.getFootnotes().getFootnoteList()) { for(CTFtnEdn ctFtnEdn : footnotesDocument.getFootnotes().getFootnoteList()) {
footnotes.addFootnote(ctFtnEdn); footnotes.addFootnote(ctFtnEdn);
} }
} else if (relation.equals(XWPFRelation.ENDNOTE.getRelation())){ } else if (relation.equals(XWPFRelation.ENDNOTE.getRelation())){
EndnotesDocument endnotesDocument = EndnotesDocument.Factory.parse(p.getPackagePart().getInputStream()); EndnotesDocument endnotesDocument = EndnotesDocument.Factory.parse(p.getPackagePart().getInputStream());
for(CTFtnEdn ctFtnEdn : endnotesDocument.getEndnotes().getEndnoteList()) { for(CTFtnEdn ctFtnEdn : endnotesDocument.getEndnotes().getEndnoteList()) {
endnotes.put(ctFtnEdn.getId().intValue(), new XWPFFootnote(this, ctFtnEdn)); endnotes.put(ctFtnEdn.getId().intValue(), new XWPFFootnote(this, ctFtnEdn));
} }
} }
} }
} }
/** /**
* Create a new WordProcessingML package and setup the default minimal content * Create a new WordProcessingML package and setup the default minimal content
*/ */
protected static OPCPackage newPackage() { protected static OPCPackage newPackage() {
try { try {
OPCPackage pkg = OPCPackage.create(new ByteArrayOutputStream()); OPCPackage pkg = OPCPackage.create(new ByteArrayOutputStream());
// Main part // Main part
PackagePartName corePartName = PackagingURIHelper.createPartName(XWPFRelation.DOCUMENT.getDefaultFileName()); PackagePartName corePartName = PackagingURIHelper.createPartName(XWPFRelation.DOCUMENT.getDefaultFileName());
@ -287,122 +287,122 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
*/ */
@Internal @Internal
public CTDocument1 getDocument() { public CTDocument1 getDocument() {
return ctDocument; return ctDocument;
} }
IdentifierManager getDrawingIdManager() { IdentifierManager getDrawingIdManager() {
return drawingIdManager; return drawingIdManager;
} }
/** /**
* returns an Iterator with paragraphs and tables * returns an Iterator with paragraphs and tables
* @see org.apache.poi.xwpf.usermodel.IBody#getBodyElements() * @see org.apache.poi.xwpf.usermodel.IBody#getBodyElements()
*/ */
public List<IBodyElement> getBodyElements(){ public List<IBodyElement> getBodyElements() {
return Collections.unmodifiableList(bodyElements); return Collections.unmodifiableList(bodyElements);
} }
public Iterator<IBodyElement> getBodyElementsIterator() { public Iterator<IBodyElement> getBodyElementsIterator() {
return bodyElements.iterator(); return bodyElements.iterator();
} }
/** /**
* @see org.apache.poi.xwpf.usermodel.IBody#getParagraphs() * @see org.apache.poi.xwpf.usermodel.IBody#getParagraphs()
*/ */
public List<XWPFParagraph> getParagraphs(){ public List<XWPFParagraph> getParagraphs(){
return Collections.unmodifiableList(paragraphs); return Collections.unmodifiableList(paragraphs);
} }
/** /**
* @see org.apache.poi.xwpf.usermodel.IBody#getTables() * @see org.apache.poi.xwpf.usermodel.IBody#getTables()
*/ */
public List<XWPFTable> getTables(){ public List<XWPFTable> getTables(){
return Collections.unmodifiableList(tables); return Collections.unmodifiableList(tables);
} }
/** /**
* @see org.apache.poi.xwpf.usermodel.IBody#getTableArray(int) * @see org.apache.poi.xwpf.usermodel.IBody#getTableArray(int)
*/ */
public XWPFTable getTableArray(int pos) { public XWPFTable getTableArray(int pos) {
if(pos > 0 && pos < tables.size()){ if(pos > 0 && pos < tables.size()){
return tables.get(pos); return tables.get(pos);
}
return null;
} }
return null;
/** }
*
* @return the list of footers /**
*/ *
public List<XWPFFooter> getFooterList(){ * @return the list of footers
return Collections.unmodifiableList(footers); */
} public List<XWPFFooter> getFooterList(){
return Collections.unmodifiableList(footers);
public XWPFFooter getFooterArray(int pos){ }
return footers.get(pos);
} public XWPFFooter getFooterArray(int pos){
return footers.get(pos);
/** }
*
* @return the list of headers /**
*/ *
public List<XWPFHeader> getHeaderList(){ * @return the list of headers
return Collections.unmodifiableList(headers); */
} public List<XWPFHeader> getHeaderList(){
return Collections.unmodifiableList(headers);
public XWPFHeader getHeaderArray(int pos){ }
return headers.get(pos);
} public XWPFHeader getHeaderArray(int pos){
return headers.get(pos);
}
public String getTblStyle(XWPFTable table){ public String getTblStyle(XWPFTable table){
return table.getStyleID(); return table.getStyleID();
} }
public XWPFHyperlink getHyperlinkByID(String id) { public XWPFHyperlink getHyperlinkByID(String id) {
Iterator<XWPFHyperlink> iter = hyperlinks.iterator(); Iterator<XWPFHyperlink> iter = hyperlinks.iterator();
while (iter.hasNext()) { while (iter.hasNext()) {
XWPFHyperlink link = iter.next(); XWPFHyperlink link = iter.next();
if(link.getId().equals(id)) if(link.getId().equals(id))
return link; return link;
} }
return null; return null;
} }
public XWPFFootnote getFootnoteByID(int id) { public XWPFFootnote getFootnoteByID(int id) {
if(footnotes == null) return null; if(footnotes == null) return null;
return footnotes.getFootnoteById(id); return footnotes.getFootnoteById(id);
} }
public XWPFFootnote getEndnoteByID(int id) { public XWPFFootnote getEndnoteByID(int id) {
if(endnotes == null) return null; if(endnotes == null) return null;
return endnotes.get(id); return endnotes.get(id);
} }
public List<XWPFFootnote> getFootnotes() { public List<XWPFFootnote> getFootnotes() {
if(footnotes == null) { if(footnotes == null) {
return Collections.emptyList(); return Collections.emptyList();
} }
return footnotes.getFootnotesList(); return footnotes.getFootnotesList();
} }
public XWPFHyperlink[] getHyperlinks() { public XWPFHyperlink[] getHyperlinks() {
return hyperlinks.toArray(new XWPFHyperlink[hyperlinks.size()]); return hyperlinks.toArray(new XWPFHyperlink[hyperlinks.size()]);
} }
public XWPFComment getCommentByID(String id) { public XWPFComment getCommentByID(String id) {
Iterator<XWPFComment> iter = comments.iterator(); Iterator<XWPFComment> iter = comments.iterator();
while (iter.hasNext()) { while (iter.hasNext()) {
XWPFComment comment = iter.next(); XWPFComment comment = iter.next();
if(comment.getId().equals(id)) if(comment.getId().equals(id))
return comment; return comment;
} }
return null; return null;
} }
public XWPFComment[] getComments() { public XWPFComment[] getComments() {
return comments.toArray(new XWPFComment[comments.size()]); return comments.toArray(new XWPFComment[comments.size()]);
} }
/** /**
@ -644,73 +644,72 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
* @param cursor * @param cursor
*/ */
private boolean isCursorInBody(XmlCursor cursor) { private boolean isCursorInBody(XmlCursor cursor) {
XmlCursor verify = cursor.newCursor(); XmlCursor verify = cursor.newCursor();
verify.toParent(); verify.toParent();
try { try {
return (verify.getObject() == this.ctDocument.getBody()); return (verify.getObject() == this.ctDocument.getBody());
} finally { } finally {
verify.dispose(); verify.dispose();
} }
} }
private int getPosOfBodyElement(IBodyElement needle) { private int getPosOfBodyElement(IBodyElement needle) {
BodyElementType type = needle.getElementType(); BodyElementType type = needle.getElementType();
IBodyElement current; IBodyElement current;
for(int i=0; i<bodyElements.size(); i++) { for(int i=0; i<bodyElements.size(); i++) {
current = bodyElements.get(i); current = bodyElements.get(i);
if(current.getElementType() == type) { if(current.getElementType() == type) {
if(current.equals(needle)) { if(current.equals(needle)) {
return i; return i;
} }
} }
}
return -1;
} }
return -1;
/**
* Get the position of the paragraph, within the list
* of all the body elements.
* @param p The paragraph to find
* @return The location, or -1 if the paragraph couldn't be found
*/
public int getPosOfParagraph(XWPFParagraph p){
return getPosOfBodyElement(p);
} }
/** /**
* Get the position of the table, within the list of * Get the position of the paragraph, within the list
* all the body elements. * of all the body elements.
* @param t The table to find * @param p The paragraph to find
* @return The location, or -1 if the table couldn't be found * @return The location, or -1 if the paragraph couldn't be found
*/ */
public int getPosOfTable(XWPFTable t){ public int getPosOfParagraph(XWPFParagraph p){
return getPosOfBodyElement(t); return getPosOfBodyElement(p);
} }
/**
* Get the position of the table, within the list of
* all the body elements.
* @param t The table to find
* @return The location, or -1 if the table couldn't be found
*/
public int getPosOfTable(XWPFTable t){
return getPosOfBodyElement(t);
}
/** /**
* commit and saves the document * commit and saves the document
*/ */
@Override @Override
protected void commit() throws IOException { protected void commit() throws IOException {
XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
xmlOptions.setSaveSyntheticDocumentElement(new QName(CTDocument1.type.getName().getNamespaceURI(), "document"));
Map<String, String> map = new HashMap<String, String>();
map.put("http://schemas.openxmlformats.org/officeDocument/2006/math", "m");
map.put("urn:schemas-microsoft-com:office:office", "o");
map.put("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "r");
map.put("urn:schemas-microsoft-com:vml", "v");
map.put("http://schemas.openxmlformats.org/markup-compatibility/2006", "ve");
map.put("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "w");
map.put("urn:schemas-microsoft-com:office:word", "w10");
map.put("http://schemas.microsoft.com/office/word/2006/wordml", "wne");
map.put("http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing", "wp");
xmlOptions.setSaveSuggestedPrefixes(map);
XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS); PackagePart part = getPackagePart();
xmlOptions.setSaveSyntheticDocumentElement(new QName(CTDocument1.type.getName().getNamespaceURI(), "document")); OutputStream out = part.getOutputStream();
Map<String, String> map = new HashMap<String, String>(); ctDocument.save(out, xmlOptions);
map.put("http://schemas.openxmlformats.org/officeDocument/2006/math", "m"); out.close();
map.put("urn:schemas-microsoft-com:office:office", "o");
map.put("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "r");
map.put("urn:schemas-microsoft-com:vml", "v");
map.put("http://schemas.openxmlformats.org/markup-compatibility/2006", "ve");
map.put("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "w");
map.put("urn:schemas-microsoft-com:office:word", "w10");
map.put("http://schemas.microsoft.com/office/word/2006/wordml", "wne");
map.put("http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing", "wp");
xmlOptions.setSaveSuggestedPrefixes(map);
PackagePart part = getPackagePart();
OutputStream out = part.getOutputStream();
ctDocument.save(out, xmlOptions);
out.close();
} }
/** /**
@ -813,23 +812,23 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
* @param pos * @param pos
* @return true if removing was successfully, else return false * @return true if removing was successfully, else return false
*/ */
public boolean removeBodyElement(int pos){ public boolean removeBodyElement(int pos) {
if(pos >= 0 && pos < bodyElements.size()) { if(pos >= 0 && pos < bodyElements.size()) {
BodyElementType type = bodyElements.get(pos).getElementType(); BodyElementType type = bodyElements.get(pos).getElementType();
if(type == BodyElementType.TABLE){ if(type == BodyElementType.TABLE){
int tablePos = getTablePos(pos); int tablePos = getTablePos(pos);
tables.remove(tablePos); tables.remove(tablePos);
ctDocument.getBody().removeTbl(tablePos); ctDocument.getBody().removeTbl(tablePos);
} }
if(type == BodyElementType.PARAGRAPH){ if(type == BodyElementType.PARAGRAPH) {
int paraPos = getParagraphPos(pos); int paraPos = getParagraphPos(pos);
paragraphs.remove(paraPos); paragraphs.remove(paraPos);
ctDocument.getBody().removeP(paraPos); ctDocument.getBody().removeP(paraPos);
} }
bodyElements.remove(pos); bodyElements.remove(pos);
return true; return true;
} }
return false; return false;
} }
/** /**
@ -1282,24 +1281,24 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
} }
public Iterator<XWPFTable> getTablesIterator() { public Iterator<XWPFTable> getTablesIterator() {
return tables.iterator(); return tables.iterator();
} }
public Iterator<XWPFParagraph> getParagraphsIterator() { public Iterator<XWPFParagraph> getParagraphsIterator() {
return paragraphs.iterator(); return paragraphs.iterator();
} }
/** /**
* Returns the paragraph that of position pos * Returns the paragraph that of position pos
* @see org.apache.poi.xwpf.usermodel.IBody#getParagraphArray(int) * @see org.apache.poi.xwpf.usermodel.IBody#getParagraphArray(int)
*/ */
public XWPFParagraph getParagraphArray(int pos) { public XWPFParagraph getParagraphArray(int pos) {
if(pos >= 0 && pos < paragraphs.size()){ if(pos >= 0 && pos < paragraphs.size()){
return paragraphs.get(pos); return paragraphs.get(pos);
}
return null;
} }
return null;
}
/** /**
* returns the Part, to which the body belongs, which you need for adding relationship to other parts * returns the Part, to which the body belongs, which you need for adding relationship to other parts
@ -1308,51 +1307,51 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
* @see org.apache.poi.xwpf.usermodel.IBody#getPart() * @see org.apache.poi.xwpf.usermodel.IBody#getPart()
*/ */
public POIXMLDocumentPart getPart() { public POIXMLDocumentPart getPart() {
return this; return this;
} }
/** /**
* get the PartType of the body, for example * get the PartType of the body, for example
* DOCUMENT, HEADER, FOOTER, FOOTNOTE, * DOCUMENT, HEADER, FOOTER, FOOTNOTE,
* *
* @see org.apache.poi.xwpf.usermodel.IBody#getPartType() * @see org.apache.poi.xwpf.usermodel.IBody#getPartType()
*/ */
public BodyType getPartType() { public BodyType getPartType() {
return BodyType.DOCUMENT; return BodyType.DOCUMENT;
} }
/** /**
* get the TableCell which belongs to the TableCell * get the TableCell which belongs to the TableCell
* @param cell * @param cell
*/ */
public XWPFTableCell getTableCell(CTTc cell) { public XWPFTableCell getTableCell(CTTc cell) {
XmlCursor cursor = cell.newCursor(); XmlCursor cursor = cell.newCursor();
cursor.toParent(); cursor.toParent();
XmlObject o = cursor.getObject(); XmlObject o = cursor.getObject();
if(!(o instanceof CTRow)){ if(!(o instanceof CTRow)){
return null; 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);
} }
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);
}
public XWPFDocument getXWPFDocument() { public XWPFDocument getXWPFDocument() {
return this; return this;
} }
} // end class }