Package org.apache.xmlbeans.XmlCursor

Examples of org.apache.xmlbeans.XmlCursor.TokenType


     *
     */
    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


    }

    public TokenType _prevTokenType() {
        _cur.push();

        TokenType tt = _toPrevToken();

        _cur.pop();

        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.