Package org.apache.xmlbeans.XmlCursor

Examples of org.apache.xmlbeans.XmlCursor.TokenType


     */
    private XMLList matchDescendantChildren(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();

                if (!tt.isAttr() && !tt.isEnd() && !tt.isEnddoc())
                {
                    // Only try to match names for elements or processing instructions.
                    if (!tt.isStart() && !tt.isProcinst())
                    {
                        // Not an element or procinst, only add if qname is all
                        if (xmlName.localName().equals("*"))
                        {
                            result.addToList(findAnnotation(curs));
                        }
                    }
                    else
                    {
                        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;
                }
            }
View Full Code Here


     */
    private XMLList matchChildren(XmlCursor.TokenType tokenType, XMLName name)
    {
        XMLList result = new XMLList(lib);
        XmlCursor curs = newCursor();
        TokenType tt = curs.currentTokenType();
        javax.xml.namespace.QName qname = new javax.xml.namespace.QName(name.uri(), name.localName());
        javax.xml.namespace.QName targetProperty = qname;

        if (tt.isStartdoc())
        {
            tt = curs.toFirstContentToken();
        }

        if (tt.isContainer())
        {
            tt = curs.toFirstContentToken();

            while (!tt.isEnd())
            {
                if (tt == tokenType)
                {
                    // Only try to match names for elements or processing instructions.
                    if (!tt.isStart() && !tt.isProcinst())
                    {
                        // Not an element or no name specified.
                        result.addToList(findAnnotation(curs));

                        // Reset target property to null in this case
                        targetProperty = null;
                    }
                    else
                    {
                        // Match names as well
                        if (qnameMatches(name, curs.getName()))
                        {
                            // Add it to the list
                            result.addToList(findAnnotation(curs));

                            // Set target property if target name is "*",
                            // Otherwise if target property does not match current, then
                            // 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();
View Full Code Here

    {
        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
            {
View Full Code Here

     *
     */
    void normalize()
    {
        XmlCursor curs = newCursor();
        TokenType tt = curs.currentTokenType();

        // Walk through the tokens removing empty text nodes and merging adjacent text nodes.
        if (tt.isStartdoc())
        {
            tt = curs.toFirstContentToken();
        }

        if (tt.isContainer())
        {
            int nestLevel = 1;
            String previousText = null;

            while (nestLevel > 0)
            {
                tt = curs.toNextToken();

                if (tt == XmlCursor.TokenType.TEXT)
                {
                    String currentText = curs.getChars().trim();

                    if (currentText.trim().length() == 0)
                    {
                        // Empty text node, remove.
                        removeToken(curs);
                        curs.toPrevToken();
                    }
                    else if (previousText == null)
                    {
                        // No previous text node, reset to trimmed version
                        previousText = currentText;
                    }
                    else
                    {
                        // It appears that this case never happens with XBeans.
                        // Previous text node exists, concatenate
                        String newText = previousText + currentText;

                        curs.toPrevToken();
                        removeToken(curs);
                        removeToken(curs);
                        curs.insertChars(newText);
                    }
                }
                else
                {
                    previousText = null;
                }

                if (tt.isStart())
                {
                    nestLevel++;
                }
                else if (tt.isEnd())
                {
                    nestLevel--;
                }
                else if (tt.isEnddoc())
                {
                    // Shouldn't get here, but just in case.
                    break;
                }
            }
View Full Code Here

        int n = 0;
       
        for ( ; ; )
        {
            TokenType t = c.toNextToken();

            n++;
           
            if (t == TokenType.NONE)
                break;
View Full Code Here

        for ( ; ; )
        {
            Assert.assertTrue( cFrom.comparePosition( cTo ) == 0 );
            Assert.assertTrue( cFrom.isAtSamePositionAs( cTo ) );

            TokenType tt = cFrom.currentTokenType();
           
            if (tt == TokenType.ENDDOC)
            {
                break;
            }
View Full Code Here

        private int attrCount;

        protected ElementXmlTreeNode(XmlCursor cursor, XmlTreeNode parent) {
            super(cursor, parent);

            TokenType token = cursor.toNextToken();
            while (token == TokenType.ATTR || token == TokenType.NAMESPACE) {
                if (token == TokenType.ATTR) {
                    elements.add(new AttributeXmlTreeNode(cursor, this));
                }
View Full Code Here

        int n = 0;
       
        for ( ; ; )
        {
            TokenType t = c.toNextToken();

            n++;
           
            if (t == TokenType.NONE)
                break;
View Full Code Here

        for ( ; ; )
        {
            Assert.assertTrue( cFrom.comparePosition( cTo ) == 0 );
            Assert.assertTrue( cFrom.isAtSamePositionAs( cTo ) );

            TokenType tt = cFrom.currentTokenType();
           
            if (tt == TokenType.ENDDOC)
            {
                break;
            }
View Full Code Here

     * @param curs
     * @return
     */
    private static TokenType skipNonElements (XmlCursor curs)
    {
        TokenType tt = curs.currentTokenType();
        while (tt.isComment() || tt.isProcinst())
        {
            tt = curs.toNextToken();
        }

        return tt;
View Full Code Here

TOP

Related Classes of org.apache.xmlbeans.XmlCursor.TokenType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.