use of org.apache.xmlbeans.XmlCursor in project poi by apache.
the class XWPFHeaderFooter method getTableCell.
/**
* get the TableCell which belongs to the TableCell
*
* @param cell
*/
public XWPFTableCell getTableCell(CTTc cell) {
XmlCursor cursor = cell.newCursor();
cursor.toParent();
XmlObject o = cursor.getObject();
if (!(o instanceof CTRow)) {
cursor.dispose();
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);
return tableRow.getTableCell(cell);
}
use of org.apache.xmlbeans.XmlCursor in project poi by apache.
the class XWPFDocument method isCursorInBody.
/**
* verifies that cursor is on the right position
*
* @param cursor
*/
private boolean isCursorInBody(XmlCursor cursor) {
XmlCursor verify = cursor.newCursor();
verify.toParent();
boolean result = (verify.getObject() == this.ctDocument.getBody());
verify.dispose();
return result;
}
use of org.apache.xmlbeans.XmlCursor in project poi by apache.
the class XWPFHeaderFooter method removeTable.
/**
* Removes a specific table from this header / footer
*
* @param table - {@link XWPFTable} object to remove
*/
public void removeTable(XWPFTable table) {
if (tables.contains(table)) {
CTTbl ctTbl = table.getCTTbl();
XmlCursor c = ctTbl.newCursor();
c.removeXml();
c.dispose();
tables.remove(table);
bodyElements.remove(table);
}
}
use of org.apache.xmlbeans.XmlCursor in project poi by apache.
the class XWPFTableCell method insertNewParagraph.
/**
* add a new paragraph at position of the cursor
*
* @param cursor The XmlCursor structure created with XmlBeans
* @return the inserted paragraph
*/
public XWPFParagraph insertNewParagraph(final XmlCursor cursor) {
if (!isCursorInTableCell(cursor)) {
return null;
}
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)) || (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);
p2.dispose();
cursor.toEndToken();
return newP;
}
use of org.apache.xmlbeans.XmlCursor in project poi by apache.
the class XWPFTableCell method getTableCell.
/**
* get the TableCell which belongs to the TableCell
*/
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 tr = table.getRow(row);
if (tr == null) {
return null;
}
return tr.getTableCell(cell);
}
Aggregations