KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xerces > internal > impl > XMLDocumentScannerImpl


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 1999-2004 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/>.
56  */

57
58 package com.sun.org.apache.xerces.internal.impl;
59
60 import java.io.CharConversionException JavaDoc;
61 import java.io.EOFException JavaDoc;
62 import java.io.IOException JavaDoc;
63
64 import com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDDescription;
65 import com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException;
66 import com.sun.org.apache.xerces.internal.impl.validation.ValidationManager;
67 import com.sun.org.apache.xerces.internal.util.NamespaceSupport;
68 import com.sun.org.apache.xerces.internal.util.XMLChar;
69 import com.sun.org.apache.xerces.internal.util.XMLEntityDescriptionImpl;
70 import com.sun.org.apache.xerces.internal.util.XMLStringBuffer;
71 import com.sun.org.apache.xerces.internal.xni.Augmentations;
72 import com.sun.org.apache.xerces.internal.xni.NamespaceContext;
73 import com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier;
74 import com.sun.org.apache.xerces.internal.xni.XMLString;
75 import com.sun.org.apache.xerces.internal.xni.XNIException;
76 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager;
77 import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;
78 import com.sun.org.apache.xerces.internal.xni.parser.XMLDTDScanner;
79 import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;
80
81 /**
82  * This class is responsible for scanning XML document structure
83  * and content. The scanner acts as the source for the document
84  * information which is communicated to the document handler.
85  * <p>
86  * This component requires the following features and properties from the
87  * component manager that uses it:
88  * <ul>
89  * <li>http://xml.org/sax/features/namespaces</li>
90  * <li>http://xml.org/sax/features/validation</li>
91  * <li>http://apache.org/xml/features/nonvalidating/load-external-dtd</li>
92  * <li>http://apache.org/xml/features/scanner/notify-char-refs</li>
93  * <li>http://apache.org/xml/features/scanner/notify-builtin-refs</li>
94  * <li>http://apache.org/xml/properties/internal/symbol-table</li>
95  * <li>http://apache.org/xml/properties/internal/error-reporter</li>
96  * <li>http://apache.org/xml/properties/internal/entity-manager</li>
97  * <li>http://apache.org/xml/properties/internal/dtd-scanner</li>
98  * </ul>
99  *
100  * @author Glenn Marcy, IBM
101  * @author Andy Clark, IBM
102  * @author Arnaud Le Hors, IBM
103  * @author Eric Ye, IBM
104  *
105  * @version $Id: XMLDocumentScannerImpl.java,v 1.45 2004/04/30 15:36:38 mrglavas Exp $
106  */

