jdk/src/share/classes/javax/swing/text/html/parser/ContentModelState.java
author rupashka
Mon, 21 Jun 2010 16:47:05 +0400
changeset 6862 f66eb6b6a6b9
parent 5506 202f599c92aa
child 24528 21c5bb3d76cc
permissions -rw-r--r--
6938813: Swing mutable statics Reviewed-by: peterz, alexp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1998, 2000, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.swing.text.html.parser;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * A content model state. This is basically a list of pointers to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * the BNF expression representing the model (the ContentModel).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * Each element in a DTD has a content model which describes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * elements that may occur inside, and the order in which they can
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * occur.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * Each time a token is reduced a new state is created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * See Annex H on page 556 of the SGML handbook for more information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * @see Parser
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * @see DTD
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * @see Element
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * @see ContentModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * @author Arthur van Hoff
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
class ContentModelState {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    ContentModel model;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    long value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    ContentModelState next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * Create a content model state for a content model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    public ContentModelState(ContentModel model) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        this(model, null, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * Create a content model state for a content model given the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * remaining state that needs to be reduce.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    ContentModelState(Object content, ContentModelState next) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        this(content, next, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * Create a content model state for a content model given the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * remaining state that needs to be reduce.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    ContentModelState(Object content, ContentModelState next, long value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        this.model = (ContentModel)content;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        this.next = next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        this.value = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * Return the content model that is relevant to the current state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public ContentModel getModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        ContentModel m = model;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        for (int i = 0; i < value; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            if (m.next != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                m = m.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        return m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * Check if the state can be terminated. That is there are no more
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * tokens required in the input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * @return true if the model can terminate without further input
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    public boolean terminate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        switch (model.type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
          case '+':
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            if ((value == 0) && !(model).empty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
          case '*':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
          case '?':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            return (next == null) || next.terminate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
          case '|':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            for (ContentModel m = (ContentModel)model.content ; m != null ; m = m.next) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                if (m.empty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                    return (next == null) || next.terminate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
          case '&': {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            ContentModel m = (ContentModel)model.content;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            for (int i = 0 ; m != null ; i++, m = m.next) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                if ((value & (1L << i)) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                    if (!m.empty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            return (next == null) || next.terminate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
          case ',': {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            ContentModel m = (ContentModel)model.content;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            for (int i = 0 ; i < value ; i++, m = m.next);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            for (; (m != null) && m.empty() ; m = m.next);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            if (m != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            return (next == null) || next.terminate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
          return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * Check if the state can be terminated. That is there are no more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * tokens required in the input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @return the only possible element that can occur next
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    public Element first() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        switch (model.type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
          case '*':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
          case '?':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
          case '|':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
          case '&':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
          case '+':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            return model.first();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
          case ',': {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
              ContentModel m = (ContentModel)model.content;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
              for (int i = 0 ; i < value ; i++, m = m.next);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
              return m.first();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            return model.first();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * Advance this state to a new state. An exception is thrown if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * token is illegal at this point in the content model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @return next state after reducing a token
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    public ContentModelState advance(Object token) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        switch (model.type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
          case '+':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            if (model.first(token)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                return new ContentModelState(model.content,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                        new ContentModelState(model, next, value + 1)).advance(token);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            if (value != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                if (next != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                    return next.advance(token);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
          case '*':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            if (model.first(token)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                return new ContentModelState(model.content, this).advance(token);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            if (next != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                return next.advance(token);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
          case '?':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            if (model.first(token)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                return new ContentModelState(model.content, next).advance(token);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            if (next != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                return next.advance(token);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
          case '|':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            for (ContentModel m = (ContentModel)model.content ; m != null ; m = m.next) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                if (m.first(token)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                    return new ContentModelState(m, next).advance(token);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
          case ',': {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            ContentModel m = (ContentModel)model.content;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            for (int i = 0 ; i < value ; i++, m = m.next);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            if (m.first(token) || m.empty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                if (m.next == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                    return new ContentModelState(m, next).advance(token);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                    return new ContentModelState(m,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                            new ContentModelState(model, next, value + 1)).advance(token);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
          case '&': {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            ContentModel m = (ContentModel)model.content;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            boolean complete = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            for (int i = 0 ; m != null ; i++, m = m.next) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                if ((value & (1L << i)) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                    if (m.first(token)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                        return new ContentModelState(m,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                                new ContentModelState(model, next, value | (1L << i))).advance(token);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                    if (!m.empty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                        complete = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            if (complete) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                if (next != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                    return next.advance(token);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            if (model.content == token) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                if (next == null && (token instanceof Element) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                    ((Element)token).content != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                    return new ContentModelState(((Element)token).content);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                return next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            // PENDING: Currently we don't correctly deal with optional start
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            // tags. This can most notably be seen with the 4.01 spec where
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            // TBODY's start and end tags are optional.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            // Uncommenting this and the PENDING in ContentModel will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            // correctly skip the omit tags, but the delegate is not notified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            // Some additional API needs to be added to track skipped tags,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            // and this can then be added back.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            if ((model.content instanceof Element)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                Element e = (Element)model.content;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                if (e.omitStart() && e.content != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                    return new ContentModelState(e.content, next).advance(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                                           token);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        // We used to throw this exception at this point.  However, it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        // was determined that throwing this exception was more expensive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        // than returning null, and we could not justify to ourselves why
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        // it was necessary to throw an exception, rather than simply
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        // returning null.  I'm leaving it in a commented out state so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        // that it can be easily restored if the situation ever arises.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        // throw new IllegalArgumentException("invalid token: " + token);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
}