jaxp/src/com/sun/org/apache/xerces/internal/impl/XML11NSDocumentScannerImpl.java
author joehw
Tue, 17 Apr 2012 11:17:59 -0700
changeset 12458 d601e4bba306
parent 12457 c348e06f0e82
child 20968 dde41f8b7b96
permissions -rw-r--r--
7160380: Sync JDK8 with JAXP 1.4.5 Summary: bring JDK8 up to date to what we have in 7u4 Reviewed-by: lancea, mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     2
 * reserved comment block
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     6
 * The Apache Software License, Version 1.1
7f561c08de6b Initial load
duke
parents:
diff changeset
     7
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
     8
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
     9
 * Copyright (c) 1999-2003 The Apache Software Foundation.
7f561c08de6b Initial load
duke
parents:
diff changeset
    10
 * All rights reserved.
7f561c08de6b Initial load
duke
parents:
diff changeset
    11
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 * Redistribution and use in source and binary forms, with or without
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 * modification, are permitted provided that the following conditions
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 * are met:
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * 1. Redistributions of source code must retain the above copyright
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 *    notice, this list of conditions and the following disclaimer.
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 * 2. Redistributions in binary form must reproduce the above copyright
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
 *    notice, this list of conditions and the following disclaimer in
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
 *    the documentation and/or other materials provided with the
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
 *    distribution.
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
 * 3. The end-user documentation included with the redistribution,
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
 *    if any, must include the following acknowledgment:
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
 *       "This product includes software developed by the
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
 *        Apache Software Foundation (http://www.apache.org/)."
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
 *    Alternately, this acknowledgment may appear in the software itself,
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
 *    if and wherever such third-party acknowledgments normally appear.
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
 * 4. The names "Xerces" and "Apache Software Foundation" must
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
 *    not be used to endorse or promote products derived from this
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
 *    software without prior written permission. For written
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
 *    permission, please contact apache@apache.org.
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
 * 5. Products derived from this software may not be called "Apache",
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
 *    nor may "Apache" appear in their name, without prior written
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
 *    permission of the Apache Software Foundation.
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
 * SUCH DAMAGE.
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
 * ====================================================================
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
 * This software consists of voluntary contributions made by many
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
 * individuals on behalf of the Apache Software Foundation and was
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
 * originally based on software copyright (c) 2002, International
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
 * Business Machines, Inc., http://www.apache.org.  For more
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
 * information on the Apache Software Foundation, please see
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
 * <http://www.apache.org/>.
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
package com.sun.org.apache.xerces.internal.impl;
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
import java.io.IOException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
import com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidatorFilter;
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter;
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
import com.sun.org.apache.xerces.internal.util.XMLAttributesImpl;
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
import com.sun.org.apache.xerces.internal.util.XMLSymbols;
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
import com.sun.org.apache.xerces.internal.xni.NamespaceContext;
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
import com.sun.org.apache.xerces.internal.xni.QName;
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
import com.sun.org.apache.xerces.internal.xni.XMLDocumentHandler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
import com.sun.org.apache.xerces.internal.xni.XNIException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager;
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentSource;
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
import javax.xml.stream.events.XMLEvent;
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
 * The scanner acts as the source for the document
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
 * information which is communicated to the document handler.
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
 * This class scans an XML document, checks if document has a DTD, and if
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
 * DTD is not found the scanner will remove the DTD Validator from the pipeline and perform
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
 * namespace binding.
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
 * Note: This scanner should only be used when the namespace processing is on!
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
 * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
 * This component requires the following features and properties from the
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
 * component manager that uses it:
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
 * <ul>
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
 *  <li>http://xml.org/sax/features/namespaces {true} -- if the value of this
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
 *      feature is set to false this scanner must not be used.</li>
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
 *  <li>http://xml.org/sax/features/validation</li>
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
 *  <li>http://apache.org/xml/features/nonvalidating/load-external-dtd</li>
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
 *  <li>http://apache.org/xml/features/scanner/notify-char-refs</li>
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
 *  <li>http://apache.org/xml/features/scanner/notify-builtin-refs</li>
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
 *  <li>http://apache.org/xml/properties/internal/symbol-table</li>
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
 *  <li>http://apache.org/xml/properties/internal/error-reporter</li>
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
 *  <li>http://apache.org/xml/properties/internal/entity-manager</li>
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
 *  <li>http://apache.org/xml/properties/internal/dtd-scanner</li>
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
 * </ul>
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
 * @xerces.internal
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
 * @author Elena Litani, IBM
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
 * @author Michael Glavassevich, IBM
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
 * @author Sunitha Reddy, Sun Microsystems
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
public class XML11NSDocumentScannerImpl extends XML11DocumentScannerImpl {
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
     * If is true, the dtd validator is no longer in the pipeline
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
     * and the scanner should bind namespaces
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
    protected boolean fBindNamespaces;
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
     * If validating parser, make sure we report an error in the
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
     *  scanner if DTD grammar is missing.
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
    protected boolean fPerformValidation;
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
    // private data
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
    /** DTD validator */
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
    private XMLDTDValidatorFilter fDTDValidator;
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
     * Saw spaces after element name or between attributes.
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
     * This is reserved for the case where scanning of a start element spans
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
     * several methods, as is the case when scanning the start of a root element
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
     * where a DTD external subset may be read after scanning the element name.
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
    private boolean fSawSpace;
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
     * The scanner is responsible for removing DTD validator
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
     * from the pipeline if it is not needed.
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
     * @param validator the DTD validator from the pipeline
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
    public void setDTDValidator(XMLDTDValidatorFilter validator) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
        fDTDValidator = validator;
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
     * Scans a start element. This method will handle the binding of
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
     * namespace information and notifying the handler of the start
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
     * of the element.
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
     * <pre>
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
     * [44] EmptyElemTag ::= '&lt;' Name (S Attribute)* S? '/>'
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
     * [40] STag ::= '&lt;' Name (S Attribute)* S? '>'
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
     * </pre>
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
     * <strong>Note:</strong> This method assumes that the leading
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
     * '&lt;' character has been consumed.
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
     * <strong>Note:</strong> This method uses the fElementQName and
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
     * fAttributes variables. The contents of these variables will be
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
     * destroyed. The caller should copy important information out of
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
     * these variables before calling this method.
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
     * @return True if element is empty. (i.e. It matches
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
     *          production [44].
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
    protected boolean scanStartElement() throws IOException, XNIException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
        if (DEBUG_START_END_ELEMENT)
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
            System.out.println(">>> scanStartElementNS()");
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
                // Note: namespace processing is on by default
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
        fEntityScanner.scanQName(fElementQName);
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
        // REVISIT - [Q] Why do we need this local variable? -- mrglavas
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
        String rawname = fElementQName.rawname;
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
        if (fBindNamespaces) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
            fNamespaceContext.pushContext();
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
            if (fScannerState == SCANNER_STATE_ROOT_ELEMENT) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
                if (fPerformValidation) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
                    fErrorReporter.reportError(
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
                        XMLMessageFormatter.XML_DOMAIN,
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
                        "MSG_GRAMMAR_NOT_FOUND",
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
                        new Object[] { rawname },
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
                        XMLErrorReporter.SEVERITY_ERROR);
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
                    if (fDoctypeName == null
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
                        || !fDoctypeName.equals(rawname)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
                        fErrorReporter.reportError(
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
                            XMLMessageFormatter.XML_DOMAIN,
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
                            "RootElementTypeMustMatchDoctypedecl",
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
                            new Object[] { fDoctypeName, rawname },
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
                            XMLErrorReporter.SEVERITY_ERROR);
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
        // push element stack
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
        fCurrentElement = fElementStack.pushElement(fElementQName);
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
        // attributes
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
        boolean empty = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
        fAttributes.removeAllAttributes();
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
        do {
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
            // spaces
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
            boolean sawSpace = fEntityScanner.skipSpaces();
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
            // end tag?
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
            int c = fEntityScanner.peekChar();
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
            if (c == '>') {
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
                fEntityScanner.scanChar();
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
                break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
            } else if (c == '/') {
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
                fEntityScanner.scanChar();
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
                if (!fEntityScanner.skipChar('>')) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
                    reportFatalError(
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
                        "ElementUnterminated",
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
                        new Object[] { rawname });
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
                empty = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
                break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
            } else if (!isValidNameStartChar(c) || !sawSpace) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
                // Second chance. Check if this character is a high
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
                // surrogate of a valid name start character.
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
                if (!isValidNameStartHighSurrogate(c) || !sawSpace) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
                    reportFatalError(
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
                        "ElementUnterminated",
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
                        new Object[] { rawname });
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
            // attributes
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
            scanAttribute(fAttributes);
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
            if (fSecurityManager != null && fAttributes.getLength() > fElementAttributeLimit){
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
                fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
                                             "ElementAttributeLimit",
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
                                             new Object[]{rawname, new Integer(fElementAttributeLimit) },
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
                                             XMLErrorReporter.SEVERITY_FATAL_ERROR );
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
        } while (true);
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
        if (fBindNamespaces) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
            // REVISIT: is it required? forbit xmlns prefix for element
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
            if (fElementQName.prefix == XMLSymbols.PREFIX_XMLNS) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
                fErrorReporter.reportError(
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
                    XMLMessageFormatter.XMLNS_DOMAIN,
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
                    "ElementXMLNSPrefix",
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
                    new Object[] { fElementQName.rawname },
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
                    XMLErrorReporter.SEVERITY_FATAL_ERROR);
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
            // bind the element
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
            String prefix =
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
                fElementQName.prefix != null
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
                    ? fElementQName.prefix
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
                    : XMLSymbols.EMPTY_STRING;
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
            // assign uri to the element
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
            fElementQName.uri = fNamespaceContext.getURI(prefix);
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
            // make sure that object in the element stack is updated as well
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
            fCurrentElement.uri = fElementQName.uri;
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
            if (fElementQName.prefix == null && fElementQName.uri != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
                fElementQName.prefix = XMLSymbols.EMPTY_STRING;
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
                // making sure that the object in the element stack is updated too.
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
                fCurrentElement.prefix = XMLSymbols.EMPTY_STRING;
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
            if (fElementQName.prefix != null && fElementQName.uri == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
                fErrorReporter.reportError(
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
                    XMLMessageFormatter.XMLNS_DOMAIN,
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
                    "ElementPrefixUnbound",
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
                    new Object[] {
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
                        fElementQName.prefix,
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
                        fElementQName.rawname },
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
                    XMLErrorReporter.SEVERITY_FATAL_ERROR);
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
            // bind attributes (xmlns are already bound bellow)
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
            int length = fAttributes.getLength();
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
            for (int i = 0; i < length; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
                fAttributes.getName(i, fAttributeQName);
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
                String aprefix =
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
                    fAttributeQName.prefix != null
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
                        ? fAttributeQName.prefix
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
                        : XMLSymbols.EMPTY_STRING;
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
                String uri = fNamespaceContext.getURI(aprefix);
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
                // REVISIT: try removing the first "if" and see if it is faster.
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
                //
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
                if (fAttributeQName.uri != null
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
                    && fAttributeQName.uri == uri) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
                    continue;
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
                if (aprefix != XMLSymbols.EMPTY_STRING) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
                    fAttributeQName.uri = uri;
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
                    if (uri == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
                        fErrorReporter.reportError(
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
                            XMLMessageFormatter.XMLNS_DOMAIN,
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
                            "AttributePrefixUnbound",
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
                            new Object[] {
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
                                fElementQName.rawname,
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
                                fAttributeQName.rawname,
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
                                aprefix },
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
                            XMLErrorReporter.SEVERITY_FATAL_ERROR);
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
                    fAttributes.setURI(i, uri);
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   314
7f561c08de6b Initial load
duke
parents:
diff changeset
   315
            if (length > 1) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   316
                QName name = fAttributes.checkDuplicatesNS();
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
                if (name != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
                    if (name.uri != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
                        fErrorReporter.reportError(
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
                            XMLMessageFormatter.XMLNS_DOMAIN,
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
                            "AttributeNSNotUnique",
7f561c08de6b Initial load
duke
parents:
diff changeset
   322
                            new Object[] {
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
                                fElementQName.rawname,
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
                                name.localpart,
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
                                name.uri },
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
                            XMLErrorReporter.SEVERITY_FATAL_ERROR);
7f561c08de6b Initial load
duke
parents:
diff changeset
   327
                    } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
                        fErrorReporter.reportError(
7f561c08de6b Initial load
duke
parents:
diff changeset
   329
                            XMLMessageFormatter.XMLNS_DOMAIN,
7f561c08de6b Initial load
duke
parents:
diff changeset
   330
                            "AttributeNotUnique",
7f561c08de6b Initial load
duke
parents:
diff changeset
   331
                            new Object[] {
7f561c08de6b Initial load
duke
parents:
diff changeset
   332
                                fElementQName.rawname,
7f561c08de6b Initial load
duke
parents:
diff changeset
   333
                                name.rawname },
7f561c08de6b Initial load
duke
parents:
diff changeset
   334
                            XMLErrorReporter.SEVERITY_FATAL_ERROR);
7f561c08de6b Initial load
duke
parents:
diff changeset
   335
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   336
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   337
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   338
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   339
7f561c08de6b Initial load
duke
parents:
diff changeset
   340
        // call handler
7f561c08de6b Initial load
duke
parents:
diff changeset
   341
7f561c08de6b Initial load
duke
parents:
diff changeset
   342
            if (empty) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   343
7f561c08de6b Initial load
duke
parents:
diff changeset
   344
                //decrease the markup depth..
7f561c08de6b Initial load
duke
parents:
diff changeset
   345
                fMarkupDepth--;
7f561c08de6b Initial load
duke
parents:
diff changeset
   346
7f561c08de6b Initial load
duke
parents:
diff changeset
   347
                // check that this element was opened in the same entity
7f561c08de6b Initial load
duke
parents:
diff changeset
   348
                if (fMarkupDepth < fEntityStack[fEntityDepth - 1]) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   349
                    reportFatalError(
7f561c08de6b Initial load
duke
parents:
diff changeset
   350
                        "ElementEntityMismatch",
7f561c08de6b Initial load
duke
parents:
diff changeset
   351
                        new Object[] { fCurrentElement.rawname });
7f561c08de6b Initial load
duke
parents:
diff changeset
   352
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   353
7f561c08de6b Initial load
duke
parents:
diff changeset
   354
                fDocumentHandler.emptyElement(fElementQName, fAttributes, null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   355
7f561c08de6b Initial load
duke
parents:
diff changeset
   356
                /*if (fBindNamespaces) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   357
                    fNamespaceContext.popContext();
7f561c08de6b Initial load
duke
parents:
diff changeset
   358
                }*/
7f561c08de6b Initial load
duke
parents:
diff changeset
   359
                fScanEndElement = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   360
7f561c08de6b Initial load
duke
parents:
diff changeset
   361
                //pop the element off the stack..
7f561c08de6b Initial load
duke
parents:
diff changeset
   362
                fElementStack.popElement();
7f561c08de6b Initial load
duke
parents:
diff changeset
   363
            } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   364
7f561c08de6b Initial load
duke
parents:
diff changeset
   365
                if(dtdGrammarUtil != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   366
                    dtdGrammarUtil.startElement(fElementQName, fAttributes);
7f561c08de6b Initial load
duke
parents:
diff changeset
   367
7f561c08de6b Initial load
duke
parents:
diff changeset
   368
                if (fDocumentHandler != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   369
                fDocumentHandler.startElement(fElementQName, fAttributes, null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   370
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   371
7f561c08de6b Initial load
duke
parents:
diff changeset
   372
        if (DEBUG_START_END_ELEMENT)
7f561c08de6b Initial load
duke
parents:
diff changeset
   373
            System.out.println("<<< scanStartElement(): " + empty);
7f561c08de6b Initial load
duke
parents:
diff changeset
   374
        return empty;
7f561c08de6b Initial load
duke
parents:
diff changeset
   375
7f561c08de6b Initial load
duke
parents:
diff changeset
   376
    } // scanStartElement():boolean
7f561c08de6b Initial load
duke
parents:
diff changeset
   377
7f561c08de6b Initial load
duke
parents:
diff changeset
   378
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   379
     * Scans the name of an element in a start or empty tag.
7f561c08de6b Initial load
duke
parents:
diff changeset
   380
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   381
     * @see #scanStartElement()
7f561c08de6b Initial load
duke
parents:
diff changeset
   382
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   383
    protected void scanStartElementName ()
7f561c08de6b Initial load
duke
parents:
diff changeset
   384
        throws IOException, XNIException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   385
        // Note: namespace processing is on by default
7f561c08de6b Initial load
duke
parents:
diff changeset
   386
        fEntityScanner.scanQName(fElementQName);
7f561c08de6b Initial load
duke
parents:
diff changeset
   387
        // Must skip spaces here because the DTD scanner
7f561c08de6b Initial load
duke
parents:
diff changeset
   388
        // would consume them at the end of the external subset.
7f561c08de6b Initial load
duke
parents:
diff changeset
   389
        fSawSpace = fEntityScanner.skipSpaces();
7f561c08de6b Initial load
duke
parents:
diff changeset
   390
    } // scanStartElementName()
7f561c08de6b Initial load
duke
parents:
diff changeset
   391
7f561c08de6b Initial load
duke
parents:
diff changeset
   392
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   393
     * Scans the remainder of a start or empty tag after the element name.
7f561c08de6b Initial load
duke
parents:
diff changeset
   394
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   395
     * @see #scanStartElement
7f561c08de6b Initial load
duke
parents:
diff changeset
   396
     * @return True if element is empty.
7f561c08de6b Initial load
duke
parents:
diff changeset
   397
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   398
    protected boolean scanStartElementAfterName()
7f561c08de6b Initial load
duke
parents:
diff changeset
   399
        throws IOException, XNIException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   400
7f561c08de6b Initial load
duke
parents:
diff changeset
   401
        // REVISIT - [Q] Why do we need this local variable? -- mrglavas
7f561c08de6b Initial load
duke
parents:
diff changeset
   402
        String rawname = fElementQName.rawname;
7f561c08de6b Initial load
duke
parents:
diff changeset
   403
        if (fBindNamespaces) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   404
            fNamespaceContext.pushContext();
7f561c08de6b Initial load
duke
parents:
diff changeset
   405
            if (fScannerState == SCANNER_STATE_ROOT_ELEMENT) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   406
                if (fPerformValidation) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   407
                    fErrorReporter.reportError(
7f561c08de6b Initial load
duke
parents:
diff changeset
   408
                        XMLMessageFormatter.XML_DOMAIN,
7f561c08de6b Initial load
duke
parents:
diff changeset
   409
                        "MSG_GRAMMAR_NOT_FOUND",
7f561c08de6b Initial load
duke
parents:
diff changeset
   410
                        new Object[] { rawname },
7f561c08de6b Initial load
duke
parents:
diff changeset
   411
                        XMLErrorReporter.SEVERITY_ERROR);
7f561c08de6b Initial load
duke
parents:
diff changeset
   412
7f561c08de6b Initial load
duke
parents:
diff changeset
   413
                    if (fDoctypeName == null
7f561c08de6b Initial load
duke
parents:
diff changeset
   414
                        || !fDoctypeName.equals(rawname)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   415
                        fErrorReporter.reportError(
7f561c08de6b Initial load
duke
parents:
diff changeset
   416
                            XMLMessageFormatter.XML_DOMAIN,
7f561c08de6b Initial load
duke
parents:
diff changeset
   417
                            "RootElementTypeMustMatchDoctypedecl",
7f561c08de6b Initial load
duke
parents:
diff changeset
   418
                            new Object[] { fDoctypeName, rawname },
7f561c08de6b Initial load
duke
parents:
diff changeset
   419
                            XMLErrorReporter.SEVERITY_ERROR);
7f561c08de6b Initial load
duke
parents:
diff changeset
   420
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   421
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   422
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   423
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   424
7f561c08de6b Initial load
duke
parents:
diff changeset
   425
        // push element stack
7f561c08de6b Initial load
duke
parents:
diff changeset
   426
        fCurrentElement = fElementStack.pushElement(fElementQName);
7f561c08de6b Initial load
duke
parents:
diff changeset
   427
7f561c08de6b Initial load
duke
parents:
diff changeset
   428
        // attributes
7f561c08de6b Initial load
duke
parents:
diff changeset
   429
        boolean empty = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   430
        fAttributes.removeAllAttributes();
7f561c08de6b Initial load
duke
parents:
diff changeset
   431
        do {
7f561c08de6b Initial load
duke
parents:
diff changeset
   432
7f561c08de6b Initial load
duke
parents:
diff changeset
   433
            // end tag?
7f561c08de6b Initial load
duke
parents:
diff changeset
   434
            int c = fEntityScanner.peekChar();
7f561c08de6b Initial load
duke
parents:
diff changeset
   435
            if (c == '>') {
7f561c08de6b Initial load
duke
parents:
diff changeset
   436
                fEntityScanner.scanChar();
7f561c08de6b Initial load
duke
parents:
diff changeset
   437
                break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   438
            } else if (c == '/') {
7f561c08de6b Initial load
duke
parents:
diff changeset
   439
                fEntityScanner.scanChar();
7f561c08de6b Initial load
duke
parents:
diff changeset
   440
                if (!fEntityScanner.skipChar('>')) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   441
                    reportFatalError(
7f561c08de6b Initial load
duke
parents:
diff changeset
   442
                        "ElementUnterminated",
7f561c08de6b Initial load
duke
parents:
diff changeset
   443
                        new Object[] { rawname });
7f561c08de6b Initial load
duke
parents:
diff changeset
   444
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   445
                empty = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   446
                break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   447
            } else if (!isValidNameStartChar(c) || !fSawSpace) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   448
                // Second chance. Check if this character is a high
7f561c08de6b Initial load
duke
parents:
diff changeset
   449
                // surrogate of a valid name start character.
7f561c08de6b Initial load
duke
parents:
diff changeset
   450
                if (!isValidNameStartHighSurrogate(c) || !fSawSpace) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   451
                    reportFatalError(
7f561c08de6b Initial load
duke
parents:
diff changeset
   452
                        "ElementUnterminated",
7f561c08de6b Initial load
duke
parents:
diff changeset
   453
                        new Object[] { rawname });
7f561c08de6b Initial load
duke
parents:
diff changeset
   454
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   455
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   456
7f561c08de6b Initial load
duke
parents:
diff changeset
   457
            // attributes
7f561c08de6b Initial load
duke
parents:
diff changeset
   458
            scanAttribute(fAttributes);
7f561c08de6b Initial load
duke
parents:
diff changeset
   459
7f561c08de6b Initial load
duke
parents:
diff changeset
   460
            // spaces
7f561c08de6b Initial load
duke
parents:
diff changeset
   461
            fSawSpace = fEntityScanner.skipSpaces();
7f561c08de6b Initial load
duke
parents:
diff changeset
   462
7f561c08de6b Initial load
duke
parents:
diff changeset
   463
        } while (true);
7f561c08de6b Initial load
duke
parents:
diff changeset
   464
7f561c08de6b Initial load
duke
parents:
diff changeset
   465
        if (fBindNamespaces) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   466
            // REVISIT: is it required? forbit xmlns prefix for element
7f561c08de6b Initial load
duke
parents:
diff changeset
   467
            if (fElementQName.prefix == XMLSymbols.PREFIX_XMLNS) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   468
                fErrorReporter.reportError(
7f561c08de6b Initial load
duke
parents:
diff changeset
   469
                    XMLMessageFormatter.XMLNS_DOMAIN,
7f561c08de6b Initial load
duke
parents:
diff changeset
   470
                    "ElementXMLNSPrefix",
7f561c08de6b Initial load
duke
parents:
diff changeset
   471
                    new Object[] { fElementQName.rawname },
7f561c08de6b Initial load
duke
parents:
diff changeset
   472
                    XMLErrorReporter.SEVERITY_FATAL_ERROR);
7f561c08de6b Initial load
duke
parents:
diff changeset
   473
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   474
7f561c08de6b Initial load
duke
parents:
diff changeset
   475
            // bind the element
7f561c08de6b Initial load
duke
parents:
diff changeset
   476
            String prefix =
7f561c08de6b Initial load
duke
parents:
diff changeset
   477
                fElementQName.prefix != null
7f561c08de6b Initial load
duke
parents:
diff changeset
   478
                    ? fElementQName.prefix
7f561c08de6b Initial load
duke
parents:
diff changeset
   479
                    : XMLSymbols.EMPTY_STRING;
7f561c08de6b Initial load
duke
parents:
diff changeset
   480
            // assign uri to the element
7f561c08de6b Initial load
duke
parents:
diff changeset
   481
            fElementQName.uri = fNamespaceContext.getURI(prefix);
7f561c08de6b Initial load
duke
parents:
diff changeset
   482
            // make sure that object in the element stack is updated as well
7f561c08de6b Initial load
duke
parents:
diff changeset
   483
            fCurrentElement.uri = fElementQName.uri;
7f561c08de6b Initial load
duke
parents:
diff changeset
   484
7f561c08de6b Initial load
duke
parents:
diff changeset
   485
            if (fElementQName.prefix == null && fElementQName.uri != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   486
                fElementQName.prefix = XMLSymbols.EMPTY_STRING;
7f561c08de6b Initial load
duke
parents:
diff changeset
   487
                // making sure that the object in the element stack is updated too.
7f561c08de6b Initial load
duke
parents:
diff changeset
   488
                fCurrentElement.prefix = XMLSymbols.EMPTY_STRING;
7f561c08de6b Initial load
duke
parents:
diff changeset
   489
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   490
            if (fElementQName.prefix != null && fElementQName.uri == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   491
                fErrorReporter.reportError(
7f561c08de6b Initial load
duke
parents:
diff changeset
   492
                    XMLMessageFormatter.XMLNS_DOMAIN,
7f561c08de6b Initial load
duke
parents:
diff changeset
   493
                    "ElementPrefixUnbound",
7f561c08de6b Initial load
duke
parents:
diff changeset
   494
                    new Object[] {
7f561c08de6b Initial load
duke
parents:
diff changeset
   495
                        fElementQName.prefix,
7f561c08de6b Initial load
duke
parents:
diff changeset
   496
                        fElementQName.rawname },
7f561c08de6b Initial load
duke
parents:
diff changeset
   497
                    XMLErrorReporter.SEVERITY_FATAL_ERROR);
7f561c08de6b Initial load
duke
parents:
diff changeset
   498
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   499
7f561c08de6b Initial load
duke
parents:
diff changeset
   500
            // bind attributes (xmlns are already bound bellow)
7f561c08de6b Initial load
duke
parents:
diff changeset
   501
            int length = fAttributes.getLength();
7f561c08de6b Initial load
duke
parents:
diff changeset
   502
            for (int i = 0; i < length; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   503
                fAttributes.getName(i, fAttributeQName);
7f561c08de6b Initial load
duke
parents:
diff changeset
   504
7f561c08de6b Initial load
duke
parents:
diff changeset
   505
                String aprefix =
7f561c08de6b Initial load
duke
parents:
diff changeset
   506
                    fAttributeQName.prefix != null
7f561c08de6b Initial load
duke
parents:
diff changeset
   507
                        ? fAttributeQName.prefix
7f561c08de6b Initial load
duke
parents:
diff changeset
   508
                        : XMLSymbols.EMPTY_STRING;
7f561c08de6b Initial load
duke
parents:
diff changeset
   509
                String uri = fNamespaceContext.getURI(aprefix);
7f561c08de6b Initial load
duke
parents:
diff changeset
   510
                // REVISIT: try removing the first "if" and see if it is faster.
7f561c08de6b Initial load
duke
parents:
diff changeset
   511
                //
7f561c08de6b Initial load
duke
parents:
diff changeset
   512
                if (fAttributeQName.uri != null
7f561c08de6b Initial load
duke
parents:
diff changeset
   513
                    && fAttributeQName.uri == uri) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   514
                    continue;
7f561c08de6b Initial load
duke
parents:
diff changeset
   515
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   516
                if (aprefix != XMLSymbols.EMPTY_STRING) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   517
                    fAttributeQName.uri = uri;
7f561c08de6b Initial load
duke
parents:
diff changeset
   518
                    if (uri == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   519
                        fErrorReporter.reportError(
7f561c08de6b Initial load
duke
parents:
diff changeset
   520
                            XMLMessageFormatter.XMLNS_DOMAIN,
7f561c08de6b Initial load
duke
parents:
diff changeset
   521
                            "AttributePrefixUnbound",
7f561c08de6b Initial load
duke
parents:
diff changeset
   522
                            new Object[] {
7f561c08de6b Initial load
duke
parents:
diff changeset
   523
                                fElementQName.rawname,
7f561c08de6b Initial load
duke
parents:
diff changeset
   524
                                fAttributeQName.rawname,
7f561c08de6b Initial load
duke
parents:
diff changeset
   525
                                aprefix },
7f561c08de6b Initial load
duke
parents:
diff changeset
   526
                            XMLErrorReporter.SEVERITY_FATAL_ERROR);
7f561c08de6b Initial load
duke
parents:
diff changeset
   527
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   528
                    fAttributes.setURI(i, uri);
7f561c08de6b Initial load
duke
parents:
diff changeset
   529
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   530
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   531
7f561c08de6b Initial load
duke
parents:
diff changeset
   532
            if (length > 1) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   533
                QName name = fAttributes.checkDuplicatesNS();
7f561c08de6b Initial load
duke
parents:
diff changeset
   534
                if (name != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   535
                    if (name.uri != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   536
                        fErrorReporter.reportError(
7f561c08de6b Initial load
duke
parents:
diff changeset
   537
                            XMLMessageFormatter.XMLNS_DOMAIN,
7f561c08de6b Initial load
duke
parents:
diff changeset
   538
                            "AttributeNSNotUnique",
7f561c08de6b Initial load
duke
parents:
diff changeset
   539
                            new Object[] {
7f561c08de6b Initial load
duke
parents:
diff changeset
   540
                                fElementQName.rawname,
7f561c08de6b Initial load
duke
parents:
diff changeset
   541
                                name.localpart,
7f561c08de6b Initial load
duke
parents:
diff changeset
   542
                                name.uri },
7f561c08de6b Initial load
duke
parents:
diff changeset
   543
                            XMLErrorReporter.SEVERITY_FATAL_ERROR);
7f561c08de6b Initial load
duke
parents:
diff changeset
   544
                    } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   545
                        fErrorReporter.reportError(
7f561c08de6b Initial load
duke
parents:
diff changeset
   546
                            XMLMessageFormatter.XMLNS_DOMAIN,
7f561c08de6b Initial load
duke
parents:
diff changeset
   547
                            "AttributeNotUnique",
7f561c08de6b Initial load
duke
parents:
diff changeset
   548
                            new Object[] {
7f561c08de6b Initial load
duke
parents:
diff changeset
   549
                                fElementQName.rawname,
7f561c08de6b Initial load
duke
parents:
diff changeset
   550
                                name.rawname },
7f561c08de6b Initial load
duke
parents:
diff changeset
   551
                            XMLErrorReporter.SEVERITY_FATAL_ERROR);
7f561c08de6b Initial load
duke
parents:
diff changeset
   552
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   553
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   554
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   555
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   556
7f561c08de6b Initial load
duke
parents:
diff changeset
   557
        // call handler
7f561c08de6b Initial load
duke
parents:
diff changeset
   558
        if (fDocumentHandler != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   559
            if (empty) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   560
7f561c08de6b Initial load
duke
parents:
diff changeset
   561
                //decrease the markup depth..
7f561c08de6b Initial load
duke
parents:
diff changeset
   562
                fMarkupDepth--;
7f561c08de6b Initial load
duke
parents:
diff changeset
   563
7f561c08de6b Initial load
duke
parents:
diff changeset
   564
                // check that this element was opened in the same entity
7f561c08de6b Initial load
duke
parents:
diff changeset
   565
                if (fMarkupDepth < fEntityStack[fEntityDepth - 1]) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   566
                    reportFatalError(
7f561c08de6b Initial load
duke
parents:
diff changeset
   567
                        "ElementEntityMismatch",
7f561c08de6b Initial load
duke
parents:
diff changeset
   568
                        new Object[] { fCurrentElement.rawname });
7f561c08de6b Initial load
duke
parents:
diff changeset
   569
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   570
7f561c08de6b Initial load
duke
parents:
diff changeset
   571
                fDocumentHandler.emptyElement(fElementQName, fAttributes, null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   572
7f561c08de6b Initial load
duke
parents:
diff changeset
   573
                if (fBindNamespaces) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   574
                    fNamespaceContext.popContext();
7f561c08de6b Initial load
duke
parents:
diff changeset
   575
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   576
                //pop the element off the stack..
7f561c08de6b Initial load
duke
parents:
diff changeset
   577
                fElementStack.popElement();
7f561c08de6b Initial load
duke
parents:
diff changeset
   578
            } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   579
                fDocumentHandler.startElement(fElementQName, fAttributes, null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   580
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   581
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   582
7f561c08de6b Initial load
duke
parents:
diff changeset
   583
        if (DEBUG_START_END_ELEMENT)
7f561c08de6b Initial load
duke
parents:
diff changeset
   584
            System.out.println("<<< scanStartElementAfterName(): " + empty);
7f561c08de6b Initial load
duke
parents:
diff changeset
   585
        return empty;
7f561c08de6b Initial load
duke
parents:
diff changeset
   586
7f561c08de6b Initial load
duke
parents:
diff changeset
   587
    } // scanStartElementAfterName()
7f561c08de6b Initial load
duke
parents:
diff changeset
   588
7f561c08de6b Initial load
duke
parents:
diff changeset
   589
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   590
     * Scans an attribute.
7f561c08de6b Initial load
duke
parents:
diff changeset
   591
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   592
     * <pre>
7f561c08de6b Initial load
duke
parents:
diff changeset
   593
     * [41] Attribute ::= Name Eq AttValue
7f561c08de6b Initial load
duke
parents:
diff changeset
   594
     * </pre>
7f561c08de6b Initial load
duke
parents:
diff changeset
   595
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   596
     * <strong>Note:</strong> This method assumes that the next
7f561c08de6b Initial load
duke
parents:
diff changeset
   597
     * character on the stream is the first character of the attribute
7f561c08de6b Initial load
duke
parents:
diff changeset
   598
     * name.
7f561c08de6b Initial load
duke
parents:
diff changeset
   599
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   600
     * <strong>Note:</strong> This method uses the fAttributeQName and
7f561c08de6b Initial load
duke
parents:
diff changeset
   601
     * fQName variables. The contents of these variables will be
7f561c08de6b Initial load
duke
parents:
diff changeset
   602
     * destroyed.
7f561c08de6b Initial load
duke
parents:
diff changeset
   603
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   604
     * @param attributes The attributes list for the scanned attribute.
7f561c08de6b Initial load
duke
parents:
diff changeset
   605
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   606
    protected void scanAttribute(XMLAttributesImpl attributes)
7f561c08de6b Initial load
duke
parents:
diff changeset
   607
        throws IOException, XNIException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   608
        if (DEBUG_START_END_ELEMENT)
7f561c08de6b Initial load
duke
parents:
diff changeset
   609
            System.out.println(">>> scanAttribute()");
7f561c08de6b Initial load
duke
parents:
diff changeset
   610
7f561c08de6b Initial load
duke
parents:
diff changeset
   611
        // name
7f561c08de6b Initial load
duke
parents:
diff changeset
   612
        fEntityScanner.scanQName(fAttributeQName);
7f561c08de6b Initial load
duke
parents:
diff changeset
   613
7f561c08de6b Initial load
duke
parents:
diff changeset
   614
        // equals
7f561c08de6b Initial load
duke
parents:
diff changeset
   615
        fEntityScanner.skipSpaces();
7f561c08de6b Initial load
duke
parents:
diff changeset
   616
        if (!fEntityScanner.skipChar('=')) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   617
            reportFatalError(
7f561c08de6b Initial load
duke
parents:
diff changeset
   618
                "EqRequiredInAttribute",
7f561c08de6b Initial load
duke
parents:
diff changeset
   619
                new Object[] {
7f561c08de6b Initial load
duke
parents:
diff changeset
   620
                    fCurrentElement.rawname,
7f561c08de6b Initial load
duke
parents:
diff changeset
   621
                    fAttributeQName.rawname });
7f561c08de6b Initial load
duke
parents:
diff changeset
   622
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   623
        fEntityScanner.skipSpaces();
7f561c08de6b Initial load
duke
parents:
diff changeset
   624
7f561c08de6b Initial load
duke
parents:
diff changeset
   625
        // content
7f561c08de6b Initial load
duke
parents:
diff changeset
   626
        int attrIndex;
7f561c08de6b Initial load
duke
parents:
diff changeset
   627
7f561c08de6b Initial load
duke
parents:
diff changeset
   628
        if (fBindNamespaces) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   629
            attrIndex = attributes.getLength();
7f561c08de6b Initial load
duke
parents:
diff changeset
   630
            attributes.addAttributeNS(
7f561c08de6b Initial load
duke
parents:
diff changeset
   631
                fAttributeQName,
7f561c08de6b Initial load
duke
parents:
diff changeset
   632
                XMLSymbols.fCDATASymbol,
7f561c08de6b Initial load
duke
parents:
diff changeset
   633
                null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   634
        } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   635
            int oldLen = attributes.getLength();
7f561c08de6b Initial load
duke
parents:
diff changeset
   636
            attrIndex =
7f561c08de6b Initial load
duke
parents:
diff changeset
   637
                attributes.addAttribute(
7f561c08de6b Initial load
duke
parents:
diff changeset
   638
                    fAttributeQName,
7f561c08de6b Initial load
duke
parents:
diff changeset
   639
                    XMLSymbols.fCDATASymbol,
7f561c08de6b Initial load
duke
parents:
diff changeset
   640
                    null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   641
7f561c08de6b Initial load
duke
parents:
diff changeset
   642
            // WFC: Unique Att Spec
7f561c08de6b Initial load
duke
parents:
diff changeset
   643
            if (oldLen == attributes.getLength()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   644
                reportFatalError(
7f561c08de6b Initial load
duke
parents:
diff changeset
   645
                    "AttributeNotUnique",
7f561c08de6b Initial load
duke
parents:
diff changeset
   646
                    new Object[] {
7f561c08de6b Initial load
duke
parents:
diff changeset
   647
                        fCurrentElement.rawname,
7f561c08de6b Initial load
duke
parents:
diff changeset
   648
                        fAttributeQName.rawname });
7f561c08de6b Initial load
duke
parents:
diff changeset
   649
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   650
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   651
7f561c08de6b Initial load
duke
parents:
diff changeset
   652
        //REVISIT: one more case needs to be included: external PE and standalone is no
7f561c08de6b Initial load
duke
parents:
diff changeset
   653
        boolean isVC = fHasExternalDTD && !fStandalone;
7f561c08de6b Initial load
duke
parents:
diff changeset
   654
7f561c08de6b Initial load
duke
parents:
diff changeset
   655
        // REVISIT: it seems that this function should not take attributes, and length
7f561c08de6b Initial load
duke
parents:
diff changeset
   656
        scanAttributeValue(
7f561c08de6b Initial load
duke
parents:
diff changeset
   657
            this.fTempString,
7f561c08de6b Initial load
duke
parents:
diff changeset
   658
            fTempString2,
7f561c08de6b Initial load
duke
parents:
diff changeset
   659
            fAttributeQName.rawname,
7f561c08de6b Initial load
duke
parents:
diff changeset
   660
            isVC,
7f561c08de6b Initial load
duke
parents:
diff changeset
   661
            fCurrentElement.rawname);
7f561c08de6b Initial load
duke
parents:
diff changeset
   662
        String value = fTempString.toString();
7f561c08de6b Initial load
duke
parents:
diff changeset
   663
        attributes.setValue(attrIndex, value);
7f561c08de6b Initial load
duke
parents:
diff changeset
   664
        attributes.setNonNormalizedValue(attrIndex, fTempString2.toString());
7f561c08de6b Initial load
duke
parents:
diff changeset
   665
        attributes.setSpecified(attrIndex, true);
7f561c08de6b Initial load
duke
parents:
diff changeset
   666
7f561c08de6b Initial load
duke
parents:
diff changeset
   667
        // record namespace declarations if any.
7f561c08de6b Initial load
duke
parents:
diff changeset
   668
        if (fBindNamespaces) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   669
7f561c08de6b Initial load
duke
parents:
diff changeset
   670
            String localpart = fAttributeQName.localpart;
7f561c08de6b Initial load
duke
parents:
diff changeset
   671
            String prefix =
7f561c08de6b Initial load
duke
parents:
diff changeset
   672
                fAttributeQName.prefix != null
7f561c08de6b Initial load
duke
parents:
diff changeset
   673
                    ? fAttributeQName.prefix
7f561c08de6b Initial load
duke
parents:
diff changeset
   674
                    : XMLSymbols.EMPTY_STRING;
7f561c08de6b Initial load
duke
parents:
diff changeset
   675
            // when it's of form xmlns="..." or xmlns:prefix="...",
7f561c08de6b Initial load
duke
parents:
diff changeset
   676
            // it's a namespace declaration. but prefix:xmlns="..." isn't.
7f561c08de6b Initial load
duke
parents:
diff changeset
   677
            if (prefix == XMLSymbols.PREFIX_XMLNS
7f561c08de6b Initial load
duke
parents:
diff changeset
   678
                || prefix == XMLSymbols.EMPTY_STRING
7f561c08de6b Initial load
duke
parents:
diff changeset
   679
                && localpart == XMLSymbols.PREFIX_XMLNS) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   680
7f561c08de6b Initial load
duke
parents:
diff changeset
   681
                // get the internalized value of this attribute
7f561c08de6b Initial load
duke
parents:
diff changeset
   682
                String uri = fSymbolTable.addSymbol(value);
7f561c08de6b Initial load
duke
parents:
diff changeset
   683
7f561c08de6b Initial load
duke
parents:
diff changeset
   684
                // 1. "xmlns" can't be bound to any namespace
7f561c08de6b Initial load
duke
parents:
diff changeset
   685
                if (prefix == XMLSymbols.PREFIX_XMLNS
7f561c08de6b Initial load
duke
parents:
diff changeset
   686
                    && localpart == XMLSymbols.PREFIX_XMLNS) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   687
                    fErrorReporter.reportError(
7f561c08de6b Initial load
duke
parents:
diff changeset
   688
                        XMLMessageFormatter.XMLNS_DOMAIN,
7f561c08de6b Initial load
duke
parents:
diff changeset
   689
                        "CantBindXMLNS",
7f561c08de6b Initial load
duke
parents:
diff changeset
   690
                        new Object[] { fAttributeQName },
7f561c08de6b Initial load
duke
parents:
diff changeset
   691
                        XMLErrorReporter.SEVERITY_FATAL_ERROR);
7f561c08de6b Initial load
duke
parents:
diff changeset
   692
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   693
7f561c08de6b Initial load
duke
parents:
diff changeset
   694
                // 2. the namespace for "xmlns" can't be bound to any prefix
7f561c08de6b Initial load
duke
parents:
diff changeset
   695
                if (uri == NamespaceContext.XMLNS_URI) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   696
                    fErrorReporter.reportError(
7f561c08de6b Initial load
duke
parents:
diff changeset
   697
                        XMLMessageFormatter.XMLNS_DOMAIN,
7f561c08de6b Initial load
duke
parents:
diff changeset
   698
                        "CantBindXMLNS",
7f561c08de6b Initial load
duke
parents:
diff changeset
   699
                        new Object[] { fAttributeQName },
7f561c08de6b Initial load
duke
parents:
diff changeset
   700
                        XMLErrorReporter.SEVERITY_FATAL_ERROR);
7f561c08de6b Initial load
duke
parents:
diff changeset
   701
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   702
7f561c08de6b Initial load
duke
parents:
diff changeset
   703
                // 3. "xml" can't be bound to any other namespace than it's own
7f561c08de6b Initial load
duke
parents:
diff changeset
   704
                if (localpart == XMLSymbols.PREFIX_XML) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   705
                    if (uri != NamespaceContext.XML_URI) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   706
                        fErrorReporter.reportError(
7f561c08de6b Initial load
duke
parents:
diff changeset
   707
                            XMLMessageFormatter.XMLNS_DOMAIN,
7f561c08de6b Initial load
duke
parents:
diff changeset
   708
                            "CantBindXML",
7f561c08de6b Initial load
duke
parents:
diff changeset
   709
                            new Object[] { fAttributeQName },
7f561c08de6b Initial load
duke
parents:
diff changeset
   710
                            XMLErrorReporter.SEVERITY_FATAL_ERROR);
7f561c08de6b Initial load
duke
parents:
diff changeset
   711
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   712
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   713
                // 4. the namespace for "xml" can't be bound to any other prefix
7f561c08de6b Initial load
duke
parents:
diff changeset
   714
                else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   715
                    if (uri == NamespaceContext.XML_URI) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   716
                        fErrorReporter.reportError(
7f561c08de6b Initial load
duke
parents:
diff changeset
   717
                            XMLMessageFormatter.XMLNS_DOMAIN,
7f561c08de6b Initial load
duke
parents:
diff changeset
   718
                            "CantBindXML",
7f561c08de6b Initial load
duke
parents:
diff changeset
   719
                            new Object[] { fAttributeQName },
7f561c08de6b Initial load
duke
parents:
diff changeset
   720
                            XMLErrorReporter.SEVERITY_FATAL_ERROR);
7f561c08de6b Initial load
duke
parents:
diff changeset
   721
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   722
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   723
7f561c08de6b Initial load
duke
parents:
diff changeset
   724
                prefix =
7f561c08de6b Initial load
duke
parents:
diff changeset
   725
                    localpart != XMLSymbols.PREFIX_XMLNS
7f561c08de6b Initial load
duke
parents:
diff changeset
   726
                        ? localpart
7f561c08de6b Initial load
duke
parents:
diff changeset
   727
                        : XMLSymbols.EMPTY_STRING;
7f561c08de6b Initial load
duke
parents:
diff changeset
   728
7f561c08de6b Initial load
duke
parents:
diff changeset
   729
                // Declare prefix in context. Removing the association between a prefix and a
7f561c08de6b Initial load
duke
parents:
diff changeset
   730
                // namespace name is permitted in XML 1.1, so if the uri value is the empty string,
7f561c08de6b Initial load
duke
parents:
diff changeset
   731
                // the prefix is being unbound. -- mrglavas
7f561c08de6b Initial load
duke
parents:
diff changeset
   732
                fNamespaceContext.declarePrefix(
7f561c08de6b Initial load
duke
parents:
diff changeset
   733
                    prefix,
7f561c08de6b Initial load
duke
parents:
diff changeset
   734
                    uri.length() != 0 ? uri : null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   735
                // bind namespace attribute to a namespace
7f561c08de6b Initial load
duke
parents:
diff changeset
   736
                attributes.setURI(
7f561c08de6b Initial load
duke
parents:
diff changeset
   737
                    attrIndex,
7f561c08de6b Initial load
duke
parents:
diff changeset
   738
                    fNamespaceContext.getURI(XMLSymbols.PREFIX_XMLNS));
7f561c08de6b Initial load
duke
parents:
diff changeset
   739
7f561c08de6b Initial load
duke
parents:
diff changeset
   740
            } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   741
                // attempt to bind attribute
7f561c08de6b Initial load
duke
parents:
diff changeset
   742
                if (fAttributeQName.prefix != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   743
                    attributes.setURI(
7f561c08de6b Initial load
duke
parents:
diff changeset
   744
                        attrIndex,
7f561c08de6b Initial load
duke
parents:
diff changeset
   745
                        fNamespaceContext.getURI(fAttributeQName.prefix));
7f561c08de6b Initial load
duke
parents:
diff changeset
   746
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   747
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   748
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   749
7f561c08de6b Initial load
duke
parents:
diff changeset
   750
        if (DEBUG_START_END_ELEMENT)
7f561c08de6b Initial load
duke
parents:
diff changeset
   751
            System.out.println("<<< scanAttribute()");
7f561c08de6b Initial load
duke
parents:
diff changeset
   752
    } // scanAttribute(XMLAttributes)
7f561c08de6b Initial load
duke
parents:
diff changeset
   753
7f561c08de6b Initial load
duke
parents:
diff changeset
   754
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   755
     * Scans an end element.
7f561c08de6b Initial load
duke
parents:
diff changeset
   756
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   757
     * <pre>
7f561c08de6b Initial load
duke
parents:
diff changeset
   758
     * [42] ETag ::= '&lt;/' Name S? '>'
7f561c08de6b Initial load
duke
parents:
diff changeset
   759
     * </pre>
7f561c08de6b Initial load
duke
parents:
diff changeset
   760
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   761
     * <strong>Note:</strong> This method uses the fElementQName variable.
7f561c08de6b Initial load
duke
parents:
diff changeset
   762
     * The contents of this variable will be destroyed. The caller should
7f561c08de6b Initial load
duke
parents:
diff changeset
   763
     * copy the needed information out of this variable before calling
7f561c08de6b Initial load
duke
parents:
diff changeset
   764
     * this method.
7f561c08de6b Initial load
duke
parents:
diff changeset
   765
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   766
     * @return The element depth.
7f561c08de6b Initial load
duke
parents:
diff changeset
   767
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   768
    protected int scanEndElement() throws IOException, XNIException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   769
        if (DEBUG_START_END_ELEMENT)
7f561c08de6b Initial load
duke
parents:
diff changeset
   770
            System.out.println(">>> scanEndElement()");
7f561c08de6b Initial load
duke
parents:
diff changeset
   771
7f561c08de6b Initial load
duke
parents:
diff changeset
   772
        // pop context
7f561c08de6b Initial load
duke
parents:
diff changeset
   773
        QName endElementName = fElementStack.popElement();
7f561c08de6b Initial load
duke
parents:
diff changeset
   774
7f561c08de6b Initial load
duke
parents:
diff changeset
   775
        // Take advantage of the fact that next string _should_ be "fElementQName.rawName",
7f561c08de6b Initial load
duke
parents:
diff changeset
   776
        //In scanners most of the time is consumed on checks done for XML characters, we can
7f561c08de6b Initial load
duke
parents:
diff changeset
   777
        // optimize on it and avoid the checks done for endElement,
7f561c08de6b Initial load
duke
parents:
diff changeset
   778
        //we will also avoid symbol table lookup - neeraj.bajaj@sun.com
7f561c08de6b Initial load
duke
parents:
diff changeset
   779
7f561c08de6b Initial load
duke
parents:
diff changeset
   780
        // this should work both for namespace processing true or false...
7f561c08de6b Initial load
duke
parents:
diff changeset
   781
7f561c08de6b Initial load
duke
parents:
diff changeset
   782
        //REVISIT: if the string is not the same as expected.. we need to do better error handling..
7f561c08de6b Initial load
duke
parents:
diff changeset
   783
        //We can skip this for now... In any case if the string doesn't match -- document is not well formed.
7f561c08de6b Initial load
duke
parents:
diff changeset
   784
7f561c08de6b Initial load
duke
parents:
diff changeset
   785
        if (!fEntityScanner.skipString(endElementName.rawname)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   786
             reportFatalError(
7f561c08de6b Initial load
duke
parents:
diff changeset
   787
                "ETagRequired",
7f561c08de6b Initial load
duke
parents:
diff changeset
   788
                new Object[] { endElementName.rawname });
7f561c08de6b Initial load
duke
parents:
diff changeset
   789
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   790
7f561c08de6b Initial load
duke
parents:
diff changeset
   791
        // end
7f561c08de6b Initial load
duke
parents:
diff changeset
   792
        fEntityScanner.skipSpaces();
7f561c08de6b Initial load
duke
parents:
diff changeset
   793
        if (!fEntityScanner.skipChar('>')) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   794
            reportFatalError(
7f561c08de6b Initial load
duke
parents:
diff changeset
   795
                "ETagUnterminated",
7f561c08de6b Initial load
duke
parents:
diff changeset
   796
                new Object[] { endElementName.rawname });
7f561c08de6b Initial load
duke
parents:
diff changeset
   797
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   798
        fMarkupDepth--;
7f561c08de6b Initial load
duke
parents:
diff changeset
   799
7f561c08de6b Initial load
duke
parents:
diff changeset
   800
        //we have increased the depth for two markup "<" characters
7f561c08de6b Initial load
duke
parents:
diff changeset
   801
        fMarkupDepth--;
7f561c08de6b Initial load
duke
parents:
diff changeset
   802
7f561c08de6b Initial load
duke
parents:
diff changeset
   803
        // check that this element was opened in the same entity
7f561c08de6b Initial load
duke
parents:
diff changeset
   804
        if (fMarkupDepth < fEntityStack[fEntityDepth - 1]) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   805
            reportFatalError(
7f561c08de6b Initial load
duke
parents:
diff changeset
   806
                "ElementEntityMismatch",
7f561c08de6b Initial load
duke
parents:
diff changeset
   807
                new Object[] { endElementName.rawname });
7f561c08de6b Initial load
duke
parents:
diff changeset
   808
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   809
7f561c08de6b Initial load
duke
parents:
diff changeset
   810
        // call handler
7f561c08de6b Initial load
duke
parents:
diff changeset
   811
        if (fDocumentHandler != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   812
            fDocumentHandler.endElement(endElementName, null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   813
7f561c08de6b Initial load
duke
parents:
diff changeset
   814
            /*if (fBindNamespaces) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   815
                fNamespaceContext.popContext();
7f561c08de6b Initial load
duke
parents:
diff changeset
   816
            }*/
7f561c08de6b Initial load
duke
parents:
diff changeset
   817
7f561c08de6b Initial load
duke
parents:
diff changeset
   818
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   819
7f561c08de6b Initial load
duke
parents:
diff changeset
   820
        if(dtdGrammarUtil != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   821
            dtdGrammarUtil.endElement(endElementName);
7f561c08de6b Initial load
duke
parents:
diff changeset
   822
7f561c08de6b Initial load
duke
parents:
diff changeset
   823
        return fMarkupDepth;
7f561c08de6b Initial load
duke
parents:
diff changeset
   824
7f561c08de6b Initial load
duke
parents:
diff changeset
   825
    } // scanEndElement():int
7f561c08de6b Initial load
duke
parents:
diff changeset
   826
7f561c08de6b Initial load
duke
parents:
diff changeset
   827
    public void reset(XMLComponentManager componentManager)
7f561c08de6b Initial load
duke
parents:
diff changeset
   828
        throws XMLConfigurationException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   829
7f561c08de6b Initial load
duke
parents:
diff changeset
   830
        super.reset(componentManager);
7f561c08de6b Initial load
duke
parents:
diff changeset
   831
        fPerformValidation = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   832
        fBindNamespaces = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   833
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   834
7f561c08de6b Initial load
duke
parents:
diff changeset
   835
    /** Creates a content Driver. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   836
    protected Driver createContentDriver() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   837
        return new NS11ContentDriver();
7f561c08de6b Initial load
duke
parents:
diff changeset
   838
    } // createContentDriver():Driver
7f561c08de6b Initial load
duke
parents:
diff changeset
   839
7f561c08de6b Initial load
duke
parents:
diff changeset
   840
7f561c08de6b Initial load
duke
parents:
diff changeset
   841
    /** return the next state on the input
7f561c08de6b Initial load
duke
parents:
diff changeset
   842
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   843
     * @return int
7f561c08de6b Initial load
duke
parents:
diff changeset
   844
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   845
7f561c08de6b Initial load
duke
parents:
diff changeset
   846
    public int next() throws IOException, XNIException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   847
        //since namespace context should still be valid when the parser is at the end element state therefore
7f561c08de6b Initial load
duke
parents:
diff changeset
   848
        //we pop the context only when next() has been called after the end element state was encountered. - nb.
7f561c08de6b Initial load
duke
parents:
diff changeset
   849
7f561c08de6b Initial load
duke
parents:
diff changeset
   850
        if((fScannerLastState == XMLEvent.END_ELEMENT) && fBindNamespaces){
7f561c08de6b Initial load
duke
parents:
diff changeset
   851
            fScannerLastState = -1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   852
            fNamespaceContext.popContext();
7f561c08de6b Initial load
duke
parents:
diff changeset
   853
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   854
7f561c08de6b Initial load
duke
parents:
diff changeset
   855
        return fScannerLastState = super.next();
7f561c08de6b Initial load
duke
parents:
diff changeset
   856
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   857
7f561c08de6b Initial load
duke
parents:
diff changeset
   858
7f561c08de6b Initial load
duke
parents:
diff changeset
   859
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   860
     * Driver to handle content scanning.
7f561c08de6b Initial load
duke
parents:
diff changeset
   861
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   862
    protected final class NS11ContentDriver extends ContentDriver {
7f561c08de6b Initial load
duke
parents:
diff changeset
   863
        /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   864
         * Scan for root element hook. This method is a hook for
7f561c08de6b Initial load
duke
parents:
diff changeset
   865
         * subclasses to add code that handles scanning for the root
7f561c08de6b Initial load
duke
parents:
diff changeset
   866
         * element. This method will also attempt to remove DTD validator
7f561c08de6b Initial load
duke
parents:
diff changeset
   867
         * from the pipeline, if there is no DTD grammar. If DTD validator
7f561c08de6b Initial load
duke
parents:
diff changeset
   868
         * is no longer in the pipeline bind namespaces in the scanner.
7f561c08de6b Initial load
duke
parents:
diff changeset
   869
         *
7f561c08de6b Initial load
duke
parents:
diff changeset
   870
         *
7f561c08de6b Initial load
duke
parents:
diff changeset
   871
         * @return True if the caller should stop and return true which
7f561c08de6b Initial load
duke
parents:
diff changeset
   872
         *          allows the scanner to switch to a new scanning
7f561c08de6b Initial load
duke
parents:
diff changeset
   873
         *          Driver. A return value of false indicates that
7f561c08de6b Initial load
duke
parents:
diff changeset
   874
         *          the content Driver should continue as normal.
7f561c08de6b Initial load
duke
parents:
diff changeset
   875
         */
7f561c08de6b Initial load
duke
parents:
diff changeset
   876
        protected boolean scanRootElementHook()
7f561c08de6b Initial load
duke
parents:
diff changeset
   877
            throws IOException, XNIException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   878
7f561c08de6b Initial load
duke
parents:
diff changeset
   879
            if (fExternalSubsetResolver != null && !fSeenDoctypeDecl
7f561c08de6b Initial load
duke
parents:
diff changeset
   880
                && !fDisallowDoctype && (fValidation || fLoadExternalDTD)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   881
                scanStartElementName();
7f561c08de6b Initial load
duke
parents:
diff changeset
   882
                resolveExternalSubsetAndRead();
7f561c08de6b Initial load
duke
parents:
diff changeset
   883
                reconfigurePipeline();
7f561c08de6b Initial load
duke
parents:
diff changeset
   884
                if (scanStartElementAfterName()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   885
                    setScannerState(SCANNER_STATE_TRAILING_MISC);
7f561c08de6b Initial load
duke
parents:
diff changeset
   886
                    setDriver(fTrailingMiscDriver);
7f561c08de6b Initial load
duke
parents:
diff changeset
   887
                    return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   888
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   889
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   890
            else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   891
                reconfigurePipeline();
7f561c08de6b Initial load
duke
parents:
diff changeset
   892
                if (scanStartElement()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   893
                    setScannerState(SCANNER_STATE_TRAILING_MISC);
7f561c08de6b Initial load
duke
parents:
diff changeset
   894
                    setDriver(fTrailingMiscDriver);
7f561c08de6b Initial load
duke
parents:
diff changeset
   895
                    return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   896
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   897
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   898
            return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   899
7f561c08de6b Initial load
duke
parents:
diff changeset
   900
        } // scanRootElementHook():boolean
7f561c08de6b Initial load
duke
parents:
diff changeset
   901
7f561c08de6b Initial load
duke
parents:
diff changeset
   902
        /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   903
         * Re-configures pipeline by removing the DTD validator
7f561c08de6b Initial load
duke
parents:
diff changeset
   904
         * if no DTD grammar exists. If no validator exists in the
7f561c08de6b Initial load
duke
parents:
diff changeset
   905
         * pipeline or there is no DTD grammar, namespace binding
7f561c08de6b Initial load
duke
parents:
diff changeset
   906
         * is performed by the scanner in the enclosing class.
7f561c08de6b Initial load
duke
parents:
diff changeset
   907
         */
7f561c08de6b Initial load
duke
parents:
diff changeset
   908
        private void reconfigurePipeline() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   909
            if (fDTDValidator == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   910
                fBindNamespaces = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   911
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   912
            else if (!fDTDValidator.hasGrammar()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   913
                fBindNamespaces = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   914
                fPerformValidation = fDTDValidator.validate();
7f561c08de6b Initial load
duke
parents:
diff changeset
   915
                // re-configure pipeline
7f561c08de6b Initial load
duke
parents:
diff changeset
   916
                XMLDocumentSource source = fDTDValidator.getDocumentSource();
7f561c08de6b Initial load
duke
parents:
diff changeset
   917
                XMLDocumentHandler handler = fDTDValidator.getDocumentHandler();
7f561c08de6b Initial load
duke
parents:
diff changeset
   918
                source.setDocumentHandler(handler);
7f561c08de6b Initial load
duke
parents:
diff changeset
   919
                if (handler != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   920
                    handler.setDocumentSource(source);
7f561c08de6b Initial load
duke
parents:
diff changeset
   921
                fDTDValidator.setDocumentSource(null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   922
                fDTDValidator.setDocumentHandler(null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   923
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   924
        } // reconfigurePipeline()
7f561c08de6b Initial load
duke
parents:
diff changeset
   925
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   926
}