12005
|
1 |
/*
|
|
2 |
* Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved.
|
|
3 |
*/
|
|
4 |
|
|
5 |
/*
|
|
6 |
* Copyright 2005 The Apache Software Foundation.
|
|
7 |
*
|
|
8 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
9 |
* you may not use this file except in compliance with the License.
|
|
10 |
* You may obtain a copy of the License at
|
|
11 |
*
|
|
12 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
13 |
*
|
|
14 |
* Unless required by applicable law or agreed to in writing, software
|
|
15 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17 |
* See the License for the specific language governing permissions and
|
|
18 |
* limitations under the License.
|
|
19 |
*/
|
|
20 |
|
|
21 |
package com.sun.org.apache.xerces.internal.impl;
|
|
22 |
|
|
23 |
|
|
24 |
import com.sun.xml.internal.stream.Entity;
|
|
25 |
import com.sun.xml.internal.stream.StaxXMLInputSource;
|
|
26 |
import com.sun.xml.internal.stream.dtd.DTDGrammarUtil;
|
|
27 |
import java.io.EOFException;
|
|
28 |
import java.io.IOException;
|
|
29 |
import javax.xml.stream.XMLInputFactory;
|
|
30 |
import javax.xml.stream.events.XMLEvent;
|
|
31 |
|
|
32 |
import com.sun.org.apache.xerces.internal.impl.validation.ValidationManager;
|
|
33 |
import com.sun.org.apache.xerces.internal.util.NamespaceSupport;
|
|
34 |
import com.sun.org.apache.xerces.internal.util.XMLChar;
|
|
35 |
import com.sun.org.apache.xerces.internal.util.XMLResourceIdentifierImpl;
|
|
36 |
import com.sun.org.apache.xerces.internal.util.XMLStringBuffer;
|
|
37 |
import com.sun.org.apache.xerces.internal.xni.NamespaceContext;
|
|
38 |
import com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier;
|
|
39 |
import com.sun.org.apache.xerces.internal.xni.XMLString;
|
|
40 |
import com.sun.org.apache.xerces.internal.xni.XNIException;
|
|
41 |
import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;
|
|
42 |
import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager;
|
|
43 |
import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;
|
|
44 |
import com.sun.org.apache.xerces.internal.xni.parser.XMLDTDScanner;
|
|
45 |
import com.sun.org.apache.xerces.internal.xni.Augmentations;
|
|
46 |
import com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDDescription;
|
|
47 |
import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentScanner;
|
|
48 |
|
|
49 |
|
|
50 |
/**
|
|
51 |
* This class is responsible for scanning XML document structure
|
|
52 |
* and content.
|
|
53 |
*
|
|
54 |
* This class has been modified as per the new design which is more suited to
|
|
55 |
* efficiently build pull parser. Lot of improvements have been done and
|
|
56 |
* the code has been added to support stax functionality/features.
|
|
57 |
*
|
|
58 |
* @author Neeraj Bajaj, Sun Microsystems
|
|
59 |
* @author K.Venugopal, Sun Microsystems
|
|
60 |
* @author Glenn Marcy, IBM
|
|
61 |
* @author Andy Clark, IBM
|
|
62 |
* @author Arnaud Le Hors, IBM
|
|
63 |
* @author Eric Ye, IBM
|
|
64 |
* @author Sunitha Reddy, Sun Microsystems
|
|
65 |
*
|
|
66 |
* Refer to the table in unit-test javax.xml.stream.XMLStreamReaderTest.SupportDTD for changes
|
|
67 |
* related to property SupportDTD.
|
|
68 |
* @author Joe Wang, Sun Microsystems
|
|
69 |
* @version $Id: XMLDocumentScannerImpl.java,v 1.17 2010-11-01 04:39:41 joehw Exp $
|
|
70 |
*/
|
|
71 |
public class XMLDocumentScannerImpl
|
|
72 |
extends XMLDocumentFragmentScannerImpl{
|
|
73 |
|
|
74 |
//
|
|
75 |
// Constants
|
|
76 |
//
|
|
77 |
|
|
78 |
// scanner states
|
|
79 |
|
|
80 |
/** Scanner state: XML declaration. */
|
|
81 |
protected static final int SCANNER_STATE_XML_DECL = 42;
|
|
82 |
|
|
83 |
/** Scanner state: prolog. */
|
|
84 |
protected static final int SCANNER_STATE_PROLOG = 43;
|
|
85 |
|
|
86 |
/** Scanner state: trailing misc. */
|
|
87 |
protected static final int SCANNER_STATE_TRAILING_MISC = 44;
|
|
88 |
|
|
89 |
/** Scanner state: DTD internal declarations. */
|
|
90 |
protected static final int SCANNER_STATE_DTD_INTERNAL_DECLS = 45;
|
|
91 |
|
|
92 |
/** Scanner state: open DTD external subset. */
|
|
93 |
protected static final int SCANNER_STATE_DTD_EXTERNAL = 46;
|
|
94 |
|
|
95 |
/** Scanner state: DTD external declarations. */
|
|
96 |
protected static final int SCANNER_STATE_DTD_EXTERNAL_DECLS = 47;
|
|
97 |
|
|
98 |
/** Scanner state: NO MORE ELEMENTS. */
|
|
99 |
protected static final int SCANNER_STATE_NO_SUCH_ELEMENT_EXCEPTION = 48;
|
|
100 |
|
|
101 |
// feature identifiers
|
|
102 |
|
|
103 |
/** Property identifier document scanner: */
|
|
104 |
protected static final String DOCUMENT_SCANNER =
|
|
105 |
Constants.XERCES_PROPERTY_PREFIX + Constants.DOCUMENT_SCANNER_PROPERTY;
|
|
106 |
|
|
107 |
/** Feature identifier: load external DTD. */
|
|
108 |
protected static final String LOAD_EXTERNAL_DTD =
|
|
109 |
Constants.XERCES_FEATURE_PREFIX + Constants.LOAD_EXTERNAL_DTD_FEATURE;
|
|
110 |
|
|
111 |
/** Feature identifier: load external DTD. */
|
|
112 |
protected static final String DISALLOW_DOCTYPE_DECL_FEATURE =
|
|
113 |
Constants.XERCES_FEATURE_PREFIX + Constants.DISALLOW_DOCTYPE_DECL_FEATURE;
|
|
114 |
|
|
115 |
// property identifiers
|
|
116 |
|
|
117 |
/** Property identifier: DTD scanner. */
|
|
118 |
protected static final String DTD_SCANNER =
|
|
119 |
Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_SCANNER_PROPERTY;
|
|
120 |
|
|
121 |
// property identifier: ValidationManager
|
|
122 |
protected static final String VALIDATION_MANAGER =
|
|
123 |
Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY;
|
|
124 |
|
|
125 |
/** property identifier: NamespaceContext */
|
|
126 |
protected static final String NAMESPACE_CONTEXT =
|
|
127 |
Constants.XERCES_PROPERTY_PREFIX + Constants.NAMESPACE_CONTEXT_PROPERTY;
|
|
128 |
|
|
129 |
// recognized features and properties
|
|
130 |
|
|
131 |
/** Recognized features. */
|
|
132 |
private static final String[] RECOGNIZED_FEATURES = {
|
|
133 |
LOAD_EXTERNAL_DTD,
|
|
134 |
DISALLOW_DOCTYPE_DECL_FEATURE,
|
|
135 |
};
|
|
136 |
|
|
137 |
/** Feature defaults. */
|
|
138 |
private static final Boolean[] FEATURE_DEFAULTS = {
|
|
139 |
Boolean.TRUE,
|
|
140 |
Boolean.FALSE,
|
|
141 |
};
|
|
142 |
|
|
143 |
/** Recognized properties. */
|
|
144 |
private static final String[] RECOGNIZED_PROPERTIES = {
|
|
145 |
DTD_SCANNER,
|
|
146 |
VALIDATION_MANAGER
|
|
147 |
};
|
|
148 |
|
|
149 |
/** Property defaults. */
|
|
150 |
private static final Object[] PROPERTY_DEFAULTS = {
|
|
151 |
null,
|
|
152 |
null
|
|
153 |
};
|
|
154 |
|
|
155 |
//
|
|
156 |
// Data((Boolean)propertyManager.getProperty(XMLInputFactory.IS_NAMESPACE_AWARE)).booleanValue();
|
|
157 |
//
|
|
158 |
|
|
159 |
// properties
|
|
160 |
|
|
161 |
/** DTD scanner. */
|
|
162 |
protected XMLDTDScanner fDTDScanner = null;
|
|
163 |
|
|
164 |
/** Validation manager . */
|
|
165 |
//xxx: fValidationManager code needs to be added yet!
|
|
166 |
protected ValidationManager fValidationManager;
|
|
167 |
|
|
168 |
protected XMLStringBuffer fDTDDecl = null;
|
|
169 |
protected boolean fReadingDTD = false;
|
|
170 |
protected boolean fAddedListener = false;
|
|
171 |
|
|
172 |
// protected data
|
|
173 |
|
|
174 |
// other info
|
|
175 |
|
|
176 |
/** Doctype name. */
|
|
177 |
protected String fDoctypeName;
|
|
178 |
|
|
179 |
/** Doctype declaration public identifier. */
|
|
180 |
protected String fDoctypePublicId;
|
|
181 |
|
|
182 |
/** Doctype declaration system identifier. */
|
|
183 |
protected String fDoctypeSystemId;
|
|
184 |
|
|
185 |
/** Namespace support. */
|
|
186 |
protected NamespaceContext fNamespaceContext = new NamespaceSupport();
|
|
187 |
|
|
188 |
// features
|
|
189 |
|
|
190 |
/** Load external DTD. */
|
|
191 |
protected boolean fLoadExternalDTD = true;
|
|
192 |
|
|
193 |
// state
|
|
194 |
|
|
195 |
/** Seen doctype declaration. */
|
|
196 |
protected boolean fSeenDoctypeDecl;
|
|
197 |
|
|
198 |
protected boolean fScanEndElement;
|
|
199 |
|
|
200 |
//protected int fScannerLastState ;
|
|
201 |
|
|
202 |
// drivers
|
|
203 |
|
|
204 |
/** XML declaration driver. */
|
|
205 |
protected Driver fXMLDeclDriver = new XMLDeclDriver();
|
|
206 |
|
|
207 |
/** Prolog driver. */
|
|
208 |
protected Driver fPrologDriver = new PrologDriver();
|
|
209 |
|
|
210 |
/** DTD driver. */
|
|
211 |
protected Driver fDTDDriver = null ;
|
|
212 |
|
|
213 |
/** Trailing miscellaneous section driver. */
|
|
214 |
protected Driver fTrailingMiscDriver = new TrailingMiscDriver();
|
|
215 |
protected int fStartPos = 0;
|
|
216 |
protected int fEndPos = 0;
|
|
217 |
protected boolean fSeenInternalSubset= false;
|
|
218 |
// temporary variables
|
|
219 |
|
|
220 |
/** Array of 3 strings. */
|
|
221 |
private String[] fStrings = new String[3];
|
|
222 |
|
|
223 |
/** External subset source. */
|
|
224 |
private XMLInputSource fExternalSubsetSource = null;
|
|
225 |
|
|
226 |
/** A DTD Description. */
|
|
227 |
private final XMLDTDDescription fDTDDescription = new XMLDTDDescription(null, null, null, null, null);
|
|
228 |
|
|
229 |
/** String. */
|
|
230 |
private XMLString fString = new XMLString();
|
|
231 |
|
|
232 |
private static final char [] DOCTYPE = {'D','O','C','T','Y','P','E'};
|
|
233 |
private static final char [] COMMENTSTRING = {'-','-'};
|
|
234 |
|
|
235 |
//
|
|
236 |
// Constructors
|
|
237 |
//
|
|
238 |
|
|
239 |
/** Default constructor. */
|
|
240 |
public XMLDocumentScannerImpl() {} // <init>()
|
|
241 |
|
|
242 |
|
|
243 |
//
|
|
244 |
// XMLDocumentScanner methods
|
|
245 |
//
|
|
246 |
|
|
247 |
|
|
248 |
/**
|
|
249 |
* Sets the input source.
|
|
250 |
*
|
|
251 |
* @param inputSource The input source.
|
|
252 |
*
|
|
253 |
* @throws IOException Thrown on i/o error.
|
|
254 |
*/
|
|
255 |
public void setInputSource(XMLInputSource inputSource) throws IOException {
|
|
256 |
fEntityManager.setEntityHandler(this);
|
|
257 |
//this starts a new entity and sets the current entity to the document entity.
|
|
258 |
fEntityManager.startDocumentEntity(inputSource);
|
|
259 |
// fDocumentSystemId = fEntityManager.expandSystemId(inputSource.getSystemId());
|
|
260 |
setScannerState(XMLEvent.START_DOCUMENT);
|
|
261 |
} // setInputSource(XMLInputSource)
|
|
262 |
|
|
263 |
|
|
264 |
|
|
265 |
/**return the state of the scanner */
|
|
266 |
public int getScannetState(){
|
|
267 |
return fScannerState ;
|
|
268 |
}
|
|
269 |
|
|
270 |
|
|
271 |
|
|
272 |
|
|
273 |
public void reset(PropertyManager propertyManager) {
|
|
274 |
super.reset(propertyManager);
|
|
275 |
// other settings
|
|
276 |
fDoctypeName = null;
|
|
277 |
fDoctypePublicId = null;
|
|
278 |
fDoctypeSystemId = null;
|
|
279 |
fSeenDoctypeDecl = false;
|
|
280 |
fNamespaceContext.reset();
|
|
281 |
fDisallowDoctype = !((Boolean)propertyManager.getProperty(XMLInputFactory.SUPPORT_DTD)).booleanValue();
|
|
282 |
|
|
283 |
// xerces features
|
|
284 |
fLoadExternalDTD = !((Boolean)propertyManager.getProperty(Constants.ZEPHYR_PROPERTY_PREFIX + Constants.IGNORE_EXTERNAL_DTD)).booleanValue();
|
|
285 |
setScannerState(XMLEvent.START_DOCUMENT);
|
|
286 |
setDriver(fXMLDeclDriver);
|
|
287 |
fSeenInternalSubset = false;
|
|
288 |
if(fDTDScanner != null){
|
|
289 |
((XMLDTDScannerImpl)fDTDScanner).reset(propertyManager);
|
|
290 |
}
|
|
291 |
fEndPos = 0;
|
|
292 |
fStartPos = 0;
|
|
293 |
if(fDTDDecl != null){
|
|
294 |
fDTDDecl.clear();
|
|
295 |
}
|
|
296 |
|
|
297 |
}
|
|
298 |
|
|
299 |
/**
|
|
300 |
* Resets the component. The component can query the component manager
|
|
301 |
* about any features and properties that affect the operation of the
|
|
302 |
* component.
|
|
303 |
*
|
|
304 |
* @param componentManager The component manager.
|
|
305 |
*
|
|
306 |
* @throws SAXException Thrown by component on initialization error.
|
|
307 |
* For example, if a feature or property is
|
|
308 |
* required for the operation of the component, the
|
|
309 |
* component manager may throw a
|
|
310 |
* SAXNotRecognizedException or a
|
|
311 |
* SAXNotSupportedException.
|
|
312 |
*/
|
|
313 |
public void reset(XMLComponentManager componentManager)
|
|
314 |
throws XMLConfigurationException {
|
|
315 |
|
|
316 |
super.reset(componentManager);
|
|
317 |
|
|
318 |
// other settings
|
|
319 |
fDoctypeName = null;
|
|
320 |
fDoctypePublicId = null;
|
|
321 |
fDoctypeSystemId = null;
|
|
322 |
fSeenDoctypeDecl = false;
|
|
323 |
fExternalSubsetSource = null;
|
|
324 |
|
|
325 |
// xerces features
|
|
326 |
fLoadExternalDTD = componentManager.getFeature(LOAD_EXTERNAL_DTD, true);
|
|
327 |
fDisallowDoctype = componentManager.getFeature(DISALLOW_DOCTYPE_DECL_FEATURE, false);
|
|
328 |
|
|
329 |
fNamespaces = componentManager.getFeature(NAMESPACES, true);
|
|
330 |
|
|
331 |
fSeenInternalSubset = false;
|
|
332 |
// xerces properties
|
|
333 |
fDTDScanner = (XMLDTDScanner)componentManager.getProperty(DTD_SCANNER);
|
|
334 |
|
|
335 |
fValidationManager = (ValidationManager)componentManager.getProperty(VALIDATION_MANAGER, null);
|
|
336 |
|
|
337 |
try {
|
|
338 |
fNamespaceContext = (NamespaceContext)componentManager.getProperty(NAMESPACE_CONTEXT);
|
|
339 |
}
|
|
340 |
catch (XMLConfigurationException e) { }
|
|
341 |
if (fNamespaceContext == null) {
|
|
342 |
fNamespaceContext = new NamespaceSupport();
|
|
343 |
}
|
|
344 |
fNamespaceContext.reset();
|
|
345 |
|
|
346 |
fEndPos = 0;
|
|
347 |
fStartPos = 0;
|
|
348 |
if(fDTDDecl != null)
|
|
349 |
fDTDDecl.clear();
|
|
350 |
|
|
351 |
|
|
352 |
//fEntityScanner.registerListener((XMLBufferListener)componentManager.getProperty(DOCUMENT_SCANNER));
|
|
353 |
|
|
354 |
// setup driver
|
|
355 |
setScannerState(SCANNER_STATE_XML_DECL);
|
|
356 |
setDriver(fXMLDeclDriver);
|
|
357 |
|
|
358 |
} // reset(XMLComponentManager)
|
|
359 |
|
|
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[] getRecognizedFeatures() {
|
|
367 |
String[] featureIds = super.getRecognizedFeatures();
|
|
368 |
int length = featureIds != null ? featureIds.length : 0;
|
|
369 |
String[] combinedFeatureIds = new String[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 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[] getRecognizedProperties() {
|
|
421 |
String[] propertyIds = super.getRecognizedProperties();
|
|
422 |
int length = propertyIds != null ? propertyIds.length : 0;
|
|
423 |
String[] combinedPropertyIds = new String[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 propertyId, Object 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 getFeatureDefault(String 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 getPropertyDefault(String 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 name,
|
|
528 |
XMLResourceIdentifier identifier,
|
|
529 |
String encoding, Augmentations augs) throws XNIException {
|
|
530 |
|
|
531 |
super.startEntity(name, identifier, encoding,augs);
|
|
532 |
|
|
533 |
//register current document scanner as a listener for XMLEntityScanner
|
|
534 |
fEntityScanner.registerListener(this);
|
|
535 |
|
|
536 |
// prepare to look for a TextDecl if external general entity
|
|
537 |
if (!name.equals("[xml]") && fEntityScanner.isExternal()) {
|
|
538 |
// Don't do this if we're skipping the entity!
|
|
539 |
if (augs == null || !((Boolean) augs.getItem(Constants.ENTITY_SKIPPED)).booleanValue()) {
|
|
540 |
setScannerState(SCANNER_STATE_TEXT_DECL);
|
|
541 |
}
|
|
542 |
}
|
|
543 |
|
|
544 |
// call handler
|
|
545 |
/** comment this part.. LOCATOR problem.. */
|
|
546 |
if (fDocumentHandler != null && name.equals("[xml]")) {
|
|
547 |
fDocumentHandler.startDocument(fEntityScanner, encoding, fNamespaceContext, null);
|
|
548 |
}
|
|
549 |
|
|
550 |
} // startEntity(String,identifier,String)
|
|
551 |
|
|
552 |
|
|
553 |
/**
|
|
554 |
* This method notifies the end of an entity. The DTD has the pseudo-name
|
|
555 |
* of "[dtd]" parameter entity names start with '%'; and general entities
|
|
556 |
* are just specified by their name.
|
|
557 |
*
|
|
558 |
* @param name The name of the entity.
|
|
559 |
*
|
|
560 |
* @throws XNIException Thrown by handler to signal an error.
|
|
561 |
*/
|
|
562 |
public void endEntity(String name, Augmentations augs) throws IOException, XNIException {
|
|
563 |
|
|
564 |
super.endEntity(name, augs);
|
|
565 |
|
|
566 |
if(name.equals("[xml]")){
|
|
567 |
//if fMarkupDepth has reached 0.
|
|
568 |
//and driver is fTrailingMiscDriver (which
|
|
569 |
//handles end of document in normal case)
|
|
570 |
//set the scanner state of SCANNER_STATE_TERMINATED
|
|
571 |
if(fMarkupDepth == 0 && fDriver == fTrailingMiscDriver){
|
|
572 |
//set the scanner set to SCANNER_STATE_TERMINATED
|
|
573 |
setScannerState(SCANNER_STATE_TERMINATED) ;
|
|
574 |
} else{
|
|
575 |
//else we have reached the end of document prematurely
|
|
576 |
//so throw EOFException.
|
|
577 |
throw new java.io.EOFException();
|
|
578 |
}
|
|
579 |
|
|
580 |
//this is taken care in wrapper which generates XNI callbacks, There are no next events
|
|
581 |
|
|
582 |
//if (fDocumentHandler != null) {
|
|
583 |
//fDocumentHandler.endDocument(null);
|
|
584 |
//}
|
|
585 |
}
|
|
586 |
} // endEntity(String)
|
|
587 |
|
|
588 |
|
|
589 |
public XMLStringBuffer getDTDDecl(){
|
|
590 |
Entity entity = fEntityScanner.getCurrentEntity();
|
|
591 |
fDTDDecl.append(((Entity.ScannedEntity)entity).ch,fStartPos , fEndPos-fStartPos);
|
|
592 |
if(fSeenInternalSubset)
|
|
593 |
fDTDDecl.append("]>");
|
|
594 |
return fDTDDecl;
|
|
595 |
}
|
|
596 |
|
|
597 |
public String getCharacterEncodingScheme(){
|
|
598 |
return fDeclaredEncoding;
|
|
599 |
}
|
|
600 |
|
|
601 |
/** return the next state on the input
|
|
602 |
*
|
|
603 |
* @return int
|
|
604 |
*/
|
|
605 |
|
|
606 |
public int next() throws IOException, XNIException {
|
|
607 |
return fDriver.next();
|
|
608 |
}
|
|
609 |
|
|
610 |
//getNamespaceContext
|
|
611 |
public NamespaceContext getNamespaceContext(){
|
|
612 |
return fNamespaceContext ;
|
|
613 |
}
|
|
614 |
|
|
615 |
|
|
616 |
|
|
617 |
//
|
|
618 |
// Protected methods
|
|
619 |
//
|
|
620 |
|
|
621 |
// driver factory methods
|
|
622 |
|
|
623 |
/** Creates a content driver. */
|
|
624 |
protected Driver createContentDriver() {
|
|
625 |
return new ContentDriver();
|
|
626 |
} // createContentDriver():Driver
|
|
627 |
|
|
628 |
// scanning methods
|
|
629 |
|
|
630 |
/** Scans a doctype declaration. */
|
|
631 |
protected boolean scanDoctypeDecl(boolean ignore) throws IOException, XNIException {
|
|
632 |
|
|
633 |
// spaces
|
|
634 |
if (!fEntityScanner.skipSpaces()) {
|
|
635 |
reportFatalError("MSG_SPACE_REQUIRED_BEFORE_ROOT_ELEMENT_TYPE_IN_DOCTYPEDECL",
|
|
636 |
null);
|
|
637 |
}
|
|
638 |
|
|
639 |
// root element name
|
|
640 |
fDoctypeName = fEntityScanner.scanName();
|
|
641 |
if (fDoctypeName == null) {
|
|
642 |
reportFatalError("MSG_ROOT_ELEMENT_TYPE_REQUIRED", null);
|
|
643 |
}
|
|
644 |
|
|
645 |
// external id
|
|
646 |
if (fEntityScanner.skipSpaces()) {
|
|
647 |
scanExternalID(fStrings, false);
|
|
648 |
fDoctypeSystemId = fStrings[0];
|
|
649 |
fDoctypePublicId = fStrings[1];
|
|
650 |
fEntityScanner.skipSpaces();
|
|
651 |
}
|
|
652 |
|
|
653 |
fHasExternalDTD = fDoctypeSystemId != null;
|
|
654 |
|
|
655 |
// Attempt to locate an external subset with an external subset resolver.
|
|
656 |
if (!ignore && !fHasExternalDTD && fExternalSubsetResolver != null) {
|
|
657 |
fDTDDescription.setValues(null, null, fEntityManager.getCurrentResourceIdentifier().getExpandedSystemId(), null);
|
|
658 |
fDTDDescription.setRootName(fDoctypeName);
|
|
659 |
fExternalSubsetSource = fExternalSubsetResolver.getExternalSubset(fDTDDescription);
|
|
660 |
fHasExternalDTD = fExternalSubsetSource != null;
|
|
661 |
}
|
|
662 |
|
|
663 |
// call handler
|
|
664 |
if (!ignore && fDocumentHandler != null) {
|
|
665 |
// NOTE: I don't like calling the doctypeDecl callback until
|
|
666 |
// end of the *full* doctype line (including internal
|
|
667 |
// subset) is parsed correctly but SAX2 requires that
|
|
668 |
// it knows the root element name and public and system
|
|
669 |
// identifier for the startDTD call. -Ac
|
|
670 |
if (fExternalSubsetSource == null) {
|
|
671 |
fDocumentHandler.doctypeDecl(fDoctypeName, fDoctypePublicId, fDoctypeSystemId, null);
|
|
672 |
}
|
|
673 |
else {
|
|
674 |
fDocumentHandler.doctypeDecl(fDoctypeName, fExternalSubsetSource.getPublicId(), fExternalSubsetSource.getSystemId(), null);
|
|
675 |
}
|
|
676 |
}
|
|
677 |
|
|
678 |
// is there an internal subset?
|
|
679 |
boolean internalSubset = true;
|
|
680 |
if (!fEntityScanner.skipChar('[')) {
|
|
681 |
internalSubset = false;
|
|
682 |
fEntityScanner.skipSpaces();
|
|
683 |
if (!fEntityScanner.skipChar('>')) {
|
|
684 |
reportFatalError("DoctypedeclUnterminated", new Object[]{fDoctypeName});
|
|
685 |
}
|
|
686 |
fMarkupDepth--;
|
|
687 |
}
|
|
688 |
return internalSubset;
|
|
689 |
|
|
690 |
} // scanDoctypeDecl():boolean
|
|
691 |
|
|
692 |
//
|
|
693 |
// Private methods
|
|
694 |
//
|
|
695 |
/** Set the scanner state after scanning DTD */
|
|
696 |
protected void setEndDTDScanState() {
|
|
697 |
setScannerState(SCANNER_STATE_PROLOG);
|
|
698 |
setDriver(fPrologDriver);
|
|
699 |
fEntityManager.setEntityHandler(XMLDocumentScannerImpl.this);
|
|
700 |
fReadingDTD=false;
|
|
701 |
}
|
|
702 |
|
|
703 |
/** Returns the scanner state name. */
|
|
704 |
protected String getScannerStateName(int state) {
|
|
705 |
|
|
706 |
switch (state) {
|
|
707 |
case SCANNER_STATE_XML_DECL: return "SCANNER_STATE_XML_DECL";
|
|
708 |
case SCANNER_STATE_PROLOG: return "SCANNER_STATE_PROLOG";
|
|
709 |
case SCANNER_STATE_TRAILING_MISC: return "SCANNER_STATE_TRAILING_MISC";
|
|
710 |
case SCANNER_STATE_DTD_INTERNAL_DECLS: return "SCANNER_STATE_DTD_INTERNAL_DECLS";
|
|
711 |
case SCANNER_STATE_DTD_EXTERNAL: return "SCANNER_STATE_DTD_EXTERNAL";
|
|
712 |
case SCANNER_STATE_DTD_EXTERNAL_DECLS: return "SCANNER_STATE_DTD_EXTERNAL_DECLS";
|
|
713 |
}
|
|
714 |
return super.getScannerStateName(state);
|
|
715 |
|
|
716 |
} // getScannerStateName(int):String
|
|
717 |
|
|
718 |
//
|
|
719 |
// Classes
|
|
720 |
//
|
|
721 |
|
|
722 |
/**
|
|
723 |
* Driver to handle XMLDecl scanning.
|
|
724 |
*
|
|
725 |
* This class has been modified as per the new design which is more suited to
|
|
726 |
* efficiently build pull parser. Lots of performance improvements have been done and
|
|
727 |
* the code has been added to support stax functionality/features.
|
|
728 |
*
|
|
729 |
* @author Neeraj Bajaj, Sun Microsystems.
|
|
730 |
*
|
|
731 |
* @author Andy Clark, IBM
|
|
732 |
*/
|
|
733 |
protected final class XMLDeclDriver
|
|
734 |
implements Driver {
|
|
735 |
|
|
736 |
//
|
|
737 |
// Driver methods
|
|
738 |
//
|
|
739 |
|
|
740 |
|
|
741 |
public int next() throws IOException, XNIException {
|
|
742 |
if(DEBUG_NEXT){
|
|
743 |
System.out.println("NOW IN XMLDeclDriver");
|
|
744 |
}
|
|
745 |
|
|
746 |
// next driver is prolog regardless of whether there
|
|
747 |
// is an XMLDecl in this document
|
|
748 |
setScannerState(SCANNER_STATE_PROLOG);
|
|
749 |
setDriver(fPrologDriver);
|
|
750 |
|
|
751 |
//System.out.println("fEntityScanner = " + fEntityScanner);
|
|
752 |
// scan XMLDecl
|
|
753 |
try {
|
|
754 |
if (fEntityScanner.skipString(xmlDecl)) {
|
|
755 |
fMarkupDepth++;
|
|
756 |
// NOTE: special case where document starts with a PI
|
|
757 |
// whose name starts with "xml" (e.g. "xmlfoo")
|
|
758 |
if (XMLChar.isName(fEntityScanner.peekChar())) {
|
|
759 |
fStringBuffer.clear();
|
|
760 |
fStringBuffer.append("xml");
|
|
761 |
while (XMLChar.isName(fEntityScanner.peekChar())) {
|
|
762 |
fStringBuffer.append((char)fEntityScanner.scanChar());
|
|
763 |
}
|
|
764 |
String target = fSymbolTable.addSymbol(fStringBuffer.ch, fStringBuffer.offset, fStringBuffer.length);
|
|
765 |
//this function should fill the data.. and set the fEvent object to this event.
|
|
766 |
fContentBuffer.clear() ;
|
|
767 |
scanPIData(target, fContentBuffer);
|
|
768 |
//REVISIT:where else we can set this value to 'true'
|
|
769 |
fEntityManager.fCurrentEntity.mayReadChunks = true;
|
|
770 |
//return PI event since PI was encountered
|
|
771 |
return XMLEvent.PROCESSING_INSTRUCTION ;
|
|
772 |
}
|
|
773 |
// standard XML declaration
|
|
774 |
else {
|
|
775 |
scanXMLDeclOrTextDecl(false);
|
|
776 |
//REVISIT:where else we can set this value to 'true'
|
|
777 |
fEntityManager.fCurrentEntity.mayReadChunks = true;
|
|
778 |
return XMLEvent.START_DOCUMENT;
|
|
779 |
}
|
|
780 |
} else{
|
|
781 |
//REVISIT:where else we can set this value to 'true'
|
|
782 |
fEntityManager.fCurrentEntity.mayReadChunks = true;
|
|
783 |
//In both case return the START_DOCUMENT. ony difference is that first block will
|
|
784 |
//cosume the XML declaration if any.
|
|
785 |
return XMLEvent.START_DOCUMENT;
|
|
786 |
}
|
|
787 |
|
|
788 |
|
|
789 |
//START_OF_THE_DOCUMENT
|
|
790 |
|
|
791 |
|
|
792 |
}
|
|
793 |
|
|
794 |
// premature end of file
|
|
795 |
catch (EOFException e) {
|
|
796 |
reportFatalError("PrematureEOF", null);
|
|
797 |
return -1;
|
|
798 |
//throw e;
|
|
799 |
}
|
|
800 |
|
|
801 |
}
|
|
802 |
} // class XMLDeclDriver
|
|
803 |
|
|
804 |
/**
|
|
805 |
* Driver to handle prolog scanning.
|
|
806 |
*
|
|
807 |
* @author Andy Clark, IBM
|
|
808 |
*/
|
|
809 |
protected final class PrologDriver
|
|
810 |
implements Driver {
|
|
811 |
|
|
812 |
/**
|
|
813 |
* Drives the parser to the next state/event on the input. Parser is guaranteed
|
|
814 |
* to stop at the next state/event.
|
|
815 |
*
|
|
816 |
* Internally XML document is divided into several states. Each state represents
|
|
817 |
* a sections of XML document. When this functions returns normally, it has read
|
|
818 |
* the section of XML document and returns the state corresponding to section of
|
|
819 |
* document which has been read. For optimizations, a particular driver
|
|
820 |
* can read ahead of the section of document (state returned) just read and
|
|
821 |
* can maintain a different internal state.
|
|
822 |
*
|
|
823 |
* @return state representing the section of document just read.
|
|
824 |
*
|
|
825 |
* @throws IOException Thrown on i/o error.
|
|
826 |
* @throws XNIException Thrown on parse error.
|
|
827 |
*/
|
|
828 |
|
|
829 |
public int next() throws IOException, XNIException {
|
|
830 |
//System.out.println("here in next");
|
|
831 |
|
|
832 |
if(DEBUG_NEXT){
|
|
833 |
System.out.println("NOW IN PrologDriver");
|
|
834 |
}
|
|
835 |
try {
|
|
836 |
do {
|
|
837 |
switch (fScannerState) {
|
|
838 |
case SCANNER_STATE_PROLOG: {
|
|
839 |
fEntityScanner.skipSpaces();
|
|
840 |
if (fEntityScanner.skipChar('<')) {
|
|
841 |
setScannerState(SCANNER_STATE_START_OF_MARKUP);
|
|
842 |
} else if (fEntityScanner.skipChar('&')) {
|
|
843 |
setScannerState(SCANNER_STATE_REFERENCE);
|
|
844 |
} else {
|
|
845 |
setScannerState(SCANNER_STATE_CONTENT);
|
|
846 |
}
|
|
847 |
break;
|
|
848 |
}
|
|
849 |
|
|
850 |
case SCANNER_STATE_START_OF_MARKUP: {
|
|
851 |
fMarkupDepth++;
|
|
852 |
|
|
853 |
if (fEntityScanner.skipChar('?')) {
|
|
854 |
setScannerState(SCANNER_STATE_PI);
|
|
855 |
} else if (fEntityScanner.skipChar('!')) {
|
|
856 |
if (fEntityScanner.skipChar('-')) {
|
|
857 |
if (!fEntityScanner.skipChar('-')) {
|
|
858 |
reportFatalError("InvalidCommentStart",
|
|
859 |
null);
|
|
860 |
}
|
|
861 |
setScannerState(SCANNER_STATE_COMMENT);
|
|
862 |
} else if (fEntityScanner.skipString(DOCTYPE)) {
|
|
863 |
setScannerState(SCANNER_STATE_DOCTYPE);
|
|
864 |
Entity entity = fEntityScanner.getCurrentEntity();
|
|
865 |
if(entity instanceof Entity.ScannedEntity){
|
|
866 |
fStartPos=((Entity.ScannedEntity)entity).position;
|
|
867 |
}
|
|
868 |
fReadingDTD=true;
|
|
869 |
if(fDTDDecl == null)
|
|
870 |
fDTDDecl = new XMLStringBuffer();
|
|
871 |
fDTDDecl.append("<!DOCTYPE");
|
|
872 |
|
|
873 |
} else {
|
|
874 |
reportFatalError("MarkupNotRecognizedInProlog",
|
|
875 |
null);
|
|
876 |
}
|
|
877 |
} else if (XMLChar.isNameStart(fEntityScanner.peekChar())) {
|
|
878 |
setScannerState(SCANNER_STATE_ROOT_ELEMENT);
|
|
879 |
setDriver(fContentDriver);
|
|
880 |
//from now onwards this would be handled by fContentDriver,in the same next() call
|
|
881 |
return fContentDriver.next();
|
|
882 |
|
|
883 |
} else {
|
|
884 |
reportFatalError("MarkupNotRecognizedInProlog",
|
|
885 |
null);
|
|
886 |
}
|
|
887 |
break;
|
|
888 |
}
|
|
889 |
}
|
|
890 |
} while (fScannerState == SCANNER_STATE_PROLOG || fScannerState == SCANNER_STATE_START_OF_MARKUP );
|
|
891 |
|
|
892 |
switch(fScannerState){
|
|
893 |
/**
|
|
894 |
//this part is handled by FragmentContentHandler
|
|
895 |
case SCANNER_STATE_ROOT_ELEMENT: {
|
|
896 |
//we have read '<' and beginning of reading the start element tag
|
|
897 |
setScannerState(SCANNER_STATE_START_ELEMENT_TAG);
|
|
898 |
setDriver(fContentDriver);
|
|
899 |
//from now onwards this would be handled by fContentDriver,in the same next() call
|
|
900 |
return fContentDriver.next();
|
|
901 |
}
|
|
902 |
*/
|
|
903 |
case SCANNER_STATE_COMMENT: {
|
|
904 |
//this function fills the data..
|
|
905 |
scanComment();
|
|
906 |
setScannerState(SCANNER_STATE_PROLOG);
|
|
907 |
return XMLEvent.COMMENT;
|
|
908 |
//setScannerState(SCANNER_STATE_PROLOG);
|
|
909 |
//break;
|
|
910 |
}
|
|
911 |
case SCANNER_STATE_PI: {
|
|
912 |
fContentBuffer.clear() ;
|
|
913 |
scanPI(fContentBuffer);
|
|
914 |
setScannerState(SCANNER_STATE_PROLOG);
|
|
915 |
return XMLEvent.PROCESSING_INSTRUCTION;
|
|
916 |
}
|
|
917 |
|
|
918 |
case SCANNER_STATE_DOCTYPE: {
|
|
919 |
|
|
920 |
if (fSeenDoctypeDecl) {
|
|
921 |
reportFatalError("AlreadySeenDoctype", null);
|
|
922 |
}
|
|
923 |
fSeenDoctypeDecl = true;
|
|
924 |
|
|
925 |
// scanDoctypeDecl() sends XNI doctypeDecl event that
|
|
926 |
// in SAX is converted to startDTD() event.
|
|
927 |
if (scanDoctypeDecl(fDisallowDoctype)) {
|
|
928 |
//allow parsing of entity decls to continue in order to stay well-formed
|
|
929 |
setScannerState(SCANNER_STATE_DTD_INTERNAL_DECLS);
|
|
930 |
fSeenInternalSubset = true;
|
|
931 |
if(fDTDDriver == null){
|
|
932 |
fDTDDriver = new DTDDriver();
|
|
933 |
}
|
|
934 |
setDriver(fContentDriver);
|
|
935 |
//always return DTD event, the event however, will not contain any entities
|
|
936 |
return fDTDDriver.next();
|
|
937 |
// If no DTD support, ignore and continue parsing
|
|
938 |
//return fDisallowDoctype ? next() : dtdEvent;
|
|
939 |
}
|
|
940 |
|
|
941 |
if(fSeenDoctypeDecl){
|
|
942 |
Entity entity = fEntityScanner.getCurrentEntity();
|
|
943 |
if(entity instanceof Entity.ScannedEntity){
|
|
944 |
fEndPos = ((Entity.ScannedEntity)entity).position;
|
|
945 |
}
|
|
946 |
fReadingDTD = false;
|
|
947 |
}
|
|
948 |
|
|
949 |
// handle external subset
|
|
950 |
if (fDoctypeSystemId != null) {
|
|
951 |
if (((fValidation || fLoadExternalDTD)
|
|
952 |
&& (fValidationManager == null || !fValidationManager.isCachedDTD()))) {
|
|
953 |
if (!fDisallowDoctype)
|
|
954 |
setScannerState(SCANNER_STATE_DTD_EXTERNAL);
|
|
955 |
else
|
|
956 |
setScannerState(SCANNER_STATE_PROLOG);
|
|
957 |
setDriver(fContentDriver);
|
|
958 |
if(fDTDDriver == null)
|
|
959 |
fDTDDriver = new DTDDriver();
|
|
960 |
return fDTDDriver.next();
|
|
961 |
|
|
962 |
}
|
|
963 |
}
|
|
964 |
else if (fExternalSubsetSource != null) {
|
|
965 |
if (((fValidation || fLoadExternalDTD)
|
|
966 |
&& (fValidationManager == null || !fValidationManager.isCachedDTD()))) {
|
|
967 |
// This handles the case of a DOCTYPE that had neither an internal subset or an external subset.
|
|
968 |
fDTDScanner.setInputSource(fExternalSubsetSource);
|
|
969 |
fExternalSubsetSource = null;
|
|
970 |
if (!fDisallowDoctype)
|
|
971 |
setScannerState(SCANNER_STATE_DTD_EXTERNAL_DECLS);
|
|
972 |
else
|
|
973 |
setScannerState(SCANNER_STATE_PROLOG);
|
|
974 |
setDriver(fContentDriver);
|
|
975 |
if(fDTDDriver == null)
|
|
976 |
fDTDDriver = new DTDDriver();
|
|
977 |
return fDTDDriver.next();
|
|
978 |
}
|
|
979 |
}
|
|
980 |
|
|
981 |
// Send endDTD() call if:
|
|
982 |
// a) systemId is null or if an external subset resolver could not locate an external subset.
|
|
983 |
// b) "load-external-dtd" and validation are false
|
|
984 |
// c) DTD grammar is cached
|
|
985 |
|
|
986 |
// in XNI this results in 3 events: doctypeDecl, startDTD, endDTD
|
|
987 |
// in SAX this results in 2 events: startDTD, endDTD
|
|
988 |
if (fDTDScanner != null) {
|
|
989 |
fDTDScanner.setInputSource(null);
|
|
990 |
}
|
|
991 |
setScannerState(SCANNER_STATE_PROLOG);
|
|
992 |
return XMLEvent.DTD;
|
|
993 |
}
|
|
994 |
|
|
995 |
case SCANNER_STATE_CONTENT: {
|
|
996 |
reportFatalError("ContentIllegalInProlog", null);
|
|
997 |
fEntityScanner.scanChar();
|
|
998 |
}
|
|
999 |
case SCANNER_STATE_REFERENCE: {
|
|
1000 |
reportFatalError("ReferenceIllegalInProlog", null);
|
|
1001 |
}
|
|
1002 |
|
|
1003 |
/**
|
|
1004 |
* if (complete) {
|
|
1005 |
* if (fEntityScanner.scanChar() != '<') {
|
|
1006 |
* reportFatalError("RootElementRequired", null);
|
|
1007 |
* }
|
|
1008 |
* setScannerState(SCANNER_STATE_ROOT_ELEMENT);
|
|
1009 |
* setDriver(fContentDriver);
|
|
1010 |
* }
|
|
1011 |
*/
|
|
1012 |
}
|
|
1013 |
}
|
|
1014 |
// premature end of file
|
|
1015 |
catch (EOFException e) {
|
|
1016 |
reportFatalError("PrematureEOF", null);
|
|
1017 |
//xxx what should be returned here.... ???
|
|
1018 |
return -1 ;
|
|
1019 |
//throw e;
|
|
1020 |
}
|
|
1021 |
//xxx what should be returned here.... ???
|
|
1022 |
return -1;
|
|
1023 |
|
|
1024 |
}
|
|
1025 |
|
|
1026 |
|
|
1027 |
} // class PrologDriver
|
|
1028 |
|
|
1029 |
/**
|
|
1030 |
* Driver to handle the internal and external DTD subsets.
|
|
1031 |
*
|
|
1032 |
* @author Andy Clark, IBM
|
|
1033 |
*/
|
|
1034 |
protected final class DTDDriver
|
|
1035 |
implements Driver {
|
|
1036 |
|
|
1037 |
//
|
|
1038 |
// Driver methods
|
|
1039 |
//
|
|
1040 |
|
|
1041 |
public int next() throws IOException, XNIException{
|
|
1042 |
// throw new XNIException("DTD Parsing is currently not supported");
|
|
1043 |
if(DEBUG_NEXT){
|
|
1044 |
System.out.println("Now in DTD Driver");
|
|
1045 |
}
|
|
1046 |
|
|
1047 |
dispatch(true);
|
|
1048 |
|
|
1049 |
if(DEBUG_NEXT){
|
|
1050 |
System.out.println("After calling dispatch(true) -- At this point whole DTD is read.");
|
|
1051 |
}
|
|
1052 |
|
|
1053 |
//xxx: remove this hack and align this with reusing DTD components
|
|
1054 |
//currently this routine will only be executed from Stax
|
|
1055 |
if(fPropertyManager != null){
|
|
1056 |
dtdGrammarUtil = new DTDGrammarUtil(((XMLDTDScannerImpl)fDTDScanner).getGrammar(),fSymbolTable, fNamespaceContext);
|
|
1057 |
}
|
|
1058 |
|
|
1059 |
return XMLEvent.DTD ;
|
|
1060 |
}
|
|
1061 |
|
|
1062 |
/**
|
|
1063 |
* Dispatch an XML "event".
|
|
1064 |
*
|
|
1065 |
* @param complete True if this driver is intended to scan
|
|
1066 |
* and dispatch as much as possible.
|
|
1067 |
*
|
|
1068 |
* @return True if there is more to dispatch either from this
|
|
1069 |
* or a another driver.
|
|
1070 |
*
|
|
1071 |
* @throws IOException Thrown on i/o error.
|
|
1072 |
* @throws XNIException Thrown on parse error.
|
|
1073 |
*/
|
|
1074 |
public boolean dispatch(boolean complete)
|
|
1075 |
throws IOException, XNIException {
|
|
1076 |
fEntityManager.setEntityHandler(null);
|
|
1077 |
try {
|
|
1078 |
boolean again;
|
|
1079 |
XMLResourceIdentifierImpl resourceIdentifier = new XMLResourceIdentifierImpl();
|
|
1080 |
if( fDTDScanner == null){
|
|
1081 |
|
|
1082 |
if (fEntityManager.getEntityScanner() instanceof XML11EntityScanner){
|
|
1083 |
fDTDScanner = new XML11DTDScannerImpl();
|
|
1084 |
} else
|
|
1085 |
|
|
1086 |
fDTDScanner = new XMLDTDScannerImpl();
|
|
1087 |
|
|
1088 |
((XMLDTDScannerImpl)fDTDScanner).reset(fPropertyManager);
|
|
1089 |
}
|
|
1090 |
do {
|
|
1091 |
again = false;
|
|
1092 |
switch (fScannerState) {
|
|
1093 |
case SCANNER_STATE_DTD_INTERNAL_DECLS: {
|
|
1094 |
// REVISIT: Should there be a feature for
|
|
1095 |
// the "complete" parameter?
|
|
1096 |
boolean completeDTD = true;
|
|
1097 |
|
|
1098 |
boolean moreToScan = fDTDScanner.scanDTDInternalSubset(completeDTD, fStandalone, fHasExternalDTD && fLoadExternalDTD);
|
|
1099 |
Entity entity = fEntityScanner.getCurrentEntity();
|
|
1100 |
if(entity instanceof Entity.ScannedEntity){
|
|
1101 |
fEndPos=((Entity.ScannedEntity)entity).position;
|
|
1102 |
}
|
|
1103 |
fReadingDTD=false;
|
|
1104 |
if (!moreToScan) {
|
|
1105 |
// end doctype declaration
|
|
1106 |
if (!fEntityScanner.skipChar(']')) {
|
|
1107 |
reportFatalError("EXPECTED_SQUARE_BRACKET_TO_CLOSE_INTERNAL_SUBSET",
|
|
1108 |
null);
|
|
1109 |
}
|
|
1110 |
fEntityScanner.skipSpaces();
|
|
1111 |
if (!fEntityScanner.skipChar('>')) {
|
|
1112 |
reportFatalError("DoctypedeclUnterminated", new Object[]{fDoctypeName});
|
|
1113 |
}
|
|
1114 |
fMarkupDepth--;
|
|
1115 |
|
|
1116 |
if (fDisallowDoctype) {
|
|
1117 |
//simply reset the entity store without having to mess around
|
|
1118 |
//with the DTD Scanner code
|
|
1119 |
fEntityStore = fEntityManager.getEntityStore();
|
|
1120 |
fEntityStore.reset();
|
|
1121 |
} else {
|
|
1122 |
// scan external subset next unless we are ignoring DTDs
|
|
1123 |
if (fDoctypeSystemId != null && (fValidation || fLoadExternalDTD)) {
|
|
1124 |
setScannerState(SCANNER_STATE_DTD_EXTERNAL);
|
|
1125 |
break;
|
|
1126 |
}
|
|
1127 |
}
|
|
1128 |
|
|
1129 |
setEndDTDScanState();
|
|
1130 |
return true;
|
|
1131 |
|
|
1132 |
}
|
|
1133 |
break;
|
|
1134 |
}
|
|
1135 |
case SCANNER_STATE_DTD_EXTERNAL: {
|
|
1136 |
/**
|
|
1137 |
fDTDDescription.setValues(fDoctypePublicId, fDoctypeSystemId, null, null);
|
|
1138 |
fDTDDescription.setRootName(fDoctypeName);
|
|
1139 |
XMLInputSource xmlInputSource =
|
|
1140 |
fEntityManager.resolveEntity(fDTDDescription);
|
|
1141 |
fDTDScanner.setInputSource(xmlInputSource);
|
|
1142 |
setScannerState(SCANNER_STATE_DTD_EXTERNAL_DECLS);
|
|
1143 |
again = true;
|
|
1144 |
break;
|
|
1145 |
*/
|
|
1146 |
|
|
1147 |
resourceIdentifier.setValues(fDoctypePublicId, fDoctypeSystemId, null, null);
|
|
1148 |
XMLInputSource xmlInputSource = null ;
|
|
1149 |
StaxXMLInputSource staxInputSource = fEntityManager.resolveEntityAsPerStax(resourceIdentifier);
|
|
1150 |
xmlInputSource = staxInputSource.getXMLInputSource();
|
|
1151 |
fDTDScanner.setInputSource(xmlInputSource);
|
|
1152 |
setScannerState(SCANNER_STATE_DTD_EXTERNAL_DECLS);
|
|
1153 |
again = true;
|
|
1154 |
break;
|
|
1155 |
}
|
|
1156 |
case SCANNER_STATE_DTD_EXTERNAL_DECLS: {
|
|
1157 |
// REVISIT: Should there be a feature for
|
|
1158 |
// the "complete" parameter?
|
|
1159 |
boolean completeDTD = true;
|
|
1160 |
boolean moreToScan = fDTDScanner.scanDTDExternalSubset(completeDTD);
|
|
1161 |
if (!moreToScan) {
|
|
1162 |
setEndDTDScanState();
|
|
1163 |
return true;
|
|
1164 |
}
|
|
1165 |
break;
|
|
1166 |
}
|
|
1167 |
case SCANNER_STATE_PROLOG : {
|
|
1168 |
// skip entity decls
|
|
1169 |
setEndDTDScanState();
|
|
1170 |
return true;
|
|
1171 |
}
|
|
1172 |
default: {
|
|
1173 |
throw new XNIException("DTDDriver#dispatch: scanner state="+fScannerState+" ("+getScannerStateName(fScannerState)+')');
|
|
1174 |
}
|
|
1175 |
}
|
|
1176 |
} while (complete || again);
|
|
1177 |
}
|
|
1178 |
|
|
1179 |
// premature end of file
|
|
1180 |
catch (EOFException e) {
|
|
1181 |
e.printStackTrace();
|
|
1182 |
reportFatalError("PrematureEOF", null);
|
|
1183 |
return false;
|
|
1184 |
//throw e;
|
|
1185 |
}
|
|
1186 |
|
|
1187 |
// cleanup
|
|
1188 |
finally {
|
|
1189 |
fEntityManager.setEntityHandler(XMLDocumentScannerImpl.this);
|
|
1190 |
}
|
|
1191 |
|
|
1192 |
return true;
|
|
1193 |
|
|
1194 |
}
|
|
1195 |
|
|
1196 |
// dispatch(boolean):boolean
|
|
1197 |
|
|
1198 |
} // class DTDDriver
|
|
1199 |
|
|
1200 |
/**
|
|
1201 |
* Driver to handle content scanning.
|
|
1202 |
*
|
|
1203 |
* @author Andy Clark, IBM
|
|
1204 |
* @author Eric Ye, IBM
|
|
1205 |
*/
|
|
1206 |
protected class ContentDriver
|
|
1207 |
extends FragmentContentDriver {
|
|
1208 |
|
|
1209 |
//
|
|
1210 |
// Protected methods
|
|
1211 |
//
|
|
1212 |
|
|
1213 |
// hooks
|
|
1214 |
|
|
1215 |
// NOTE: These hook methods are added so that the full document
|
|
1216 |
// scanner can share the majority of code with this class.
|
|
1217 |
|
|
1218 |
/**
|
|
1219 |
* Scan for DOCTYPE hook. This method is a hook for subclasses
|
|
1220 |
* to add code to handle scanning for a the "DOCTYPE" string
|
|
1221 |
* after the string "<!" has been scanned.
|
|
1222 |
*
|
|
1223 |
* @return True if the "DOCTYPE" was scanned; false if "DOCTYPE"
|
|
1224 |
* was not scanned.
|
|
1225 |
*/
|
|
1226 |
protected boolean scanForDoctypeHook()
|
|
1227 |
throws IOException, XNIException {
|
|
1228 |
|
|
1229 |
if (fEntityScanner.skipString(DOCTYPE)) {
|
|
1230 |
setScannerState(SCANNER_STATE_DOCTYPE);
|
|
1231 |
// fEntityScanner.markStartOfDTD();
|
|
1232 |
return true;
|
|
1233 |
}
|
|
1234 |
return false;
|
|
1235 |
|
|
1236 |
} // scanForDoctypeHook():boolean
|
|
1237 |
|
|
1238 |
/**
|
|
1239 |
* Element depth iz zero. This methos is a hook for subclasses
|
|
1240 |
* to add code to handle when the element depth hits zero. When
|
|
1241 |
* scanning a document fragment, an element depth of zero is
|
|
1242 |
* normal. However, when scanning a full XML document, the
|
|
1243 |
* scanner must handle the trailing miscellanous section of
|
|
1244 |
* the document after the end of the document's root element.
|
|
1245 |
*
|
|
1246 |
* @return True if the caller should stop and return true which
|
|
1247 |
* allows the scanner to switch to a new scanning
|
|
1248 |
* driver. A return value of false indicates that
|
|
1249 |
* the content driver should continue as normal.
|
|
1250 |
*/
|
|
1251 |
protected boolean elementDepthIsZeroHook()
|
|
1252 |
throws IOException, XNIException {
|
|
1253 |
|
|
1254 |
setScannerState(SCANNER_STATE_TRAILING_MISC);
|
|
1255 |
setDriver(fTrailingMiscDriver);
|
|
1256 |
return true;
|
|
1257 |
|
|
1258 |
} // elementDepthIsZeroHook():boolean
|
|
1259 |
|
|
1260 |
/**
|
|
1261 |
* Scan for root element hook. This method is a hook for
|
|
1262 |
* subclasses to add code that handles scanning for the root
|
|
1263 |
* element. When scanning a document fragment, there is no
|
|
1264 |
* "root" element. However, when scanning a full XML document,
|
|
1265 |
* the scanner must handle the root element specially.
|
|
1266 |
*
|
|
1267 |
* @return True if the caller should stop and return true which
|
|
1268 |
* allows the scanner to switch to a new scanning
|
|
1269 |
* driver. A return value of false indicates that
|
|
1270 |
* the content driver should continue as normal.
|
|
1271 |
*/
|
|
1272 |
protected boolean scanRootElementHook()
|
|
1273 |
throws IOException, XNIException {
|
|
1274 |
|
|
1275 |
if (scanStartElement()) {
|
|
1276 |
setScannerState(SCANNER_STATE_TRAILING_MISC);
|
|
1277 |
setDriver(fTrailingMiscDriver);
|
|
1278 |
return true;
|
|
1279 |
}
|
|
1280 |
return false;
|
|
1281 |
|
|
1282 |
} // scanRootElementHook():boolean
|
|
1283 |
|
|
1284 |
/**
|
|
1285 |
* End of file hook. This method is a hook for subclasses to
|
|
1286 |
* add code that handles the end of file. The end of file in
|
|
1287 |
* a document fragment is OK if the markup depth is zero.
|
|
1288 |
* However, when scanning a full XML document, an end of file
|
|
1289 |
* is always premature.
|
|
1290 |
*/
|
|
1291 |
protected void endOfFileHook(EOFException e)
|
|
1292 |
throws IOException, XNIException {
|
|
1293 |
|
|
1294 |
reportFatalError("PrematureEOF", null);
|
|
1295 |
// in case continue-after-fatal-error set, should not do this...
|
|
1296 |
//throw e;
|
|
1297 |
|
|
1298 |
} // endOfFileHook()
|
|
1299 |
|
|
1300 |
protected void resolveExternalSubsetAndRead()
|
|
1301 |
throws IOException, XNIException {
|
|
1302 |
|
|
1303 |
fDTDDescription.setValues(null, null, fEntityManager.getCurrentResourceIdentifier().getExpandedSystemId(), null);
|
|
1304 |
fDTDDescription.setRootName(fElementQName.rawname);
|
|
1305 |
XMLInputSource src = fExternalSubsetResolver.getExternalSubset(fDTDDescription);
|
|
1306 |
|
|
1307 |
if (src != null) {
|
|
1308 |
fDoctypeName = fElementQName.rawname;
|
|
1309 |
fDoctypePublicId = src.getPublicId();
|
|
1310 |
fDoctypeSystemId = src.getSystemId();
|
|
1311 |
// call document handler
|
|
1312 |
if (fDocumentHandler != null) {
|
|
1313 |
// This inserts a doctypeDecl event into the stream though no
|
|
1314 |
// DOCTYPE existed in the instance document.
|
|
1315 |
fDocumentHandler.doctypeDecl(fDoctypeName, fDoctypePublicId, fDoctypeSystemId, null);
|
|
1316 |
}
|
|
1317 |
try {
|
|
1318 |
fDTDScanner.setInputSource(src);
|
|
1319 |
while (fDTDScanner.scanDTDExternalSubset(true));
|
|
1320 |
} finally {
|
|
1321 |
fEntityManager.setEntityHandler(XMLDocumentScannerImpl.this);
|
|
1322 |
}
|
|
1323 |
}
|
|
1324 |
} // resolveExternalSubsetAndRead()
|
|
1325 |
|
|
1326 |
|
|
1327 |
|
|
1328 |
} // class ContentDriver
|
|
1329 |
|
|
1330 |
/**
|
|
1331 |
* Driver to handle trailing miscellaneous section scanning.
|
|
1332 |
*
|
|
1333 |
* @author Andy Clark, IBM
|
|
1334 |
* @author Eric Ye, IBM
|
|
1335 |
*/
|
|
1336 |
protected final class TrailingMiscDriver
|
|
1337 |
implements Driver {
|
|
1338 |
|
|
1339 |
//
|
|
1340 |
// Driver methods
|
|
1341 |
//
|
|
1342 |
public int next() throws IOException, XNIException{
|
|
1343 |
//this could for cases like <foo/>
|
|
1344 |
//look at scanRootElementHook
|
|
1345 |
if(fEmptyElement){
|
|
1346 |
fEmptyElement = false;
|
|
1347 |
return XMLEvent.END_ELEMENT;
|
|
1348 |
}
|
|
1349 |
|
|
1350 |
try {
|
|
1351 |
if(fScannerState == SCANNER_STATE_TERMINATED){
|
|
1352 |
return XMLEvent.END_DOCUMENT ;}
|
|
1353 |
do {
|
|
1354 |
switch (fScannerState) {
|
|
1355 |
case SCANNER_STATE_TRAILING_MISC: {
|
|
1356 |
|
|
1357 |
fEntityScanner.skipSpaces();
|
|
1358 |
//we should have reached the end of the document in
|
|
1359 |
//most cases.
|
|
1360 |
if(fScannerState == SCANNER_STATE_TERMINATED ){
|
|
1361 |
return XMLEvent.END_DOCUMENT ;
|
|
1362 |
}
|
|
1363 |
if (fEntityScanner.skipChar('<')) {
|
|
1364 |
setScannerState(SCANNER_STATE_START_OF_MARKUP);
|
|
1365 |
} else {
|
|
1366 |
setScannerState(SCANNER_STATE_CONTENT);
|
|
1367 |
}
|
|
1368 |
break;
|
|
1369 |
}
|
|
1370 |
case SCANNER_STATE_START_OF_MARKUP: {
|
|
1371 |
fMarkupDepth++;
|
|
1372 |
if (fEntityScanner.skipChar('?')) {
|
|
1373 |
setScannerState(SCANNER_STATE_PI);
|
|
1374 |
} else if (fEntityScanner.skipChar('!')) {
|
|
1375 |
setScannerState(SCANNER_STATE_COMMENT);
|
|
1376 |
} else if (fEntityScanner.skipChar('/')) {
|
|
1377 |
reportFatalError("MarkupNotRecognizedInMisc",
|
|
1378 |
null);
|
|
1379 |
} else if (XMLChar.isNameStart(fEntityScanner.peekChar())) {
|
|
1380 |
reportFatalError("MarkupNotRecognizedInMisc",
|
|
1381 |
null);
|
|
1382 |
scanStartElement();
|
|
1383 |
setScannerState(SCANNER_STATE_CONTENT);
|
|
1384 |
} else {
|
|
1385 |
reportFatalError("MarkupNotRecognizedInMisc",
|
|
1386 |
null);
|
|
1387 |
}
|
|
1388 |
break;
|
|
1389 |
}
|
|
1390 |
}
|
|
1391 |
}while(fScannerState == SCANNER_STATE_START_OF_MARKUP || fScannerState == SCANNER_STATE_TRAILING_MISC);
|
|
1392 |
if(DEBUG_NEXT){
|
|
1393 |
System.out.println("State set by deciding while loop [TrailingMiscellaneous] is = " + getScannerStateName(fScannerState));
|
|
1394 |
}
|
|
1395 |
switch (fScannerState){
|
|
1396 |
case SCANNER_STATE_PI: {
|
|
1397 |
fContentBuffer.clear();
|
|
1398 |
scanPI(fContentBuffer);
|
|
1399 |
setScannerState(SCANNER_STATE_TRAILING_MISC);
|
|
1400 |
return XMLEvent.PROCESSING_INSTRUCTION ;
|
|
1401 |
}
|
|
1402 |
case SCANNER_STATE_COMMENT: {
|
|
1403 |
if (!fEntityScanner.skipString(COMMENTSTRING)) {
|
|
1404 |
reportFatalError("InvalidCommentStart", null);
|
|
1405 |
}
|
|
1406 |
scanComment();
|
|
1407 |
setScannerState(SCANNER_STATE_TRAILING_MISC);
|
|
1408 |
return XMLEvent.COMMENT;
|
|
1409 |
}
|
|
1410 |
case SCANNER_STATE_CONTENT: {
|
|
1411 |
int ch = fEntityScanner.peekChar();
|
|
1412 |
if (ch == -1) {
|
|
1413 |
setScannerState(SCANNER_STATE_TERMINATED);
|
|
1414 |
return XMLEvent.END_DOCUMENT ;
|
|
1415 |
} else{
|
|
1416 |
reportFatalError("ContentIllegalInTrailingMisc",
|
|
1417 |
null);
|
|
1418 |
fEntityScanner.scanChar();
|
|
1419 |
setScannerState(SCANNER_STATE_TRAILING_MISC);
|
|
1420 |
return XMLEvent.CHARACTERS;
|
|
1421 |
}
|
|
1422 |
|
|
1423 |
}
|
|
1424 |
case SCANNER_STATE_REFERENCE: {
|
|
1425 |
reportFatalError("ReferenceIllegalInTrailingMisc",
|
|
1426 |
null);
|
|
1427 |
setScannerState(SCANNER_STATE_TRAILING_MISC);
|
|
1428 |
return XMLEvent.ENTITY_REFERENCE ;
|
|
1429 |
}
|
|
1430 |
case SCANNER_STATE_TERMINATED: {
|
|
1431 |
//there can't be any element after SCANNER_STATE_TERMINATED or when the parser
|
|
1432 |
//has reached the end of document
|
|
1433 |
setScannerState(SCANNER_STATE_NO_SUCH_ELEMENT_EXCEPTION);
|
|
1434 |
//xxx what to do when the scanner has reached the terminating state.
|
|
1435 |
return XMLEvent.END_DOCUMENT ;
|
|
1436 |
}
|
|
1437 |
case SCANNER_STATE_NO_SUCH_ELEMENT_EXCEPTION:{
|
|
1438 |
throw new java.util.NoSuchElementException("No more events to be parsed");
|
|
1439 |
}
|
|
1440 |
default: throw new XNIException("Scanner State " + fScannerState + " not Recognized ");
|
|
1441 |
}//switch
|
|
1442 |
|
|
1443 |
} catch (EOFException e) {
|
|
1444 |
// NOTE: This is the only place we're allowed to reach
|
|
1445 |
// the real end of the document stream. Unless the
|
|
1446 |
// end of file was reached prematurely.
|
|
1447 |
if (fMarkupDepth != 0) {
|
|
1448 |
reportFatalError("PrematureEOF", null);
|
|
1449 |
return -1;
|
|
1450 |
//throw e;
|
|
1451 |
}
|
|
1452 |
//System.out.println("EOFException thrown") ;
|
|
1453 |
setScannerState(SCANNER_STATE_TERMINATED);
|
|
1454 |
}
|
|
1455 |
|
|
1456 |
return XMLEvent.END_DOCUMENT;
|
|
1457 |
|
|
1458 |
}//next
|
|
1459 |
|
|
1460 |
} // class TrailingMiscDriver
|
|
1461 |
|
|
1462 |
/**
|
|
1463 |
* Implements XMLBufferListener interface.
|
|
1464 |
*/
|
|
1465 |
|
|
1466 |
|
|
1467 |
/**
|
|
1468 |
* receives callbacks from {@link XMLEntityReader } when buffer
|
|
1469 |
* is being changed.
|
|
1470 |
* @param refreshPosition
|
|
1471 |
*/
|
|
1472 |
public void refresh(int refreshPosition){
|
|
1473 |
super.refresh(refreshPosition);
|
|
1474 |
if(fReadingDTD){
|
|
1475 |
Entity entity = fEntityScanner.getCurrentEntity();
|
|
1476 |
if(entity instanceof Entity.ScannedEntity){
|
|
1477 |
fEndPos=((Entity.ScannedEntity)entity).position;
|
|
1478 |
}
|
|
1479 |
fDTDDecl.append(((Entity.ScannedEntity)entity).ch,fStartPos , fEndPos-fStartPos);
|
|
1480 |
fStartPos = refreshPosition;
|
|
1481 |
}
|
|
1482 |
}
|
|
1483 |
|
|
1484 |
} // class XMLDocumentScannerImpl
|