Search in sources :

Example 26 with XmlObject

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);
}
Also used : XmlObject(org.apache.xmlbeans.XmlObject) CTTbl(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl) CTRow(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow) XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 27 with XmlObject

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;
}
Also used : XmlException(org.apache.xmlbeans.XmlException) ArrayList(java.util.ArrayList) CTPicture(org.openxmlformats.schemas.drawingml.x2006.picture.CTPicture) XmlAnyTypeImpl(org.apache.xmlbeans.impl.values.XmlAnyTypeImpl) XmlObject(org.apache.xmlbeans.XmlObject) POIXMLException(org.apache.poi.POIXMLException)

Example 28 with XmlObject

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;
}
Also used : XmlObject(org.apache.xmlbeans.XmlObject) CTTbl(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl) CTP(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP) XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 29 with XmlObject

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);
}
Also used : XmlObject(org.apache.xmlbeans.XmlObject) CTTbl(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl) CTRow(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow) XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 30 with XmlObject

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;
}
Also used : CTShapeProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties) XmlObject(org.apache.xmlbeans.XmlObject)

Aggregations

XmlObject (org.apache.xmlbeans.XmlObject)87 XmlCursor (org.apache.xmlbeans.XmlCursor)42 Test (org.junit.Test)14 XmlException (org.apache.xmlbeans.XmlException)13 CTTbl (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl)13 DefaultExchange (org.apache.camel.impl.DefaultExchange)10 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)9 CTP (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP)9 CTPicture (org.openxmlformats.schemas.presentationml.x2006.main.CTPicture)7 POIXMLException (org.apache.poi.POIXMLException)6 CTAxDataSource (org.openxmlformats.schemas.drawingml.x2006.chart.CTAxDataSource)6 CTNumDataSource (org.openxmlformats.schemas.drawingml.x2006.chart.CTNumDataSource)6 CTShapeProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties)6 CTGroupShape (org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape)6 ArrayList (java.util.ArrayList)5 QName (javax.xml.namespace.QName)5 CTGraphicalObjectFrame (org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame)5 Node (org.w3c.dom.Node)5 CTConnector (org.openxmlformats.schemas.presentationml.x2006.main.CTConnector)4 CTShape (org.openxmlformats.schemas.presentationml.x2006.main.CTShape)4