make/jdk/src/classes/build/tools/dtdbuilder/DTDParser.java
author jcbeyler
Thu, 30 Aug 2018 09:47:12 -0700
changeset 51594 dc79850e0254
parent 47216 71c04702a3d5
permissions -rw-r--r--
8203356: VM Object Allocation Collector can infinite recurse Summary: VM Event callback do not provoke a VM alloc event Reviewed-by: sspitsyn, phh, amenkov, cjplummer
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
36110
91a3a6df36ec 8150203: Incremental update from build-infra project
ihse
parents: 34885
diff changeset
     2
 * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package build.tools.dtdbuilder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.swing.text.html.parser.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.InputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.BitSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.text.MessageFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * A parser for DTDs. This parser roughly corresponds to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * rules specified in "The SGML Handbook" by Charles F. Goldfarb.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * The end result of parsing the stream is a DTD object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * @see DTD
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * @see DTDInputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * @author Arthur van Hoff
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
final
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
class DTDParser implements DTDConstants {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    DTDBuilder dtd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    DTDInputStream in;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    int ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    char str[] = new char[128];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    int strpos = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    int nerrors = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * Report an error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    void error(String err, String arg1, String arg2, String arg3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        nerrors++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        String msgParams[] = {arg1, arg2, arg3};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        String str = getSubstProp("dtderr." + err, msgParams);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        if (str == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            str = err + "[" + arg1 + "," + arg2 + "," + arg3 + "]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        System.err.println("line " + in.ln + ", dtd " + dtd + ": " + str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    void error(String err, String arg1, String arg2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        error(err, arg1, arg2, "?");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    void error(String err, String arg1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        error(err, arg1, "?", "?");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    void error(String err) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        error(err, "?", "?", "?");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private String getSubstProp(String propName, String args[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        String prop = System.getProperty(propName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        if (prop == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
    88
        return MessageFormat.format(prop, (Object[])args);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * Expect a character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    boolean expect(int c) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        if (ch != c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            char str[] = {(char)c};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            error("expected", "'" + new String(str) + "'");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * Add a char to the string buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    void addString(int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        if (strpos == str.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            char newstr[] = new char[str.length * 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            System.arraycopy(str, 0, newstr, 0, str.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            str = newstr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        str[strpos++] = (char)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * Get the string which was accumulated in the buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * Pos is the starting position of the string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    String getString(int pos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        char newstr[] = new char[strpos - pos];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        System.arraycopy(str, pos, newstr, 0, strpos - pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        strpos = pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        return new String(newstr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * Get the chars which were accumulated in the buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * Pos is the starting position of the string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    char[] getChars(int pos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        char newstr[] = new char[strpos - pos];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        System.arraycopy(str, pos, newstr, 0, strpos - pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        strpos = pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        return newstr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * Skip spaces. [5] 297:23
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    void skipSpace() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            switch (ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
              case '\n':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
              case ' ':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
              case '\t':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
              default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * Skip tag spaces (includes comments). [65] 372:1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    void skipParameterSpace() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            switch (ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
              case '\n':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
              case ' ':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
              case '\t':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
              case '-':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                if ((ch = in.read()) != '-') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                    in.push(ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                    ch = '-';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                in.replace++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                    switch (ch = in.read()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                      case '-':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                        if ((ch = in.read()) == '-') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                            ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                            in.replace--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                            skipParameterSpace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                      case -1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                        error("eof.arg", "comment");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                        in.replace--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
              default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * Parse identifier. Uppercase characters are automatically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * folded to lowercase. Returns falsed if no identifier is found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     */
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   202
    @SuppressWarnings("fallthrough")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    boolean parseIdentifier(boolean lower) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        switch (ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
          case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
          case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
          case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
          case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
          case 'Y': case 'Z':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            if (lower) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                ch = 'a' + (ch - 'A');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            }
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   213
            /* fall through */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
          case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
          case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
          case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
          case 's': case 't': case 'u': case 'v': case 'w': case 'x':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
          case 'y': case 'z':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        addString(ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        parseNameToken(lower);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * Parses name token. If <code>lower</code> is true, upper case letters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * are folded to lower case. Returns falsed if no token is found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     */
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   236
    @SuppressWarnings("fallthrough")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    boolean parseNameToken(boolean lower) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        boolean first = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            switch (ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
              case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
              case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
              case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
              case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
              case 'Y': case 'Z':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                if (lower) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                    ch = 'a' + (ch - 'A');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                }
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   250
                /* fall through */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
              case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
              case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
              case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
              case 's': case 't': case 'u': case 'v': case 'w': case 'x':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
              case 'y': case 'z':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
              case '0': case '1': case '2': case '3': case '4':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
              case '5': case '6': case '7': case '8': case '9':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
              case '.': case '-':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                addString(ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                first = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
              default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                return !first;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * Parse a list of identifiers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     */
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   276
    Vector<String> parseIdentifierList(boolean lower) throws IOException {
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   277
        Vector<String> elems = new Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        skipSpace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        switch (ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
          case '(':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            skipParameterSpace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            while (parseNameToken(lower)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                elems.addElement(getString(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                skipParameterSpace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                if (ch == '|') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                    ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                    skipParameterSpace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            expect(')');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            skipParameterSpace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            if (!parseIdentifier(lower)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                error("expected", "identifier");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            elems.addElement(getString(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            skipParameterSpace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        return elems;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * Parse and Entity reference. Should be called when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * a &amp; is encountered. The data is put in the string buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * [59] 350:17
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    private void parseEntityReference() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        int pos = strpos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        if ((ch = in.read()) == '#') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            int n = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            if (((ch >= 'a') && (ch <= 'z')) || ((ch >= 'A') && (ch <= 'Z'))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                addString('#');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                while ((ch >= '0') && (ch <= '9')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                    n = (n * 10) + ch - '0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                    ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                if ((ch == ';') || (ch == '\n')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                    ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                addString(n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            switch (ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
              case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
              case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
              case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
              case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
              case 'Y': case 'Z':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
              case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
              case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
              case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
              case 's': case 't': case 'u': case 'v': case 'w': case 'x':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
              case 'y': case 'z':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
              case '0': case '1': case '2': case '3': case '4':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
              case '5': case '6': case '7': case '8': case '9':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
              case '.': case '-':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                addString(ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
              default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                if (strpos == pos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                    addString('&');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                String nm = getString(pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                Entity ent = dtd.getEntity(nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                if (ent == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                    error("undef.entref" + nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                if ((ch == ';') || (ch == '\n')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                    ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                char data[] = ent.getData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                for (int i = 0 ; i < data.length ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                    addString(data[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * Parse an entity declaration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * [101] 394:18
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * REMIND: external entity type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    private void parseEntityDeclaration() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        int type = GENERAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        skipSpace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        if (ch == '%') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            type = PARAMETER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            skipSpace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        if (ch == '#') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            addString('#');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        if (!parseIdentifier(false)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            error("expected", "identifier");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        String nm = getString(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        skipParameterSpace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        if (parseIdentifier(false)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            String tnm = getString(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            int t = Entity.name2type(tnm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            if (t == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                error("invalid.arg", "entity type", tnm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                type |= t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            skipParameterSpace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        if ((ch != '"') && (ch != '\'')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            error("expected", "entity value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            skipParameterSpace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            if (ch == '>') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        int term = ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        while ((ch != -1) && (ch != term)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            if (ch == '&') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                parseEntityReference();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                addString(ch & 0xFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        if (ch == term) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        if (in.replace == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            char data[] = getChars(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            dtd.defineEntity(nm, type, data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            strpos = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        skipParameterSpace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        expect('>');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * Parse content model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * [126] 410:1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * REMIND: data tag group
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    ContentModel parseContentModel() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        ContentModel m = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        switch (ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
          case '(':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            skipParameterSpace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            ContentModel e = parseContentModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            if (ch != ')') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                m = new ContentModel(ch, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                    ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                    skipParameterSpace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                    e.next = parseContentModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                    if (e.next.type == m.type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                        e.next = (ContentModel)e.next.content;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                    for (; e.next != null ; e = e.next);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                } while (ch == m.type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                m = new ContentModel(',', e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            expect(')');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
          case '#':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            if (parseIdentifier(true)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                m = new ContentModel('*', new ContentModel(dtd.getElement("#" + getString(0))));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                error("invalid", "content model");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            if (parseIdentifier(true)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                m = new ContentModel(dtd.getElement(getString(0)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                error("invalid", "content model");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        switch (ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
          case '?':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
          case '*':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
          case '+':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            m = new ContentModel(ch, m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        skipParameterSpace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        return m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * Parse element declaration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * [116] 405:6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    void parseElementDeclaration() throws IOException {
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   512
        Vector<String> elems = parseIdentifierList(true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        BitSet inclusions = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        BitSet exclusions = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        boolean omitStart = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        boolean omitEnd = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        if ((ch == '-') || (ch == 'O')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            omitStart = ch == 'O';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            skipParameterSpace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            if ((ch == '-') || (ch == 'O')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                omitEnd = ch == 'O';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                skipParameterSpace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                expect('-');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        int type = MODEL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        ContentModel content = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        if (parseIdentifier(false)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            String nm = getString(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            type = Element.name2type(nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            if (type == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                error("invalid.arg", "content type", nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                type = EMPTY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            skipParameterSpace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            content = parseContentModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        if ((type == MODEL) || (type == ANY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            if (ch == '-') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                ch = in.read();
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   549
                Vector<String> v = parseIdentifierList(true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                exclusions = new BitSet();
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   551
                for (Enumeration<String> e = v.elements() ; e.hasMoreElements() ;) {
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   552
                    exclusions.set(dtd.getElement(e.nextElement()).getIndex());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            if (ch == '+') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                ch = in.read();
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   557
                Vector<String> v = parseIdentifierList(true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                inclusions = new BitSet();
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   559
                for (Enumeration<String> e = v.elements() ; e.hasMoreElements() ;) {
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   560
                    inclusions.set(dtd.getElement(e.nextElement()).getIndex());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        expect('>');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        if (in.replace == 0) {
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   567
            for (Enumeration<String> e = elems.elements() ; e.hasMoreElements() ;) {
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   568
                dtd.defineElement(e.nextElement(), type, omitStart, omitEnd, content, exclusions, inclusions, null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * Parse an attribute declared value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * [145] 422:6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    void parseAttributeDeclaredValue(AttributeList atts) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        if (ch == '(') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            atts.values = parseIdentifierList(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            atts.type = NMTOKEN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        if (!parseIdentifier(false)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            error("invalid", "attribute value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        }
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   587
        atts.type = AttributeList.name2type(getString(0));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        skipParameterSpace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        if (atts.type == NOTATION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            atts.values = parseIdentifierList(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * Parse an attribute value specification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * [33] 331:1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     */
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   598
    @SuppressWarnings("fallthrough")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    String parseAttributeValueSpecification() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        int delim = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        switch (ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
          case '\'':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
          case '"':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            delim = ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            switch (ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
              case -1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                error("eof.arg", "attribute value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                return getString(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
              case '&':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                parseEntityReference();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
              case ' ':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
              case '\t':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
              case '\n':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                if (delim == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                    return getString(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                addString(' ');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
              case '\'':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
              case '"':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                if (delim == ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                    ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                    return getString(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                }
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   633
                /* fall through */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
              default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
                addString(ch & 0xFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * Parse an attribute default value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * [147] 425:1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    void parseAttributeDefaultValue(AttributeList atts) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        if (ch == '#') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
            if (!parseIdentifier(true)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                error("invalid", "attribute value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            skipParameterSpace();
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   655
            atts.modifier = AttributeList.name2type(getString(0));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
            if (atts.modifier != FIXED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        atts.value = parseAttributeValueSpecification();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        skipParameterSpace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     * Parse an attribute definition list declaration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * [141] 420:15
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * REMIND: associated notation name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    void parseAttlistDeclaration() throws IOException {
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   670
        Vector<String> elems = parseIdentifierList(true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        AttributeList attlist = null, atts = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        while (parseIdentifier(true)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
            if (atts == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                attlist = atts = new AttributeList(getString(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                atts.next = new AttributeList(getString(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                atts = atts.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            skipParameterSpace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
            parseAttributeDeclaredValue(atts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
            parseAttributeDefaultValue(atts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
            if ((atts.modifier == IMPLIED) && (atts.values != null) && (atts.values.size() == 1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                atts.value = (String)atts.values.elementAt(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        expect('>');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        if (in.replace == 0) {
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   692
            for (Enumeration<String> e = elems.elements() ; e.hasMoreElements() ;) {
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   693
                dtd.defineAttributes(e.nextElement(), attlist);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * Parse an ignored section until ]]> is encountered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
    void parseIgnoredSection() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        int depth = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        in.replace++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
            switch (ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
              case '<':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
                if ((ch = in.read()) == '!') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
                    if ((ch = in.read()) == '[') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
                        ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                        depth++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
              case ']':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
                if ((ch = in.read()) == ']') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
                    if ((ch = in.read()) == '>') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                        ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                        if (--depth == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                            in.replace--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
              case -1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
                error("eof");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
                in.replace--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
              default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     * Parse a marked section declaration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     * [93] 391:13
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     * REMIND: deal with all status keywords
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    void parseMarkedSectionDeclaration() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        skipSpace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        if (!parseIdentifier(true)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
            error("expected", "section status keyword");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        String str = getString(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        skipSpace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        expect('[');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        if ("ignore".equals(str)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            parseIgnoredSection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            if (!"include".equals(str)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
                error("invalid.arg", "section status keyword", str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            parseSection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
            expect(']');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
            expect(']');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            expect('>');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     * Parse an external identifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     * [73] 379:1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
    void parseExternalIdentifier() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        if (parseIdentifier(false)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
            String id = getString(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
            skipParameterSpace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
            if (id.equals("PUBLIC")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                if ((ch == '\'') || (ch == '"')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                    parseAttributeValueSpecification();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                    error("expected", "public identifier");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                skipParameterSpace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
            } else if (!id.equals("SYSTEM")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
                error("invalid", "external identifier");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
            if ((ch == '\'') || (ch == '"')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                parseAttributeValueSpecification();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
            skipParameterSpace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     * Parse document type declaration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     * [110] 403:1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
    void parseDocumentTypeDeclaration() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        skipParameterSpace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        if (!parseIdentifier(true)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
            error("expected", "identifier");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
            skipParameterSpace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        strpos = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
        parseExternalIdentifier();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        if (ch == '[') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
            ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
            parseSection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
            expect(']');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
            skipParameterSpace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        expect('>');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     * Parse a section of the input upto EOF or ']'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     */
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   817
    @SuppressWarnings("fallthrough")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
    void parseSection() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
            switch (ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
              case ']':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
              case '<':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
                switch (ch = in.read()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
                  case '!':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
                    switch (ch = in.read()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
                      case '[':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
                        parseMarkedSectionDeclaration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
                      case '-':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
                        skipParameterSpace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                        expect('>');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
                      default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
                        if (parseIdentifier(true)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
                            String str = getString(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
                            if (str.equals("element")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
                                parseElementDeclaration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
                            } else if (str.equals("entity")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
                                parseEntityDeclaration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
                            } else if (str.equals("attlist")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
                                parseAttlistDeclaration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
                            } else if (str.equals("doctype")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
                                parseDocumentTypeDeclaration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
                            } else if (str.equals("usemap")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
                                error("ignoring", "usemap");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
                                while ((ch != -1) && (ch != '>')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
                                    ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
                                expect('>');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
                            } else if (str.equals("shortref")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
                                error("ignoring", "shortref");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
                                while ((ch != -1) && (ch != '>')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
                                    ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
                                expect('>');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
                            } else if (str.equals("notation")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
                                error("ignoring", "notation");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
                                while ((ch != -1) && (ch != '>')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
                                    ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
                                expect('>');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
                            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
                                error("markup");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
                            error("markup");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
                            while ((ch != -1) && (ch != '>')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
                                ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
                            expect('>');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
              case -1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
              default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
                char str[] = {(char)ch};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
                error("invalid.arg", "character", "'" + new String(str) + "' / " + ch);
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   891
                /* fall through */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
              case ' ':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
              case '\t':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
              case '\n':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
                ch = in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
     * Parse a DTD.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
     * @return the dtd or null if an error occurred.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
    DTD parse(InputStream in, DTDBuilder dtd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
            this.dtd = dtd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
            this.in = new DTDInputStream(in, dtd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
            ch = this.in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
            parseSection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
            if (ch != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
                error("premature");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            error("ioexception");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
            error("exception", e.getClass().getName(), e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
        } catch (ThreadDeath e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
            error("terminated");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
        return (nerrors > 0) ? null : dtd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
}