Package javax.xml.stream

Examples of javax.xml.stream.XMLStreamException


        //ASSUMPTION: seen <!-
       
        try {
            char ch = more();
            if(ch != '-') {
                throw new XMLStreamException("expected <!-- for COMMENT start", getLocation());
            }
            posStart = pos;
           
            int curLine = lineNumber;
            int curColumn = columnNumber;
            try {
                int expDash = -2;
                int skipLfAt = -2;
                int at = -1;
                boolean anySkipped = false;

                while(true) {
                    ch = more();
                    ++at;
                    // scan until it hits -->
                    if(ch == '-') {
                        if(expDash < at) { // first dash
                            expDash = at+1;
                        } else { // second dash
                            ch = more();
                            if(ch != '>') {
                                throw new XMLStreamException("in COMMENT after two dashes (--) next character must be '>' not "+printable(ch), getLocation());
                            }
                            break;
                        }
                    } else if(ch == '\r') {
                        columnNumber = 1; // more() fails to set this
                        skipLfAt = at+1; // to skip trailing \n, if any
                        // Need to replace current char with \n:
                        if (!anySkipped) { // no gaps yet?
                            buf[pos-1] = '\n';
                            continue;
                        }
                        // If gaps, let's just follow through:
                        ch = '\n';
                    } else if(ch == '\n') { // part of \r\n?
                        if (skipLfAt == at) { // yes, let's skip
                            anySkipped = true;
                            posEnd = pos-1; // to replace this \n next time
                            continue;
                        }
                    }
                    /* Ok, need to add at the end of buffer, if we have
                     * replaced any \r\n combos with \n... or
                     */
                    if (anySkipped) {
                        buf[posEnd] = ch;
                        ++posEnd;
                    }
                }
                if (anySkipped) { // need to trim one '-'
                    --posEnd;
                } else { // the whole '-->' is in input buffer
                    posEnd = pos-3;
                }
            } catch(EOFException ex) {
                // detect EOF and create meaningful error ...
                throw new XMLStreamException(
                    "COMMENT started on line "+curLine+" and column "+curColumn+" was not closed",
                    getLocation(), ex);
            }
           
        } catch (EOFException eofe) {
            throw new XMLStreamException(EOF_MSG, getLocation(), eofe);
        }
    }
View Full Code Here


                } else if (isNameChar(ch)) {
                    ; // good
                } else if (isS(ch)) {
                    break;
                } else {
                    throw new XMLStreamException("unexpected character "+printable(ch)+" after processing instruction name; expected a white space or '?>'",
                                                 getLocation());
                }
            }
            int len = pos-posStart-1;
            // Let's first verify there was a target:
            if (len == 0) { // missing target
                throw new XMLStreamException("processing instruction must have PITarget name", getLocation());
            }

            // [17] PITarget ::= Name - (('X' | 'x') ('M' | 'm') ('L' | 'l'))
            piTarget=new String(buf, posStart, len);
           
            /* And then let's skip (unnecessary) white space, if we hit white
             * space.
             */
            if (ch != '?') {
                ch = skipS(ch);
            }

            boolean isXMLDecl = piTarget.equalsIgnoreCase("xml");
           
            // Do we now have the xml declaration?
            if(isXMLDecl) {
                /* 10-Mar-2006, TSa: This is not really sufficient I think.
                 *   We really should check xml declaration earlier, and
                 *   never have double check here. But, usually this should
                 *   work, too...
                 */
                if((posStart+bufAbsoluteStart) > 2) {  //<?xml is allowed as first characters in input ...
                    throw new XMLStreamException("processing instruction can not have PITarget with reserved name 'xml'",
                                                 getLocation());
                }
                if (!"xml".equals(piTarget)) {
                    throw new XMLStreamException("XMLDecl must have xml name in lowercase",
                                                 getLocation());
                }
                posStart = pos-1;
                parseXmlDecl(ch);
                isXMLDecl = true;
                posEnd = pos - 2;
            } else { // nope, just a regular PI:
                posStart = pos-1;

                int expLT = -2;
                int skipLfAt = -2;
                int at = -1;
                boolean anySkipped = false;

                for (;; ch = more()) {
                    ++at;
                    if (ch == '?') {
                        expLT = at+1;
                    } else if (ch == '>') {
                        if (at == expLT) {
                            break;
                        }
                    } else if(ch == '\r') {
                        columnNumber = 1; // more() fails to set this
                        skipLfAt = at+1; // to skip trailing \n, if any
                        // Need to replace current char with \n:
                        if (!anySkipped) { // no gaps yet?
                            buf[pos-1] = '\n';
                            continue;
                        }
                        // If gaps, let's just follow through:
                        ch = '\n';
                    } else if(ch == '\n') { // part of \r\n?
                        if (skipLfAt == at) { // yes, let's skip
                            anySkipped = true;
                            posEnd = pos-1; // to replace this \n next time
                            continue;
                        }
                    }
                    /* Ok, need to add at the end of buffer, if we have
                     * replaced any \r\n combos with \n... or
                     */
                    if (anySkipped) {
                        buf[posEnd] = ch;
                        ++posEnd;
                    }
                }
                if (anySkipped) { // need to trim one '?'
                    --posEnd;
                } else { // "?>" is in input buffer
                    posEnd = pos-2;
                }
            }
            piData = new String(buf, posStart, (posEnd-posStart));
            return isXMLDecl;
           
        } catch(EOFException ex) {
            // detect EOF and create meaningful error ...
            throw new XMLStreamException("processing instruction started on line "+curLine+" and column "+curColumn
                                             +" was not closed",
                                         getLocation(), ex);
        }
    }
