~ubuntu-branches/ubuntu/karmic/libxerces2-java/karmic

« back to all changes in this revision

Viewing changes to src/org/apache/xerces/impl/dtd/XMLDTDValidator.java

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2006-12-04 17:37:55 UTC
  • mfrom: (2.1.2 etch)
  • Revision ID: james.westby@ubuntu.com-20061204173755-hb6ybrrrk097zhx7
Tags: 2.8.1-1ubuntu1
* Merge with Debian unstable; remaining changes:
  - Build -gcj package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * The Apache Software License, Version 1.1
3
 
 *
4
 
 *
5
 
 * Copyright (c) 1999-2003 The Apache Software Foundation.  
6
 
 * All rights reserved.
7
 
 *
8
 
 * Redistribution and use in source and binary forms, with or without
9
 
 * modification, are permitted provided that the following conditions
10
 
 * are met:
11
 
 *
12
 
 * 1. Redistributions of source code must retain the above copyright
13
 
 *    notice, this list of conditions and the following disclaimer. 
14
 
 *
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
18
 
 *    distribution.
19
 
 *
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.
26
 
 *
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.
31
 
 *
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.
35
 
 *
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
47
 
 * SUCH DAMAGE.
48
 
 * ====================================================================
49
 
 *
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.
 
3
 * 
 
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
 
7
 * 
 
8
 *      http://www.apache.org/licenses/LICENSE-2.0
 
9
 * 
 
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.
56
15
 */
57
16
 
58
17
package org.apache.xerces.impl.dtd;
59
18
 
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>
114
73
 * </ul>
 
74
 * 
 
75
 * @xerces.internal
115
76
 *
116
77
 * @author Eric Ye, IBM
117
78
 * @author Andy Clark, IBM
118
79
 * @author Jeffrey Rodriguez IBM
119
80
 * @author Neil Graham, IBM
120
81
 *
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 $
122
83
 */
123
84
public class XMLDTDValidator
124
 
        implements XMLComponent, XMLDocumentFilter, XMLDTDValidatorFilter {
 
85
        implements XMLComponent, XMLDocumentFilter, XMLDTDValidatorFilter, RevalidationHandler {
125
86
 
126
87
    //
127
88
    // Constants
136
97
 
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;
140
101
 
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;
144
105
 
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;
 
109
    
 
110
    /** Feature identifier: balance syntax trees. */
 
111
    protected static final String BALANCE_SYNTAX_TREES =
 
112
        Constants.XERCES_FEATURE_PREFIX + Constants.BALANCE_SYNTAX_TREES;
148
113
 
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; 
152
117
    
153
118
        protected static final String PARSER_SETTINGS = 
154
119
                Constants.XERCES_FEATURE_PREFIX + Constants.PARSER_SETTINGS;    
183
148
    private static final String[] RECOGNIZED_FEATURES = {
184
149
        NAMESPACES,
185
150
        VALIDATION,
186
 
        DYNAMIC_VALIDATION
 
151
        DYNAMIC_VALIDATION,
 
152
        BALANCE_SYNTAX_TREES
187
153
    };
188
154
 
189
155
    /** Feature defaults. */
191
157
        null,
192
158
        null,
193
159
        Boolean.FALSE,
 
160
        Boolean.FALSE,
194
161
    };
195
162
 
196
163
    /** Recognized properties. */
245
212
     * the validation feature is set to <code>true</code>.
246
213
     */
247
214
    protected boolean fDynamicValidation;
 
215
    
 
216
    /** Controls whether the DTD grammar produces balanced syntax trees. */
 
217
    protected boolean fBalanceSyntaxTrees;
248
218
 
249
219
    /** warn on duplicate attribute definition, this feature works only when validation is true */
250
220
    protected boolean fWarnDuplicateAttdef;
508
478
        }
509
479
        
510
480
        try {
 
481
            fBalanceSyntaxTrees = componentManager.getFeature(BALANCE_SYNTAX_TREES);
 
482
        }
 
483
        catch (XMLConfigurationException e) {
 
484
            fBalanceSyntaxTrees = false;
 
485
        }
 
486
        
 
487
        try {
511
488
            fWarnDuplicateAttdef = componentManager.getFeature(WARN_ON_DUPLICATE_ATTDEF);
512
489
        }
513
490
        catch (XMLConfigurationException e) {
759
736
        fDTDGrammar = fGrammarBucket.getGrammar(grammarDesc);
760
737
        if(fDTDGrammar == null) {
761
738
            // give grammar pool a chance...
762
 
            if(fGrammarPool != null) {
 
739
            //
 
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);
764
748
            }
765
749
        }
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);
 
754
            }
 
755
            else {
 
756
                fDTDGrammar = new BalancedDTDGrammar(fSymbolTable, grammarDesc);
 
757
            }
769
758
        } else {
770
759
            // we've found a cached one;so let's make sure not to read
771
760
            // any external subset!
874
863
                }
875
864
                
876
865
                // For E15.2
877
 
                if (augs != null && augs.getItem(XMLDocumentFragmentScannerImpl.CHAR_REF) == Boolean.TRUE) {
 
866
                if (augs != null && augs.getItem(Constants.CHAR_REF_PROBABLE_WS) == Boolean.TRUE) {
878
867
                    fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 
879
868
                                               "MSG_CONTENT_INVALID_SPECIFIED",
880
869
                                               new Object[]{ fCurrentElement.rawname, 
1863
1852
    } // init()
1864
1853
 
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];
1869
1857
 
1870
1858
            QName[] newStackOfQueue = new QName[newElementDepth * 2];
1871
1859
            System.arraycopy(this.fElementQNamePartsStack, 0, newStackOfQueue, 0, newElementDepth );
1872
 
            fElementQNamePartsStack      = newStackOfQueue;
 
1860
            fElementQNamePartsStack = newStackOfQueue;
1873
1861
 
1874
1862
            QName qname = fElementQNamePartsStack[newElementDepth];
1875
1863
            if (qname == null) {
1878
1866
                }
1879
1867
            }
1880
1868
 
1881
 
            newStack = new int[newElementDepth * 2];
 
1869
            int[] newStack = new int[newElementDepth * 2];
1882
1870
            System.arraycopy(fElementIndexStack, 0, newStack, 0, newElementDepth);
1883
1871
            fElementIndexStack = newStack;
1884
1872
 
2116
2104
        return XMLChar.isSpace(c);
2117
2105
    } // isSpace(int):  boolean
2118
2106
 
 
2107
    public boolean characterData(String data, Augmentations augs) {       
 
2108
        characters(new XMLString(data.toCharArray(), 0, data.length()), augs);
 
2109
        return true;
 
2110
    }
 
2111
 
2119
2112
} // class XMLDTDValidator