Search in sources :

Example 16 with XmlCursor

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

the class XML method toXMLString.

/**
     *
     * @return
     */
String toXMLString(int indent) {
    // XXX indent is ignored
    String result;
    XmlCursor curs = newCursor();
    if (curs.isStartdoc()) {
        curs.toFirstContentToken();
    }
    try {
        if (curs.isText()) {
            result = curs.getChars();
        } else if (curs.isAttr()) {
            result = curs.getTextValue();
        } else if (curs.isComment() || curs.isProcinst()) {
            result = XML.dumpNode(curs, getOptions());
            // todo: XBeans-dependent hack here
            // If it's a comment or PI, take off the xml-frament stuff
            String start = "<xml-fragment>";
            String end = "</xml-fragment>";
            if (result.startsWith(start)) {
                result = result.substring(start.length());
            }
            if (result.endsWith(end)) {
                result = result.substring(0, result.length() - end.length());
            }
        } else {
            result = XML.dumpNode(curs, getOptions());
        }
    } finally {
        curs.dispose();
    }
    return result;
}
Also used : XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 17 with XmlCursor

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

the class XML method parent.

/**
     *
     * @return
     */
Object parent() {
    Object parent;
    XmlCursor curs = newCursor();
    if (curs.isStartdoc()) {
        // At doc level - no parent
        parent = Undefined.instance;
    } else {
        if (curs.toParent()) {
            if (curs.isStartdoc()) {
                // Was top-level - no parent
                parent = Undefined.instance;
            } else {
                parent = getFromAnnotation(lib, findAnnotation(curs));
            }
        } else {
            // No parent
            parent = Undefined.instance;
        }
    }
    curs.dispose();
    return parent;
}
Also used : XmlObject(org.apache.xmlbeans.XmlObject) XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 18 with XmlCursor

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

the class XML method hasSimpleContent.

/**
     *
     * @return
     */
boolean hasSimpleContent() {
    boolean simpleContent = false;
    XmlCursor curs = newCursor();
    if (curs.isAttr() || curs.isText()) {
        return true;
    }
    if (curs.isStartdoc()) {
        curs.toFirstContentToken();
    }
    simpleContent = !(curs.toFirstChild());
    curs.dispose();
    return simpleContent;
}
Also used : XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 19 with XmlCursor

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

the class XML method setAttribute.

/**
     *
     * @param attrName
     * @param value
     */
void setAttribute(XMLName xmlName, Object value) {
    if (xmlName.uri() == null && xmlName.localName().equals("*")) {
        throw ScriptRuntime.typeError("@* assignment not supported.");
    }
    XmlCursor curs = newCursor();
    String strValue = ScriptRuntime.toString(value);
    if (curs.currentTokenType().isStartdoc()) {
        curs.toFirstContentToken();
    }
    javax.xml.namespace.QName qName;
    try {
        qName = new javax.xml.namespace.QName(xmlName.uri(), xmlName.localName());
    } catch (Exception e) {
        throw ScriptRuntime.typeError(e.getMessage());
    }
    if (!curs.setAttributeText(qName, strValue)) {
        if (curs.currentTokenType().isStart()) {
            // Can only add attributes inside of a start.
            curs.toNextToken();
        }
        curs.insertAttributeWithValue(qName, strValue);
    }
    curs.dispose();
}
Also used : XmlException(org.apache.xmlbeans.XmlException) XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 20 with XmlCursor

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

the class XML method newCursor.

/**
     *
     * @return
     */
private XmlCursor newCursor() {
    XmlCursor curs;
    if (_anno != null) {
        curs = _anno.createCursor();
        if (curs == null) {
            // Orphaned case.
            XmlObject doc = XmlObject.Factory.newInstance();
            curs = doc.newCursor();
            if (_anno._name != null) {
                curs.toNextToken();
                curs.insertElement(_anno._name);
                curs.toPrevSibling();
            }
            curs.setBookmark(_anno);
        }
    } else {
        XmlObject doc = XmlObject.Factory.newInstance();
        curs = doc.newCursor();
    }
    return curs;
}
Also used : XmlObject(org.apache.xmlbeans.XmlObject) 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