Search in sources :

Example 86 with XmlCursor

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

the class XML method insertChild.

/**
     *
     * @param childToMatch
     * @param xmlToInsert
     * @param addToType
     */
private void insertChild(XML childToMatch, Object xmlToInsert, int addToType) {
    XmlCursor curs = newCursor();
    TokenType tt = curs.currentTokenType();
    XmlCursor xmlChildCursor = childToMatch.newCursor();
    if (tt.isStartdoc()) {
        tt = curs.toFirstContentToken();
    }
    if (tt.isContainer()) {
        tt = curs.toNextToken();
        while (!tt.isEnd()) {
            if (tt.isStart()) {
                // See if this child is the same as the one thep passed in
                if (curs.comparePosition(xmlChildCursor) == 0) {
                    // Found it
                    if (addToType == APPEND_CHILD) {
                        // Move the cursor to just past the end of this element
                        curs.toEndToken();
                        curs.toNextToken();
                    }
                    insertChild(curs, xmlToInsert);
                    break;
                }
            }
            // Skip over child elements
            if (tt.isStart()) {
                tt = curs.toEndToken();
            }
            tt = curs.toNextToken();
        }
    }
    xmlChildCursor.dispose();
    curs.dispose();
}
Also used : TokenType(org.apache.xmlbeans.XmlCursor.TokenType) XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 87 with XmlCursor

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

the class XMLLibImpl method escapeAttributeValue.

/**
     * Escapes the reserved characters in a value of an attribute
     *
     * @param value Unescaped text
     * @return The escaped text
     */
public String escapeAttributeValue(Object value) {
    String text = ScriptRuntime.toString(value);
    if (text.length() == 0)
        return "";
    XmlObject xo = XmlObject.Factory.newInstance();
    XmlCursor cursor = xo.newCursor();
    cursor.toNextToken();
    cursor.beginElement("a");
    cursor.insertAttributeWithValue("a", text);
    cursor.dispose();
    String elementText = xo.toString();
    int begin = elementText.indexOf('"');
    int end = elementText.lastIndexOf('"');
    return elementText.substring(begin + 1, end);
}
Also used : XmlObject(org.apache.xmlbeans.XmlObject) XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 88 with XmlCursor

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

the class XML method namespaceDeclarations.

/**
     *
     * @return
     */
Object[] namespaceDeclarations() {
    XmlCursor cursor = newCursor();
    Object[] namespaces = NamespaceHelper.namespaceDeclarations(lib, cursor);
    cursor.dispose();
    return namespaces;
}
Also used : XmlObject(org.apache.xmlbeans.XmlObject) XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 89 with XmlCursor

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

the class XML method deleteXMLProperty.

/**
     *
     * @param name
     */
void deleteXMLProperty(XMLName name) {
    if (!name.isDescendants() && name.isAttributeName()) {
        XmlCursor curs = newCursor();
        // TODO: Cover the case *::name
        if (name.localName().equals("*")) {
            // Delete all attributes.
            if (curs.toFirstAttribute()) {
                while (curs.currentTokenType().isAttr()) {
                    curs.removeXml();
                }
            }
        } else {
            // Delete an attribute.
            javax.xml.namespace.QName qname = new javax.xml.namespace.QName(name.uri(), name.localName());
            curs.removeAttribute(qname);
        }
        curs.dispose();
    } else {
        XMLList matches = getPropertyList(name);
        matches.remove();
    }
}
Also used : XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 90 with XmlCursor

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

the class XML method replaceAll.

/**
     *
     * @param value
     */
void replaceAll(XML value) {
    XmlCursor curs = newCursor();
    replace(curs, value);
    _anno = value._anno;
    curs.dispose();
}
Also used : 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