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. package com.sun.org.apache.xerces.internal.impl;
  58. import java.io.CharConversionException;
  59. import java.io.EOFException;
  60. import java.io.IOException;
  61. import com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDDescription;
  62. import com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException;
  63. import com.sun.org.apache.xerces.internal.impl.validation.ValidationManager;
  64. import com.sun.org.apache.xerces.internal.util.NamespaceSupport;
  65. import com.sun.org.apache.xerces.internal.util.XMLChar;
  66. import com.sun.org.apache.xerces.internal.util.XMLEntityDescriptionImpl;
  67. import com.sun.org.apache.xerces.internal.util.XMLStringBuffer;
  68. import com.sun.org.apache.xerces.internal.xni.Augmentations;
  69. import com.sun.org.apache.xerces.internal.xni.NamespaceContext;
  70. import com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier;
  71. import com.sun.org.apache.xerces.internal.xni.XMLString;
  72. import com.sun.org.apache.xerces.internal.xni.XNIException;
  73. import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager;
  74. import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;
  75. import com.sun.org.apache.xerces.internal.xni.parser.XMLDTDScanner;
  76. import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;
  77. /**
  78. * This class is responsible for scanning XML document structure
  79. * and content. The scanner acts as the source for the document
  80. * information which is communicated to the document handler.
  81. * <p>
  82. * This component requires the following features and properties from the
  83. * component manager that uses it:
  84. * <ul>
  85. * <li>http://xml.org/sax/features/namespaces</li>
  86. * <li>http://xml.org/sax/features/validation</li>
  87. * <li>http://apache.org/xml/features/nonvalidating/load-external-dtd</li>
  88. * <li>http://apache.org/xml/features/scanner/notify-char-refs</li>
  89. * <li>http://apache.org/xml/features/scanner/notify-builtin-refs</li>
  90. * <li>http://apache.org/xml/properties/internal/symbol-table</li>
  91. * <li>http://apache.org/xml/properties/internal/error-reporter</li>
  92. * <li>http://apache.org/xml/properties/internal/entity-manager</li>
  93. * <li>http://apache.org/xml/properties/internal/dtd-scanner</li>
  94. * </ul>
  95. *
  96. * @author Glenn Marcy, IBM
  97. * @author Andy Clark, IBM
  98. * @author Arnaud Le Hors, IBM
  99. * @author Eric Ye, IBM
  100. *
  101. * @version $Id: XMLDocumentScannerImpl.java,v 1.45 2004/04/30 15:36:38 mrglavas Exp $
  102. */
  103. public class XMLDocumentScannerImpl
  104. extends XMLDocumentFragmentScannerImpl {
  105. //
  106. // Constants
  107. //
  108. // scanner states
  109. /** Scanner state: XML declaration. */
  110. protected static final int SCANNER_STATE_XML_DECL = 0;
  111. /** Scanner state: prolog. */
  112. protected static final int SCANNER_STATE_PROLOG = 5;
  113. /** Scanner state: trailing misc. */
  114. protected static final int SCANNER_STATE_TRAILING_MISC = 12;
  115. /** Scanner state: DTD internal declarations. */
  116. protected static final int SCANNER_STATE_DTD_INTERNAL_DECLS = 17;
  117. /** Scanner state: open DTD external subset. */
  118. protected static final int SCANNER_STATE_DTD_EXTERNAL = 18;
  119. /** Scanner state: DTD external declarations. */
  120. protected static final int SCANNER_STATE_DTD_EXTERNAL_DECLS = 19;
  121. // feature identifiers
  122. /** Feature identifier: load external DTD. */
  123. protected static final String LOAD_EXTERNAL_DTD =
  124. Constants.XERCES_FEATURE_PREFIX + Constants.LOAD_EXTERNAL_DTD_FEATURE;
  125. /** Feature identifier: load external DTD. */
  126. protected static final String DISALLOW_DOCTYPE_DECL_FEATURE =
  127. Constants.XERCES_FEATURE_PREFIX + Constants.DISALLOW_DOCTYPE_DECL_FEATURE;
  128. // property identifiers
  129. /** Property identifier: DTD scanner. */
  130. protected static final String DTD_SCANNER =
  131. Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_SCANNER_PROPERTY;
  132. /** property identifier: ValidationManager */
  133. protected static final String VALIDATION_MANAGER =
  134. Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY;
  135. /** property identifier: NamespaceContext */
  136. protected static final String NAMESPACE_CONTEXT =
  137. Constants.XERCES_PROPERTY_PREFIX + Constants.NAMESPACE_CONTEXT_PROPERTY;
  138. // recognized features and properties
  139. /** Recognized features. */
  140. private static final String[] RECOGNIZED_FEATURES = {
  141. LOAD_EXTERNAL_DTD,
  142. DISALLOW_DOCTYPE_DECL_FEATURE,
  143. };
  144. /** Feature defaults. */
  145. private static final Boolean[] FEATURE_DEFAULTS = {
  146. Boolean.TRUE,
  147. Boolean.FALSE,
  148. };
  149. /** Recognized properties. */
  150. private static final String[] RECOGNIZED_PROPERTIES = {
  151. DTD_SCANNER,
  152. VALIDATION_MANAGER,
  153. NAMESPACE_CONTEXT,
  154. };
  155. /** Property defaults. */
  156. private static final Object[] PROPERTY_DEFAULTS = {
  157. null,
  158. null,
  159. null,
  160. };
  161. //
  162. // Data
  163. //
  164. // properties
  165. /** DTD scanner. */
  166. protected XMLDTDScanner fDTDScanner;
  167. /** Validation manager . */
  168. protected ValidationManager fValidationManager;
  169. // protected data
  170. /** Scanning DTD. */
  171. protected boolean fScanningDTD;
  172. // other info
  173. /** Doctype name. */
  174. protected String fDoctypeName;
  175. /** Doctype declaration public identifier. */
  176. protected String fDoctypePublicId;
  177. /** Doctype declaration system identifier. */
  178. protected String fDoctypeSystemId;
  179. /** Namespace support. */
  180. protected NamespaceContext fNamespaceContext = new NamespaceSupport();
  181. // features
  182. /** Load external DTD. */
  183. protected boolean fLoadExternalDTD = true;
  184. /** Disallow doctype declaration. */
  185. protected boolean fDisallowDoctype = false;
  186. // state
  187. /** Seen doctype declaration. */
  188. protected boolean fSeenDoctypeDecl;
  189. // dispatchers
  190. /** XML declaration dispatcher. */
  191. protected Dispatcher fXMLDeclDispatcher = new XMLDeclDispatcher();
  192. /** Prolog dispatcher. */
  193. protected Dispatcher fPrologDispatcher = new PrologDispatcher();
  194. /** DTD dispatcher. */
  195. protected Dispatcher fDTDDispatcher = new DTDDispatcher();
  196. /** Trailing miscellaneous section dispatcher. */
  197. protected Dispatcher fTrailingMiscDispatcher = new TrailingMiscDispatcher();
  198. // temporary variables
  199. /** Array of 3 strings. */
  200. private String[] fStrings = new String[3];
  201. /** String. */
  202. private XMLString fString = new XMLString();
  203. /** String buffer. */
  204. private XMLStringBuffer fStringBuffer = new XMLStringBuffer();
  205. /** External subset source. */
  206. private XMLInputSource fExternalSubsetSource = null;
  207. //
  208. // Constructors
  209. //
  210. /** Default constructor. */
  211. public XMLDocumentScannerImpl() {} // <init>()
  212. //
  213. // XMLDocumentScanner methods
  214. //
  215. /**
  216. * Sets the input source.
  217. *
  218. * @param inputSource The input source.
  219. *
  220. * @throws IOException Thrown on i/o error.
  221. */
  222. public void setInputSource(XMLInputSource inputSource) throws IOException {
  223. fEntityManager.setEntityHandler(this);
  224. fEntityManager.startDocumentEntity(inputSource);
  225. //fDocumentSystemId = fEntityManager.expandSystemId(inputSource.getSystemId());
  226. } // setInputSource(XMLInputSource)
  227. //
  228. // XMLComponent methods
  229. //
  230. /**
  231. * Resets the component. The component can query the component manager
  232. * about any features and properties that affect the operation of the
  233. * component.
  234. *
  235. * @param componentManager The component manager.
  236. *
  237. * @throws SAXException Thrown by component on initialization error.
  238. * For example, if a feature or property is
  239. * required for the operation of the component, the
  240. * component manager may throw a
  241. * SAXNotRecognizedException or a
  242. * SAXNotSupportedException.
  243. */
  244. public void reset(XMLComponentManager componentManager)
  245. throws XMLConfigurationException {
  246. super.reset(componentManager);
  247. // other settings
  248. fDoctypeName = null;
  249. fDoctypePublicId = null;
  250. fDoctypeSystemId = null;
  251. fSeenDoctypeDecl = false;
  252. fScanningDTD = false;
  253. fExternalSubsetSource = null;
  254. if (!fParserSettings) {
  255. // parser settings have not been changed
  256. fNamespaceContext.reset();
  257. // setup dispatcher
  258. setScannerState(SCANNER_STATE_XML_DECL);
  259. setDispatcher(fXMLDeclDispatcher);
  260. return;
  261. }
  262. // xerces features
  263. try {
  264. fLoadExternalDTD = componentManager.getFeature(LOAD_EXTERNAL_DTD);
  265. }
  266. catch (XMLConfigurationException e) {
  267. fLoadExternalDTD = true;
  268. }
  269. try {
  270. fDisallowDoctype = componentManager.getFeature(DISALLOW_DOCTYPE_DECL_FEATURE);
  271. }
  272. catch (XMLConfigurationException e) {
  273. fDisallowDoctype = false;
  274. }
  275. // xerces properties
  276. fDTDScanner = (XMLDTDScanner)componentManager.getProperty(DTD_SCANNER);
  277. try {
  278. fValidationManager = (ValidationManager)componentManager.getProperty(VALIDATION_MANAGER);
  279. }
  280. catch (XMLConfigurationException e) {
  281. fValidationManager = null;
  282. }
  283. try {
  284. fNamespaceContext = (NamespaceContext)componentManager.getProperty(NAMESPACE_CONTEXT);
  285. }
  286. catch (XMLConfigurationException e) { }
  287. if (fNamespaceContext == null) {
  288. fNamespaceContext = new NamespaceSupport();
  289. }
  290. fNamespaceContext.reset();
  291. // setup dispatcher
  292. setScannerState(SCANNER_STATE_XML_DECL);
  293. setDispatcher(fXMLDeclDispatcher);
  294. } // reset(XMLComponentManager)
  295. /**
  296. * Returns a list of feature identifiers that are recognized by
  297. * this component. This method may return null if no features
  298. * are recognized by this component.
  299. */
  300. public String[] getRecognizedFeatures() {
  301. String[] featureIds = super.getRecognizedFeatures();
  302. int length = featureIds != null ? featureIds.length : 0;
  303. String[] combinedFeatureIds = new String[length + RECOGNIZED_FEATURES.length];
  304. if (featureIds != null) {
  305. System.arraycopy(featureIds, 0, combinedFeatureIds, 0, featureIds.length);
  306. }
  307. System.arraycopy(RECOGNIZED_FEATURES, 0, combinedFeatureIds, length, RECOGNIZED_FEATURES.length);
  308. return combinedFeatureIds;
  309. } // getRecognizedFeatures():String[]
  310. /**
  311. * Sets the state of a feature. This method is called by the component
  312. * manager any time after reset when a feature changes state.
  313. * <p>
  314. * <strong>Note:</strong> Components should silently ignore features
  315. * that do not affect the operation of the component.
  316. *
  317. * @param featureId The feature identifier.
  318. * @param state The state of the feature.
  319. *
  320. * @throws SAXNotRecognizedException The component should not throw
  321. * this exception.
  322. * @throws SAXNotSupportedException The component should not throw
  323. * this exception.
  324. */
  325. public void setFeature(String featureId, boolean state)
  326. throws XMLConfigurationException {
  327. super.setFeature(featureId, state);
  328. // Xerces properties
  329. if (featureId.startsWith(Constants.XERCES_FEATURE_PREFIX)) {
  330. final int suffixLength = featureId.length() - Constants.XERCES_FEATURE_PREFIX.length();
  331. if (suffixLength == Constants.LOAD_EXTERNAL_DTD_FEATURE.length() &&
  332. featureId.endsWith(Constants.LOAD_EXTERNAL_DTD_FEATURE)) {
  333. fLoadExternalDTD = state;
  334. return;
  335. }
  336. else if (suffixLength == Constants.DISALLOW_DOCTYPE_DECL_FEATURE.length() &&
  337. featureId.endsWith(Constants.DISALLOW_DOCTYPE_DECL_FEATURE)) {
  338. fDisallowDoctype = state;
  339. return;
  340. }
  341. }
  342. } // setFeature(String,boolean)
  343. /**
  344. * Returns a list of property identifiers that are recognized by
  345. * this component. This method may return null if no properties
  346. * are recognized by this component.
  347. */
  348. public String[] getRecognizedProperties() {
  349. String[] propertyIds = super.getRecognizedProperties();
  350. int length = propertyIds != null ? propertyIds.length : 0;
  351. String[] combinedPropertyIds = new String[length + RECOGNIZED_PROPERTIES.length];
  352. if (propertyIds != null) {
  353. System.arraycopy(propertyIds, 0, combinedPropertyIds, 0, propertyIds.length);
  354. }
  355. System.arraycopy(RECOGNIZED_PROPERTIES, 0, combinedPropertyIds, length, RECOGNIZED_PROPERTIES.length);
  356. return combinedPropertyIds;
  357. } // getRecognizedProperties():String[]
  358. /**
  359. * Sets the value of a property. This method is called by the component
  360. * manager any time after reset when a property changes value.
  361. * <p>
  362. * <strong>Note:</strong> Components should silently ignore properties
  363. * that do not affect the operation of the component.
  364. *
  365. * @param propertyId The property identifier.
  366. * @param value The value of the property.
  367. *
  368. * @throws SAXNotRecognizedException The component should not throw
  369. * this exception.
  370. * @throws SAXNotSupportedException The component should not throw
  371. * this exception.
  372. */
  373. public void setProperty(String propertyId, Object value)
  374. throws XMLConfigurationException {
  375. super.setProperty(propertyId, value);
  376. // Xerces properties
  377. if (propertyId.startsWith(Constants.XERCES_PROPERTY_PREFIX)) {
  378. final int suffixLength = propertyId.length() - Constants.XERCES_PROPERTY_PREFIX.length();
  379. if (suffixLength == Constants.DTD_SCANNER_PROPERTY.length() &&
  380. propertyId.endsWith(Constants.DTD_SCANNER_PROPERTY)) {
  381. fDTDScanner = (XMLDTDScanner)value;
  382. }
  383. if (suffixLength == Constants.NAMESPACE_CONTEXT_PROPERTY.length() &&
  384. propertyId.endsWith(Constants.NAMESPACE_CONTEXT_PROPERTY)) {
  385. if (value != null) {
  386. fNamespaceContext = (NamespaceContext)value;
  387. }
  388. }
  389. return;
  390. }
  391. } // setProperty(String,Object)
  392. /**
  393. * Returns the default state for a feature, or null if this
  394. * component does not want to report a default value for this
  395. * feature.
  396. *
  397. * @param featureId The feature identifier.
  398. *
  399. * @since Xerces 2.2.0
  400. */
  401. public Boolean getFeatureDefault(String featureId) {
  402. for (int i = 0; i < RECOGNIZED_FEATURES.length; i++) {
  403. if (RECOGNIZED_FEATURES[i].equals(featureId)) {
  404. return FEATURE_DEFAULTS[i];
  405. }
  406. }
  407. return super.getFeatureDefault(featureId);
  408. } // getFeatureDefault(String):Boolean
  409. /**
  410. * Returns the default state for a property, or null if this
  411. * component does not want to report a default value for this
  412. * property.
  413. *
  414. * @param propertyId The property identifier.
  415. *
  416. * @since Xerces 2.2.0
  417. */
  418. public Object getPropertyDefault(String propertyId) {
  419. for (int i = 0; i < RECOGNIZED_PROPERTIES.length; i++) {
  420. if (RECOGNIZED_PROPERTIES[i].equals(propertyId)) {
  421. return PROPERTY_DEFAULTS[i];
  422. }
  423. }
  424. return super.getPropertyDefault(propertyId);
  425. } // getPropertyDefault(String):Object
  426. //
  427. // XMLEntityHandler methods
  428. //
  429. /**
  430. * This method notifies of the start of an entity. The DTD has the
  431. * pseudo-name of "[dtd]" parameter entity names start with '%'; and
  432. * general entities are just specified by their name.
  433. *
  434. * @param name The name of the entity.
  435. * @param identifier The resource identifier.
  436. * @param encoding The auto-detected IANA encoding name of the entity
  437. * stream. This value will be null in those situations
  438. * where the entity encoding is not auto-detected (e.g.
  439. * internal entities or a document entity that is
  440. * parsed from a java.io.Reader).
  441. *
  442. * @throws XNIException Thrown by handler to signal an error.
  443. */
  444. public void startEntity(String name,
  445. XMLResourceIdentifier identifier,
  446. String encoding, Augmentations augs) throws XNIException {
  447. super.startEntity(name, identifier, encoding, augs);
  448. // prepare to look for a TextDecl if external general entity
  449. if (!name.equals("[xml]") && fEntityScanner.isExternal()) {
  450. setScannerState(SCANNER_STATE_TEXT_DECL);
  451. }
  452. // call handler
  453. if (fDocumentHandler != null && name.equals("[xml]")) {
  454. fDocumentHandler.startDocument(fEntityScanner, encoding, fNamespaceContext, null);
  455. }
  456. } // startEntity(String,identifier,String)
  457. /**
  458. * This method notifies the end of an entity. The DTD has the pseudo-name
  459. * of "[dtd]" parameter entity names start with '%'; and general entities
  460. * are just specified by their name.
  461. *
  462. * @param name The name of the entity.
  463. *
  464. * @throws XNIException Thrown by handler to signal an error.
  465. */
  466. public void endEntity(String name, Augmentations augs) throws XNIException {
  467. super.endEntity(name, augs);
  468. // call handler
  469. if (fDocumentHandler != null && name.equals("[xml]")) {
  470. fDocumentHandler.endDocument(null);
  471. }
  472. } // endEntity(String)
  473. //
  474. // Protected methods
  475. //
  476. // dispatcher factory methods
  477. /** Creates a content dispatcher. */
  478. protected Dispatcher createContentDispatcher() {
  479. return new ContentDispatcher();
  480. } // createContentDispatcher():Dispatcher
  481. // scanning methods
  482. /** Scans a doctype declaration. */
  483. protected boolean scanDoctypeDecl() throws IOException, XNIException {
  484. // spaces
  485. if (!fEntityScanner.skipSpaces()) {
  486. reportFatalError("MSG_SPACE_REQUIRED_BEFORE_ROOT_ELEMENT_TYPE_IN_DOCTYPEDECL",
  487. null);
  488. }
  489. // root element name
  490. fDoctypeName = fEntityScanner.scanName();
  491. if (fDoctypeName == null) {
  492. reportFatalError("MSG_ROOT_ELEMENT_TYPE_REQUIRED", null);
  493. }
  494. // external id
  495. if (fEntityScanner.skipSpaces()) {
  496. scanExternalID(fStrings, false);
  497. fDoctypeSystemId = fStrings[0];
  498. fDoctypePublicId = fStrings[1];
  499. fEntityScanner.skipSpaces();
  500. }
  501. fHasExternalDTD = fDoctypeSystemId != null;
  502. // Attempt to locate an external subset with an external subset resolver.
  503. if (!fHasExternalDTD && fExternalSubsetResolver != null) {
  504. XMLDTDDescription desc = new XMLDTDDescription(null,
  505. null, fEntityManager.getCurrentResourceIdentifier().getExpandedSystemId(), null, fDoctypeName);
  506. fExternalSubsetSource = fExternalSubsetResolver.getExternalSubset(desc);
  507. fHasExternalDTD = fExternalSubsetSource != null;
  508. }
  509. // call handler
  510. if (fDocumentHandler != null) {
  511. // NOTE: I don't like calling the doctypeDecl callback until
  512. // end of the *full* doctype line (including internal
  513. // subset) is parsed correctly but SAX2 requires that
  514. // it knows the root element name and public and system
  515. // identifier for the startDTD call. -Ac
  516. if (fExternalSubsetSource == null) {
  517. fDocumentHandler.doctypeDecl(fDoctypeName, fDoctypePublicId, fDoctypeSystemId, null);
  518. }
  519. else {
  520. fDocumentHandler.doctypeDecl(fDoctypeName, fExternalSubsetSource.getPublicId(), fExternalSubsetSource.getSystemId(), null);
  521. }
  522. }
  523. // is there an internal subset?
  524. boolean internalSubset = true;
  525. if (!fEntityScanner.skipChar('[')) {
  526. internalSubset = false;
  527. fEntityScanner.skipSpaces();
  528. if (!fEntityScanner.skipChar('>')) {
  529. reportFatalError("DoctypedeclUnterminated", new Object[]{fDoctypeName});
  530. }
  531. fMarkupDepth--;
  532. }
  533. return internalSubset;
  534. } // scanDoctypeDecl():boolean
  535. //
  536. // Private methods
  537. //
  538. /** Returns the scanner state name. */
  539. protected String getScannerStateName(int state) {
  540. switch (state) {
  541. case SCANNER_STATE_XML_DECL: return "SCANNER_STATE_XML_DECL";
  542. case SCANNER_STATE_PROLOG: return "SCANNER_STATE_PROLOG";
  543. case SCANNER_STATE_TRAILING_MISC: return "SCANNER_STATE_TRAILING_MISC";
  544. case SCANNER_STATE_DTD_INTERNAL_DECLS: return "SCANNER_STATE_DTD_INTERNAL_DECLS";
  545. case SCANNER_STATE_DTD_EXTERNAL: return "SCANNER_STATE_DTD_EXTERNAL";
  546. case SCANNER_STATE_DTD_EXTERNAL_DECLS: return "SCANNER_STATE_DTD_EXTERNAL_DECLS";
  547. }
  548. return super.getScannerStateName(state);
  549. } // getScannerStateName(int):String
  550. //
  551. // Classes
  552. //
  553. /**
  554. * Dispatcher to handle XMLDecl scanning.
  555. *
  556. * @author Andy Clark, IBM
  557. */
  558. protected final class XMLDeclDispatcher
  559. implements Dispatcher {
  560. //
  561. // Dispatcher methods
  562. //
  563. /**
  564. * Dispatch an XML "event".
  565. *
  566. * @param complete True if this dispatcher is intended to scan
  567. * and dispatch as much as possible.
  568. *
  569. * @return True if there is more to dispatch either from this
  570. * or a another dispatcher.
  571. *
  572. * @throws IOException Thrown on i/o error.
  573. * @throws XNIException Thrown on parse error.
  574. */
  575. public boolean dispatch(boolean complete)
  576. throws IOException, XNIException {
  577. // next dispatcher is prolog regardless of whether there
  578. // is an XMLDecl in this document
  579. setScannerState(SCANNER_STATE_PROLOG);
  580. setDispatcher(fPrologDispatcher);
  581. // scan XMLDecl
  582. try {
  583. if (fEntityScanner.skipString("<?xml")) {
  584. fMarkupDepth++;
  585. // NOTE: special case where document starts with a PI
  586. // whose name starts with "xml" (e.g. "xmlfoo")
  587. if (XMLChar.isName(fEntityScanner.peekChar())) {
  588. fStringBuffer.clear();
  589. fStringBuffer.append("xml");
  590. if (fNamespaces) {
  591. while (XMLChar.isNCName(fEntityScanner.peekChar())) {
  592. fStringBuffer.append((char)fEntityScanner.scanChar());
  593. }
  594. }
  595. else {
  596. while (XMLChar.isName(fEntityScanner.peekChar())) {
  597. fStringBuffer.append((char)fEntityScanner.scanChar());
  598. }
  599. }
  600. String target = fSymbolTable.addSymbol(fStringBuffer.ch, fStringBuffer.offset, fStringBuffer.length);
  601. scanPIData(target, fString);
  602. }
  603. // standard XML declaration
  604. else {
  605. scanXMLDeclOrTextDecl(false);
  606. }
  607. }
  608. fEntityManager.fCurrentEntity.mayReadChunks = true;
  609. // if no XMLDecl, then scan piece of prolog
  610. return true;
  611. }
  612. // encoding errors
  613. catch (MalformedByteSequenceException e) {
  614. fErrorReporter.reportError(e.getDomain(), e.getKey(),
  615. e.getArguments(), XMLErrorReporter.SEVERITY_FATAL_ERROR);
  616. return false;
  617. }
  618. catch (CharConversionException e) {
  619. reportFatalError("CharConversionFailure", null);
  620. return false;
  621. }
  622. // premature end of file
  623. catch (EOFException e) {
  624. reportFatalError("PrematureEOF", null);
  625. return false;
  626. //throw e;
  627. }
  628. } // dispatch(boolean):boolean
  629. } // class XMLDeclDispatcher
  630. /**
  631. * Dispatcher to handle prolog scanning.
  632. *
  633. * @author Andy Clark, IBM
  634. */
  635. protected final class PrologDispatcher
  636. implements Dispatcher {
  637. //
  638. // Dispatcher methods
  639. //
  640. /**
  641. * Dispatch an XML "event".
  642. *
  643. * @param complete True if this dispatcher is intended to scan
  644. * and dispatch as much as possible.
  645. *
  646. * @return True if there is more to dispatch either from this
  647. * or a another dispatcher.
  648. *
  649. * @throws IOException Thrown on i/o error.
  650. * @throws XNIException Thrown on parse error.
  651. */
  652. public boolean dispatch(boolean complete)
  653. throws IOException, XNIException {
  654. try {
  655. boolean again;
  656. do {
  657. again = false;
  658. switch (fScannerState) {
  659. case SCANNER_STATE_PROLOG: {
  660. fEntityScanner.skipSpaces();
  661. if (fEntityScanner.skipChar('<')) {
  662. setScannerState(SCANNER_STATE_START_OF_MARKUP);
  663. again = true;
  664. }
  665. else if (fEntityScanner.skipChar('&')) {
  666. setScannerState(SCANNER_STATE_REFERENCE);
  667. again = true;
  668. }
  669. else {
  670. setScannerState(SCANNER_STATE_CONTENT);
  671. again = true;
  672. }
  673. break;
  674. }
  675. case SCANNER_STATE_START_OF_MARKUP: {
  676. fMarkupDepth++;
  677. if (fEntityScanner.skipChar('!')) {
  678. if (fEntityScanner.skipChar('-')) {
  679. if (!fEntityScanner.skipChar('-')) {
  680. reportFatalError("InvalidCommentStart",
  681. null);
  682. }
  683. setScannerState(SCANNER_STATE_COMMENT);
  684. again = true;
  685. }
  686. else if (fEntityScanner.skipString("DOCTYPE")) {
  687. setScannerState(SCANNER_STATE_DOCTYPE);
  688. again = true;
  689. }
  690. else {
  691. reportFatalError("MarkupNotRecognizedInProlog",
  692. null);
  693. }
  694. }
  695. else if (isValidNameStartChar(fEntityScanner.peekChar())) {
  696. setScannerState(SCANNER_STATE_ROOT_ELEMENT);
  697. setDispatcher(fContentDispatcher);
  698. return true;
  699. }
  700. else if (fEntityScanner.skipChar('?')) {
  701. setScannerState(SCANNER_STATE_PI);
  702. again = true;
  703. }
  704. else if (isValidNameStartHighSurrogate(fEntityScanner.peekChar())) {
  705. setScannerState(SCANNER_STATE_ROOT_ELEMENT);
  706. setDispatcher(fContentDispatcher);
  707. return true;
  708. }
  709. else {
  710. reportFatalError("MarkupNotRecognizedInProlog",
  711. null);
  712. }
  713. break;
  714. }
  715. case SCANNER_STATE_COMMENT: {
  716. scanComment();
  717. setScannerState(SCANNER_STATE_PROLOG);
  718. break;
  719. }
  720. case SCANNER_STATE_PI: {
  721. scanPI();
  722. setScannerState(SCANNER_STATE_PROLOG);
  723. break;
  724. }
  725. case SCANNER_STATE_DOCTYPE: {
  726. if (fDisallowDoctype) {
  727. reportFatalError("DoctypeNotAllowed", null);
  728. }
  729. if (fSeenDoctypeDecl) {
  730. reportFatalError("AlreadySeenDoctype", null);
  731. }
  732. fSeenDoctypeDecl = true;
  733. // scanDoctypeDecl() sends XNI doctypeDecl event that
  734. // in SAX is converted to startDTD() event.
  735. if (scanDoctypeDecl()) {
  736. setScannerState(SCANNER_STATE_DTD_INTERNAL_DECLS);
  737. setDispatcher(fDTDDispatcher);
  738. return true;
  739. }
  740. // handle external subset
  741. if (fDoctypeSystemId != null) {
  742. if (((fValidation || fLoadExternalDTD)
  743. && (fValidationManager == null || !fValidationManager.isCachedDTD()))) {
  744. setScannerState(SCANNER_STATE_DTD_EXTERNAL);
  745. setDispatcher(fDTDDispatcher);
  746. return true;
  747. }
  748. }
  749. else if (fExternalSubsetSource != null) {
  750. if (((fValidation || fLoadExternalDTD)
  751. && (fValidationManager == null || !fValidationManager.isCachedDTD()))) {
  752. // This handles the case of a DOCTYPE that had neither an internal subset or an external subset.
  753. fDTDScanner.setInputSource(fExternalSubsetSource);
  754. fExternalSubsetSource = null;
  755. setScannerState(SCANNER_STATE_DTD_EXTERNAL_DECLS);
  756. setDispatcher(fDTDDispatcher);
  757. return true;
  758. }
  759. }
  760. // Send endDTD() call if:
  761. // a) systemId is null or if an external subset resolver could not locate an external subset.
  762. // b) "load-external-dtd" and validation are false
  763. // c) DTD grammar is cached
  764. // in XNI this results in 3 events: doctypeDecl, startDTD, endDTD
  765. // in SAX this results in 2 events: startDTD, endDTD
  766. fDTDScanner.setInputSource(null);
  767. setScannerState(SCANNER_STATE_PROLOG);
  768. break;
  769. }
  770. case SCANNER_STATE_CONTENT: {
  771. reportFatalError("ContentIllegalInProlog", null);
  772. fEntityScanner.scanChar();
  773. }
  774. case SCANNER_STATE_REFERENCE: {
  775. reportFatalError("ReferenceIllegalInProlog", null);
  776. }
  777. }
  778. } while (complete || again);
  779. if (complete) {
  780. if (fEntityScanner.scanChar() != '<') {
  781. reportFatalError("RootElementRequired", null);
  782. }
  783. setScannerState(SCANNER_STATE_ROOT_ELEMENT);
  784. setDispatcher(fContentDispatcher);
  785. }
  786. }
  787. // encoding errors
  788. catch (MalformedByteSequenceException e) {
  789. fErrorReporter.reportError(e.getDomain(), e.getKey(),
  790. e.getArguments(), XMLErrorReporter.SEVERITY_FATAL_ERROR);
  791. return false;
  792. }
  793. catch (CharConversionException e) {
  794. reportFatalError("CharConversionFailure", null);
  795. return false;
  796. }
  797. // premature end of file
  798. catch (EOFException e) {
  799. reportFatalError("PrematureEOF", null);
  800. return false;
  801. //throw e;
  802. }
  803. return true;
  804. } // dispatch(boolean):boolean
  805. } // class PrologDispatcher
  806. /**
  807. * Dispatcher to handle the internal and external DTD subsets.
  808. *
  809. * @author Andy Clark, IBM
  810. */
  811. protected final class DTDDispatcher
  812. implements Dispatcher {
  813. //
  814. // Dispatcher methods
  815. //
  816. /**
  817. * Dispatch an XML "event".
  818. *
  819. * @param complete True if this dispatcher is intended to scan
  820. * and dispatch as much as possible.
  821. *
  822. * @return True if there is more to dispatch either from this
  823. * or a another dispatcher.
  824. *
  825. * @throws IOException Thrown on i/o error.
  826. * @throws XNIException Thrown on parse error.
  827. */
  828. public boolean dispatch(boolean complete)
  829. throws IOException, XNIException {
  830. fEntityManager.setEntityHandler(null);
  831. try {
  832. boolean again;
  833. XMLEntityDescriptionImpl entityDescription = new XMLEntityDescriptionImpl();
  834. do {
  835. again = false;
  836. switch (fScannerState) {
  837. case SCANNER_STATE_DTD_INTERNAL_DECLS: {
  838. // REVISIT: Should there be a feature for
  839. // the "complete" parameter?
  840. boolean completeDTD = true;
  841. boolean moreToScan = fDTDScanner.scanDTDInternalSubset(completeDTD, fStandalone, fHasExternalDTD && fLoadExternalDTD);
  842. if (!moreToScan) {
  843. // end doctype declaration
  844. if (!fEntityScanner.skipChar(']')) {
  845. reportFatalError("EXPECTED_SQUARE_BRACKET_TO_CLOSE_INTERNAL_SUBSET",
  846. null);
  847. }
  848. fEntityScanner.skipSpaces();
  849. if (!fEntityScanner.skipChar('>')) {
  850. reportFatalError("DoctypedeclUnterminated", new Object[]{fDoctypeName});
  851. }
  852. fMarkupDepth--;
  853. // scan external subset next
  854. if (fDoctypeSystemId != null) {
  855. if ((fValidation || fLoadExternalDTD)
  856. && (fValidationManager == null || !fValidationManager.isCachedDTD())) {
  857. setScannerState(SCANNER_STATE_DTD_EXTERNAL);
  858. break;
  859. }
  860. }
  861. else if (fExternalSubsetSource != null) {
  862. if ((fValidation || fLoadExternalDTD)
  863. && (fValidationManager == null || !fValidationManager.isCachedDTD())) {
  864. // This handles the case of a DOCTYPE that only had an internal subset.
  865. fDTDScanner.setInputSource(fExternalSubsetSource);
  866. fExternalSubsetSource = null;
  867. setScannerState(SCANNER_STATE_DTD_EXTERNAL_DECLS);
  868. break;
  869. }
  870. }
  871. // break out of this dispatcher.
  872. setScannerState(SCANNER_STATE_PROLOG);
  873. setDispatcher(fPrologDispatcher);
  874. fEntityManager.setEntityHandler(XMLDocumentScannerImpl.this);
  875. return true;
  876. }
  877. break;
  878. }
  879. case SCANNER_STATE_DTD_EXTERNAL: {
  880. entityDescription.setDescription("[dtd]", fDoctypePublicId, fDoctypeSystemId, null, null);
  881. XMLInputSource xmlInputSource =
  882. fEntityManager.resolveEntity(entityDescription);
  883. fDTDScanner.setInputSource(xmlInputSource);
  884. setScannerState(SCANNER_STATE_DTD_EXTERNAL_DECLS);
  885. again = true;
  886. break;
  887. }
  888. case SCANNER_STATE_DTD_EXTERNAL_DECLS: {
  889. // REVISIT: Should there be a feature for
  890. // the "complete" parameter?
  891. boolean completeDTD = true;
  892. boolean moreToScan = fDTDScanner.scanDTDExternalSubset(completeDTD);
  893. if (!moreToScan) {
  894. setScannerState(SCANNER_STATE_PROLOG);
  895. setDispatcher(fPrologDispatcher);
  896. fEntityManager.setEntityHandler(XMLDocumentScannerImpl.this);
  897. return true;
  898. }
  899. break;
  900. }
  901. default: {
  902. throw new XNIException("DTDDispatcher#dispatch: scanner state="+fScannerState+" ("+getScannerStateName(fScannerState)+')');
  903. }
  904. }
  905. } while (complete || again);
  906. }
  907. // encoding errors
  908. catch (MalformedByteSequenceException e) {
  909. fErrorReporter.reportError(e.getDomain(), e.getKey(),
  910. e.getArguments(), XMLErrorReporter.SEVERITY_FATAL_ERROR);
  911. return false;
  912. }
  913. catch (CharConversionException e) {
  914. reportFatalError("CharConversionFailure", null);
  915. return false;
  916. }
  917. // premature end of file
  918. catch (EOFException e) {
  919. reportFatalError("PrematureEOF", null);
  920. return false;
  921. //throw e;
  922. }
  923. // cleanup
  924. finally {
  925. fEntityManager.setEntityHandler(XMLDocumentScannerImpl.this);
  926. }
  927. return true;
  928. } // dispatch(boolean):boolean
  929. } // class DTDDispatcher
  930. /**
  931. * Dispatcher to handle content scanning.
  932. *
  933. * @author Andy Clark, IBM
  934. * @author Eric Ye, IBM
  935. */
  936. protected class ContentDispatcher
  937. extends FragmentContentDispatcher {
  938. //
  939. // Protected methods
  940. //
  941. // hooks
  942. // NOTE: These hook methods are added so that the full document
  943. // scanner can share the majority of code with this class.
  944. /**
  945. * Scan for DOCTYPE hook. This method is a hook for subclasses
  946. * to add code to handle scanning for a the "DOCTYPE" string
  947. * after the string "<!" has been scanned.
  948. *
  949. * @return True if the "DOCTYPE" was scanned; false if "DOCTYPE"
  950. * was not scanned.
  951. */
  952. protected boolean scanForDoctypeHook()
  953. throws IOException, XNIException {
  954. if (fEntityScanner.skipString("DOCTYPE")) {
  955. setScannerState(SCANNER_STATE_DOCTYPE);
  956. return true;
  957. }
  958. return false;
  959. } // scanForDoctypeHook():boolean
  960. /**
  961. * Element depth iz zero. This methos is a hook for subclasses
  962. * to add code to handle when the element depth hits zero. When
  963. * scanning a document fragment, an element depth of zero is
  964. * normal. However, when scanning a full XML document, the
  965. * scanner must handle the trailing miscellanous section of
  966. * the document after the end of the document's root element.
  967. *
  968. * @return True if the caller should stop and return true which
  969. * allows the scanner to switch to a new scanning
  970. * dispatcher. A return value of false indicates that
  971. * the content dispatcher should continue as normal.
  972. */
  973. protected boolean elementDepthIsZeroHook()
  974. throws IOException, XNIException {
  975. setScannerState(SCANNER_STATE_TRAILING_MISC);
  976. setDispatcher(fTrailingMiscDispatcher);
  977. return true;
  978. } // elementDepthIsZeroHook():boolean
  979. /**
  980. * Scan for root element hook. This method is a hook for
  981. * subclasses to add code that handles scanning for the root
  982. * element. When scanning a document fragment, there is no
  983. * "root" element. However, when scanning a full XML document,
  984. * the scanner must handle the root element specially.
  985. *
  986. * @return True if the caller should stop and return true which
  987. * allows the scanner to switch to a new scanning
  988. * dispatcher. A return value of false indicates that
  989. * the content dispatcher should continue as normal.
  990. */
  991. protected boolean scanRootElementHook()
  992. throws IOException, XNIException {
  993. if (fExternalSubsetResolver != null && !fSeenDoctypeDecl
  994. && !fDisallowDoctype && (fValidation || fLoadExternalDTD)) {
  995. scanStartElementName();
  996. resolveExternalSubsetAndRead();
  997. if (scanStartElementAfterName()) {
  998. setScannerState(SCANNER_STATE_TRAILING_MISC);
  999. setDispatcher(fTrailingMiscDispatcher);
  1000. return true;
  1001. }
  1002. }
  1003. else if (scanStartElement()) {
  1004. setScannerState(SCANNER_STATE_TRAILING_MISC);
  1005. setDispatcher(fTrailingMiscDispatcher);
  1006. return true;
  1007. }
  1008. return false;
  1009. } // scanRootElementHook():boolean
  1010. /**
  1011. * End of file hook. This method is a hook for subclasses to
  1012. * add code that handles the end of file. The end of file in
  1013. * a document fragment is OK if the markup depth is zero.
  1014. * However, when scanning a full XML document, an end of file
  1015. * is always premature.
  1016. */
  1017. protected void endOfFileHook(EOFException e)
  1018. throws IOException, XNIException {
  1019. reportFatalError("PrematureEOF", null);
  1020. // in case continue-after-fatal-error set, should not do this...
  1021. //throw e;
  1022. } // endOfFileHook()
  1023. /**
  1024. * <p>Attempt to locate an external subset for a document that does not otherwise
  1025. * have one. If an external subset is located, then it is scanned.</p>
  1026. */
  1027. protected void resolveExternalSubsetAndRead()
  1028. throws IOException, XNIException {
  1029. XMLDTDDescription desc = new XMLDTDDescription(null,
  1030. null, fEntityManager.getCurrentResourceIdentifier().getExpandedSystemId(), null, fElementQName.rawname);
  1031. XMLInputSource src = fExternalSubsetResolver.getExternalSubset(desc);
  1032. if (src != null) {
  1033. fDoctypeName = fElementQName.rawname;
  1034. fDoctypePublicId = src.getPublicId();
  1035. fDoctypeSystemId = src.getSystemId();
  1036. // call document handler
  1037. if (fDocumentHandler != null) {
  1038. // This inserts a doctypeDecl event into the stream though no
  1039. // DOCTYPE existed in the instance document.
  1040. fDocumentHandler.doctypeDecl(fDoctypeName, fDoctypePublicId, fDoctypeSystemId, null);
  1041. }
  1042. try {
  1043. fDTDScanner.setInputSource(src);
  1044. while (fDTDScanner.scanDTDExternalSubset(true));
  1045. }
  1046. finally {
  1047. fEntityManager.setEntityHandler(XMLDocumentScannerImpl.this);
  1048. }
  1049. }
  1050. } // resolveExternalSubsetAndRead()
  1051. } // class ContentDispatcher
  1052. /**
  1053. * Dispatcher to handle trailing miscellaneous section scanning.
  1054. *
  1055. * @author Andy Clark, IBM
  1056. * @author Eric Ye, IBM
  1057. */
  1058. protected final class TrailingMiscDispatcher
  1059. implements Dispatcher {
  1060. //
  1061. // Dispatcher methods
  1062. //
  1063. /**
  1064. * Dispatch an XML "event".
  1065. *
  1066. * @param complete True if this dispatcher is intended to scan
  1067. * and dispatch as much as possible.
  1068. *
  1069. * @return True if there is more to dispatch either from this
  1070. * or a another dispatcher.
  1071. *
  1072. * @throws IOException Thrown on i/o error.
  1073. * @throws XNIException Thrown on parse error.
  1074. */
  1075. public boolean dispatch(boolean complete)
  1076. throws IOException, XNIException {
  1077. try {
  1078. boolean again;
  1079. do {
  1080. again = false;
  1081. switch (fScannerState) {
  1082. case SCANNER_STATE_TRAILING_MISC: {
  1083. fEntityScanner.skipSpaces();
  1084. if (fEntityScanner.skipChar('<')) {
  1085. setScannerState(SCANNER_STATE_START_OF_MARKUP);
  1086. again = true;
  1087. }
  1088. else {
  1089. setScannerState(SCANNER_STATE_CONTENT);
  1090. again = true;
  1091. }
  1092. break;
  1093. }
  1094. case SCANNER_STATE_START_OF_MARKUP: {
  1095. fMarkupDepth++;
  1096. if (fEntityScanner.skipChar('?')) {
  1097. setScannerState(SCANNER_STATE_PI);
  1098. again = true;
  1099. }
  1100. else if (fEntityScanner.skipChar('!')) {
  1101. setScannerState(SCANNER_STATE_COMMENT);
  1102. again = true;
  1103. }
  1104. else if (fEntityScanner.skipChar('/')) {
  1105. reportFatalError("MarkupNotRecognizedInMisc",
  1106. null);
  1107. again = true;
  1108. }
  1109. else if (isValidNameStartChar(fEntityScanner.peekChar())) {
  1110. reportFatalError("MarkupNotRecognizedInMisc",
  1111. null);
  1112. scanStartElement();
  1113. setScannerState(SCANNER_STATE_CONTENT);
  1114. }
  1115. else if (isValidNameStartHighSurrogate(fEntityScanner.peekChar())) {
  1116. reportFatalError("MarkupNotRecognizedInMisc",
  1117. null);
  1118. scanStartElement();
  1119. setScannerState(SCANNER_STATE_CONTENT);
  1120. }
  1121. else {
  1122. reportFatalError("MarkupNotRecognizedInMisc",
  1123. null);
  1124. }
  1125. break;
  1126. }
  1127. case SCANNER_STATE_PI: {
  1128. scanPI();
  1129. setScannerState(SCANNER_STATE_TRAILING_MISC);
  1130. break;
  1131. }
  1132. case SCANNER_STATE_COMMENT: {
  1133. if (!fEntityScanner.skipString("--")) {
  1134. reportFatalError("InvalidCommentStart", null);
  1135. }
  1136. scanComment();
  1137. setScannerState(SCANNER_STATE_TRAILING_MISC);
  1138. break;
  1139. }
  1140. case SCANNER_STATE_CONTENT: {
  1141. int ch = fEntityScanner.peekChar();
  1142. if (ch == -1) {
  1143. setScannerState(SCANNER_STATE_TERMINATED);
  1144. return false;
  1145. }
  1146. reportFatalError("ContentIllegalInTrailingMisc",
  1147. null);
  1148. fEntityScanner.scanChar();
  1149. setScannerState(SCANNER_STATE_TRAILING_MISC);
  1150. break;
  1151. }
  1152. case SCANNER_STATE_REFERENCE: {
  1153. reportFatalError("ReferenceIllegalInTrailingMisc",
  1154. null);
  1155. setScannerState(SCANNER_STATE_TRAILING_MISC);
  1156. break;
  1157. }
  1158. case SCANNER_STATE_TERMINATED: {
  1159. return false;
  1160. }
  1161. }
  1162. } while (complete || again);
  1163. }
  1164. // encoding errors
  1165. catch (MalformedByteSequenceException e) {
  1166. fErrorReporter.reportError(e.getDomain(), e.getKey(),
  1167. e.getArguments(), XMLErrorReporter.SEVERITY_FATAL_ERROR);
  1168. return false;
  1169. }
  1170. catch (CharConversionException e) {
  1171. reportFatalError("CharConversionFailure", null);
  1172. return false;
  1173. }
  1174. catch (EOFException e) {
  1175. // NOTE: This is the only place we're allowed to reach
  1176. // the real end of the document stream. Unless the
  1177. // end of file was reached prematurely.
  1178. if (fMarkupDepth != 0) {
  1179. reportFatalError("PrematureEOF", null);
  1180. return false;
  1181. //throw e;
  1182. }
  1183. setScannerState(SCANNER_STATE_TERMINATED);
  1184. return false;
  1185. }
  1186. return true;
  1187. } // dispatch(boolean):boolean
  1188. } // class TrailingMiscDispatcher
  1189. } // class XMLDocumentScannerImpl