2
* The Apache Software License, Version 1.1
5
* Copyright (c) 1999-2003 The Apache Software Foundation.
8
* Redistribution and use in source and binary forms, with or without
9
* modification, are permitted provided that the following conditions
12
* 1. Redistributions of source code must retain the above copyright
13
* notice, this list of conditions and the following disclaimer.
15
* 2. Redistributions in binary form must reproduce the above copyright
16
* notice, this list of conditions and the following disclaimer in
17
* the documentation and/or other materials provided with the
20
* 3. The end-user documentation included with the redistribution,
21
* if any, must include the following acknowledgment:
22
* "This product includes software developed by the
23
* Apache Software Foundation (http://www.apache.org/)."
24
* Alternately, this acknowledgment may appear in the software itself,
25
* if and wherever such third-party acknowledgments normally appear.
27
* 4. The names "Xerces" and "Apache Software Foundation" must
28
* not be used to endorse or promote products derived from this
29
* software without prior written permission. For written
30
* permission, please contact apache@apache.org.
32
* 5. Products derived from this software may not be called "Apache",
33
* nor may "Apache" appear in their name, without prior written
34
* permission of the Apache Software Foundation.
36
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48
* ====================================================================
50
* This software consists of voluntary contributions made by many
51
* individuals on behalf of the Apache Software Foundation and was
52
* originally based on software copyright (c) 1999, International
53
* Business Machines, Inc., http://www.apache.org. For more
54
* information on the Apache Software Foundation, please see
55
* <http://www.apache.org/>.
2
* Copyright 1999-2006 The Apache Software Foundation.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
58
17
package org.apache.xerces.impl.dtd;
60
19
import org.apache.xerces.impl.Constants;
61
import org.apache.xerces.impl.XMLDocumentFragmentScannerImpl;
20
import org.apache.xerces.impl.RevalidationHandler;
62
21
import org.apache.xerces.impl.XMLEntityManager;
63
22
import org.apache.xerces.impl.XMLErrorReporter;
64
23
import org.apache.xerces.impl.dtd.models.ContentModelValidator;
112
71
* <li>http://apache.org/xml/properties/internal/grammar-pool</li>
113
72
* <li>http://apache.org/xml/properties/internal/datatype-validator-factory</li>
116
77
* @author Eric Ye, IBM
117
78
* @author Andy Clark, IBM
118
79
* @author Jeffrey Rodriguez IBM
119
80
* @author Neil Graham, IBM
121
* @version $Id: XMLDTDValidator.java,v 1.56 2003/12/09 07:41:28 venu Exp $
82
* @version $Id: XMLDTDValidator.java 441882 2006-09-10 00:24:52Z mrglavas $
123
84
public class XMLDTDValidator
124
implements XMLComponent, XMLDocumentFilter, XMLDTDValidatorFilter {
85
implements XMLComponent, XMLDocumentFilter, XMLDTDValidatorFilter, RevalidationHandler {
137
98
/** Feature identifier: namespaces. */
138
99
protected static final String NAMESPACES =
139
Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE;
100
Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE;
141
102
/** Feature identifier: validation. */
142
103
protected static final String VALIDATION =
143
Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE;
104
Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE;
145
106
/** Feature identifier: dynamic validation. */
146
107
protected static final String DYNAMIC_VALIDATION =
147
Constants.XERCES_FEATURE_PREFIX + Constants.DYNAMIC_VALIDATION_FEATURE;
108
Constants.XERCES_FEATURE_PREFIX + Constants.DYNAMIC_VALIDATION_FEATURE;
110
/** Feature identifier: balance syntax trees. */
111
protected static final String BALANCE_SYNTAX_TREES =
112
Constants.XERCES_FEATURE_PREFIX + Constants.BALANCE_SYNTAX_TREES;
149
114
/** Feature identifier: warn on duplicate attdef */
150
115
protected static final String WARN_ON_DUPLICATE_ATTDEF =
151
Constants.XERCES_FEATURE_PREFIX +Constants.WARN_ON_DUPLICATE_ATTDEF_FEATURE;
116
Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_DUPLICATE_ATTDEF_FEATURE;
153
118
protected static final String PARSER_SETTINGS =
154
119
Constants.XERCES_FEATURE_PREFIX + Constants.PARSER_SETTINGS;
759
736
fDTDGrammar = fGrammarBucket.getGrammar(grammarDesc);
760
737
if(fDTDGrammar == null) {
761
738
// give grammar pool a chance...
762
if(fGrammarPool != null) {
740
// Do not bother checking the pool if no public or system identifier was provided.
741
// Since so many different DTDs have roots in common, using only a root name as the
742
// key may cause an unexpected grammar to be retrieved from the grammar pool. This scenario
743
// would occur when an ExternalSubsetResolver has been queried and the
744
// XMLInputSource returned contains an input stream but no external identifier.
745
// This can never happen when the instance document specified a DOCTYPE. -- mrglavas
746
if (fGrammarPool != null && (systemId != null || publicId != null)) {
763
747
fDTDGrammar = (DTDGrammar)fGrammarPool.retrieveGrammar(grammarDesc);
766
750
if(fDTDGrammar == null) {
767
751
// we'll have to create it...
768
fDTDGrammar = new DTDGrammar(fSymbolTable, grammarDesc);
752
if (!fBalanceSyntaxTrees) {
753
fDTDGrammar = new DTDGrammar(fSymbolTable, grammarDesc);
756
fDTDGrammar = new BalancedDTDGrammar(fSymbolTable, grammarDesc);
770
759
// we've found a cached one;so let's make sure not to read
771
760
// any external subset!
1865
1854
/** ensure element stack capacity */
1866
private void ensureStackCapacity ( int newElementDepth) {
1855
private void ensureStackCapacity (int newElementDepth) {
1867
1856
if (newElementDepth == fElementQNamePartsStack.length) {
1868
int[] newStack = new int[newElementDepth * 2];
1870
1858
QName[] newStackOfQueue = new QName[newElementDepth * 2];
1871
1859
System.arraycopy(this.fElementQNamePartsStack, 0, newStackOfQueue, 0, newElementDepth );
1872
fElementQNamePartsStack = newStackOfQueue;
1860
fElementQNamePartsStack = newStackOfQueue;
1874
1862
QName qname = fElementQNamePartsStack[newElementDepth];
1875
1863
if (qname == null) {