use of org.apache.xmlbeans.XmlObject 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.XmlObject in project poi by apache.
the class XWPFRun method getCTPictures.
private List<CTPicture> getCTPictures(XmlObject o) {
List<CTPicture> pics = new ArrayList<CTPicture>();
XmlObject[] picts = o.selectPath("declare namespace pic='" + CTPicture.type.getName().getNamespaceURI() + "' .//pic:pic");
for (XmlObject pict : picts) {
if (pict instanceof XmlAnyTypeImpl) {
// Pesky XmlBeans bug - see Bugzilla #49934
try {
pict = CTPicture.Factory.parse(pict.toString(), DEFAULT_XML_OPTIONS);
} catch (XmlException e) {
throw new POIXMLException(e);
}
}
if (pict instanceof CTPicture) {
pics.add((CTPicture) pict);
}
}
return pics;
}
use of org.apache.xmlbeans.XmlObject 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.XmlObject 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);
}
use of org.apache.xmlbeans.XmlObject in project poi by apache.
the class TestXSLFSimpleShape method getSpPr.
static CTShapeProperties getSpPr(XSLFShape shape) {
XmlObject xo = shape.getShapeProperties();
assertTrue(xo instanceof CTShapeProperties);
return (CTShapeProperties) xo;
}
Aggregations