Search in sources :

Example 11 with TokenType

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

the class XML method remove.

/**
     *
     */
void remove() {
    XmlCursor childCurs = newCursor();
    if (childCurs.currentTokenType().isStartdoc()) {
        // Remove on the document removes all children.
        TokenType tt = childCurs.toFirstContentToken();
        while (!tt.isEnd() && !tt.isEnddoc()) {
            removeToken(childCurs);
            // Now see where we're pointing after the delete -- next token.
            tt = childCurs.currentTokenType();
        }
    } else {
        removeToken(childCurs);
    }
    childCurs.dispose();
}
Also used : TokenType(org.apache.xmlbeans.XmlCursor.TokenType) XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 12 with TokenType

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

the class XML method allChildNodes.

/**
     *
     * @param namespace
     * @return
     */
private XMLList allChildNodes(String namespace) {
    XMLList result = new XMLList(lib);
    XmlCursor curs = newCursor();
    TokenType tt = curs.currentTokenType();
    javax.xml.namespace.QName targetProperty = new javax.xml.namespace.QName(namespace, "*");
    if (tt.isStartdoc()) {
        tt = curs.toFirstContentToken();
    }
    if (tt.isContainer()) {
        tt = curs.toFirstContentToken();
        while (!tt.isEnd()) {
            if (!tt.isStart()) {
                // Not an element
                result.addToList(findAnnotation(curs));
                // Reset target property to null in this case
                targetProperty = null;
            } else {
                // Match namespace as well if specified
                if (namespace == null || namespace.length() == 0 || namespace.equals("*") || curs.getName().getNamespaceURI().equals(namespace)) {
                    // Add it to the list
                    result.addToList(findAnnotation(curs));
                    // set to null
                    if (targetProperty != null) {
                        if (targetProperty.getLocalPart().equals("*")) {
                            targetProperty = curs.getName();
                        } else if (!targetProperty.getLocalPart().equals(curs.getName().getLocalPart())) {
                            // Not a match, unset target property
                            targetProperty = null;
                        }
                    }
                }
            }
            // Skip over child elements
            if (tt.isStart()) {
                tt = curs.toEndToken();
            }
            tt = curs.toNextToken();
        }
    }
    curs.dispose();
    // Set the targets for this XMLList.
    result.setTargets(this, targetProperty);
    return result;
}
Also used : TokenType(org.apache.xmlbeans.XmlCursor.TokenType) XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 13 with TokenType

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

the class XML method matchDescendantAttributes.

/**
     *
     * @return
     */
private XMLList matchDescendantAttributes(XMLName xmlName) {
    XMLList result = new XMLList(lib);
    XmlCursor curs = newCursor();
    TokenType tt = curs.currentTokenType();
    // Set the targets for this XMLList.
    result.setTargets(this, null);
    if (tt.isStartdoc()) {
        tt = curs.toFirstContentToken();
    }
    if (tt.isContainer()) {
        int nestLevel = 1;
        while (nestLevel > 0) {
            tt = curs.toNextToken();
            // Only try to match names for attributes
            if (tt.isAttr()) {
                if (qnameMatches(xmlName, curs.getName())) {
                    result.addToList(findAnnotation(curs));
                }
            }
            if (tt.isStart()) {
                nestLevel++;
            } else if (tt.isEnd()) {
                nestLevel--;
            } else if (tt.isEnddoc()) {
                // Shouldn't get here, but just in case.
                break;
            }
        }
    }
    curs.dispose();
    return result;
}
Also used : TokenType(org.apache.xmlbeans.XmlCursor.TokenType) XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 14 with TokenType

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

the class XML method changeNS.

protected void changeNS(String oldURI, String newURI) {
    XmlCursor curs = newCursor();
    while (curs.toParent()) {
    /* Goto the top of the document */
    }
    TokenType tt = curs.currentTokenType();
    if (tt.isStartdoc()) {
        tt = curs.toFirstContentToken();
    }
    if (tt.isStart()) {
        do {
            if (tt.isStart() || tt.isAttr() || tt.isNamespace()) {
                javax.xml.namespace.QName currQName = curs.getName();
                if (oldURI.equals(currQName.getNamespaceURI())) {
                    curs.setName(new javax.xml.namespace.QName(newURI, currQName.getLocalPart()));
                }
            }
            tt = curs.toNextToken();
        } while (!tt.isEnddoc() && !tt.isNone());
    }
    curs.dispose();
}
Also used : TokenType(org.apache.xmlbeans.XmlCursor.TokenType) XmlCursor(org.apache.xmlbeans.XmlCursor)

Aggregations

TokenType (org.apache.xmlbeans.XmlCursor.TokenType)14 XmlCursor (org.apache.xmlbeans.XmlCursor)13