View Full Code Here

        throws XMLStreamException
    {
        for (int i = 0; i < input.length; i++)
        {
            if(ch != input[i]) {
                throw new XMLStreamException(
                    "expected "+printable(input[i])+" in "+new String(input)
                        +" and not "+printable(ch), getLocation());
            }
            try {
                ch = more();
            } catch (EOFException eofe) {
                throw new XMLStreamException(EOF_MSG, getLocation(), eofe);
            }
        }
        return ch;
    }
View Full Code Here

    {
        char ch;
        try {
            ch = more();
        } catch (EOFException eofe) {
            throw new XMLStreamException(EOF_MSG, getLocation(), eofe);
        }
        if(!isS(ch)) {
            throw new XMLStreamException(
                "white space is required and not "+printable(ch), getLocation());
        }
        return skipS(ch);
    }
View Full Code Here

    {
        try {
            while(isS(ch)) { ch = more(); } // skip additional spaces
            return ch;
        } catch (EOFException eofe) {
            throw new XMLStreamException(EOF_MSG, getLocation(), eofe);
        }
    }
View Full Code Here

            ch = skipS(ch);
            ch = requireInput(ch, VERSION);
            // [25] Eq ::= S? '=' S?
            ch = skipS(ch);
            if(ch != '=') {
                throw new XMLStreamException(
                    "expected equals sign (=) after version and not "+printable(ch), getLocation());
            }
            ch = more();
            ch = skipS(ch);
            if(ch != '\'' && ch != '"') {
                throw new XMLStreamException(
                    "expected apostrophe (') or quotation mark (\") after version and not "
                        +printable(ch), getLocation());
            }
            char quotChar = ch;
            int versionStart = pos;
            ch = more();
            // [26] VersionNum ::= ([a-zA-Z0-9_.:] | '-')+
            while(ch != quotChar) {
                if((ch  < 'a' || ch > 'z') && (ch  < 'A' || ch > 'Z') && (ch  < '0' || ch > '9')
                       && ch != '_' && ch != '.' && ch != ':' && ch != '-')
                {
                    throw new XMLStreamException(
                        "<?xml version value expected to be in ([a-zA-Z0-9_.:] | '-')"
                            +" not "+printable(ch), getLocation());
                }
                ch = more();
            }
            int versionEnd = pos - 1;
            parseXmlDeclWithVersion(versionStart, versionEnd);
           
        } catch (EOFException eofe) {
            throw new XMLStreamException(EOF_MSG, getLocation(), eofe);
        }
    }
