Search in sources :

Example 41 with XmlCursor

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);
}
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 42 with XmlCursor

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;
}
Also used : XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 43 with XmlCursor

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

Example 44 with XmlCursor

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;
}
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 45 with XmlCursor

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);
}
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)

Aggregations

XmlCursor (org.apache.xmlbeans.XmlCursor)160 XmlObject (org.apache.xmlbeans.XmlObject)68 QName (javax.xml.namespace.QName)21 XmlException (org.apache.xmlbeans.XmlException)16 TokenType (org.apache.xmlbeans.XmlCursor.TokenType)14 CTTbl (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl)14 CTP (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP)10 ArrayList (java.util.ArrayList)9 POSIXApplicationType (org.ggf.schemas.jsdl.x2005.x11.jsdlPosix.POSIXApplicationType)8 HPCProfileApplicationType (org.ggf.schemas.jsdl.x2006.x07.jsdlHpcpa.HPCProfileApplicationType)8 SPMDApplicationType (org.ogf.schemas.jsdl.x2007.x02.jsdlSpmd.SPMDApplicationType)8 IOException (java.io.IOException)5 POIXMLException (org.apache.poi.POIXMLException)5 InputStream (java.io.InputStream)4 DrawPaint (org.apache.poi.sl.draw.DrawPaint)3 ArrayType (org.dmg.pmml.ArrayType)3 ApplicationType (org.ggf.schemas.jsdl.x2005.x11.jsdl.ApplicationType)3 LineString (org.locationtech.jts.geom.LineString)3 CTRow (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow)3 CTSdtBlock (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock)3