Search in sources :

Example 81 with XmlCursor

use of org.apache.xmlbeans.XmlCursor in project hackpad by dropbox.

the class XML method removeToken.

/**
     *
     * @param curs
     */
protected void removeToken(XmlCursor curs) {
    XmlObject xo = XmlObject.Factory.newInstance();
    // Don't delete anything move to another document so it gets orphaned nicely.
    XmlCursor tmpCurs = xo.newCursor();
    tmpCurs.toFirstContentToken();
    curs.moveXml(tmpCurs);
    tmpCurs.dispose();
}
Also used : XmlObject(org.apache.xmlbeans.XmlObject) XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 82 with XmlCursor

use of org.apache.xmlbeans.XmlCursor in project hackpad by dropbox.

the class XML method childIndex.

/**
     *
     * @return
     */
int childIndex() {
    int index = 0;
    XmlCursor curs = newCursor();
    TokenType tt = curs.currentTokenType();
    while (true) {
        if (tt.isText()) {
            index++;
            if (!curs.toPrevSibling()) {
                break;
            }
        } else if (tt.isStart()) {
            tt = curs.toPrevToken();
            if (tt.isEnd()) {
                curs.toNextToken();
                if (!curs.toPrevSibling()) {
                    break;
                }
                index++;
            } else {
                // Hit the parent start tag so get out we're down counting children.
                break;
            }
        } else if (tt.isComment() || tt.isProcinst()) {
            curs.toPrevToken();
        } else {
            break;
        }
        tt = curs.currentTokenType();
    }
    index = curs.currentTokenType().isStartdoc() ? -1 : index;
    curs.dispose();
    return index;
}
Also used : TokenType(org.apache.xmlbeans.XmlCursor.TokenType) XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 83 with XmlCursor

use of org.apache.xmlbeans.XmlCursor in project hackpad by dropbox.

the class XML method prependChild.

/**
     *
     * @param xml
     * @return
     */
XML prependChild(Object xml) {
    XmlCursor curs = newCursor();
    if (curs.isStartdoc()) {
        curs.toFirstContentToken();
    }
    // Move the cursor to the first content token
    curs.toFirstContentToken();
    insertChild(curs, xml);
    curs.dispose();
    return this;
}
Also used : XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 84 with XmlCursor

use of org.apache.xmlbeans.XmlCursor in project hackpad by dropbox.

the class XML method copy.

/**
     *
     * @return
     */
Object copy() {
    XmlCursor srcCurs = newCursor();
    if (srcCurs.isStartdoc()) {
        srcCurs.toFirstContentToken();
    }
    XML xml = createEmptyXML(lib);
    XmlCursor destCurs = xml.newCursor();
    destCurs.toFirstContentToken();
    srcCurs.copyXml(destCurs);
    destCurs.dispose();
    srcCurs.dispose();
    return xml;
}
Also used : XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 85 with XmlCursor

use of org.apache.xmlbeans.XmlCursor in project hackpad by dropbox.

the class XML method copy.

/**
     *
     * @param cursToCopy
     * @return
     */
private XmlCursor copy(XmlCursor cursToCopy) {
    XmlObject xo = XmlObject.Factory.newInstance();
    XmlCursor copyCurs = null;
    if (cursToCopy.currentTokenType().isText()) {
        try {
            // Try just as a textnode, to do that we need to wrap the text in a special fragment tag
            // that is not visible from the XmlCursor.
            copyCurs = XmlObject.Factory.parse("<x:fragment xmlns:x=\"http://www.openuri.org/fragment\">" + cursToCopy.getChars() + "</x:fragment>").newCursor();
            if (!cursToCopy.toNextSibling()) {
                if (cursToCopy.currentTokenType().isText()) {
                    // It's not an element it's text so skip it.
                    cursToCopy.toNextToken();
                }
            }
        } catch (Exception ex) {
            throw ScriptRuntime.typeError(ex.getMessage());
        }
    } else {
        copyCurs = xo.newCursor();
        copyCurs.toFirstContentToken();
        if (cursToCopy.currentTokenType() == XmlCursor.TokenType.STARTDOC) {
            cursToCopy.toNextToken();
        }
        cursToCopy.copyXml(copyCurs);
        if (// If element skip element.
        !cursToCopy.toNextSibling()) {
            if (cursToCopy.currentTokenType().isText()) {
                // It's not an element it's text so skip it.
                cursToCopy.toNextToken();
            }
        }
    }
    copyCurs.toStartDoc();
    copyCurs.toFirstContentToken();
    return copyCurs;
}
Also used : XmlObject(org.apache.xmlbeans.XmlObject) XmlException(org.apache.xmlbeans.XmlException) 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