View Full Code Here

            if((versionEnd - versionStart != 3)
                   || buf[versionStart] != '1'
                   || buf[versionStart+1] != '.'
                   || buf[versionStart+2] != '0')
            {
                throw new XMLStreamException(
                    "only 1.0 is supported as <?xml version not '"
                        +printable(new String(buf, versionStart, versionEnd))+"'", getLocation());
            }
            xmlVersion = new String(buf, versionStart, versionEnd-versionStart);
           
            // [80] EncodingDecl ::= S 'encoding' Eq ('"' EncName '"' | "'" EncName "'" )
            char ch = more();
            ch = skipS(ch);
            if(ch != '?') {
                ch = skipS(ch);
               
                if(ch == ENCODING[0]) {
                    ch = requireInput(ch, ENCODING);
                    ch = skipS(ch);
                    if(ch != '=') {
                        throw new XMLStreamException(
                            "expected equals sign (=) after encoding and not "+printable(ch), getLocation());
                    }
                    ch = more();
                    ch = skipS(ch);
                    if(ch != '\'' && ch != '"') {
                        throw new XMLStreamException(
                            "expected apostrophe (') or quotation mark (\") after encoding and not "
                                +printable(ch), getLocation());
                    }
                    char quotChar = ch;
                    int encodingStart = pos;
                    ch = more();
                    // [81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')*
                    if((ch  < 'a' || ch > 'z') && (ch  < 'A' || ch > 'Z'))
                    {
                        throw new XMLStreamException(
                            "<?xml encoding name expected to start with [A-Za-z]"
                                +" not "+printable(ch), getLocation());
                    }
                    ch = more();
                    while(ch != quotChar) {
                        if((ch  < 'a' || ch > 'z') && (ch  < 'A' || ch > 'Z') && (ch  < '0' || ch > '9')
                               && ch != '.' && ch != '_' && ch != '-')
                        {
                            throw new XMLStreamException(
                                "<?xml encoding value expected to be in ([A-Za-z0-9._] | '-')"
                                    +" not "+printable(ch), getLocation());
                        }
                        ch = more();
                    }
                    int encodingEnd = pos - 1;
                    //String encodingName = newStringIntern(buf, encodingStart, encodingEnd);
                    // TODO reconcile with setInput encodingName
                    charEncodingScheme = newString(buf, encodingStart, encodingEnd-encodingStart);
                    ch = more();
                    ch = skipS(ch);
                }
                // [32] SDDecl ::= S 'standalone' Eq (("'" ('yes' | 'no') "'") | ('"' ('yes' | 'no') '"'))
                if(ch != '?') {
                    ch = skipS(ch);
                    ch = requireInput(ch, STANDALONE);
                    ch = skipS(ch);
                    if(ch != '=') {
                        throw new XMLStreamException(
                            "expected equals sign (=) after standalone and not "+printable(ch),
                            getLocation());
                    }
                    ch = more();
                    ch = skipS(ch);
                    if(ch != '\'' && ch != '"') {
                        throw new XMLStreamException(
                            "expected apostrophe (') or quotation mark (\") after encoding and not "
                                +printable(ch), getLocation());
                    }
                    char quotChar = ch;
                    int standaloneStart = pos;
                    ch = more();
                    if(ch == 'y') {
                        ch = requireInput(ch, YES);
                        standalone = true;
                    } else if(ch == 'n') {
                        ch = requireInput(ch, NO);
                        standalone = false;
                    } else {
                        throw new XMLStreamException(
                            "expected 'yes' or 'no' after standalone and not "
                                +printable(ch), getLocation());
                    }
                    standaloneSet = true;
                    if(ch != quotChar) {
                        throw new XMLStreamException(
                            "expected "+quotChar+" after standalone value not "
                                +printable(ch), getLocation());
                    }
                    ch = more();
                }
            }
            ch = skipS(ch);
            if(ch != '?') {
                throw new XMLStreamException(
                    "expected ?> as last part of <?xml not "
                        +printable(ch), getLocation());
            }
            ch = more();
            if(ch != '>') {
                throw new XMLStreamException(
                    "expected ?> as last part of <?xml not "
                        +printable(ch), getLocation());
            }
           
        } catch (EOFException eofe) {
            throw new XMLStreamException(EOF_MSG, getLocation(), eofe);
        }
    }