107 public class XMLDocumentScannerImpl
108     extends XMLDocumentFragmentScannerImpl {
109
110     //
111
// Constants
112
//
113

114     // scanner states
115

116     /** Scanner state: XML declaration. */
117     protected static final int SCANNER_STATE_XML_DECL = 0;
118
119     /** Scanner state: prolog. */
120     protected static final int SCANNER_STATE_PROLOG = 5;
121
122     /** Scanner state: trailing misc. */
123     protected static final int SCANNER_STATE_TRAILING_MISC = 12;
124
125     /** Scanner state: DTD internal declarations. */
126     protected static final int SCANNER_STATE_DTD_INTERNAL_DECLS = 17;
127
128     /** Scanner state: open DTD external subset. */
129     protected static final int SCANNER_STATE_DTD_EXTERNAL = 18;
130
131     /** Scanner state: DTD external declarations. */
132     protected static final int SCANNER_STATE_DTD_EXTERNAL_DECLS = 19;
133
134     // feature identifiers
135

136     /** Feature identifier: load external DTD. */
137     protected static final String JavaDoc LOAD_EXTERNAL_DTD =
138         Constants.XERCES_FEATURE_PREFIX + Constants.LOAD_EXTERNAL_DTD_FEATURE;
139
140     /** Feature identifier: load external DTD. */
141     protected static final String JavaDoc DISALLOW_DOCTYPE_DECL_FEATURE =
142         Constants.XERCES_FEATURE_PREFIX + Constants.DISALLOW_DOCTYPE_DECL_FEATURE;
143
144     // property identifiers
145

146     /** Property identifier: DTD scanner. */
147     protected static final String JavaDoc DTD_SCANNER =
148         Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_SCANNER_PROPERTY;
149
150     /** property identifier: ValidationManager */
151     protected static final String JavaDoc VALIDATION_MANAGER =
152         Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY;
153
154     /** property identifier: NamespaceContext */
155     protected static final String JavaDoc NAMESPACE_CONTEXT =
156         Constants.XERCES_PROPERTY_PREFIX + Constants.NAMESPACE_CONTEXT_PROPERTY;
157         
158
159
160     // recognized features and properties
161

162     /** Recognized features. */
163     private static final String JavaDoc[] RECOGNIZED_FEATURES = {
164         LOAD_EXTERNAL_DTD,
165         DISALLOW_DOCTYPE_DECL_FEATURE,
166     };
167
168     /** Feature defaults. */
169     private static final Boolean JavaDoc[] FEATURE_DEFAULTS = {
170         Boolean.TRUE,
171         Boolean.FALSE,
172     };
173
174     /** Recognized properties. */
175     private static final String JavaDoc[] RECOGNIZED_PROPERTIES = {
176         DTD_SCANNER,
177         VALIDATION_MANAGER,
178         NAMESPACE_CONTEXT,
179     };
180
181     /** Property defaults. */
182     private static final Object JavaDoc[] PROPERTY_DEFAULTS = {
183         null,
184         null,
185         null,
186     };
187
188     //
189
// Data
190
//
191

192     // properties
193

194     /** DTD scanner. */
195     protected XMLDTDScanner fDTDScanner;
196     /** Validation manager . */
197     protected ValidationManager fValidationManager;
198
199     // protected data
200

201     /** Scanning DTD. */
202     protected boolean fScanningDTD;
203
204     // other info
205

206     /** Doctype name. */
207     protected String JavaDoc fDoctypeName;
208
209     /** Doctype declaration public identifier. */
210     protected String JavaDoc fDoctypePublicId;
211
212     /** Doctype declaration system identifier. */
213     protected String JavaDoc fDoctypeSystemId;
214
215     /** Namespace support. */
216     protected NamespaceContext fNamespaceContext = new NamespaceSupport();
217
218     // features
219

220     /** Load external DTD. */
221     protected boolean fLoadExternalDTD = true;
222
223     /** Disallow doctype declaration. */
224     protected boolean fDisallowDoctype = false;
225
226     // state
227

228     /** Seen doctype declaration. */
229     protected boolean fSeenDoctypeDecl;
230
231     // dispatchers
232

233     /** XML declaration dispatcher. */
234     protected Dispatcher fXMLDeclDispatcher = new XMLDeclDispatcher();
235
236     /** Prolog dispatcher. */
237     protected Dispatcher fPrologDispatcher = new PrologDispatcher();
238
239     /** DTD dispatcher. */
240     protected Dispatcher fDTDDispatcher = new DTDDispatcher();
241
242     /** Trailing miscellaneous section dispatcher. */
243     protected Dispatcher fTrailingMiscDispatcher = new TrailingMiscDispatcher();
244
245     // temporary variables
246

247     /** Array of 3 strings. */
248     private String JavaDoc[] fStrings = new String JavaDoc[3];
249
250     /** String. */
251     private XMLString fString = new XMLString();
252
253     /** String buffer. */
254     private XMLStringBuffer fStringBuffer = new XMLStringBuffer();
255     
256     /** External subset source. */
257     private XMLInputSource fExternalSubsetSource = null;
258
259     //
260
// Constructors
261
//
262

263     /** Default constructor. */
264     public XMLDocumentScannerImpl() {} // <init>()
265

266     //
267
// XMLDocumentScanner methods
268
//
269

270     /**
271      * Sets the input source.
272      *
273      * @param inputSource The input source.
274      *
275      * @throws IOException Thrown on i/o error.
276      */

277     public void setInputSource(XMLInputSource inputSource) throws IOException JavaDoc {
278         fEntityManager.setEntityHandler(this);
279         fEntityManager.startDocumentEntity(inputSource);
280         //fDocumentSystemId = fEntityManager.expandSystemId(inputSource.getSystemId());
281
} // setInputSource(XMLInputSource)
282

283     //
284
// XMLComponent methods
285
//
286

287     /**
288      * Resets the component. The component can query the component manager
289      * about any features and properties that affect the operation of the
290      * component.
291      *
292      * @param componentManager The component manager.
293      *
294      * @throws SAXException Thrown by component on initialization error.
295      * For example, if a feature or property is
296      * required for the operation of the component, the
297      * component manager may throw a
298      * SAXNotRecognizedException or a
299      * SAXNotSupportedException.
300      */

301     public void reset(XMLComponentManager componentManager)
302         throws XMLConfigurationException {
303
304         super.reset(componentManager);
305
306         // other settings
307
fDoctypeName = null;
308         fDoctypePublicId = null;
309         fDoctypeSystemId = null;
310         fSeenDoctypeDecl = false;
311         fScanningDTD = false;
312         fExternalSubsetSource = null;
313
314         if (!fParserSettings) {
315             // parser settings have not been changed
316
fNamespaceContext.reset();
317             // setup dispatcher
318
setScannerState(SCANNER_STATE_XML_DECL);
319             setDispatcher(fXMLDeclDispatcher);
320             return;
321         }
322
323         // xerces features
324
try {
325             fLoadExternalDTD = componentManager.getFeature(LOAD_EXTERNAL_DTD);
326         }
327         catch (XMLConfigurationException e) {
328             fLoadExternalDTD = true;
329         }
330         try {
331             fDisallowDoctype = componentManager.getFeature(DISALLOW_DOCTYPE_DECL_FEATURE);
332         }
333         catch (XMLConfigurationException e) {
334             fDisallowDoctype = false;
335         }
336
337         // xerces properties
338
fDTDScanner = (XMLDTDScanner)componentManager.getProperty(DTD_SCANNER);
339         try {
340             fValidationManager = (ValidationManager)componentManager.getProperty(VALIDATION_MANAGER);
341         }
342         catch (XMLConfigurationException e) {
343             fValidationManager = null;
344         }
345
346         try {
347             fNamespaceContext = (NamespaceContext)componentManager.getProperty(NAMESPACE_CONTEXT);
348         }
349         catch (XMLConfigurationException e) { }
350         if (fNamespaceContext == null) {
351             fNamespaceContext = new NamespaceSupport();
352         }
353         fNamespaceContext.reset();
354         
355         // setup dispatcher
356
setScannerState(SCANNER_STATE_XML_DECL);
357         setDispatcher(fXMLDeclDispatcher);
358
359     } // reset(XMLComponentManager)
360

361     /**
362      * Returns a list of feature identifiers that are recognized by
363      * this component. This method may return null if no features
364      * are recognized by this component.
365      */

366     public String JavaDoc[] getRecognizedFeatures() {
367         String JavaDoc[] featureIds = super.getRecognizedFeatures();
368         int length = featureIds != null ? featureIds.length : 0;
369         String JavaDoc[] combinedFeatureIds = new String JavaDoc[length + RECOGNIZED_FEATURES.length];
370         if (featureIds != null) {
371             System.arraycopy(featureIds, 0, combinedFeatureIds, 0, featureIds.length);
372         }
373         System.arraycopy(RECOGNIZED_FEATURES, 0, combinedFeatureIds, length, RECOGNIZED_FEATURES.length);
374         return combinedFeatureIds;
375     } // getRecognizedFeatures():String[]
376

377     /**
378      * Sets the state of a feature. This method is called by the component
379      * manager any time after reset when a feature changes state.
380      * <p>
381      * <strong>Note:</strong> Components should silently ignore features
382      * that do not affect the operation of the component.
383      *
384      * @param featureId The feature identifier.
385      * @param state The state of the feature.
386      *
387      * @throws SAXNotRecognizedException The component should not throw
388      * this exception.
389      * @throws SAXNotSupportedException The component should not throw
390      * this exception.
391      */

392     public void setFeature(String JavaDoc featureId, boolean state)
393         throws XMLConfigurationException {
394
395         super.setFeature(featureId, state);
396
397         // Xerces properties
398
if (featureId.startsWith(Constants.XERCES_FEATURE_PREFIX)) {
399             final int suffixLength = featureId.length() - Constants.XERCES_FEATURE_PREFIX.length();
400             
401             if (suffixLength == Constants.LOAD_EXTERNAL_DTD_FEATURE.length() &&
402                 featureId.endsWith(Constants.LOAD_EXTERNAL_DTD_FEATURE)) {
403                 fLoadExternalDTD = state;
404                 return;
405             }
406             else if (suffixLength == Constants.DISALLOW_DOCTYPE_DECL_FEATURE.length() &&
407                 featureId.endsWith(Constants.DISALLOW_DOCTYPE_DECL_FEATURE)) {
408                 fDisallowDoctype = state;
409                 return;
410             }
411         }
412
413     } // setFeature(String,boolean)
414

415     /**
416      * Returns a list of property identifiers that are recognized by
417      * this component. This method may return null if no properties
418      * are recognized by this component.
419      */

420     public String JavaDoc[] getRecognizedProperties() {
421         String JavaDoc[] propertyIds = super.getRecognizedProperties();
422         int length = propertyIds != null ? propertyIds.length : 0;
423         String JavaDoc[] combinedPropertyIds = new String JavaDoc[length + RECOGNIZED_PROPERTIES.length];
424         if (propertyIds != null) {
425             System.arraycopy(propertyIds, 0, combinedPropertyIds, 0, propertyIds.length);
426         }
427         System.arraycopy(RECOGNIZED_PROPERTIES, 0, combinedPropertyIds, length, RECOGNIZED_PROPERTIES.length);
428         return combinedPropertyIds;
429     } // getRecognizedProperties():String[]
430

431     /**
432      * Sets the value of a property. This method is called by the component
433      * manager any time after reset when a property changes value.
434      * <p>
435      * <strong>Note:</strong> Components should silently ignore properties
436      * that do not affect the operation of the component.
437      *
438      * @param propertyId The property identifier.
439      * @param value The value of the property.
440      *
441      * @throws SAXNotRecognizedException The component should not throw
442      * this exception.
443      * @throws SAXNotSupportedException The component should not throw
444      * this exception.
445      */

446     public void setProperty(String JavaDoc propertyId, Object JavaDoc value)
447         throws XMLConfigurationException {
448
449         super.setProperty(propertyId, value);
450
451         // Xerces properties
452
if (propertyId.startsWith(Constants.XERCES_PROPERTY_PREFIX)) {
453             final int suffixLength = propertyId.length() - Constants.XERCES_PROPERTY_PREFIX.length();
454             
455             if (suffixLength == Constants.DTD_SCANNER_PROPERTY.length() &&
456                 propertyId.endsWith(Constants.DTD_SCANNER_PROPERTY)) {
457                 fDTDScanner = (XMLDTDScanner)value;
458             }
459             if (suffixLength == Constants.NAMESPACE_CONTEXT_PROPERTY.length() &&
460                 propertyId.endsWith(Constants.NAMESPACE_CONTEXT_PROPERTY)) {
461                 if (value != null) {
462                     fNamespaceContext = (NamespaceContext)value;
463                 }
464             }
465
466             return;
467         }
468
469     } // setProperty(String,Object)
470

471     /**
472      * Returns the default state for a feature, or null if this
473      * component does not want to report a default value for this
474      * feature.
475      *
476      * @param featureId The feature identifier.
477      *
478      * @since Xerces 2.2.0
479      */

480     public Boolean JavaDoc getFeatureDefault(String JavaDoc featureId) {
481
482         for (int i = 0; i < RECOGNIZED_FEATURES.length; i++) {
483             if (RECOGNIZED_FEATURES[i].equals(featureId)) {
484                 return FEATURE_DEFAULTS[i];
485             }
486         }
487         return super.getFeatureDefault(featureId);
488     } // getFeatureDefault(String):Boolean
489

490     /**
491      * Returns the default state for a property, or null if this
492      * component does not want to report a default value for this
493      * property.
494      *
495      * @param propertyId The property identifier.
496      *
497      * @since Xerces 2.2.0
498      */

499     public Object JavaDoc getPropertyDefault(String JavaDoc propertyId) {
500         for (int i = 0; i < RECOGNIZED_PROPERTIES.length; i++) {
501             if (RECOGNIZED_PROPERTIES[i].equals(propertyId)) {
502                 return PROPERTY_DEFAULTS[i];
503             }
504         }
505         return super.getPropertyDefault(propertyId);
506     } // getPropertyDefault(String):Object
507

508     //
509
// XMLEntityHandler methods
510
//
511

512     /**
513      * This method notifies of the start of an entity. The DTD has the
514      * pseudo-name of "[dtd]" parameter entity names start with '%'; and
515      * general entities are just specified by their name.
516      *
517      * @param name The name of the entity.
518      * @param identifier The resource identifier.
519      * @param encoding The auto-detected IANA encoding name of the entity
520      * stream. This value will be null in those situations
521      * where the entity encoding is not auto-detected (e.g.
522      * internal entities or a document entity that is
523      * parsed from a java.io.Reader).
524      *
525      * @throws XNIException Thrown by handler to signal an error.
526      */

527     public void startEntity(String JavaDoc name,
528                             XMLResourceIdentifier identifier,
529                             String JavaDoc encoding, Augmentations augs) throws XNIException {
530
531         super.startEntity(name, identifier, encoding, augs);
532
533         // prepare to look for a TextDecl if external general entity
534
if (!name.equals("[xml]") && fEntityScanner.isExternal()) {
535             setScannerState(SCANNER_STATE_TEXT_DECL);
536         }
537
538         // call handler
539
if (fDocumentHandler != null && name.equals("[xml]")) {
540             fDocumentHandler.startDocument(fEntityScanner, encoding, fNamespaceContext, null);
541         }
542
543     } // startEntity(String,identifier,String)
544

545     /**
546      * This method notifies the end of an entity. The DTD has the pseudo-name
547      * of "[dtd]" parameter entity names start with '%'; and general entities
548      * are just specified by their name.
549      *
550      * @param name The name of the entity.
551      *
552      * @throws XNIException Thrown by handler to signal an error.
553      */

554     public void endEntity(String JavaDoc name, Augmentations augs) throws XNIException {
555
556         super.endEntity(name, augs);
557
558         // call handler
559
if (fDocumentHandler != null && name.equals("[xml]")) {
560             fDocumentHandler.endDocument(null);
561         }
562
563     } // endEntity(String)
564

565     //
566
// Protected methods
567
//
568

569     // dispatcher factory methods
570

571     /** Creates a content dispatcher. */
572     protected Dispatcher createContentDispatcher() {
573         return new ContentDispatcher();
574     } // createContentDispatcher():Dispatcher
575

576     // scanning methods
577

578     /** Scans a doctype declaration. */
579     protected boolean scanDoctypeDecl() throws IOException JavaDoc, XNIException {
580
581         // spaces
582
if (!fEntityScanner.skipSpaces()) {
583             reportFatalError("MSG_SPACE_REQUIRED_BEFORE_ROOT_ELEMENT_TYPE_IN_DOCTYPEDECL",
584                              null);
585         }
586
587         // root element name
588
fDoctypeName = fEntityScanner.scanName();
589         if (fDoctypeName == null) {
590             reportFatalError("MSG_ROOT_ELEMENT_TYPE_REQUIRED", null);
591         }
592
593         // external id
594
if (fEntityScanner.skipSpaces()) {
595             scanExternalID(fStrings, false);
596             fDoctypeSystemId = fStrings[0];
597             fDoctypePublicId = fStrings[1];
598             fEntityScanner.skipSpaces();
599         }
600
601         fHasExternalDTD = fDoctypeSystemId != null;
602         
603         // Attempt to locate an external subset with an external subset resolver.
604
if (!fHasExternalDTD && fExternalSubsetResolver != null) {
605             XMLDTDDescription desc = new XMLDTDDescription(null,
606                 null, fEntityManager.getCurrentResourceIdentifier().getExpandedSystemId(), null, fDoctypeName);
607             fExternalSubsetSource = fExternalSubsetResolver.getExternalSubset(desc);
608             fHasExternalDTD = fExternalSubsetSource != null;
609         }
610
611         // call handler
612
if (fDocumentHandler != null) {
613             // NOTE: I don't like calling the doctypeDecl callback until
614
// end of the *full* doctype line (including internal
615
// subset) is parsed correctly but SAX2 requires that
616
// it knows the root element name and public and system
617
// identifier for the startDTD call. -Ac
618
if (fExternalSubsetSource == null) {
619                 fDocumentHandler.doctypeDecl(fDoctypeName, fDoctypePublicId, fDoctypeSystemId, null);
620             }
621             else {
622                 fDocumentHandler.doctypeDecl(fDoctypeName, fExternalSubsetSource.getPublicId(), fExternalSubsetSource.getSystemId(), null);
623             }
624         }
625
626         // is there an internal subset?
627
boolean internalSubset = true;
628         if (!fEntityScanner.skipChar('[')) {
629             internalSubset = false;
630             fEntityScanner.skipSpaces();
631             if (!fEntityScanner.skipChar('>')) {
632                 reportFatalError("DoctypedeclUnterminated", new Object JavaDoc[]{fDoctypeName});
633             }
634             fMarkupDepth--;
635         }
636
637         return internalSubset;
638
639     } // scanDoctypeDecl():boolean
640

641     //
642
// Private methods
643
//
644

645     /** Returns the scanner state name. */
646     protected String JavaDoc getScannerStateName(int state) {
647
648         switch (state) {
649             case SCANNER_STATE_XML_DECL: return "SCANNER_STATE_XML_DECL";
650             case SCANNER_STATE_PROLOG: return "SCANNER_STATE_PROLOG";
651             case SCANNER_STATE_TRAILING_MISC: return "SCANNER_STATE_TRAILING_MISC";
652             case SCANNER_STATE_DTD_INTERNAL_DECLS: return "SCANNER_STATE_DTD_INTERNAL_DECLS";
653             case SCANNER_STATE_DTD_EXTERNAL: return "SCANNER_STATE_DTD_EXTERNAL";
654             case SCANNER_STATE_DTD_EXTERNAL_DECLS: return "SCANNER_STATE_DTD_EXTERNAL_DECLS";
655         }
656         return super.getScannerStateName(state);
657
658     } // getScannerStateName(int):String
659

660     //
661
// Classes
662
//
663

664     /**
665      * Dispatcher to handle XMLDecl scanning.
666      *
667      * @author Andy Clark, IBM
668      */

669     protected final class XMLDeclDispatcher
670         implements Dispatcher {
671
672         //
673
// Dispatcher methods
674
//
675

676         /**
677          * Dispatch an XML "event".
678          *
679          * @param complete True if this dispatcher is intended to scan
680          * and dispatch as much as possible.
681          *
682          * @return True if there is more to dispatch either from this
683          * or a another dispatcher.
684          *
685          * @throws IOException Thrown on i/o error.
686          * @throws XNIException Thrown on parse error.
687          */

688         public boolean dispatch(boolean complete)
689             throws IOException JavaDoc, XNIException {
690
691             // next dispatcher is prolog regardless of whether there
692
// is an XMLDecl in this document
693
setScannerState(SCANNER_STATE_PROLOG);
694             setDispatcher(fPrologDispatcher);
695
696             // scan XMLDecl
697
try {
698                 if (fEntityScanner.skipString("<?xml")) {
699                     fMarkupDepth++;
700                     // NOTE: special case where document starts with a PI
701
// whose name starts with "xml" (e.g. "xmlfoo")
702
if (XMLChar.isName(fEntityScanner.peekChar())) {
703                         fStringBuffer.clear();
704                         fStringBuffer.append("xml");
705                         if (fNamespaces) {
706                             while (XMLChar.isNCName(fEntityScanner.peekChar())) {
707                                 fStringBuffer.append((char)fEntityScanner.scanChar());
708                             }
709                         }
710                         else {
711                             while (XMLChar.isName(fEntityScanner.peekChar())) {
712                                 fStringBuffer.append((char)fEntityScanner.scanChar());
713                             }
714                         }
715                         String JavaDoc target = fSymbolTable.addSymbol(fStringBuffer.ch, fStringBuffer.offset, fStringBuffer.length);
716                         scanPIData(target, fString);
717                     }
718
719                     // standard XML declaration
720
else {
721                         scanXMLDeclOrTextDecl(false);
722                     }
723                 }
724                 fEntityManager.fCurrentEntity.mayReadChunks = true;
725
726                 // if no XMLDecl, then scan piece of prolog
727
return true;
728             }
729             // encoding errors
730
catch (MalformedByteSequenceException e) {
731                 fErrorReporter.reportError(e.getDomain(), e.getKey(),
732                     e.getArguments(), XMLErrorReporter.SEVERITY_FATAL_ERROR);
733                 return false;
734             }
735             catch (CharConversionException JavaDoc e) {
736                 reportFatalError("CharConversionFailure", null);
737                 return false;
738             }
739             // premature end of file
740
catch (EOFException JavaDoc e) {
741                 reportFatalError("PrematureEOF", null);
742                 return false;
743                 //throw e;
744
}
745
746
747         } // dispatch(boolean):boolean
748

749     } // class XMLDeclDispatcher
750

751     /**
752      * Dispatcher to handle prolog scanning.
753      *
754      * @author Andy Clark, IBM
755      */

756     protected final class PrologDispatcher
757         implements Dispatcher {
758
759         //
760
// Dispatcher methods
761
//
762

763         /**
764          * Dispatch an XML "event".
765          *
766          * @param complete True if this dispatcher is intended to scan
767          * and dispatch as much as possible.
768          *
769          * @return True if there is more to dispatch either from this
770          * or a another dispatcher.
771          *
772          * @throws IOException Thrown on i/o error.
773          * @throws XNIException Thrown on parse error.
774          */

775         public boolean dispatch(boolean complete)
776             throws IOException JavaDoc, XNIException {
777
778             try {
779                 boolean again;
780                 do {
781                     again = false;
782                     switch (fScannerState) {
783                         case SCANNER_STATE_PROLOG: {
784                             fEntityScanner.skipSpaces();
785                             if (fEntityScanner.skipChar('<')) {
786                                 setScannerState(SCANNER_STATE_START_OF_MARKUP);
787                                 again = true;
788                             }
789                             else if (fEntityScanner.skipChar('&')) {
790                                 setScannerState(SCANNER_STATE_REFERENCE);
791                                 again = true;
792                             }
793                             else {
794                                 setScannerState(SCANNER_STATE_CONTENT);
795                                 again = true;
796                             }
797                             break;
798                         }
799                         case SCANNER_STATE_START_OF_MARKUP: {
800                             fMarkupDepth++;
801                             if (fEntityScanner.skipChar('!')) {
802                                 if (fEntityScanner.skipChar('-')) {
803                                     if (!fEntityScanner.skipChar('-')) {
804                                         reportFatalError("InvalidCommentStart",
805                                                          null);
806                                     }
807                                     setScannerState(SCANNER_STATE_COMMENT);
808                                     again = true;
809                                 }
810                                 else if (fEntityScanner.skipString("DOCTYPE")) {
811                                     setScannerState(SCANNER_STATE_DOCTYPE);
812                                     again = true;
813                                 }
814                                 else {
815                                     reportFatalError("MarkupNotRecognizedInProlog",
816                                                      null);
817                                 }
818                             }
819                             else if (isValidNameStartChar(fEntityScanner.peekChar())) {
820                                 setScannerState(SCANNER_STATE_ROOT_ELEMENT);
821                                 setDispatcher(fContentDispatcher);
822                                 return true;
823                             }
824                             else if (fEntityScanner.skipChar('?')) {
825                                 setScannerState(SCANNER_STATE_PI);
826                                 again = true;
827                             }
828                             else if (isValidNameStartHighSurrogate(fEntityScanner.peekChar())) {
829                                 setScannerState(SCANNER_STATE_ROOT_ELEMENT);
830                                 setDispatcher(fContentDispatcher);
831                                 return true;
832                             }
833                             else {
834                                 reportFatalError("MarkupNotRecognizedInProlog",
835                                                  null);
836                             }
837                             break;
838                         }
839                         case SCANNER_STATE_COMMENT: {
840                             scanComment();
841                             setScannerState(SCANNER_STATE_PROLOG);
842                             break;
843                         }
844                         case SCANNER_STATE_PI: {
845                             scanPI();
846                             setScannerState(SCANNER_STATE_PROLOG);
847                             break;
848                         }
849                         case SCANNER_STATE_DOCTYPE: {
850                             if (fDisallowDoctype) {
851                                 reportFatalError("DoctypeNotAllowed", null);
852                             }
853                             if (fSeenDoctypeDecl) {
854                                 reportFatalError("AlreadySeenDoctype", null);
855                             }
856                             fSeenDoctypeDecl = true;
857
858                             // scanDoctypeDecl() sends XNI doctypeDecl event that
859
// in SAX is converted to startDTD() event.
860
if (scanDoctypeDecl()) {
861                                 setScannerState(SCANNER_STATE_DTD_INTERNAL_DECLS);
862                                 setDispatcher(fDTDDispatcher);
863                                 return true;
864                             }
865                             
866                             // handle external subset
867
if (fDoctypeSystemId != null) {
868                                 if (((fValidation || fLoadExternalDTD)
869                                     && (fValidationManager == null || !fValidationManager.isCachedDTD()))) {
870                                     setScannerState(SCANNER_STATE_DTD_EXTERNAL);
871                                     setDispatcher(fDTDDispatcher);
872                                     return true;
873                                 }
874                             }
875                             else if (fExternalSubsetSource != null) {
876                                 if (((fValidation || fLoadExternalDTD)
877                                     && (fValidationManager == null || !fValidationManager.isCachedDTD()))) {
878                                     // This handles the case of a DOCTYPE that had neither an internal subset or an external subset.
879
fDTDScanner.setInputSource(fExternalSubsetSource);
880                                     fExternalSubsetSource = null;
881                                     setScannerState(SCANNER_STATE_DTD_EXTERNAL_DECLS);
882                                     setDispatcher(fDTDDispatcher);
883                                     return true;
884                                 }
885                             }
886                             
887                             // Send endDTD() call if:
888
// a) systemId is null or if an external subset resolver could not locate an external subset.
889
// b) "load-external-dtd" and validation are false
890
// c) DTD grammar is cached
891

892                             // in XNI this results in 3 events: doctypeDecl, startDTD, endDTD
893
// in SAX this results in 2 events: startDTD, endDTD
894
fDTDScanner.setInputSource(null);
895                             setScannerState(SCANNER_STATE_PROLOG);
896                             break;
897                         }
898                         case SCANNER_STATE_CONTENT: {
899                             reportFatalError("ContentIllegalInProlog", null);
900                             fEntityScanner.scanChar();
901                         }
902                         case SCANNER_STATE_REFERENCE: {
903                             reportFatalError("ReferenceIllegalInProlog", null);
904                         }
905                     }
906                 } while (complete || again);
907
908                 if (complete) {
909                     if (fEntityScanner.scanChar() != '<') {
910                         reportFatalError("RootElementRequired", null);
911                     }
912                     setScannerState(SCANNER_STATE_ROOT_ELEMENT);
913                     setDispatcher(fContentDispatcher);
914                 }
915             }
916             // encoding errors
917
catch (MalformedByteSequenceException e) {
918                 fErrorReporter.reportError(e.getDomain(), e.getKey(),
919                     e.getArguments(), XMLErrorReporter.SEVERITY_FATAL_ERROR);
920                 return false;
921             }
922             catch (CharConversionException JavaDoc e) {
923                 reportFatalError("CharConversionFailure", null);
924                 return false;
925             }
926             // premature end of file
927
catch (EOFException JavaDoc e) {
928                 reportFatalError("PrematureEOF", null);
929                 return false;
930                 //throw e;
931
}
932
933             return true;
934
935         } // dispatch(boolean):boolean
936

937     } // class PrologDispatcher
938

939     /**
940      * Dispatcher to handle the internal and external DTD subsets.
941      *
942      * @author Andy Clark, IBM
943      */

944     protected final class DTDDispatcher
945         implements Dispatcher {
946
947         //
948
// Dispatcher methods
949
//
950

951         /**
952          * Dispatch an XML "event".
953          *
954          * @param complete True if this dispatcher is intended to scan
955          * and dispatch as much as possible.
956          *
957          * @return True if there is more to dispatch either from this
958          * or a another dispatcher.
959          *
960          * @throws IOException Thrown on i/o error.
961          * @throws XNIException Thrown on parse error.
962          */

963         public boolean dispatch(boolean complete)
964             throws IOException JavaDoc, XNIException {
965             fEntityManager.setEntityHandler(null);
966             try {
967                 boolean again;
968                 XMLEntityDescriptionImpl entityDescription = new XMLEntityDescriptionImpl();
969                 do {
970                     again = false;
971                     switch (fScannerState) {
972                         case SCANNER_STATE_DTD_INTERNAL_DECLS: {
973                             // REVISIT: Should there be a feature for
974
// the "complete" parameter?
975
boolean completeDTD = true;
976
977                             boolean moreToScan = fDTDScanner.scanDTDInternalSubset(completeDTD, fStandalone, fHasExternalDTD && fLoadExternalDTD);
978                             if (!moreToScan) {
979                                 // end doctype declaration
980
if (!fEntityScanner.skipChar(']')) {
981                                     reportFatalError("EXPECTED_SQUARE_BRACKET_TO_CLOSE_INTERNAL_SUBSET",
982                                                      null);
983                                 }
984                                 fEntityScanner.skipSpaces();
985                                 if (!fEntityScanner.skipChar('>')) {
986                                     reportFatalError("DoctypedeclUnterminated", new Object JavaDoc[]{fDoctypeName});
987                                 }
988                                 fMarkupDepth--;
989
990                                 // scan external subset next
991
if (fDoctypeSystemId != null) {
992                                     if ((fValidation || fLoadExternalDTD)
993                                         && (fValidationManager == null || !fValidationManager.isCachedDTD())) {
994                                         setScannerState(SCANNER_STATE_DTD_EXTERNAL);
995                                         break;
996                                     }
997                                 }
998                                 else if (fExternalSubsetSource != null) {
999                                     if ((fValidation || fLoadExternalDTD)
1000                                        && (fValidationManager == null || !fValidationManager.isCachedDTD())) {
1001                                        // This handles the case of a DOCTYPE that only had an internal subset.
1002
fDTDScanner.setInputSource(fExternalSubsetSource);
1003                                        fExternalSubsetSource = null;
1004                                        setScannerState(SCANNER_STATE_DTD_EXTERNAL_DECLS);
1005                                        break;
1006                                    }
1007                                }
1008                                
1009                                // break out of this dispatcher.
1010
setScannerState(SCANNER_STATE_PROLOG);
1011                                setDispatcher(fPrologDispatcher);
1012                                fEntityManager.setEntityHandler(XMLDocumentScannerImpl.this);
1013                                return true;
1014                            }
1015                            break;
1016                        }
1017                        case SCANNER_STATE_DTD_EXTERNAL: {
1018                            entityDescription.setDescription("[dtd]", fDoctypePublicId, fDoctypeSystemId, null, null);
1019                            XMLInputSource xmlInputSource =
1020                                fEntityManager.resolveEntity(entityDescription);
1021                            fDTDScanner.setInputSource(xmlInputSource);
1022                            setScannerState(SCANNER_STATE_DTD_EXTERNAL_DECLS);
1023                            again = true;
1024                            break;
1025                        }
1026                        case SCANNER_STATE_DTD_EXTERNAL_DECLS: {
1027                            // REVISIT: Should there be a feature for
1028
// the "complete" parameter?
1029
boolean completeDTD = true;
1030                            boolean moreToScan = fDTDScanner.scanDTDExternalSubset(completeDTD);
1031                            if (!moreToScan) {
1032                                setScannerState(SCANNER_STATE_PROLOG);
1033                                setDispatcher(fPrologDispatcher);
1034                                fEntityManager.setEntityHandler(XMLDocumentScannerImpl.this);
1035                                return true;
1036                            }
1037                            break;
1038                        }
1039                        default: {
1040                            throw new XNIException("DTDDispatcher#dispatch: scanner state="+fScannerState+" ("+getScannerStateName(fScannerState)+')');
1041                        }
1042                    }
1043                } while (complete || again);
1044            }
1045            // encoding errors
1046
catch (MalformedByteSequenceException e) {
1047                fErrorReporter.reportError(e.getDomain(), e.getKey(),
1048                    e.getArguments(), XMLErrorReporter.SEVERITY_FATAL_ERROR);
1049                return false;
1050            }
1051            catch (CharConversionException JavaDoc e) {
1052                reportFatalError("CharConversionFailure", null);
1053                return false;
1054            }
1055            // premature end of file
1056
catch (EOFException JavaDoc e) {
1057                reportFatalError("PrematureEOF", null);
1058                return false;
1059                //throw e;
1060
}
1061
1062            // cleanup
1063
finally {
1064                fEntityManager.setEntityHandler(XMLDocumentScannerImpl.this);
1065            }
1066
1067            return true;
1068
1069        } // dispatch(boolean):boolean
1070

1071    } // class DTDDispatcher
1072

1073    /**
1074     * Dispatcher to handle content scanning.
1075     *
1076     * @author Andy Clark, IBM
1077     * @author Eric Ye, IBM
1078     */

1079    protected class ContentDispatcher
1080        extends FragmentContentDispatcher {
1081
1082        //
1083
// Protected methods
1084
//
1085

1086        // hooks
1087

1088        // NOTE: These hook methods are added so that the full document
1089
// scanner can share the majority of code with this class.
1090

1091        /**
1092         * Scan for DOCTYPE hook. This method is a hook for subclasses
1093         * to add code to handle scanning for a the "DOCTYPE" string
1094         * after the string "<!" has been scanned.
1095         *
1096         * @return True if the "DOCTYPE" was scanned; false if "DOCTYPE"
1097         * was not scanned.
1098         */

1099        protected boolean scanForDoctypeHook()
1100            throws IOException JavaDoc, XNIException {
1101
1102            if (fEntityScanner.skipString("DOCTYPE")) {
1103                setScannerState(SCANNER_STATE_DOCTYPE);
1104                return true;
1105            }
1106            return false;
1107
1108        } // scanForDoctypeHook():boolean
1109

1110        /**
1111         * Element depth iz zero. This methos is a hook for subclasses
1112         * to add code to handle when the element depth hits zero. When
1113         * scanning a document fragment, an element depth of zero is
1114         * normal. However, when scanning a full XML document, the
1115         * scanner must handle the trailing miscellanous section of
1116         * the document after the end of the document's root element.
1117         *
1118         * @return True if the caller should stop and return true which
1119         * allows the scanner to switch to a new scanning
1120         * dispatcher. A return value of false indicates that
1121         * the content dispatcher should continue as normal.
1122         */

1123        protected boolean elementDepthIsZeroHook()
1124            throws IOException JavaDoc, XNIException {
1125
1126            setScannerState(SCANNER_STATE_TRAILING_MISC);
1127            setDispatcher(fTrailingMiscDispatcher);
1128            return true;
1129
1130        } // elementDepthIsZeroHook():boolean
1131

1132        /**
1133         * Scan for root element hook. This method is a hook for
1134         * subclasses to add code that handles scanning for the root
1135         * element. When scanning a document fragment, there is no
1136         * "root" element. However, when scanning a full XML document,
1137         * the scanner must handle the root element specially.
1138         *
1139         * @return True if the caller should stop and return true which
1140         * allows the scanner to switch to a new scanning
1141         * dispatcher. A return value of false indicates that
1142         * the content dispatcher should continue as normal.
1143         */

1144        protected boolean scanRootElementHook()
1145            throws IOException JavaDoc, XNIException {
1146
1147            if (fExternalSubsetResolver != null && !fSeenDoctypeDecl
1148                && !fDisallowDoctype && (fValidation || fLoadExternalDTD)) {
1149                scanStartElementName();
1150                resolveExternalSubsetAndRead();
1151                if (scanStartElementAfterName()) {
1152                    setScannerState(SCANNER_STATE_TRAILING_MISC);
1153                    setDispatcher(fTrailingMiscDispatcher);
1154                    return true;
1155                }
1156            }
1157            else if (scanStartElement()) {
1158                setScannerState(SCANNER_STATE_TRAILING_MISC);
1159                setDispatcher(fTrailingMiscDispatcher);
1160                return true;
1161            }
1162            return false;
1163
1164        } // scanRootElementHook():boolean
1165

1166        /**
1167         * End of file hook. This method is a hook for subclasses to
1168         * add code that handles the end of file. The end of file in
1169         * a document fragment is OK if the markup depth is zero.
1170         * However, when scanning a full XML document, an end of file
1171         * is always premature.
1172         */

1173        protected void endOfFileHook(EOFException JavaDoc e)
1174            throws IOException JavaDoc, XNIException {
1175
1176            reportFatalError("PrematureEOF", null);
1177            // in case continue-after-fatal-error set, should not do this...
1178
//throw e;
1179

1180        } // endOfFileHook()
1181

1182        /**
1183         * <p>Attempt to locate an external subset for a document that does not otherwise
1184         * have one. If an external subset is located, then it is scanned.</p>
1185         */

1186        protected void resolveExternalSubsetAndRead()
1187            throws IOException JavaDoc, XNIException {
1188            XMLDTDDescription desc = new XMLDTDDescription(null,
1189                null, fEntityManager.getCurrentResourceIdentifier().getExpandedSystemId(), null, fElementQName.rawname);
1190            XMLInputSource src = fExternalSubsetResolver.getExternalSubset(desc);
1191            if (src != null) {
1192                fDoctypeName = fElementQName.rawname;
1193                fDoctypePublicId = src.getPublicId();
1194                fDoctypeSystemId = src.getSystemId();
1195                // call document handler
1196
if (fDocumentHandler != null) {
1197                    // This inserts a doctypeDecl event into the stream though no
1198
// DOCTYPE existed in the instance document.
1199
fDocumentHandler.doctypeDecl(fDoctypeName, fDoctypePublicId, fDoctypeSystemId, null);
1200                }
1201                try {
1202                    fDTDScanner.setInputSource(src);
1203                    while (fDTDScanner.scanDTDExternalSubset(true));
1204                }
1205                finally {
1206                    fEntityManager.setEntityHandler(XMLDocumentScannerImpl.this);
1207                }
1208            }
1209        } // resolveExternalSubsetAndRead()
1210

1211    } // class ContentDispatcher
1212

1213    /**
1214     * Dispatcher to handle trailing miscellaneous section scanning.
1215     *
1216     * @author Andy Clark, IBM
1217     * @author Eric Ye, IBM
1218     */

1219    protected final class TrailingMiscDispatcher
1220        implements Dispatcher {
1221
1222        //
1223
// Dispatcher methods
1224
//
1225

1226        /**
1227         * Dispatch an XML "event".
1228         *
1229         * @param complete True if this dispatcher is intended to scan
1230         * and dispatch as much as possible.
1231         *
1232         * @return True if there is more to dispatch either from this
1233         * or a another dispatcher.
1234         *
1235         * @throws IOException Thrown on i/o error.
1236         * @throws XNIException Thrown on parse error.
1237         */

1238        public boolean dispatch(boolean complete)
1239            throws IOException JavaDoc, XNIException {
1240
1241            try {
1242                boolean again;
1243                do {
1244                    again = false;
1245                    switch (fScannerState) {
1246                        case SCANNER_STATE_TRAILING_MISC: {
1247                            fEntityScanner.skipSpaces();
1248                            if (fEntityScanner.skipChar('<')) {
1249                                setScannerState(SCANNER_STATE_START_OF_MARKUP);
1250                                again = true;
1251                            }
1252                            else {
1253                                setScannerState(SCANNER_STATE_CONTENT);
1254                                again = true;
1255                            }
1256                            break;
1257                        }
1258                        case SCANNER_STATE_START_OF_MARKUP: {
1259                            fMarkupDepth++;
1260                            if (fEntityScanner.skipChar('?')) {
1261                                setScannerState(SCANNER_STATE_PI);
1262                                again = true;
1263                            }
1264                            else if (fEntityScanner.skipChar('!')) {
1265                                setScannerState(SCANNER_STATE_COMMENT);
1266                                again = true;
1267                            }
1268                            else if (fEntityScanner.skipChar('/')) {
1269                                reportFatalError("MarkupNotRecognizedInMisc",
1270                                                 null);
1271                                again = true;
1272                            }
1273                            else if (isValidNameStartChar(fEntityScanner.peekChar())) {
1274                                reportFatalError("MarkupNotRecognizedInMisc",
1275                                                 null);
1276                                scanStartElement();
1277                                setScannerState(SCANNER_STATE_CONTENT);
1278                            }
1279                            else if (isValidNameStartHighSurrogate(fEntityScanner.peekChar())) {
1280                                reportFatalError("MarkupNotRecognizedInMisc",
1281                                                 null);
1282                                scanStartElement();
1283                                setScannerState(SCANNER_STATE_CONTENT);
1284                            }
1285                            else {
1286                                reportFatalError("MarkupNotRecognizedInMisc",
1287                                                 null);
1288                            }
1289                            break;
1290                        }
1291                        case SCANNER_STATE_PI: {
1292                            scanPI();
1293                            setScannerState(SCANNER_STATE_TRAILING_MISC);
1294                            break;
1295                        }
1296                        case SCANNER_STATE_COMMENT: {
1297                            if (!fEntityScanner.skipString("--")) {
1298                                reportFatalError("InvalidCommentStart", null);
1299                            }
1300                            scanComment();
1301                            setScannerState(SCANNER_STATE_TRAILING_MISC);
1302                            break;
1303                        }
1304                        case SCANNER_STATE_CONTENT: {
1305                            int ch = fEntityScanner.peekChar();
1306                            if (ch == -1) {
1307                                setScannerState(SCANNER_STATE_TERMINATED);
1308                                return false;
1309                            }
1310                            reportFatalError("ContentIllegalInTrailingMisc",
1311                                             null);
1312                            fEntityScanner.scanChar();
1313                            setScannerState(SCANNER_STATE_TRAILING_MISC);
1314                            break;
1315                        }
1316                        case SCANNER_STATE_REFERENCE: {
1317                            reportFatalError("ReferenceIllegalInTrailingMisc",
1318                                             null);
1319                            setScannerState(SCANNER_STATE_TRAILING_MISC);
1320                            break;
1321                        }
1322                        case SCANNER_STATE_TERMINATED: {
1323                            return false;
1324                        }
1325                    }
1326                } while (complete || again);
1327            }
1328            // encoding errors
1329
catch (MalformedByteSequenceException e) {
1330                fErrorReporter.reportError(e.getDomain(), e.getKey(),
1331                    e.getArguments(), XMLErrorReporter.SEVERITY_FATAL_ERROR);
1332                return false;
1333            }
1334            catch (CharConversionException JavaDoc e) {
1335                reportFatalError("CharConversionFailure", null);
1336                return false;
1337            }
1338            catch (EOFException JavaDoc e) {
1339                // NOTE: This is the only place we're allowed to reach
1340
// the real end of the document stream. Unless the
1341
// end of file was reached prematurely.
1342
if (fMarkupDepth != 0) {
1343                    reportFatalError("PrematureEOF", null);
1344                    return false;
1345                    //throw e;
1346
}
1347
1348                setScannerState(SCANNER_STATE_TERMINATED);
1349                return false;
1350            }
1351
1352            return true;
1353
1354        } // dispatch(boolean):boolean
1355

1356    } // class TrailingMiscDispatcher
1357

1358} // class XMLDocumentScannerImpl
1359
Popular Tags