protected int nextInDocumentStart()

in batik-xml/src/main/java/org/apache/batik/xml/XMLScanner.java [523:602]


    protected int nextInDocumentStart() throws IOException, XMLException {
        switch (current) {
        case 0x9:
        case 0xA:
        case 0xD:
        case 0x20:
            do {
                nextChar();
            } while (current != -1 && XMLUtilities.isXMLSpace((char)current));
            context = (depth == 0) ? TOP_LEVEL_CONTEXT : CONTENT_CONTEXT;
            return LexicalUnits.S;

        case '<':
            switch (nextChar()) {
            case '?':
                int c1 = nextChar();
                if (c1 == -1 ||
                    !XMLUtilities.isXMLNameFirstCharacter((char)c1)) {
                    throw createXMLException("invalid.pi.target");
                }
                context = PI_CONTEXT;
                int c2 = nextChar();
                if (c2 == -1 || !XMLUtilities.isXMLNameCharacter((char)c2)) {
                    return LexicalUnits.PI_START;
                }
                int c3 = nextChar();
                if (c3 == -1 || !XMLUtilities.isXMLNameCharacter((char)c3)) {
                    return LexicalUnits.PI_START;
                }
                int c4 = nextChar();
                if (c4 != -1 && XMLUtilities.isXMLNameCharacter((char)c4)) {
                    do {
                        nextChar();
                    } while (current != -1 &&
                             XMLUtilities.isXMLNameCharacter((char)current));
                    return LexicalUnits.PI_START;
                }
                if (c1 == 'x' && c2 == 'm' && c3 == 'l') {
                    context = XML_DECL_CONTEXT;
                    return LexicalUnits.XML_DECL_START;
                }
                if ((c1 == 'x' || c1 == 'X') &&
                    (c2 == 'm' || c2 == 'M') &&
                    (c3 == 'l' || c3 == 'L')) {
                    throw createXMLException("xml.reserved");
                }
                return LexicalUnits.PI_START;

            case '!':
                switch (nextChar()) {
                case '-':
                    return readComment();

                case 'D':
                    context = DOCTYPE_CONTEXT;
                    return readIdentifier("OCTYPE",
                                          LexicalUnits.DOCTYPE_START,
                                          -1);

                default:
                    throw createXMLException("invalid.doctype");
                }

            default:
                context = START_TAG_CONTEXT;
                depth++;
                return readName(LexicalUnits.START_TAG);
            }

        case -1:
            return LexicalUnits.EOF;

        default:
            if (depth == 0) {
                throw createXMLException("invalid.character");
            } else {
                return nextInContent();
            }
        }
    }