View Full Code Here

                   || more() != 'C'
                   || more() != 'T'
                   || more() != 'Y'
                   || more() != 'P'
                   || more() != 'E') {
                throw new XMLStreamException("expected <!DOCTYPE", getLocation());
            }
           
            // do simple and crude scanning for end of doctype
           
            // [28]  doctypedecl ::= '<!DOCTYPE' S Name (S ExternalID)? S? ('['
            //                      (markupdecl | DeclSep)* ']' S?)? '>'
           
            /* 07-Nov-2004, TSa: Should be fairly easy to verify (obligatory)
             *   root element, and optional public/system ids too.
             */
            // (but only in validating mode, since that's a VC, not WFC)

            // First obligatory white space:
            char ch = requireNextS();

            // Then obligatory root element name (copied from parseEndTag())
            if(!isNameStartChar(ch)) {
                throwNotNameStart(ch);
            }
            int nameStart = pos - 1 + bufAbsoluteStart;
            do {
                ch = more();
            } while(isNameChar(ch));

            // Ok, root element name gotten. Any white space to skip?
            ch = skipS(ch);

            if (ch == 'S' || ch == 'P') { // SYSTEM/PUBLIC identifier
                if (ch == 'S') {
                    if (more() != 'Y' || more() != 'S' || more() != 'T'
                        || more() != 'E' || more() != 'M') {
                        throw new XMLStreamException("expected keyword SYSTEM", getLocation());
                    }
                } else {
                    if(more() != 'U' || more() != 'B' || more() != 'L'
                       || more() != 'I' || more() != 'C') {
                        throw new XMLStreamException("expected keyword PUBLIC", getLocation());
                    }
                    // Need to skip the public id
                    char quotChar = requireNextS();
                    if (quotChar != '"' && quotChar != '\'') {
                        throw new XMLStreamException("Public identifier has to be enclosed in quotes, not "+printable(ch), getLocation());
                    }
                    while ((ch = more()) != quotChar) {
                        // should probably check if it's valid...
                    }
                }

                char quotChar = requireNextS();
                if (quotChar != '"' && quotChar != '\'') {
                    throw new XMLStreamException("System identifier has to be enclosed in quotes, not "+printable(ch), getLocation());
                }
                while ((ch = more()) != quotChar) {
                    // should probably check if it's valid...
                }
                // Ok, great, names skipped, can try to locate the int. subset
                ch = skipS(more());
            }

            if (ch == '[') {
                posStart = pos;
                int bracketLevel = 1;
                loop:
                /* Ok, let's try to find the boundary of the internal
                 * subset. It's not 100% reliable, since we don't really
                 * parse... but should be good enough for now
                 */
                while(true) {
                    ch = more();
                    switch (ch) {
                    case '[':
                        ++bracketLevel;
                        break;
                    case ']': // should we check for underflow?
                        --bracketLevel;
                        break;
                    case '>':
                        if (bracketLevel <= 0) {
                            break loop;
                        }
                        break;
                    case '\'': // entity expansion value, attr. default or such?
                    case '"':
                        while (more() != ch) {
                            // let's just loop over it...
                        }
                        break;
                    }
                }
                posEnd = pos-2; // to exclude closing bracket
                processDTD();
            } else {
                // No internal subset, empty contents
                posStart = posEnd = pos;
                ch = skipS(ch);
                if (ch != '>') {
                    throw new XMLStreamException("Expected closing '>' after internal DTD subset, not '"
                                                 +printable(ch)+"'", getLocation());
                }
            }
        } catch (EOFException eofe) {
            throw new XMLStreamException(EOF_MSG, getLocation(), eofe);
        }
    }
View Full Code Here

                }
            }
        } catch (IOException ioe) {
            //System.out.println(ioe);
            //ioe.printStackTrace();
            throw new XMLStreamException(ioe);
        }
    }
View Full Code Here

                   || more() != 'A'
                   || more() != 'T'
                   || more() != 'A'
                   || more() != '['
              ) {
                throw new XMLStreamException("expected <[CDATA[ for CDATA start", getLocation());
            }
        } catch (EOFException eofe) {
            throw new XMLStreamException("Unexpected EOF in directive", getLocation(), eofe);
        }
       
        char ch;
       
        //if(tokenize) {
        posStart = pos;
        int curLine = lineNumber;
        int curColumn = columnNumber;
        try {
            int bracketCount = 0;
            int skipLfAt = -2;
            int at = -1;
            boolean anySkipped = false;
            while(true) {
                // scan until it hits ]]>
                ++at;
                ch = more();
                if(ch == ']') {
                    ++bracketCount;
                } else {
                    if(ch == '>') {
                        if (bracketCount >= 2) {
                            break// found end sequence!!!!
                        }
                        bracketCount = 0;
                    } else {
                        bracketCount = 0;
                        if (ch == '\r') {
                            columnNumber = 1; // more() fails to set this
                            skipLfAt = at+1; // to skip trailing \n, if any
                            // Need to replace current char with \n:
                            if (!anySkipped) { // no gaps yet?
                                buf[pos-1] = '\n';
                                continue;
                            }
                            // If gaps, let's just fall through:
                            ch = '\n';
                        } else if(ch == '\n') { // part of \r\n?
                            if (skipLfAt == at) { // yes, let's skip
                                anySkipped = true;
                                posEnd = pos-1; // to replace this \n next time
                                continue;
                            }
                        }
                    }
                }
                /* Ok, need to add at the end of buffer, if we have
                 * replaced any \r\n combos with \n... or
                 */
                if (anySkipped) {
                    buf[posEnd] = ch;
                    ++posEnd;
                }
            }
            if (anySkipped) { // have extra ']]' in there
                posEnd -= 2;
            } else { // the whole ']]>' is in input buffer
                posEnd = pos-3;
            }
        } catch(EOFException ex) {
            // detect EOF and create meaningful error ...
            throw new XMLStreamException(
                "CDATA section on line "+curLine+" and column "+curColumn+" was not closed",
                getLocation(), ex);
        }
    }
View Full Code Here

TOP

Related Classes of javax.xml.stream.XMLStreamException

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.