ContentModelState.java revision 2362
286N/A * Copyright (c) 1998, 2000, Oracle and/or its affiliates. All rights reserved. 286N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 286N/A * This code is free software; you can redistribute it and/or modify it 286N/A * under the terms of the GNU General Public License version 2 only, as 286N/A * published by the Free Software Foundation. Oracle designates this 286N/A * particular file as subject to the "Classpath" exception as provided 286N/A * by Oracle in the LICENSE file that accompanied this code. 286N/A * This code is distributed in the hope that it will be useful, but WITHOUT 286N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 286N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 286N/A * version 2 for more details (a copy is included in the LICENSE file that 286N/A * accompanied this code). 286N/A * You should have received a copy of the GNU General Public License version 286N/A * 2 along with this work; if not, write to the Free Software Foundation, 286N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 286N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 286N/A * or visit www.oracle.com if you need additional information or have any 286N/A * A content model state. This is basically a list of pointers to 286N/A * the BNF expression representing the model (the ContentModel). 286N/A * Each element in a DTD has a content model which describes the 286N/A * elements that may occur inside, and the order in which they can 286N/A * Each time a token is reduced a new state is created. 286N/A * See Annex H on page 556 of the SGML handbook for more information. 286N/A * @author Arthur van Hoff 286N/A * Create a content model state for a content model. 286N/A * Create a content model state for a content model given the 286N/A * remaining state that needs to be reduce. 286N/A * Create a content model state for a content model given the 286N/A * remaining state that needs to be reduce. 286N/A * Return the content model that is relevant to the current state. * Check if the state can be terminated. That is there are no more * tokens required in the input stream. * @return true if the model can terminate without further input for (
int i =
0 ; m !=
null ; i++, m = m.
next) {
if ((
value & (
1L << i)) ==
0) {
for (
int i =
0 ; i <
value ; i++, m = m.
next);
* Check if the state can be terminated. That is there are no more * tokens required in the input stream. * @return the only possible element that can occur next for (
int i =
0 ; i <
value ; i++, m = m.
next);
* Advance this state to a new state. An exception is thrown if the * token is illegal at this point in the content model. * @return next state after reducing a token for (
int i =
0 ; i <
value ; i++, m = m.
next);
for (
int i =
0 ; m !=
null ; i++, m = m.
next) {
if ((
value & (
1L << i)) ==
0) {
// PENDING: Currently we don't correctly deal with optional start // tags. This can most notably be seen with the 4.01 spec where // TBODY's start and end tags are optional. // Uncommenting this and the PENDING in ContentModel will // correctly skip the omit tags, but the delegate is not notified. // Some additional API needs to be added to track skipped tags, // and this can then be added back. if ((model.content instanceof Element)) { Element e = (Element)model.content; if (e.omitStart() && e.content != null) { return new ContentModelState(e.content, next).advance( // We used to throw this exception at this point. However, it // was determined that throwing this exception was more expensive // than returning null, and we could not justify to ourselves why // it was necessary to throw an exception, rather than simply // returning null. I'm leaving it in a commented out state so // that it can be easily restored if the situation ever arises. // throw new IllegalArgumentException("invalid token: " + token);