jdk/src/java.desktop/share/classes/javax/swing/text/html/parser/Parser.java
author martin
Thu, 30 Oct 2014 07:31:41 -0700
changeset 28059 e576535359cc
parent 25859 3317bb8137f4
child 34885 63d4a8c733f8
permissions -rw-r--r--
8067377: My hobby: caning, then then canning, the the can-can Summary: Fix ALL the stutters! Reviewed-by: rriggs, mchung, lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23262
41f2413bba45 8028616: Htmleditorkit parser doesn't handle leading slash (/)
dmarkov
parents: 21278
diff changeset
     2
 * Copyright (c) 1998, 2014, 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: 1299
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: 1299
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: 1299
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1299
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1299
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 javax.swing.text.html.parser;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.swing.text.SimpleAttributeSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.swing.text.html.HTML;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.swing.text.ChangedCharSetException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.Properties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import sun.misc.MessageUtils;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * A simple DTD-driven HTML parser. The parser reads an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * HTML file from an InputStream and calls various methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * (which should be overridden in a subclass) when tags and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * data are encountered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * Unfortunately there are many badly implemented HTML parsers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * out there, and as a result there are many badly formatted
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * HTML files. This parser attempts to parse most HTML files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * This means that the implementation sometimes deviates from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * the SGML specification in favor of HTML.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * The parser treats \r and \r\n as \n. Newlines after starttags
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * and before end tags are ignored just as specified in the SGML/HTML
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * specification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * The html spec does not specify how spaces are to be coalesced very well.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * Specifically, the following scenarios are not discussed (note that a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * space should be used here, but I am using &amp;nbsp to force the space to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * be displayed):
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <p>
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 17678
diff changeset
    61
 * '&lt;b&gt;blah&nbsp;&lt;i&gt;&nbsp;&lt;strike&gt;&nbsp;foo' which can be treated as:
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 17678
diff changeset
    62
 * '&lt;b&gt;blah&nbsp;&lt;i&gt;&lt;strike&gt;foo'
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * <p>as well as:
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 17678
diff changeset
    64
 * '&lt;p&gt;&lt;a href="xx"&gt;&nbsp;&lt;em&gt;Using&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;'
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * which appears to be treated as:
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 17678
diff changeset
    66
 * '&lt;p&gt;&lt;a href="xx"&gt;&lt;em&gt;Using&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;'
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * If <code>strict</code> is false, when a tag that breaks flow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * (<code>TagElement.breaksFlows</code>) or trailing whitespace is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * encountered, all whitespace will be ignored until a non whitespace
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * character is encountered. This appears to give behavior closer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * the popular browsers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * @see DTD
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * @see TagElement
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * @see SimpleAttributeSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * @author Arthur van Hoff
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * @author Sunita Mani
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
public
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
class Parser implements DTDConstants {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    private char text[] = new char[1024];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    private int textpos = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private TagElement last;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    private boolean space;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    private char str[] = new char[128];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private int strpos = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
25147
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24567
diff changeset
    91
    /**
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24567
diff changeset
    92
     * The dtd.
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24567
diff changeset
    93
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    protected DTD dtd = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    private int ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private int ln;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private Reader in;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    private Element recent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    private TagStack stack;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    private boolean skipTag = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    private TagElement lastFormSent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    private SimpleAttributeSet attributes = new SimpleAttributeSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    // State for <html>, <head> and <body>.  Since people like to slap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    // together HTML documents without thinking, occasionally they
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    // have multiple instances of these tags.  These booleans track
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    // the first sightings of these tags so they can be safely ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    // by the parser if repeated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    private boolean seenHtml = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    private boolean seenHead = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    private boolean seenBody = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * The html spec does not specify how spaces are coalesced very well.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * If strict == false, ignoreSpace is used to try and mimic the behavior
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * of the popular browsers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * The problematic scenarios are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * '&lt;b>blah &lt;i> &lt;strike> foo' which can be treated as:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * '&lt;b>blah &lt;i>&lt;strike>foo'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * as well as:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * '&lt;p>&lt;a href="xx"> &lt;em>Using&lt;/em>&lt;/a>&lt;/p>'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * which appears to be treated as:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * '&lt;p>&lt;a href="xx">&lt;em>Using&lt;/em>&lt;/a>&lt;/p>'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * When a tag that breaks flow, or trailing whitespace is encountered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * ignoreSpace is set to true. From then on, all whitespace will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * ignoreSpace will be set back to false the first time a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * non whitespace character is encountered. This appears to give
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * behavior closer to the popular browsers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    private boolean ignoreSpace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * This flag determines whether or not the Parser will be strict
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * in enforcing SGML compatibility.  If false, it will be lenient
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * with certain common classes of erroneous HTML constructs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * Strict or not, in either case an error will be recorded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    protected boolean strict = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    /** Number of \r\n's encountered. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    private int crlfCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    /** Number of \r's encountered. A \r\n will not increment this. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    private int crCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    /** Number of \n's encountered. A \r\n will not increment this. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    private int lfCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    // To correctly identify the start of a tag/comment/text we need two
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    // ivars. Two are needed as handleText isn't invoked until the tag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    // after the text has been parsed, that is the parser parses the text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    // then a tag, then invokes handleText followed by handleStart.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    /** The start position of the current block. Block is overloaded here,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * it really means the current start position for the current comment,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * tag, text. Use getBlockStartPosition to access this. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    private int currentBlockStartPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    /** Start position of the last block. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    private int lastBlockStartPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * array for mapping numeric references in range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * 130-159 to displayable Unicode characters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    private static final char[] cp1252Map = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        8218,  // &#130;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        402,   // &#131;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        8222,  // &#132;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        8230,  // &#133;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        8224,  // &#134;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        8225,  // &#135;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        710,   // &#136;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        8240,  // &#137;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        352,   // &#138;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        8249,  // &#139;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        338,   // &#140;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        141,   // &#141;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        142,   // &#142;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        143,   // &#143;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        144,   // &#144;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        8216,  // &#145;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        8217,  // &#146;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        8220,  // &#147;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        8221,  // &#148;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        8226,  // &#149;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        8211,  // &#150;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        8212,  // &#151;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        732,   // &#152;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        8482,  // &#153;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        353,   // &#154;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        8250,  // &#155;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        339,   // &#156;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        157,   // &#157;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        158,   // &#158;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        376    // &#159;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
25147
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24567
diff changeset
   204
    /**
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24567
diff changeset
   205
     * Creates parser with the specified {@code dtd}.
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24567
diff changeset
   206
     *
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24567
diff changeset
   207
     * @param dtd the dtd.
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24567
diff changeset
   208
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    public Parser(DTD dtd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        this.dtd = dtd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @return the line number of the line currently being parsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    protected int getCurrentLine() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        return ln;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * Returns the start position of the current block. Block is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * overloaded here, it really means the current start position for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * the current comment tag, text, block.... This is provided for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * subclassers that wish to know the start of the current block when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * called with one of the handleXXX methods.
24494
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   227
     *
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   228
     * @return the start position of the current block
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    int getBlockStartPosition() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        return Math.max(0, lastBlockStartPos - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * Makes a TagElement.
24494
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   236
     *
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   237
     * @param elem       the element storing the tag definition
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   238
     * @param fictional  the value of the flag "{@code fictional}" to be set for the tag
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   239
     *
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   240
     * @return the created {@code TagElement}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    protected TagElement makeTag(Element elem, boolean fictional) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        return new TagElement(elem, fictional);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
24494
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   246
    /**
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   247
     * Makes a TagElement.
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   248
     *
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   249
     * @param elem  the element storing the tag definition
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   250
     *
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   251
     * @return the created {@code TagElement}
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   252
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    protected TagElement makeTag(Element elem) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        return makeTag(elem, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
24494
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   257
    /**
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   258
     * Returns attributes for the current tag.
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   259
     *
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   260
     * @return {@code SimpleAttributeSet} containing the attributes
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   261
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    protected SimpleAttributeSet getAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        return attributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
24494
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   266
    /**
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   267
     * Removes the current attributes.
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   268
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    protected void flushAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        attributes.removeAttributes(attributes);
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
     * Called when PCDATA is encountered.
24494
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   275
     *
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   276
     * @param text  the section text
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    protected void handleText(char text[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * Called when an HTML title tag is encountered.
24494
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   283
     *
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   284
     * @param text  the title text
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    protected void handleTitle(char text[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        // default behavior is to call handleText. Subclasses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        // can override if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        handleText(text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * Called when an HTML comment is encountered.
24494
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   294
     *
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   295
     * @param text  the comment being handled
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    protected void handleComment(char text[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
24494
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   300
    /**
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   301
     * Called when the content terminates without closing the HTML comment.
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   302
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    protected void handleEOFInComment() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        // We've reached EOF.  Our recovery strategy is to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        // see if we have more than one line in the comment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        // if so, we pretend that the comment was an unterminated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        // single line comment, and reparse the lines after the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        // first line as normal HTML content.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        int commentEndPos = strIndexOf('\n');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        if (commentEndPos >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            handleComment(getChars(0, commentEndPos));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                in.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                in = new CharArrayReader(getChars(commentEndPos + 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                ch = '>';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                error("ioexception");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            resetStrBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            // no newline, so signal an error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            error("eof.comment");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * Called when an empty tag is encountered.
24494
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   330
     *
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   331
     * @param tag  the tag being handled
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   332
     * @throws ChangedCharSetException if the document charset was changed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    protected void handleEmptyTag(TagElement tag) throws ChangedCharSetException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * Called when a start tag is encountered.
24494
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   339
     *
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   340
     * @param tag  the tag being handled
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    protected void handleStartTag(TagElement tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * Called when an end tag is encountered.
24494
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   347
     *
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   348
     * @param tag  the tag being handled
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    protected void handleEndTag(TagElement tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * An error has occurred.
24494
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   355
     *
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   356
     * @param ln   the number of line containing the error
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   357
     * @param msg  the error message
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    protected void handleError(int ln, String msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        Thread.dumpStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        System.out.println("**** " + stack);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        System.out.println("line " + ln + ": error: " + msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * Output text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    void handleText(TagElement tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        if (tag.breaksFlow()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            space = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            if (!strict) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                ignoreSpace = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        if (textpos == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            if ((!space) || (stack == null) || last.breaksFlow() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                !stack.advance(dtd.pcdata)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                last = tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                space = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                lastBlockStartPos = currentBlockStartPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        if (space) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            if (!ignoreSpace) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                // enlarge buffer if needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                if (textpos + 1 > text.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                    char newtext[] = new char[text.length + 200];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                    System.arraycopy(text, 0, newtext, 0, text.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                    text = newtext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                // output pending space
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                text[textpos++] = ' ';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                if (!strict && !tag.getElement().isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                    ignoreSpace = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            space = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        char newtext[] = new char[textpos];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        System.arraycopy(text, 0, newtext, 0, textpos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        // Handles cases of bad html where the title tag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        // was getting lost when we did error recovery.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        if (tag.getElement().getName().equals("title")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            handleTitle(newtext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            handleText(newtext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        lastBlockStartPos = currentBlockStartPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        textpos = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        last = tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        space = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    /**
24494
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   420
     * Invokes the error handler.
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   421
     *
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   422
     * @param err   the error type
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   423
     * @param arg1  the 1st error message argument
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   424
     * @param arg2  the 2nd error message argument
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   425
     * @param arg3  the 3rd error message argument
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    protected void error(String err, String arg1, String arg2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        String arg3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        handleError(ln, err + " " + arg1 + " " + arg2 + " " + arg3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
25147
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24567
diff changeset
   432
    /**
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24567
diff changeset
   433
     * Invokes the error handler with the 3rd error message argument "?".
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24567
diff changeset
   434
     *
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24567
diff changeset
   435
     * @param err   the error type
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24567
diff changeset
   436
     * @param arg1  the 1st error message argument
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24567
diff changeset
   437
     * @param arg2  the 2nd error message argument
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24567
diff changeset
   438
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    protected void error(String err, String arg1, String arg2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        error(err, arg1, arg2, "?");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    }
25147
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24567
diff changeset
   442
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24567
diff changeset
   443
    /**
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24567
diff changeset
   444
     * Invokes the error handler with the 2nd and 3rd error message argument "?".
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24567
diff changeset
   445
     *
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24567
diff changeset
   446
     * @param err   the error type
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24567
diff changeset
   447
     * @param arg1  the 1st error message argument
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24567
diff changeset
   448
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    protected void error(String err, String arg1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        error(err, arg1, "?", "?");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    }
25147
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24567
diff changeset
   452
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24567
diff changeset
   453
    /**
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24567
diff changeset
   454
     * Invokes the error handler with the 1st, 2nd and 3rd error message argument "?".
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24567
diff changeset
   455
     *
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24567
diff changeset
   456
     * @param err   the error type
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24567
diff changeset
   457
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    protected void error(String err) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        error(err, "?", "?", "?");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * Handle a start tag. The new tag is pushed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * onto the tag stack. The attribute list is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * checked for required attributes.
24494
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   467
     *
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   468
     * @param tag  the tag
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   469
     * @throws ChangedCharSetException if the document charset was changed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    protected void startTag(TagElement tag) throws ChangedCharSetException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        Element elem = tag.getElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        // If the tag is an empty tag and texpos != 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        // this implies that there is text before the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        // start tag that needs to be processed before
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        // handling the tag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        if (!elem.isEmpty() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                    ((last != null) && !last.breaksFlow()) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                    (textpos != 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            handleText(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            // this variable gets updated in handleText().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            // Since in this case we do not call handleText()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            // we need to update it here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            last = tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            // Note that we should really check last.breakFlows before
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            // assuming this should be false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            space = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        lastBlockStartPos = currentBlockStartPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        // check required attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        for (AttributeList a = elem.atts ; a != null ; a = a.next) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            if ((a.modifier == REQUIRED) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                ((attributes.isEmpty()) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                 ((!attributes.isDefined(a.name)) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                  (!attributes.isDefined(HTML.getAttributeKey(a.name)))))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                error("req.att ", a.getName(), elem.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        if (elem.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            handleEmptyTag(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        } else if (elem.getName().equals("form")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            handleStartTag(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            recent = elem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            stack = new TagStack(tag, stack);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            handleStartTag(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * Handle an end tag. The end tag is popped
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * from the tag stack.
24494
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   521
     *
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   522
     * @param omitted  {@code true} if the tag is no actually present in the
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   523
     *                 document, but is supposed by the parser
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    protected void endTag(boolean omitted) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        handleText(stack.tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        if (omitted && !stack.elem.omitEnd()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            error("end.missing", stack.elem.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        } else if (!stack.terminate()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            error("end.unexpected", stack.elem.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        // handle the tag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        handleEndTag(stack.tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        stack = stack.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        recent = (stack != null) ? stack.elem : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    boolean ignoreElement(Element elem) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        String stackElement = stack.elem.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        String elemName = elem.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        /* We ignore all elements that are not valid in the context of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
           a table except <td>, <th> (these we handle in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
           legalElementContext()) and #pcdata.  We also ignore the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
           <font> tag in the context of <ul> and <ol> We additonally
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
           ignore the <meta> and the <style> tag if the body tag has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
           been seen. **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        if ((elemName.equals("html") && seenHtml) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            (elemName.equals("head") && seenHead) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            (elemName.equals("body") && seenBody)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        if (elemName.equals("dt") || elemName.equals("dd")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            TagStack s = stack;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            while (s != null && !s.elem.getName().equals("dl")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                s = s.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            if (s == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        if (((stackElement.equals("table")) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
             (!elemName.equals("#pcdata")) && (!elemName.equals("input"))) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            ((elemName.equals("font")) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
             (stackElement.equals("ul") || stackElement.equals("ol"))) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
            (elemName.equals("meta") && stack != null) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            (elemName.equals("style") && seenBody) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
            (stackElement.equals("table") && elemName.equals("a"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * Marks the first time a tag has been seen in a document
24494
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   581
     *
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
   582
     * @param elem  the element represented by the tag
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    protected void markFirstTime(Element elem) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        String elemName = elem.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        if (elemName.equals("html")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            seenHtml = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        } else if (elemName.equals("head")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            seenHead = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        } else if (elemName.equals("body")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            if (buf.length == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                // Refer to note in definition of buf for details on this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                char[] newBuf = new char[256];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                newBuf[0] = buf[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                buf = newBuf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            seenBody = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * Create a legal content for an element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    boolean legalElementContext(Element elem) throws ChangedCharSetException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        // System.out.println("-- legalContext -- " + elem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        // Deal with the empty stack
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        if (stack == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            // System.out.println("-- stack is empty");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            if (elem != dtd.html) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                // System.out.println("-- pushing html");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                startTag(makeTag(dtd.html, true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                return legalElementContext(elem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        // Is it allowed in the current context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        if (stack.advance(elem)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            // System.out.println("-- legal context");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
            markFirstTime(elem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        boolean insertTag = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        // The use of all error recovery strategies are contingent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        // on the value of the strict property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        //
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
   632
        // These are commonly occurring errors.  if insertTag is true,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        // then we want to adopt an error recovery strategy that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        // involves attempting to insert an additional tag to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        // legalize the context.  The two errors addressed here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        // are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        // 1) when a <td> or <th> is seen soon after a <table> tag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        //    In this case we insert a <tr>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        // 2) when any other tag apart from a <tr> is seen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        //    in the context of a <tr>.  In this case we would
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        //    like to add a <td>.  If a <tr> is seen within a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        //    <tr> context, then we will close out the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        //    <tr>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        // This insertion strategy is handled later in the method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        // The reason for checking this now, is that in other cases
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        // we would like to apply other error recovery strategies for example
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        // ignoring tags.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        // In certain cases it is better to ignore a tag than try to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        // fix the situation.  So the first test is to see if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        // is what we need to do.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        String stackElemName = stack.elem.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        String elemName = elem.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        if (!strict &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            ((stackElemName.equals("table") && elemName.equals("td")) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
             (stackElemName.equals("table") && elemName.equals("th")) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
             (stackElemName.equals("tr") && !elemName.equals("tr")))){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
             insertTag = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        if (!strict && !insertTag && (stack.elem.getName() != elem.getName() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                                      elem.getName().equals("body"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
            if (skipTag = ignoreElement(elem)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                error("tag.ignore", elem.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                return skipTag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        // Check for anything after the start of the table besides tr, td, th
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        // or caption, and if those aren't there, insert the <tr> and call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        // legalElementContext again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        if (!strict && stackElemName.equals("table") &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
            !elemName.equals("tr") && !elemName.equals("td") &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            !elemName.equals("th") && !elemName.equals("caption")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            Element e = dtd.getElement("tr");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
            TagElement t = makeTag(e, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
            legalTagContext(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
            startTag(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
            error("start.missing", elem.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
            return legalElementContext(elem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        // They try to find a legal context by checking if the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        // tag is valid in an enclosing context.  If so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        // close out the tags by outputing end tags and then
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
   691
        // insert the current tag.  If the tags that are
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        // being closed out do not have an optional end tag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        // specification in the DTD then an html error is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        // reported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        if (!insertTag && stack.terminate() && (!strict || stack.elem.omitEnd())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            for (TagStack s = stack.next ; s != null ; s = s.next) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                if (s.advance(elem)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                    while (stack != s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                        endTag(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
                if (!s.terminate() || (strict && !s.elem.omitEnd())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        // Check if we know what tag is expected next.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        // If so insert the tag.  Report an error if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        // tag does not have its start tag spec in the DTD as optional.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        Element next = stack.first();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        if (next != null && (!strict || next.omitStart()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
           !(next==dtd.head && elem==dtd.pcdata) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
            // System.out.println("-- omitting start tag: " + next);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
            TagElement t = makeTag(next, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
            legalTagContext(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
            startTag(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            if (!next.omitStart()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
                error("start.missing", elem.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
            return legalElementContext(elem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        // Traverse the list of expected elements and determine if adding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        // any of these elements would make for a legal context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        if (!strict) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            ContentModel content = stack.contentModel();
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
   734
            Vector<Element> elemVec = new Vector<Element>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
            if (content != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                content.getElements(elemVec);
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
   737
                for (Element e : elemVec) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                    // Ensure that this element has not been included as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
                    // part of the exclusions in the DTD.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
                    if (stack.excluded(e.getIndex())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
                    boolean reqAtts = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                    for (AttributeList a = e.getAttributes(); a != null ; a = a.next) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
                        if (a.modifier == REQUIRED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
                            reqAtts = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                    // Ensure that no tag that has required attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                    // gets inserted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
                    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
                    if (reqAtts) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                    ContentModel m = e.getContent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
                    if (m != null && m.first(elem)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
                        // System.out.println("-- adding a legal tag: " + e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                        TagElement t = makeTag(e, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
                        legalTagContext(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                        startTag(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                        error("start.missing", e.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                        return legalElementContext(elem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        // Check if the stack can be terminated.  If so add the appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        // end tag.  Report an error if the tag being ended does not have its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        // end tag spec in the DTD as optional.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
        if (stack.terminate() && (stack.elem != dtd.body) && (!strict || stack.elem.omitEnd())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
            // System.out.println("-- omitting end tag: " + stack.elem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
            if (!stack.elem.omitEnd()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                error("end.missing", elem.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
            endTag(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
            return legalElementContext(elem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        // At this point we know that something is screwed up.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        return false;
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
     * Create a legal context for a tag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
    void legalTagContext(TagElement tag) throws ChangedCharSetException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        if (legalElementContext(tag.getElement())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
            markFirstTime(tag.getElement());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
        // Avoid putting a block tag in a flow tag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        if (tag.breaksFlow() && (stack != null) && !stack.tag.breaksFlow()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
            endTag(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
            legalTagContext(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        // Avoid putting something wierd in the head of the document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        for (TagStack s = stack ; s != null ; s = s.next) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
            if (s.tag.getElement() == dtd.head) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
                while (stack != s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                    endTag(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
                endTag(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                legalTagContext(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
        // Everything failed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        error("tag.unexpected", tag.getElement().getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     * Error context. Something went wrong, make sure we are in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     * the document's body context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
    void errorContext() throws ChangedCharSetException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        for (; (stack != null) && (stack.tag.getElement() != dtd.body) ; stack = stack.next) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
            handleEndTag(stack.tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
        if (stack == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
            legalElementContext(dtd.body);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
            startTag(makeTag(dtd.body, true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     * Add a char to the string buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
    void addString(int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
        if (strpos  == str.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
            char newstr[] = new char[str.length + 128];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
            System.arraycopy(str, 0, newstr, 0, str.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
            str = newstr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
        str[strpos++] = (char)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     * Get the string that's been accumulated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
    String getString(int pos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        char newStr[] = new char[strpos - pos];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        System.arraycopy(str, pos, newStr, 0, strpos - pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        strpos = pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        return new String(newStr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
    char[] getChars(int pos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
        char newStr[] = new char[strpos - pos];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        System.arraycopy(str, pos, newStr, 0, strpos - pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
        strpos = pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        return newStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
    char[] getChars(int pos, int endPos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        char newStr[] = new char[endPos - pos];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        System.arraycopy(str, pos, newStr, 0, endPos - pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        // REMIND: it's not clear whether this version should set strpos or not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        // strpos = pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        return newStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
    void resetStrBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        strpos = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
    int strIndexOf(char target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
        for (int i = 0; i < strpos; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
            if (str[i] == target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
                return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
     * Skip space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
     * [5] 297:5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    void skipSpace() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
            switch (ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
              case '\n':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
                ln++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
                ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
                lfCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
              case '\r':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
                ln++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
                if ((ch = readCh()) == '\n') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
                    ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
                    crlfCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
                    crCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
              case ' ':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
              case '\t':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
                ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
              default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     * Parse identifier. Uppercase characters are folded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     * to lowercase when lower is true. Returns falsed if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
     * no identifier is found. [55] 346:17
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
    boolean parseIdentifier(boolean lower) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
        switch (ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
          case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
          case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
          case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
          case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
          case 'Y': case 'Z':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
            if (lower) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
                ch = 'a' + (ch - 'A');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
            }
24528
21c5bb3d76cc 8039860: Fix fallthrough lint warnings in swing
darcy
parents: 23262
diff changeset
   937
            break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
          case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
          case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
          case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
          case 's': case 't': case 'u': case 'v': case 'w': case 'x':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
          case 'y': case 'z':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
            addString(ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
            switch (ch = readCh()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
              case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
              case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
              case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
              case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
              case 'Y': case 'Z':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
                if (lower) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
                    ch = 'a' + (ch - 'A');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
                }
24528
21c5bb3d76cc 8039860: Fix fallthrough lint warnings in swing
darcy
parents: 23262
diff changeset
   962
                break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
              case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
              case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
              case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
              case 's': case 't': case 'u': case 'v': case 'w': case 'x':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
              case 'y': case 'z':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
              case '0': case '1': case '2': case '3': case '4':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
              case '5': case '6': case '7': case '8': case '9':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
              case '.': case '-':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
              case '_': // not officially allowed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
              default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
     * Parse an entity reference. [59] 350:17
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
    private char[] parseEntityReference() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
        int pos = strpos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
        if ((ch = readCh()) == '#') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
            int n = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
            ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
            if ((ch >= '0') && (ch <= '9') ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
                    ch == 'x' || ch == 'X') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
                if ((ch >= '0') && (ch <= '9')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
                    // parse decimal reference
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
                    while ((ch >= '0') && (ch <= '9')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
                        n = (n * 10) + ch - '0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
                        ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
                    // parse hexadecimal reference
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
                    ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
                    char lch = (char) Character.toLowerCase(ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
                    while ((lch >= '0') && (lch <= '9') ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
                            (lch >= 'a') && (lch <= 'f')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
                        if (lch >= '0' && lch <= '9') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
                            n = (n * 16) + lch - '0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
                            n = (n * 16) + lch - 'a' + 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
                        ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
                        lch = (char) Character.toLowerCase(ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
                switch (ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
                    case '\n':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
                        ln++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
                        ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
                        lfCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
                    case '\r':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
                        ln++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
                        if ((ch = readCh()) == '\n') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
                            ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
                            crlfCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
                        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
                            crCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
                    case ';':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
                        ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
                }
14309
425e2c6b5941 2229575: Swing HTML parser can't properly decode codepoints outside the Unicode Plane 0 into a surrogate pair
VKARNAUK
parents: 12999
diff changeset
  1039
                char data[] = mapNumericReference(n);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
                return data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
            addString('#');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
            if (!parseIdentifier(false)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
                error("ident.expected");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
                strpos = pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
                char data[] = {'&', '#'};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
                return data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
        } else if (!parseIdentifier(false)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
            char data[] = {'&'};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
            return data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
        }
9213
856f16c729a5 7003777: Nonexistent html entities not parsed properly.
rupashka
parents: 7668
diff changeset
  1053
856f16c729a5 7003777: Nonexistent html entities not parsed properly.
rupashka
parents: 7668
diff changeset
  1054
        boolean semicolon = false;
856f16c729a5 7003777: Nonexistent html entities not parsed properly.
rupashka
parents: 7668
diff changeset
  1055
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
        switch (ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
          case '\n':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
            ln++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
            ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
            lfCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
          case '\r':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
            ln++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
            if ((ch = readCh()) == '\n') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
                ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
                crlfCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
                crCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
          case ';':
9213
856f16c729a5 7003777: Nonexistent html entities not parsed properly.
rupashka
parents: 7668
diff changeset
  1075
            semicolon = true;
856f16c729a5 7003777: Nonexistent html entities not parsed properly.
rupashka
parents: 7668
diff changeset
  1076
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
            ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
        String nm = getString(pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
        Entity ent = dtd.getEntity(nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
        // entities are case sensitive - however if strict
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
        // is false then we will try to make a match by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
        // converting the string to all lowercase.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
        if (!strict && (ent == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
            ent = dtd.getEntity(nm.toLowerCase());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
        if ((ent == null) || !ent.isGeneral()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
            if (nm.length() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
                error("invalid.entref", nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
                return new char[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
            /* given that there is not a match restore the entity reference */
9213
856f16c729a5 7003777: Nonexistent html entities not parsed properly.
rupashka
parents: 7668
diff changeset
  1098
            String str = "&" + nm + (semicolon ? ";" : "");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
            char b[] = new char[str.length()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
            str.getChars(0, b.length, b, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
            return b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
        return ent.getData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
    /**
14309
425e2c6b5941 2229575: Swing HTML parser can't properly decode codepoints outside the Unicode Plane 0 into a surrogate pair
VKARNAUK
parents: 12999
diff changeset
  1108
     * Converts numeric character reference to char array.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
     * Normally the code in a reference should be always converted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
     * to the Unicode character with the same code, but due to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
     * wide usage of Cp1252 charset most browsers map numeric references
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
     * in the range 130-159 (which are control chars in Unicode set)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
     * to displayable characters with other codes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
     * @param c the code of numeric character reference.
14309
425e2c6b5941 2229575: Swing HTML parser can't properly decode codepoints outside the Unicode Plane 0 into a surrogate pair
VKARNAUK
parents: 12999
diff changeset
  1117
     * @return a char array corresponding to the reference code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
     */
14309
425e2c6b5941 2229575: Swing HTML parser can't properly decode codepoints outside the Unicode Plane 0 into a surrogate pair
VKARNAUK
parents: 12999
diff changeset
  1119
    private char[] mapNumericReference(int c) {
425e2c6b5941 2229575: Swing HTML parser can't properly decode codepoints outside the Unicode Plane 0 into a surrogate pair
VKARNAUK
parents: 12999
diff changeset
  1120
        char[] data;
425e2c6b5941 2229575: Swing HTML parser can't properly decode codepoints outside the Unicode Plane 0 into a surrogate pair
VKARNAUK
parents: 12999
diff changeset
  1121
        if (c >= 0xffff) { // outside unicode BMP.
425e2c6b5941 2229575: Swing HTML parser can't properly decode codepoints outside the Unicode Plane 0 into a surrogate pair
VKARNAUK
parents: 12999
diff changeset
  1122
            try {
425e2c6b5941 2229575: Swing HTML parser can't properly decode codepoints outside the Unicode Plane 0 into a surrogate pair
VKARNAUK
parents: 12999
diff changeset
  1123
                data = Character.toChars(c);
425e2c6b5941 2229575: Swing HTML parser can't properly decode codepoints outside the Unicode Plane 0 into a surrogate pair
VKARNAUK
parents: 12999
diff changeset
  1124
            } catch (IllegalArgumentException e) {
425e2c6b5941 2229575: Swing HTML parser can't properly decode codepoints outside the Unicode Plane 0 into a surrogate pair
VKARNAUK
parents: 12999
diff changeset
  1125
                data = new char[0];
425e2c6b5941 2229575: Swing HTML parser can't properly decode codepoints outside the Unicode Plane 0 into a surrogate pair
VKARNAUK
parents: 12999
diff changeset
  1126
            }
425e2c6b5941 2229575: Swing HTML parser can't properly decode codepoints outside the Unicode Plane 0 into a surrogate pair
VKARNAUK
parents: 12999
diff changeset
  1127
        } else {
425e2c6b5941 2229575: Swing HTML parser can't properly decode codepoints outside the Unicode Plane 0 into a surrogate pair
VKARNAUK
parents: 12999
diff changeset
  1128
            data = new char[1];
425e2c6b5941 2229575: Swing HTML parser can't properly decode codepoints outside the Unicode Plane 0 into a surrogate pair
VKARNAUK
parents: 12999
diff changeset
  1129
            data[0] = (c < 130 || c > 159) ? (char) c : cp1252Map[c - 130];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
        }
14309
425e2c6b5941 2229575: Swing HTML parser can't properly decode codepoints outside the Unicode Plane 0 into a surrogate pair
VKARNAUK
parents: 12999
diff changeset
  1131
        return data;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
     * Parse a comment. [92] 391:7
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
    void parseComment() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
            int c = ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
            switch (c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
              case '-':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
                  /** Presuming that the start string of a comment "<!--" has
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
                      already been parsed, the '-' character is valid only as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
                      part of a comment termination and further more it must
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
                      be present in even numbers. Hence if strict is true, we
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
                      presume the comment has been terminated and return.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
                      However if strict is false, then there is no even number
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
                      requirement and this character can appear anywhere in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
                      comment.  The parser reads on until it sees the following
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
                      pattern: "-->" or "--!>".
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
                   **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
                if (!strict && (strpos != 0) && (str[strpos - 1] == '-')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
                    if ((ch = readCh()) == '>') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
                    if (ch == '!') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
                        if ((ch = readCh()) == '>') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
                            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
                            /* to account for extra read()'s that happened */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
                            addString('-');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
                            addString('!');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
                            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
                if ((ch = readCh()) == '-') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
                    ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
                    if (strict || ch == '>') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
                    if (ch == '!') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
                        if ((ch = readCh()) == '>') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
                            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
                            /* to account for extra read()'s that happened */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
                            addString('-');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
                            addString('!');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
                            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
                    /* to account for the extra read() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
                    addString('-');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
              case -1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
                  handleEOFInComment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
                  return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
              case '\n':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
                ln++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
                ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
                lfCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
              case '>':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
                ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
              case '\r':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
                ln++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
                if ((ch = readCh()) == '\n') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
                    ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
                    crlfCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
                    crCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
                c = '\n';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
              default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
                ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
            addString(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
     * Parse literal content. [46] 343:1 and [47] 344:1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
    void parseLiteral(boolean replace) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
            int c = ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
            switch (c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
              case -1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
                error("eof.literal", stack.elem.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
                endTag(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
              case '>':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
                ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
                int i = textpos - (stack.elem.name.length() + 2), j = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
                // match end tag
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
                if ((i >= 0) && (text[i++] == '<') && (text[i] == '/')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
                    while ((++i < textpos) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
                           (Character.toLowerCase(text[i]) == stack.elem.name.charAt(j++)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
                    if (i == textpos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
                        textpos -= (stack.elem.name.length() + 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
                        if ((textpos > 0) && (text[textpos-1] == '\n')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
                            textpos--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
                        endTag(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
              case '&':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
                char data[] = parseEntityReference();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
                if (textpos + data.length > text.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
                    char newtext[] = new char[Math.max(textpos + data.length + 128, text.length * 2)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
                    System.arraycopy(text, 0, newtext, 0, text.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
                    text = newtext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
                System.arraycopy(data, 0, text, textpos, data.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
                textpos += data.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
              case '\n':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
                ln++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
                ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
                lfCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
              case '\r':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
                ln++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
                if ((ch = readCh()) == '\n') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
                    ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
                    crlfCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
                    crCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
                c = '\n';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
              default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
                ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
            // output character
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
            if (textpos == text.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
                char newtext[] = new char[text.length + 128];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
                System.arraycopy(text, 0, newtext, 0, text.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
                text = newtext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
            text[textpos++] = (char)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
     * Parse attribute value. [33] 331:1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
     */
24528
21c5bb3d76cc 8039860: Fix fallthrough lint warnings in swing
darcy
parents: 23262
diff changeset
  1301
    @SuppressWarnings("fallthrough")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
    String parseAttributeValue(boolean lower) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
        int delim = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
        // Check for a delimiter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
        switch(ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
          case '\'':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
          case '"':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
            delim = ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
            ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
        // Parse the rest of the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
            int c = ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
            switch (c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
              case '\n':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
                ln++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
                ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
                lfCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
                if (delim < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
                    return getString(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
              case '\r':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
                ln++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
                if ((ch = readCh()) == '\n') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
                    ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
                    crlfCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
                    crCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
                if (delim < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
                    return getString(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
              case '\t':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
                  if (delim < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
                      c = ' ';
24528
21c5bb3d76cc 8039860: Fix fallthrough lint warnings in swing
darcy
parents: 23262
diff changeset
  1346
                  // Fall through
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
              case ' ':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
                ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
                if (delim < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
                    return getString(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
              case '>':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
              case '<':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
                if (delim < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
                    return getString(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
                ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
              case '\'':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
              case '"':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
                ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
                if (c == delim) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
                    return getString(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
                } else if (delim == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
                    error("attvalerr");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
                    if (strict || ch == ' ') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
                        return getString(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
            case '=':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
                if (delim < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
                    /* In SGML a construct like <img src=/cgi-bin/foo?x=1>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
                       is considered invalid since an = sign can only be contained
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
                       in an attributes value if the string is quoted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
                       */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
                    error("attvalerr");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
                    /* If strict is true then we return with the string we have thus far.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
                       Otherwise we accept the = sign as part of the attribute's value and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
                       process the rest of the img tag. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
                    if (strict) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
                        return getString(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
                ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
              case '&':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
                if (strict && delim < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
                    ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
                char data[] = parseEntityReference();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
                for (int i = 0 ; i < data.length ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
                    c = data[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
                    addString((lower && (c >= 'A') && (c <= 'Z')) ? 'a' + c - 'A' : c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
              case -1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
                return getString(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
              default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
                if (lower && (c >= 'A') && (c <= 'Z')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
                    c = 'a' + c - 'A';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
                ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
            addString(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
     * Parse attribute specification List. [31] 327:17
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
    void parseAttributeSpecificationList(Element elem) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
            skipSpace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
            switch (ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
              case '/':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
              case '>':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
              case '<':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
              case -1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
              case '-':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
                if ((ch = readCh()) == '-') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
                    ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
                    parseComment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
                    strpos = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
                    error("invalid.tagchar", "-", elem.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
                    ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
  1449
            AttributeList att;
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
  1450
            String attname;
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
  1451
            String attvalue;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
            if (parseIdentifier(true)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
                attname = getString(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
                skipSpace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
                if (ch == '=') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
                    ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
                    skipSpace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
                    att = elem.getAttribute(attname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
//  Bug ID 4102750
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
//  Load the NAME of an Attribute Case Sensitive
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
//  The case of the NAME  must be intact
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
//  MG 021898
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
                    attvalue = parseAttributeValue((att != null) && (att.type != CDATA) && (att.type != NOTATION) && (att.type != NAME));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
//                  attvalue = parseAttributeValue((att != null) && (att.type != CDATA) && (att.type != NOTATION));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
                    attvalue = attname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
                    att = elem.getAttributeByValue(attvalue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
                    if (att == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
                        att = elem.getAttribute(attname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
                        if (att != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
                            attvalue = att.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
                        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
                            // Make it null so that NULL_ATTRIBUTE_VALUE is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
                            // used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
                            attvalue = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
            } else if (!strict && ch == ',') { // allows for comma separated attribute-value pairs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
                ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
            } else if (!strict && ch == '"') { // allows for quoted attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
                ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
                skipSpace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
                if (parseIdentifier(true)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
                    attname = getString(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
                    if (ch == '"') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
                        ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
                    skipSpace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
                    if (ch == '=') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
                        ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
                        skipSpace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
                        att = elem.getAttribute(attname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
                        attvalue = parseAttributeValue((att != null) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
                                                (att.type != CDATA) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
                                                (att.type != NOTATION));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
                        attvalue = attname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
                        att = elem.getAttributeByValue(attvalue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
                        if (att == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
                            att = elem.getAttribute(attname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
                            if (att != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
                                attvalue = att.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
                    char str[] = {(char)ch};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
                    error("invalid.tagchar", new String(str), elem.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
                    ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
            } else if (!strict && (attributes.isEmpty()) && (ch == '=')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
                ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
                skipSpace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
                attname = elem.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
                att = elem.getAttribute(attname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
                attvalue = parseAttributeValue((att != null) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
                                               (att.type != CDATA) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
                                               (att.type != NOTATION));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
            } else if (!strict && (ch == '=')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
                ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
                skipSpace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
                attvalue = parseAttributeValue(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
                error("attvalerr");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
                char str[] = {(char)ch};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
                error("invalid.tagchar", new String(str), elem.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
                if (!strict) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
                    ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
            if (att != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
                attname = att.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
                error("invalid.tagatt", attname, elem.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
            // Check out the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
            if (attributes.isDefined(attname)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
                error("multi.tagatt", attname, elem.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
            if (attvalue == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
                attvalue = ((att != null) && (att.value != null)) ? att.value :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
                    HTML.NULL_ATTRIBUTE_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
            } else if ((att != null) && (att.values != null) && !att.values.contains(attvalue)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
                error("invalid.tagattval", attname, elem.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
            HTML.Attribute attkey = HTML.getAttributeKey(attname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
            if (attkey == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
                attributes.addAttribute(attname, attvalue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
                attributes.addAttribute(attkey, attvalue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
    /**
24494
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
  1567
     * Parses the Document Type Declaration markup declaration.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
     * Currently ignores it.
24494
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
  1569
     *
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
  1570
     * @return the string representation of the markup declaration
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
  1571
     * @throws IOException if an I/O error occurs
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
    public String parseDTDMarkup() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
7014
eb4fcf73ee99 6432566: Replace usage of StringBuffer with StringBuilder in Swing
rupashka
parents: 5506
diff changeset
  1575
        StringBuilder strBuff = new StringBuilder();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
        ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
        while(true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
            switch (ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
            case '>':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
                ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
                return strBuff.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
            case -1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
                error("invalid.markup");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
                return strBuff.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
            case '\n':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
                ln++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
                ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
                lfCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
            case '"':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
                ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
            case '\r':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
                ln++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
                if ((ch = readCh()) == '\n') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
                    ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
                    crlfCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
                    crCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
                strBuff.append((char)(ch & 0xFF));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
                ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
     * Parse markup declarations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
     * Currently only handles the Document Type Declaration markup.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
     * Returns true if it is a markup declaration false otherwise.
24494
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
  1615
     *
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
  1616
     * @param strBuff  the markup declaration
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
  1617
     * @return {@code true} if this is a valid markup declaration;
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
  1618
     *         otherwise {@code false}
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
  1619
     * @throws IOException if an I/O error occurs
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
    protected boolean parseMarkupDeclarations(StringBuffer strBuff) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
        /* Currently handles only the DOCTYPE */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
        if ((strBuff.length() == "DOCTYPE".length()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
            (strBuff.toString().toUpperCase().equals("DOCTYPE"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
            parseDTDMarkup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
     * Parse an invalid tag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
    void parseInvalidTag() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
        // ignore all data upto the close bracket '>'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
            skipSpace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
            switch (ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
              case '>':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
              case -1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
                  ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
              case '<':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
                  return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
              default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
                  ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
     * Parse a start or end tag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
     */
24528
21c5bb3d76cc 8039860: Fix fallthrough lint warnings in swing
darcy
parents: 23262
diff changeset
  1656
    @SuppressWarnings("fallthrough")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
    void parseTag() throws IOException {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
  1658
        Element elem;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
        boolean net = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
        boolean warned = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
        boolean unknown = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
        switch (ch = readCh()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
          case '!':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
            switch (ch = readCh()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
              case '-':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
                // Parse comment. [92] 391:7
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
                while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
                    if (ch == '-') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
                        if (!strict || ((ch = readCh()) == '-')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
                            ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
                            if (!strict && ch == '-') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
                                ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
                            // send over any text you might see
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
                            // before parsing and sending the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
                            // comment
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
                            if (textpos != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
                                char newtext[] = new char[textpos];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
                                System.arraycopy(text, 0, newtext, 0, textpos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
                                handleText(newtext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
                                lastBlockStartPos = currentBlockStartPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
                                textpos = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
                            parseComment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
                            last = makeTag(dtd.getElement("comment"), true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
                            handleComment(getChars(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
                            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
                        } else if (!warned) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
                            warned = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
                            error("invalid.commentchar", "-");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
                    skipSpace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
                    switch (ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
                      case '-':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
                      case '>':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
                        ch = readCh();
24528
21c5bb3d76cc 8039860: Fix fallthrough lint warnings in swing
darcy
parents: 23262
diff changeset
  1700
                        return;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
                      case -1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
                      default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
                        ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
                        if (!warned) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
                            warned = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
                            error("invalid.commentchar",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
                                  String.valueOf((char)ch));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
              default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
                // deal with marked sections
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
                StringBuffer strBuff = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
                while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
                    strBuff.append((char)ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
                    if (parseMarkupDeclarations(strBuff)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
                    switch(ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
                      case '>':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
                        ch = readCh();
24528
21c5bb3d76cc 8039860: Fix fallthrough lint warnings in swing
darcy
parents: 23262
diff changeset
  1725
                        // Fall through
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
                      case -1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
                        error("invalid.markup");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
                      case '\n':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
                        ln++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
                        ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
                        lfCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
                      case '\r':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
                        ln++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
                        if ((ch = readCh()) == '\n') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
                            ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
                            crlfCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
                        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
                            crCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
                      default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
                        ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
          case '/':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
            // parse end tag [19] 317:4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
            switch (ch = readCh()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
              case '>':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
                ch = readCh();
24528
21c5bb3d76cc 8039860: Fix fallthrough lint warnings in swing
darcy
parents: 23262
diff changeset
  1757
                // Fall through
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
              case '<':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
                // empty end tag. either </> or </<
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
                if (recent == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
                    error("invalid.shortend");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
                elem = recent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
              default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
                if (!parseIdentifier(true)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
                    error("expected.endtagname");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
                skipSpace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
                switch (ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
                  case '>':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
                    ch = readCh();
24528
21c5bb3d76cc 8039860: Fix fallthrough lint warnings in swing
darcy
parents: 23262
diff changeset
  1776
                    break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
                  case '<':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
                  default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
                    error("expected", "'>'");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
                    while ((ch != -1) && (ch != '\n') && (ch != '>')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
                        ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
                    if (ch == '>') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
                        ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
                String elemStr = getString(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
                if (!dtd.elementExists(elemStr)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
                    error("end.unrecognized", elemStr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
                    // Ignore RE before end tag
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
                    if ((textpos > 0) && (text[textpos-1] == '\n')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
                        textpos--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
                    elem = dtd.getElement("unknown");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
                    elem.name = elemStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
                    unknown = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
                    elem = dtd.getElement(elemStr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
            // If the stack is null, we're seeing end tags without any begin
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
            // tags.  Ignore them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
            if (stack == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
                error("end.extra.tag", elem.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
            // Ignore RE before end tag
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
            if ((textpos > 0) && (text[textpos-1] == '\n')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
                // In a pre tag, if there are blank lines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
                // we do not want to remove the newline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
                // before the end tag.  Hence this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
                if (stack.pre) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
                    if ((textpos > 1) && (text[textpos-2] != '\n')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
                        textpos--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
                    textpos--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
            // If the end tag is a form, since we did not put it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
            // on the tag stack, there is no corresponding start
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
            // start tag to find. Hence do not touch the tag stack.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
            if (!strict && elem.getName().equals("form")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
                if (lastFormSent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
                    handleEndTag(lastFormSent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
                    // do nothing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
            */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
            if (unknown) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
                // we will not see a corresponding start tag
28059
e576535359cc 8067377: My hobby: caning, then then canning, the the can-can
martin
parents: 25859
diff changeset
  1849
                // on the stack.  If we are seeing an
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
                // end tag, lets send this on as an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
                // tag with the end tag attribute set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
                // true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
                TagElement t = makeTag(elem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
                handleText(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
                attributes.addAttribute(HTML.Attribute.ENDTAG, "true");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
                handleEmptyTag(makeTag(elem));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
                unknown = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
            // find the corresponding start tag
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
  1863
            // A commonly occurring error appears to be the insertion
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
            // of extra end tags in a table.  The intent here is ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
            // such extra end tags.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
            if (!strict) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
                String stackElem = stack.elem.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
                if (stackElem.equals("table")) {
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
  1871
                    // If it is not a valid end tag ignore it and return
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
                    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
                    if (!elem.getName().equals(stackElem)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
                        error("tag.ignore", elem.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
                if (stackElem.equals("tr") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
                    stackElem.equals("td")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
                    if ((!elem.getName().equals("table")) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
                        (!elem.getName().equals(stackElem))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
                        error("tag.ignore", elem.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
            TagStack sp = stack;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
            while ((sp != null) && (elem != sp.elem)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
                sp = sp.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
            if (sp == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
                error("unmatched.endtag", elem.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
            // People put font ending tags in the darndest places.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
            // Don't close other contexts based on them being between
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
            // a font tag and the corresponding end tag.  Instead,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
            // ignore the end tag like it doesn't exist and allow the end
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
            // of the document to close us out.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
            String elemName = elem.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
            if (stack != sp &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
                (elemName.equals("font") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
                 elemName.equals("center"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
                // Since closing out a center tag can have real wierd
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
                // effects on the formatting,  make sure that tags
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
                // for which omitting an end tag is legimitate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
                // get closed out.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
                if (elemName.equals("center")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
                    while(stack.elem.omitEnd() && stack != sp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
                        endTag(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
                    if (stack.elem == elem) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
                        endTag(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
            // People do the same thing with center tags.  In this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
            // case we would like to close off the center tag but
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
            // not necessarily all enclosing tags.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
            // end tags
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
            while (stack != sp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
                endTag(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
            endTag(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
          case -1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
            error("eof");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
        // start tag [14] 314:1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
        if (!parseIdentifier(true)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
            elem = recent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
            if ((ch != '>') || (elem == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
                error("expected.tagname");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
            String elemStr = getString(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
            if (elemStr.equals("image")) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
  1955
                elemStr = "img";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
            /* determine if this element is part of the dtd. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
            if (!dtd.elementExists(elemStr)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
                //              parseInvalidTag();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
                error("tag.unrecognized ", elemStr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
                elem = dtd.getElement("unknown");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
                elem.name = elemStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
                unknown = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
                elem = dtd.getElement(elemStr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
        // Parse attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
        parseAttributeSpecificationList(elem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
        switch (ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
          case '/':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
            net = true;
24528
21c5bb3d76cc 8039860: Fix fallthrough lint warnings in swing
darcy
parents: 23262
diff changeset
  1977
            // Fall through
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
          case '>':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
            ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
            if (ch == '>' && net) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
                ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
          case '<':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
            error("expected", "'>'");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
        if (!strict) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
          if (elem.getName().equals("script")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
            error("javascript.unsupported");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
        // ignore RE after start tag
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
        if (!elem.isEmpty())  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
            if (ch == '\n') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
                ln++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
                lfCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
                ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
            } else if (ch == '\r') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
                ln++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
                if ((ch = readCh()) == '\n') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
                    ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
                    crlfCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
                    crCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
        // ensure a legal context for the tag
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
        TagElement tag = makeTag(elem, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
        /** In dealing with forms, we have decided to treat
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
            them as legal in any context.  Also, even though
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
            they do have a start and an end tag, we will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
            not put this tag on the stack.  This is to deal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
            several pages in the web oasis that choose to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
            start and end forms in any possible location. **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
        if (!strict && elem.getName().equals("form")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
            if (lastFormSent == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
                lastFormSent = tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
                handleEndTag(lastFormSent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
                lastFormSent = tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
            // Smlly, if a tag is unknown, we will apply
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
            // no legalTagContext logic to it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
            if (!unknown) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
                legalTagContext(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
                // If skip tag is true,  this implies that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
                // the tag was illegal and that the error
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
                // recovery strategy adopted is to ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
                // the tag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
                if (!strict && skipTag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
                    skipTag = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
            */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
        startTag(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
        if (!elem.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
            switch (elem.getType()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
              case CDATA:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
                parseLiteral(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
              case RCDATA:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
                parseLiteral(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
              default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
                if (stack != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
                    stack.net = net;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
    private static final String START_COMMENT = "<!--";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
    private static final String END_COMMENT = "-->";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
    private static final char[] SCRIPT_END_TAG = "</script>".toCharArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
    private static final char[] SCRIPT_END_TAG_UPPER_CASE =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
                                        "</SCRIPT>".toCharArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
    void parseScript() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
        char[] charsToAdd = new char[SCRIPT_END_TAG.length];
17678
ec24ad8455ec 7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents: 14309
diff changeset
  2083
        boolean insideComment = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
        /* Here, ch should be the first character after <script> */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
            int i = 0;
17678
ec24ad8455ec 7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents: 14309
diff changeset
  2088
            while (!insideComment && i < SCRIPT_END_TAG.length
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
                       && (SCRIPT_END_TAG[i] == ch
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
                           || SCRIPT_END_TAG_UPPER_CASE[i] == ch)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
                charsToAdd[i] = (char) ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
                ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
                i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
            if (i == SCRIPT_END_TAG.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
                /*  '</script>' tag detected */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
                /* Here, ch == the first character after </script> */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
                /* To account for extra read()'s that happened */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
                for (int j = 0; j < i; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
                    addString(charsToAdd[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
                switch (ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
                case -1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
                    error("eof.script");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
                case '\n':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
                    ln++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
                    ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
                    lfCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
                    addString('\n');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
                case '\r':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
                    ln++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
                    if ((ch = readCh()) == '\n') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
                        ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
                        crlfCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
                        crCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
                    addString('\n');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
                    addString(ch);
17678
ec24ad8455ec 7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents: 14309
diff changeset
  2129
                    String str = new String(getChars(0, strpos));
ec24ad8455ec 7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents: 14309
diff changeset
  2130
                    if (!insideComment && str.endsWith(START_COMMENT)) {
ec24ad8455ec 7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents: 14309
diff changeset
  2131
                        insideComment = true;
ec24ad8455ec 7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents: 14309
diff changeset
  2132
                    }
ec24ad8455ec 7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents: 14309
diff changeset
  2133
                    if (insideComment && str.endsWith(END_COMMENT)) {
ec24ad8455ec 7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents: 14309
diff changeset
  2134
                        insideComment = false;
ec24ad8455ec 7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents: 14309
diff changeset
  2135
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
                    ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2137
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
                } // switch
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
        } // while
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2142
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2143
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
     * Parse Content. [24] 320:1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2146
    void parseContent() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
        Thread curThread = Thread.currentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
        for (;;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
            if (curThread.isInterrupted()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
                curThread.interrupt(); // resignal the interrupt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
            int c = ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
            currentBlockStartPos = currentPosition;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
            if (recent == dtd.script) { // means: if after starting <script> tag
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
                /* Here, ch has to be the first character after <script> */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
                parseScript();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
                last = makeTag(dtd.getElement("comment"), true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
                /* Remove leading and trailing HTML comment declarations */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
                String str = new String(getChars(0)).trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
                int minLength = START_COMMENT.length() + END_COMMENT.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
                if (str.startsWith(START_COMMENT) && str.endsWith(END_COMMENT)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
                       && str.length() >= (minLength)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
                    str = str.substring(START_COMMENT.length(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
                                      str.length() - END_COMMENT.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
                /* Handle resulting chars as comment */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
                handleComment(str.toCharArray());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
                endTag(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
                lastBlockStartPos = currentPosition;
12999
d0cec5582bd7 7165725: JAVA6 HTML PARSER CANNOT PARSE MULTIPLE SCRIPT TAGS IN A LINE CORRECTLY
rupashka
parents: 9213
diff changeset
  2177
d0cec5582bd7 7165725: JAVA6 HTML PARSER CANNOT PARSE MULTIPLE SCRIPT TAGS IN A LINE CORRECTLY
rupashka
parents: 9213
diff changeset
  2178
                continue;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
                switch (c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
                  case '<':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
                    parseTag();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
                    lastBlockStartPos = currentPosition;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
                  case '/':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
                    ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
                    if ((stack != null) && stack.net) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
                        // null end tag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
                        endTag(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
                        continue;
23262
41f2413bba45 8028616: Htmleditorkit parser doesn't handle leading slash (/)
dmarkov
parents: 21278
diff changeset
  2192
                    } else if (textpos == 0) {
41f2413bba45 8028616: Htmleditorkit parser doesn't handle leading slash (/)
dmarkov
parents: 21278
diff changeset
  2193
                        if (!legalElementContext(dtd.pcdata)) {
41f2413bba45 8028616: Htmleditorkit parser doesn't handle leading slash (/)
dmarkov
parents: 21278
diff changeset
  2194
                            error("unexpected.pcdata");
41f2413bba45 8028616: Htmleditorkit parser doesn't handle leading slash (/)
dmarkov
parents: 21278
diff changeset
  2195
                        }
41f2413bba45 8028616: Htmleditorkit parser doesn't handle leading slash (/)
dmarkov
parents: 21278
diff changeset
  2196
                        if (last.breaksFlow()) {
41f2413bba45 8028616: Htmleditorkit parser doesn't handle leading slash (/)
dmarkov
parents: 21278
diff changeset
  2197
                            space = false;
41f2413bba45 8028616: Htmleditorkit parser doesn't handle leading slash (/)
dmarkov
parents: 21278
diff changeset
  2198
                        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
                  case -1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2204
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
                  case '&':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
                    if (textpos == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
                        if (!legalElementContext(dtd.pcdata)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
                            error("unexpected.pcdata");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
                        if (last.breaksFlow()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
                            space = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
                    char data[] = parseEntityReference();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
                    if (textpos + data.length + 1 > text.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
                        char newtext[] = new char[Math.max(textpos + data.length + 128, text.length * 2)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2217
                        System.arraycopy(text, 0, newtext, 0, text.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2218
                        text = newtext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
                    if (space) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
                        space = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
                        text[textpos++] = ' ';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
                    System.arraycopy(data, 0, text, textpos, data.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
                    textpos += data.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
                    ignoreSpace = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
                  case '\n':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
                    ln++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
                    lfCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2232
                    ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
                    if ((stack != null) && stack.pre) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
                    if (textpos == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
                        lastBlockStartPos = currentPosition;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
                    if (!ignoreSpace) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2240
                        space = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
                  case '\r':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2245
                    ln++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
                    c = '\n';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2247
                    if ((ch = readCh()) == '\n') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2248
                        ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2249
                        crlfCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2250
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2251
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2252
                        crCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2253
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2254
                    if ((stack != null) && stack.pre) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2255
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2256
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2257
                    if (textpos == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2258
                        lastBlockStartPos = currentPosition;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2259
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2260
                    if (!ignoreSpace) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2261
                        space = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2262
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2263
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2264
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2265
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2266
                  case '\t':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2267
                  case ' ':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2268
                    ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2269
                    if ((stack != null) && stack.pre) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2270
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2271
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2272
                    if (textpos == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
                        lastBlockStartPos = currentPosition;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
                    if (!ignoreSpace) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
                        space = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2277
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2278
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2279
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2280
                  default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2281
                    if (textpos == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2282
                        if (!legalElementContext(dtd.pcdata)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2283
                            error("unexpected.pcdata");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2284
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2285
                        if (last.breaksFlow()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2286
                            space = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
                    ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2291
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2292
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2294
            // enlarge buffer if needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
            if (textpos + 2 > text.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2296
                char newtext[] = new char[text.length + 128];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2297
                System.arraycopy(text, 0, newtext, 0, text.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2298
                text = newtext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2299
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2300
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2301
            // output pending space
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2302
            if (space) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2303
                if (textpos == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2304
                    lastBlockStartPos--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2305
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2306
                text[textpos++] = ' ';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2307
                space = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2308
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2309
            text[textpos++] = (char)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2310
            ignoreSpace = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2311
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2312
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2313
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2315
     * Returns the end of line string. This will return the end of line
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2316
     * string that has been encountered the most, one of \r, \n or \r\n.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2318
    String getEndOfLineString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2319
        if (crlfCount >= crCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2320
            if (lfCount >= crlfCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2321
                return "\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2322
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2323
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2324
                return "\r\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2325
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2326
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2327
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2328
            if (crCount > lfCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2329
                return "\r";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2330
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2331
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2332
                return "\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2333
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2334
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2335
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2336
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2337
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2338
     * Parse an HTML stream, given a DTD.
24494
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
  2339
     *
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
  2340
     * @param in  the reader to read the source from
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 23262
diff changeset
  2341
     * @throws IOException if an I/O error occurs
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2342
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2343
    public synchronized void parse(Reader in) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2344
        this.in = in;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2345
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2346
        this.ln = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2347
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2348
        seenHtml = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2349
        seenHead = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2350
        seenBody = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2351
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2352
        crCount = lfCount = crlfCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2353
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2354
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2355
            ch = readCh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2356
            text = new char[1024];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2357
            str = new char[128];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2358
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2359
            parseContent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2360
            // NOTE: interruption may have occurred.  Control flows out
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2361
            // of here normally.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2362
            while (stack != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2363
                endTag(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2364
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2365
            in.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2366
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2367
            errorContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2368
            error("ioexception");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2369
            throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2370
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2371
            errorContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2372
            error("exception", e.getClass().getName(), e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2373
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2374
        } catch (ThreadDeath e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2375
            errorContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2376
            error("terminated");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2377
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2378
            throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2379
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2380
            for (; stack != null ; stack = stack.next) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2381
                handleEndTag(stack.tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2382
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2383
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2384
            text = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2385
            str = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2386
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2387
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2388
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2389
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2390
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2391
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2392
     * Input cache.  This is much faster than calling down to a synchronized
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2393
     * method of BufferedReader for each byte.  Measurements done 5/30/97
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2394
     * show that there's no point in having a bigger buffer:  Increasing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2395
     * the buffer to 8192 had no measurable impact for a program discarding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2396
     * one character at a time (reading from an http URL to a local machine).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2397
     * NOTE: If the current encoding is bogus, and we read too much
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2398
     * (past the content-type) we may suffer a MalformedInputException. For
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2399
     * this reason the initial size is 1 and when the body is encountered the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2400
     * size is adjusted to 256.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2401
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2402
    private char buf[] = new char[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2403
    private int pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2404
    private int len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2405
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2406
        tracks position relative to the beginning of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2407
        document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2408
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2409
    private int currentPosition;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2410
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2411
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2412
    private final int readCh() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2413
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2414
        if (pos >= len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2415
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2416
            // This loop allows us to ignore interrupts if the flag
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2417
            // says so
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2418
            for (;;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2419
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2420
                    len = in.read(buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2421
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2422
                } catch (InterruptedIOException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2423
                    throw ex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2424
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2425
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2426
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2427
            if (len <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2428
                return -1;      // eof
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2429
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2430
            pos = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2431
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2432
        ++currentPosition;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2433
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2434
        return buf[pos++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2435
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2436
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2437
25147
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24567
diff changeset
  2438
    /**
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24567
diff changeset
  2439
     * Returns the current position.
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24567
diff changeset
  2440
     *
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24567
diff changeset
  2441
     * @return the current position
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24567
diff changeset
  2442
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2443
    protected int getCurrentPos() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2444
        return currentPosition;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2445
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2446
}