|
|
|
|
|
*/ |
|
|
|
/* |
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
|
* contributor license agreements. See the NOTICE file distributed with |
|
* this work for additional information regarding copyright ownership. |
|
* The ASF licenses this file to You under the Apache License, Version 2.0 |
|
* (the "License"); you may not use this file except in compliance with |
|
* the License. You may obtain a copy of the License at |
|
* |
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
* |
|
* Unless required by applicable law or agreed to in writing, software |
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
* See the License for the specific language governing permissions and |
|
* limitations under the License. |
|
*/ |
|
|
|
package com.sun.org.apache.xerces.internal.impl; |
|
|
|
import com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDDescription; |
|
import com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException; |
|
import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter; |
|
import com.sun.org.apache.xerces.internal.impl.validation.ValidationManager; |
|
import com.sun.org.apache.xerces.internal.util.NamespaceSupport; |
|
import com.sun.org.apache.xerces.internal.util.XMLChar; |
|
import com.sun.org.apache.xerces.internal.util.XMLResourceIdentifierImpl; |
|
import com.sun.org.apache.xerces.internal.util.XMLStringBuffer; |
|
import com.sun.org.apache.xerces.internal.xni.Augmentations; |
|
import com.sun.org.apache.xerces.internal.xni.NamespaceContext; |
|
import com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier; |
|
import com.sun.org.apache.xerces.internal.xni.XNIException; |
|
import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager; |
|
import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException; |
|
import com.sun.org.apache.xerces.internal.xni.parser.XMLDTDScanner; |
|
import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource; |
|
import com.sun.xml.internal.stream.Entity; |
|
import com.sun.xml.internal.stream.StaxXMLInputSource; |
|
import com.sun.xml.internal.stream.dtd.DTDGrammarUtil; |
|
import java.io.CharConversionException; |
|
import java.io.EOFException; |
|
import java.io.IOException; |
|
import javax.xml.stream.XMLInputFactory; |
|
import javax.xml.stream.events.XMLEvent; |
|
import jdk.xml.internal.SecuritySupport; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public class XMLDocumentScannerImpl |
|
extends XMLDocumentFragmentScannerImpl{ |
|
|
|
// |
|
// Constants |
|
// |
|
|
|
// scanner states |
|
|
|
|
|
protected static final int SCANNER_STATE_XML_DECL = 42; |
|
|
|
|
|
protected static final int SCANNER_STATE_PROLOG = 43; |
|
|
|
|
|
protected static final int SCANNER_STATE_TRAILING_MISC = 44; |
|
|
|
|
|
protected static final int SCANNER_STATE_DTD_INTERNAL_DECLS = 45; |
|
|
|
|
|
protected static final int SCANNER_STATE_DTD_EXTERNAL = 46; |
|
|
|
|
|
protected static final int SCANNER_STATE_DTD_EXTERNAL_DECLS = 47; |
|
|
|
|
|
protected static final int SCANNER_STATE_NO_SUCH_ELEMENT_EXCEPTION = 48; |
|
|
|
// feature identifiers |
|
|
|
|
|
protected static final String DOCUMENT_SCANNER = |
|
Constants.XERCES_PROPERTY_PREFIX + Constants.DOCUMENT_SCANNER_PROPERTY; |
|
|
|
|
|
protected static final String LOAD_EXTERNAL_DTD = |
|
Constants.XERCES_FEATURE_PREFIX + Constants.LOAD_EXTERNAL_DTD_FEATURE; |
|
|
|
|
|
protected static final String DISALLOW_DOCTYPE_DECL_FEATURE = |
|
Constants.XERCES_FEATURE_PREFIX + Constants.DISALLOW_DOCTYPE_DECL_FEATURE; |
|
|
|
// property identifiers |
|
|
|
|
|
protected static final String DTD_SCANNER = |
|
Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_SCANNER_PROPERTY; |
|
|
|
|
|
protected static final String VALIDATION_MANAGER = |
|
Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY; |
|
|
|
|
|
protected static final String NAMESPACE_CONTEXT = |
|
Constants.XERCES_PROPERTY_PREFIX + Constants.NAMESPACE_CONTEXT_PROPERTY; |
|
|
|
// recognized features and properties |
|
|
|
|
|
private static final String[] RECOGNIZED_FEATURES = { |
|
LOAD_EXTERNAL_DTD, |
|
DISALLOW_DOCTYPE_DECL_FEATURE, |
|
}; |
|
|
|
|
|
private static final Boolean[] FEATURE_DEFAULTS = { |
|
Boolean.TRUE, |
|
Boolean.FALSE, |
|
}; |
|
|
|
|
|
private static final String[] RECOGNIZED_PROPERTIES = { |
|
DTD_SCANNER, |
|
VALIDATION_MANAGER |
|
}; |
|
|
|
|
|
private static final Object[] PROPERTY_DEFAULTS = { |
|
null, |
|
null |
|
}; |
|
|
|
// |
|
// Data((Boolean)propertyManager.getProperty(XMLInputFactory.IS_NAMESPACE_AWARE)).booleanValue(); |
|
// |
|
|
|
// properties |
|
|
|
|
|
protected XMLDTDScanner fDTDScanner = null; |
|
|
|
/** Validation manager . */ |
|
|
|
protected ValidationManager fValidationManager; |
|
|
|
protected XMLStringBuffer fDTDDecl = null; |
|
protected boolean fReadingDTD = false; |
|
protected boolean fAddedListener = false; |
|
|
|
// protected data |
|
|
|
// other info |
|
|
|
|
|
protected String fDoctypeName; |
|
|
|
|
|
protected String fDoctypePublicId; |
|
|
|
|
|
protected String fDoctypeSystemId; |
|
|
|
|
|
protected NamespaceContext fNamespaceContext = new NamespaceSupport(); |
|
|
|
// features |
|
|
|
|
|
protected boolean fLoadExternalDTD = true; |
|
|
|
// state |
|
|
|
|
|
protected boolean fSeenDoctypeDecl; |
|
|
|
protected boolean fScanEndElement; |
|
|
|
//protected int fScannerLastState ; |
|
|
|
// drivers |
|
|
|
|
|
protected Driver fXMLDeclDriver = new XMLDeclDriver(); |
|
|
|
|
|
protected Driver fPrologDriver = new PrologDriver(); |
|
|
|
|
|
protected Driver fDTDDriver = null ; |
|
|
|
|
|
protected Driver fTrailingMiscDriver = new TrailingMiscDriver(); |
|
protected int fStartPos = 0; |
|
protected int fEndPos = 0; |
|
protected boolean fSeenInternalSubset= false; |
|
// temporary variables |
|
|
|
|
|
private String[] fStrings = new String[3]; |
|
|
|
|
|
private XMLInputSource fExternalSubsetSource = null; |
|
|
|
|
|
private final XMLDTDDescription fDTDDescription = new XMLDTDDescription(null, null, null, null, null); |
|
|
|
private static final char [] DOCTYPE = {'D','O','C','T','Y','P','E'}; |
|
private static final char [] COMMENTSTRING = {'-','-'}; |
|
|
|
// |
|
// Constructors |
|
// |
|
|
|
/** Default constructor. */ |
|
public XMLDocumentScannerImpl() {} |
|
|
|
|
|
// |
|
// XMLDocumentScanner methods |
|
// |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public void setInputSource(XMLInputSource inputSource) throws IOException { |
|
fEntityManager.setEntityHandler(this); |
|
|
|
fEntityManager.startDocumentEntity(inputSource); |
|
|
|
setScannerState(XMLEvent.START_DOCUMENT); |
|
} // setInputSource(XMLInputSource) |
|
|
|
|
|
|
|
|
|
public int getScannetState(){ |
|
return fScannerState ; |
|
} |
|
|
|
|
|
|
|
|
|
public void reset(PropertyManager propertyManager) { |
|
super.reset(propertyManager); |
|
|
|
fDoctypeName = null; |
|
fDoctypePublicId = null; |
|
fDoctypeSystemId = null; |
|
fSeenDoctypeDecl = false; |
|
fNamespaceContext.reset(); |
|
fSupportDTD = ((Boolean)propertyManager.getProperty(XMLInputFactory.SUPPORT_DTD)).booleanValue(); |
|
|
|
|
|
fLoadExternalDTD = !((Boolean)propertyManager.getProperty(Constants.ZEPHYR_PROPERTY_PREFIX + Constants.IGNORE_EXTERNAL_DTD)).booleanValue(); |
|
setScannerState(XMLEvent.START_DOCUMENT); |
|
setDriver(fXMLDeclDriver); |
|
fSeenInternalSubset = false; |
|
if(fDTDScanner != null){ |
|
((XMLDTDScannerImpl)fDTDScanner).reset(propertyManager); |
|
} |
|
fEndPos = 0; |
|
fStartPos = 0; |
|
if(fDTDDecl != null){ |
|
fDTDDecl.clear(); |
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public void reset(XMLComponentManager componentManager) |
|
throws XMLConfigurationException { |
|
|
|
super.reset(componentManager); |
|
|
|
|
|
fDoctypeName = null; |
|
fDoctypePublicId = null; |
|
fDoctypeSystemId = null; |
|
fSeenDoctypeDecl = false; |
|
fExternalSubsetSource = null; |
|
|
|
|
|
fLoadExternalDTD = componentManager.getFeature(LOAD_EXTERNAL_DTD, true); |
|
fDisallowDoctype = componentManager.getFeature(DISALLOW_DOCTYPE_DECL_FEATURE, false); |
|
|
|
fNamespaces = componentManager.getFeature(NAMESPACES, true); |
|
|
|
fSeenInternalSubset = false; |
|
|
|
fDTDScanner = (XMLDTDScanner)componentManager.getProperty(DTD_SCANNER); |
|
|
|
fValidationManager = (ValidationManager)componentManager.getProperty(VALIDATION_MANAGER, null); |
|
|
|
try { |
|
fNamespaceContext = (NamespaceContext)componentManager.getProperty(NAMESPACE_CONTEXT); |
|
} |
|
catch (XMLConfigurationException e) { } |
|
if (fNamespaceContext == null) { |
|
fNamespaceContext = new NamespaceSupport(); |
|
} |
|
fNamespaceContext.reset(); |
|
|
|
fEndPos = 0; |
|
fStartPos = 0; |
|
if(fDTDDecl != null) |
|
fDTDDecl.clear(); |
|
|
|
|
|
//fEntityScanner.registerListener((XMLBufferListener)componentManager.getProperty(DOCUMENT_SCANNER)); |
|
|
|
|
|
setScannerState(SCANNER_STATE_XML_DECL); |
|
setDriver(fXMLDeclDriver); |
|
|
|
} // reset(XMLComponentManager) |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public String[] getRecognizedFeatures() { |
|
String[] featureIds = super.getRecognizedFeatures(); |
|
int length = featureIds != null ? featureIds.length : 0; |
|
String[] combinedFeatureIds = new String[length + RECOGNIZED_FEATURES.length]; |
|
if (featureIds != null) { |
|
System.arraycopy(featureIds, 0, combinedFeatureIds, 0, featureIds.length); |
|
} |
|
System.arraycopy(RECOGNIZED_FEATURES, 0, combinedFeatureIds, length, RECOGNIZED_FEATURES.length); |
|
return combinedFeatureIds; |
|
} // getRecognizedFeatures():String[] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public void setFeature(String featureId, boolean state) |
|
throws XMLConfigurationException { |
|
|
|
super.setFeature(featureId, state); |
|
|
|
|
|
if (featureId.startsWith(Constants.XERCES_FEATURE_PREFIX)) { |
|
final int suffixLength = featureId.length() - Constants.XERCES_FEATURE_PREFIX.length(); |
|
|
|
if (suffixLength == Constants.LOAD_EXTERNAL_DTD_FEATURE.length() && |
|
featureId.endsWith(Constants.LOAD_EXTERNAL_DTD_FEATURE)) { |
|
fLoadExternalDTD = state; |
|
return; |
|
} |
|
else if (suffixLength == Constants.DISALLOW_DOCTYPE_DECL_FEATURE.length() && |
|
featureId.endsWith(Constants.DISALLOW_DOCTYPE_DECL_FEATURE)) { |
|
fDisallowDoctype = state; |
|
return; |
|
} |
|
} |
|
|
|
} // setFeature(String,boolean) |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public String[] getRecognizedProperties() { |
|
String[] propertyIds = super.getRecognizedProperties(); |
|
int length = propertyIds != null ? propertyIds.length : 0; |
|
String[] combinedPropertyIds = new String[length + RECOGNIZED_PROPERTIES.length]; |
|
if (propertyIds != null) { |
|
System.arraycopy(propertyIds, 0, combinedPropertyIds, 0, propertyIds.length); |
|
} |
|
System.arraycopy(RECOGNIZED_PROPERTIES, 0, combinedPropertyIds, length, RECOGNIZED_PROPERTIES.length); |
|
return combinedPropertyIds; |
|
} // getRecognizedProperties():String[] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public void setProperty(String propertyId, Object value) |
|
throws XMLConfigurationException { |
|
|
|
super.setProperty(propertyId, value); |
|
|
|
|
|
if (propertyId.startsWith(Constants.XERCES_PROPERTY_PREFIX)) { |
|
final int suffixLength = propertyId.length() - Constants.XERCES_PROPERTY_PREFIX.length(); |
|
|
|
if (suffixLength == Constants.DTD_SCANNER_PROPERTY.length() && |
|
propertyId.endsWith(Constants.DTD_SCANNER_PROPERTY)) { |
|
fDTDScanner = (XMLDTDScanner)value; |
|
} |
|
if (suffixLength == Constants.NAMESPACE_CONTEXT_PROPERTY.length() && |
|
propertyId.endsWith(Constants.NAMESPACE_CONTEXT_PROPERTY)) { |
|
if (value != null) { |
|
fNamespaceContext = (NamespaceContext)value; |
|
} |
|
} |
|
|
|
return; |
|
} |
|
|
|
} // setProperty(String,Object) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public Boolean getFeatureDefault(String featureId) { |
|
|
|
for (int i = 0; i < RECOGNIZED_FEATURES.length; i++) { |
|
if (RECOGNIZED_FEATURES[i].equals(featureId)) { |
|
return FEATURE_DEFAULTS[i]; |
|
} |
|
} |
|
return super.getFeatureDefault(featureId); |
|
} // getFeatureDefault(String):Boolean |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public Object getPropertyDefault(String propertyId) { |
|
for (int i = 0; i < RECOGNIZED_PROPERTIES.length; i++) { |
|
if (RECOGNIZED_PROPERTIES[i].equals(propertyId)) { |
|
return PROPERTY_DEFAULTS[i]; |
|
} |
|
} |
|
return super.getPropertyDefault(propertyId); |
|
} // getPropertyDefault(String):Object |
|
|
|
// |
|
// XMLEntityHandler methods |
|
// |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public void startEntity(String name, |
|
XMLResourceIdentifier identifier, |
|
String encoding, Augmentations augs) throws XNIException { |
|
|
|
super.startEntity(name, identifier, encoding,augs); |
|
|
|
|
|
fEntityScanner.registerListener(this); |
|
|
|
|
|
if (!name.equals("[xml]") && fEntityScanner.isExternal()) { |
|
|
|
if (augs == null || !((Boolean) augs.getItem(Constants.ENTITY_SKIPPED)).booleanValue()) { |
|
setScannerState(SCANNER_STATE_TEXT_DECL); |
|
} |
|
} |
|
|
|
// call handler |
|
|
|
if (fDocumentHandler != null && name.equals("[xml]")) { |
|
fDocumentHandler.startDocument(fEntityScanner, encoding, fNamespaceContext, null); |
|
} |
|
|
|
} // startEntity(String,identifier,String) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public void endEntity(String name, Augmentations augs) throws IOException, XNIException { |
|
|
|
super.endEntity(name, augs); |
|
|
|
if(name.equals("[xml]")){ |
|
//if fMarkupDepth has reached 0. |
|
//and driver is fTrailingMiscDriver (which |
|
//handles end of document in normal case) |
|
|
|
if(fMarkupDepth == 0 && fDriver == fTrailingMiscDriver){ |
|
|
|
setScannerState(SCANNER_STATE_TERMINATED) ; |
|
} else{ |
|
//else we have reached the end of document prematurely |
|
|
|
throw new java.io.EOFException(); |
|
} |
|
|
|
//this is taken care in wrapper which generates XNI callbacks, There are no next events |
|
|
|
//if (fDocumentHandler != null) { |
|
//fDocumentHandler.endDocument(null); |
|
//} |
|
} |
|
} // endEntity(String) |
|
|
|
|
|
public XMLStringBuffer getDTDDecl(){ |
|
Entity entity = fEntityScanner.getCurrentEntity(); |
|
fDTDDecl.append(((Entity.ScannedEntity)entity).ch,fStartPos , fEndPos-fStartPos); |
|
if(fSeenInternalSubset) |
|
fDTDDecl.append("]>"); |
|
return fDTDDecl; |
|
} |
|
|
|
public String getCharacterEncodingScheme(){ |
|
return fDeclaredEncoding; |
|
} |
|
|
|
/** return the next state on the input |
|
* |
|
* @return int |
|
*/ |
|
|
|
public int next() throws IOException, XNIException { |
|
return fDriver.next(); |
|
} |
|
|
|
|
|
public NamespaceContext getNamespaceContext(){ |
|
return fNamespaceContext ; |
|
} |
|
|
|
|
|
|
|
// |
|
// Protected methods |
|
// |
|
|
|
// driver factory methods |
|
|
|
|
|
protected Driver createContentDriver() { |
|
return new ContentDriver(); |
|
} // createContentDriver():Driver |
|
|
|
// scanning methods |
|
|
|
|
|
protected boolean scanDoctypeDecl(boolean supportDTD) throws IOException, XNIException { |
|
|
|
|
|
if (!fEntityScanner.skipSpaces()) { |
|
reportFatalError("MSG_SPACE_REQUIRED_BEFORE_ROOT_ELEMENT_TYPE_IN_DOCTYPEDECL", |
|
null); |
|
} |
|
|
|
|
|
fDoctypeName = fEntityScanner.scanName(NameType.DOCTYPE); |
|
if (fDoctypeName == null) { |
|
reportFatalError("MSG_ROOT_ELEMENT_TYPE_REQUIRED", null); |
|
} |
|
|
|
|
|
if (fEntityScanner.skipSpaces()) { |
|
scanExternalID(fStrings, false); |
|
fDoctypeSystemId = fStrings[0]; |
|
fDoctypePublicId = fStrings[1]; |
|
fEntityScanner.skipSpaces(); |
|
} |
|
|
|
fHasExternalDTD = fDoctypeSystemId != null; |
|
|
|
|
|
if (supportDTD && !fHasExternalDTD && fExternalSubsetResolver != null) { |
|
fDTDDescription.setValues(null, null, fEntityManager.getCurrentResourceIdentifier().getExpandedSystemId(), null); |
|
fDTDDescription.setRootName(fDoctypeName); |
|
fExternalSubsetSource = fExternalSubsetResolver.getExternalSubset(fDTDDescription); |
|
fHasExternalDTD = fExternalSubsetSource != null; |
|
} |
|
|
|
|
|
if (supportDTD && fDocumentHandler != null) { |
|
// NOTE: I don't like calling the doctypeDecl callback until |
|
// end of the *full* doctype line (including internal |
|
// subset) is parsed correctly but SAX2 requires that |
|
// it knows the root element name and public and system |
|
|
|
if (fExternalSubsetSource == null) { |
|
fDocumentHandler.doctypeDecl(fDoctypeName, fDoctypePublicId, fDoctypeSystemId, null); |
|
} |
|
else { |
|
fDocumentHandler.doctypeDecl(fDoctypeName, fExternalSubsetSource.getPublicId(), fExternalSubsetSource.getSystemId(), null); |
|
} |
|
} |
|
|
|
|
|
boolean internalSubset = true; |
|
if (!fEntityScanner.skipChar('[', null)) { |
|
internalSubset = false; |
|
fEntityScanner.skipSpaces(); |
|
if (!fEntityScanner.skipChar('>', null)) { |
|
reportFatalError("DoctypedeclUnterminated", new Object[]{fDoctypeName}); |
|
} |
|
fMarkupDepth--; |
|
} |
|
return internalSubset; |
|
|
|
} // scanDoctypeDecl():boolean |
|
|
|
// |
|
// Private methods |
|
// |
|
|
|
protected void setEndDTDScanState() { |
|
setScannerState(SCANNER_STATE_PROLOG); |
|
setDriver(fPrologDriver); |
|
fEntityManager.setEntityHandler(XMLDocumentScannerImpl.this); |
|
fReadingDTD=false; |
|
} |
|
|
|
|
|
protected String getScannerStateName(int state) { |
|
|
|
switch (state) { |
|
case SCANNER_STATE_XML_DECL: return "SCANNER_STATE_XML_DECL"; |
|
case SCANNER_STATE_PROLOG: return "SCANNER_STATE_PROLOG"; |
|
case SCANNER_STATE_TRAILING_MISC: return "SCANNER_STATE_TRAILING_MISC"; |
|
case SCANNER_STATE_DTD_INTERNAL_DECLS: return "SCANNER_STATE_DTD_INTERNAL_DECLS"; |
|
case SCANNER_STATE_DTD_EXTERNAL: return "SCANNER_STATE_DTD_EXTERNAL"; |
|
case SCANNER_STATE_DTD_EXTERNAL_DECLS: return "SCANNER_STATE_DTD_EXTERNAL_DECLS"; |
|
} |
|
return super.getScannerStateName(state); |
|
|
|
} // getScannerStateName(int):String |
|
|
|
// |
|
// Classes |
|
// |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
protected final class XMLDeclDriver |
|
implements Driver { |
|
|
|
// |
|
// Driver methods |
|
// |
|
|
|
|
|
public int next() throws IOException, XNIException { |
|
|
|
// next driver is prolog regardless of whether there |
|
|
|
setScannerState(SCANNER_STATE_PROLOG); |
|
setDriver(fPrologDriver); |
|
|
|
//System.out.println("fEntityScanner = " + fEntityScanner); |
|
|
|
try { |
|
if (fEntityScanner.skipString(XMLDECL)) { |
|
if (XMLChar.isSpace(fEntityScanner.peekChar())) { |
|
fMarkupDepth++; |
|
scanXMLDeclOrTextDecl(false); |
|
} else { |
|
|
|
fEntityManager.fCurrentEntity.position = 0; |
|
} |
|
} |
|
|
|
|
|
fEntityManager.fCurrentEntity.mayReadChunks = true; |
|
return XMLEvent.START_DOCUMENT; |
|
|
|
} |
|
|
|
catch (MalformedByteSequenceException e) { |
|
fErrorReporter.reportError(e.getDomain(), e.getKey(), |
|
e.getArguments(), XMLErrorReporter.SEVERITY_FATAL_ERROR, e); |
|
return -1; |
|
} catch (CharConversionException e) { |
|
fErrorReporter.reportError( |
|
XMLMessageFormatter.XML_DOMAIN, |
|
"CharConversionFailure", |
|
null, |
|
XMLErrorReporter.SEVERITY_FATAL_ERROR, e); |
|
return -1; |
|
} |
|
|
|
catch (EOFException e) { |
|
reportFatalError("PrematureEOF", null); |
|
return -1; |
|
//throw e; |
|
} |
|
|
|
} |
|
} // class XMLDeclDriver |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
protected final class PrologDriver |
|
implements Driver { |
|
|
|
/** |
|
* Drives the parser to the next state/event on the input. Parser is guaranteed |
|
* to stop at the next state/event. |
|
* |
|
* Internally XML document is divided into several states. Each state represents |
|
* a sections of XML document. When this functions returns normally, it has read |
|
* the section of XML document and returns the state corresponding to section of |
|
* document which has been read. For optimizations, a particular driver |
|
* can read ahead of the section of document (state returned) just read and |
|
* can maintain a different internal state. |
|
* |
|
* @return state representing the section of document just read. |
|
* |
|
* @throws IOException Thrown on i/o error. |
|
* @throws XNIException Thrown on parse error. |
|
*/ |
|
|
|
public int next() throws IOException, XNIException { |
|
|
|
try { |
|
do { |
|
switch (fScannerState) { |
|
case SCANNER_STATE_PROLOG: { |
|
fEntityScanner.skipSpaces(); |
|
if (fEntityScanner.skipChar('<', null)) { |
|
setScannerState(SCANNER_STATE_START_OF_MARKUP); |
|
} else if (fEntityScanner.skipChar('&', NameType.REFERENCE)) { |
|
setScannerState(SCANNER_STATE_REFERENCE); |
|
} else { |
|
setScannerState(SCANNER_STATE_CONTENT); |
|
} |
|
break; |
|
} |
|
|
|
case SCANNER_STATE_START_OF_MARKUP: { |
|
fMarkupDepth++; |
|
if (isValidNameStartChar(fEntityScanner.peekChar()) || |
|
isValidNameStartHighSurrogate(fEntityScanner.peekChar())) { |
|
setScannerState(SCANNER_STATE_ROOT_ELEMENT); |
|
setDriver(fContentDriver); |
|
|
|
return fContentDriver.next(); |
|
} else if (fEntityScanner.skipChar('!', null)) { |
|
if (fEntityScanner.skipChar('-', null)) { |
|
if (!fEntityScanner.skipChar('-', null)) { |
|
reportFatalError("InvalidCommentStart", |
|
null); |
|
} |
|
setScannerState(SCANNER_STATE_COMMENT); |
|
} else if (fEntityScanner.skipString(DOCTYPE)) { |
|
setScannerState(SCANNER_STATE_DOCTYPE); |
|
Entity entity = fEntityScanner.getCurrentEntity(); |
|
if(entity instanceof Entity.ScannedEntity){ |
|
fStartPos=((Entity.ScannedEntity)entity).position; |
|
} |
|
fReadingDTD=true; |
|
if(fDTDDecl == null) |
|
fDTDDecl = new XMLStringBuffer(); |
|
fDTDDecl.append("<!DOCTYPE"); |
|
|
|
} else { |
|
reportFatalError("MarkupNotRecognizedInProlog", |
|
null); |
|
} |
|
} else if (fEntityScanner.skipChar('?', null)) { |
|
setScannerState(SCANNER_STATE_PI); |
|
} else { |
|
reportFatalError("MarkupNotRecognizedInProlog", |
|
null); |
|
} |
|
break; |
|
} |
|
} |
|
} while (fScannerState == SCANNER_STATE_PROLOG || fScannerState == SCANNER_STATE_START_OF_MARKUP ); |
|
|
|
switch(fScannerState){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
case SCANNER_STATE_COMMENT: { |
|
|
|
scanComment(); |
|
setScannerState(SCANNER_STATE_PROLOG); |
|
return XMLEvent.COMMENT; |
|
//setScannerState(SCANNER_STATE_PROLOG); |
|
//break; |
|
} |
|
case SCANNER_STATE_PI: { |
|
fContentBuffer.clear() ; |
|
scanPI(fContentBuffer); |
|
setScannerState(SCANNER_STATE_PROLOG); |
|
return XMLEvent.PROCESSING_INSTRUCTION; |
|
} |
|
|
|
case SCANNER_STATE_DOCTYPE: { |
|
if (fDisallowDoctype) { |
|
reportFatalError("DoctypeNotAllowed", null); |
|
} |
|
|
|
if (fSeenDoctypeDecl) { |
|
reportFatalError("AlreadySeenDoctype", null); |
|
} |
|
fSeenDoctypeDecl = true; |
|
|
|
// scanDoctypeDecl() sends XNI doctypeDecl event that |
|
|
|
if (scanDoctypeDecl(fSupportDTD)) { |
|
|
|
setScannerState(SCANNER_STATE_DTD_INTERNAL_DECLS); |
|
fSeenInternalSubset = true; |
|
if(fDTDDriver == null){ |
|
fDTDDriver = new DTDDriver(); |
|
} |
|
setDriver(fContentDriver); |
|
|
|
return fDTDDriver.next(); |
|
} |
|
|
|
if(fSeenDoctypeDecl){ |
|
Entity entity = fEntityScanner.getCurrentEntity(); |
|
if(entity instanceof Entity.ScannedEntity){ |
|
fEndPos = ((Entity.ScannedEntity)entity).position; |
|
} |
|
fReadingDTD = false; |
|
} |
|
|
|
|
|
if (fDoctypeSystemId != null) { |
|
if (((fValidation || fLoadExternalDTD) |
|
&& (fValidationManager == null || !fValidationManager.isCachedDTD()))) { |
|
if (fSupportDTD) { |
|
setScannerState(SCANNER_STATE_DTD_EXTERNAL); |
|
} else { |
|
setScannerState(SCANNER_STATE_PROLOG); |
|
} |
|
|
|
setDriver(fContentDriver); |
|
if(fDTDDriver == null) { |
|
fDTDDriver = new DTDDriver(); |
|
} |
|
|
|
return fDTDDriver.next(); |
|
} |
|
} |
|
else if (fExternalSubsetSource != null) { |
|
if (((fValidation || fLoadExternalDTD) |
|
&& (fValidationManager == null || !fValidationManager.isCachedDTD()))) { |
|
|
|
fDTDScanner.setInputSource(fExternalSubsetSource); |
|
fExternalSubsetSource = null; |
|
if (fSupportDTD) |
|
setScannerState(SCANNER_STATE_DTD_EXTERNAL_DECLS); |
|
else |
|
setScannerState(SCANNER_STATE_PROLOG); |
|
setDriver(fContentDriver); |
|
if(fDTDDriver == null) |
|
fDTDDriver = new DTDDriver(); |
|
return fDTDDriver.next(); |
|
} |
|
} |
|
|
|
// Send endDTD() call if: |
|
// a) systemId is null or if an external subset resolver could not locate an external subset. |
|
// b) "load-external-dtd" and validation are false |
|
// c) DTD grammar is cached |
|
|
|
// in XNI this results in 3 events: doctypeDecl, startDTD, endDTD |
|
|
|
if (fDTDScanner != null) { |
|
fDTDScanner.setInputSource(null); |
|
} |
|
setScannerState(SCANNER_STATE_PROLOG); |
|
return XMLEvent.DTD; |
|
} |
|
|
|
case SCANNER_STATE_CONTENT: { |
|
reportFatalError("ContentIllegalInProlog", null); |
|
fEntityScanner.scanChar(null); |
|
return -1; |
|
} |
|
case SCANNER_STATE_REFERENCE: { |
|
reportFatalError("ReferenceIllegalInProlog", null); |
|
return -1; |
|
} |
|
|
|
/** |
|
* if (complete) { |
|
* if (fEntityScanner.scanChar() != '<') { |
|
* reportFatalError("RootElementRequired", null); |
|
* } |
|
* setScannerState(SCANNER_STATE_ROOT_ELEMENT); |
|
* setDriver(fContentDriver); |
|
* } |
|
*/ |
|
} |
|
} |
|
|
|
catch (MalformedByteSequenceException e) { |
|
fErrorReporter.reportError(e.getDomain(), e.getKey(), |
|
e.getArguments(), XMLErrorReporter.SEVERITY_FATAL_ERROR, e); |
|
return -1; |
|
} catch (CharConversionException e) { |
|
fErrorReporter.reportError( |
|
XMLMessageFormatter.XML_DOMAIN, |
|
"CharConversionFailure", |
|
null, |
|
XMLErrorReporter.SEVERITY_FATAL_ERROR, e); |
|
return -1; |
|
} |
|
|
|
catch (EOFException e) { |
|
reportFatalError("PrematureEOF", null); |
|
|
|
return -1 ; |
|
//throw e; |
|
} |
|
|
|
return -1; |
|
|
|
} |
|
|
|
|
|
} // class PrologDriver |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
protected final class DTDDriver |
|
implements Driver { |
|
|
|
// |
|
// Driver methods |
|
// |
|
|
|
public int next() throws IOException, XNIException{ |
|
|
|
dispatch(true); |
|
|
|
//xxx: remove this hack and align this with reusing DTD components |
|
|
|
if(fPropertyManager != null){ |
|
dtdGrammarUtil = new DTDGrammarUtil(((XMLDTDScannerImpl)fDTDScanner).getGrammar(),fSymbolTable, fNamespaceContext); |
|
} |
|
|
|
return XMLEvent.DTD ; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public boolean dispatch(boolean complete) |
|
throws IOException, XNIException { |
|
fEntityManager.setEntityHandler(null); |
|
try { |
|
boolean again; |
|
XMLResourceIdentifierImpl resourceIdentifier = new XMLResourceIdentifierImpl(); |
|
if( fDTDScanner == null){ |
|
|
|
if (fEntityManager.getEntityScanner() instanceof XML11EntityScanner){ |
|
fDTDScanner = new XML11DTDScannerImpl(); |
|
} else |
|
|
|
fDTDScanner = new XMLDTDScannerImpl(); |
|
|
|
((XMLDTDScannerImpl)fDTDScanner).reset(fPropertyManager); |
|
} |
|
|
|
fDTDScanner.setLimitAnalyzer(fLimitAnalyzer); |
|
do { |
|
again = false; |
|
switch (fScannerState) { |
|
case SCANNER_STATE_DTD_INTERNAL_DECLS: { |
|
boolean moreToScan = false; |
|
if (!fDTDScanner.skipDTD(fSupportDTD)) { |
|
// REVISIT: Should there be a feature for |
|
|
|
boolean completeDTD = true; |
|
|
|
moreToScan = fDTDScanner.scanDTDInternalSubset(completeDTD, fStandalone, fHasExternalDTD && fLoadExternalDTD); |
|
} |
|
Entity entity = fEntityScanner.getCurrentEntity(); |
|
if(entity instanceof Entity.ScannedEntity){ |
|
fEndPos=((Entity.ScannedEntity)entity).position; |
|
} |
|
fReadingDTD=false; |
|
if (!moreToScan) { |
|
|
|
if (!fEntityScanner.skipChar(']', null)) { |
|
reportFatalError("DoctypedeclNotClosed", new Object[]{fDoctypeName}); |
|
} |
|
fEntityScanner.skipSpaces(); |
|
if (!fEntityScanner.skipChar('>', null)) { |
|
reportFatalError("DoctypedeclUnterminated", new Object[]{fDoctypeName}); |
|
} |
|
fMarkupDepth--; |
|
|
|
if (!fSupportDTD) { |
|
//simply reset the entity store without having to mess around |
|
|
|
fEntityStore = fEntityManager.getEntityStore(); |
|
fEntityStore.reset(); |
|
} else { |
|
|
|
if (fDoctypeSystemId != null && (fValidation || fLoadExternalDTD)) { |
|
setScannerState(SCANNER_STATE_DTD_EXTERNAL); |
|
break; |
|
} |
|
} |
|
|
|
setEndDTDScanState(); |
|
return true; |
|
|
|
} |
|
break; |
|
} |
|
case SCANNER_STATE_DTD_EXTERNAL: { |
|
/** |
|
fDTDDescription.setValues(fDoctypePublicId, fDoctypeSystemId, null, null); |
|
fDTDDescription.setRootName(fDoctypeName); |
|
XMLInputSource xmlInputSource = |
|
fEntityManager.resolveEntity(fDTDDescription); |
|
fDTDScanner.setInputSource(xmlInputSource); |
|
setScannerState(SCANNER_STATE_DTD_EXTERNAL_DECLS); |
|
again = true; |
|
break; |
|
*/ |
|
|
|
resourceIdentifier.setValues(fDoctypePublicId, fDoctypeSystemId, null, null); |
|
XMLInputSource xmlInputSource = null ; |
|
StaxXMLInputSource staxInputSource = fEntityManager.resolveEntityAsPerStax(resourceIdentifier); |
|
|
|
|
|
if (!staxInputSource.isCreatedByResolver()) { |
|
String accessError = checkAccess(fDoctypeSystemId, fAccessExternalDTD); |
|
if (accessError != null) { |
|
reportFatalError("AccessExternalDTD", new Object[]{ SecuritySupport.sanitizePath(fDoctypeSystemId), accessError }); |
|
} |
|
} |
|
xmlInputSource = staxInputSource.getXMLInputSource(); |
|
fDTDScanner.setInputSource(xmlInputSource); |
|
if (fEntityScanner.fCurrentEntity != null) { |
|
setScannerState(SCANNER_STATE_DTD_EXTERNAL_DECLS); |
|
} else { |
|
setScannerState(SCANNER_STATE_PROLOG); |
|
} |
|
again = true; |
|
break; |
|
} |
|
case SCANNER_STATE_DTD_EXTERNAL_DECLS: { |
|
// REVISIT: Should there be a feature for |
|
|
|
boolean completeDTD = true; |
|
boolean moreToScan = fDTDScanner.scanDTDExternalSubset(completeDTD); |
|
if (!moreToScan) { |
|
setEndDTDScanState(); |
|
return true; |
|
} |
|
break; |
|
} |
|
case SCANNER_STATE_PROLOG : { |
|
|
|
setEndDTDScanState(); |
|
return true; |
|
} |
|
default: { |
|
throw new XNIException("DTDDriver#dispatch: scanner state="+fScannerState+" ("+getScannerStateName(fScannerState)+')'); |
|
} |
|
} |
|
} while (complete || again); |
|
} |
|
|
|
catch (MalformedByteSequenceException e) { |
|
fErrorReporter.reportError(e.getDomain(), e.getKey(), |
|
e.getArguments(), XMLErrorReporter.SEVERITY_FATAL_ERROR, e); |
|
return false; |
|
} catch (CharConversionException e) { |
|
fErrorReporter.reportError( |
|
XMLMessageFormatter.XML_DOMAIN, |
|
"CharConversionFailure", |
|
null, |
|
XMLErrorReporter.SEVERITY_FATAL_ERROR, e); |
|
return false; |
|
} |
|
|
|
catch (EOFException e) { |
|
e.printStackTrace(); |
|
reportFatalError("PrematureEOF", null); |
|
return false; |
|
//throw e; |
|
} |
|
|
|
|
|
finally { |
|
fEntityManager.setEntityHandler(XMLDocumentScannerImpl.this); |
|
} |
|
|
|
return true; |
|
|
|
} |
|
|
|
// dispatch(boolean):boolean |
|
|
|
} // class DTDDriver |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
protected class ContentDriver |
|
extends FragmentContentDriver { |
|
|
|
// |
|
// Protected methods |
|
// |
|
|
|
// hooks |
|
|
|
// NOTE: These hook methods are added so that the full document |
|
// scanner can share the majority of code with this class. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
protected boolean scanForDoctypeHook() |
|
throws IOException, XNIException { |
|
|
|
if (fEntityScanner.skipString(DOCTYPE)) { |
|
setScannerState(SCANNER_STATE_DOCTYPE); |
|
|
|
return true; |
|
} |
|
return false; |
|
|
|
} // scanForDoctypeHook():boolean |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
protected boolean elementDepthIsZeroHook() |
|
throws IOException, XNIException { |
|
|
|
setScannerState(SCANNER_STATE_TRAILING_MISC); |
|
setDriver(fTrailingMiscDriver); |
|
return true; |
|
|
|
} // elementDepthIsZeroHook():boolean |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
protected boolean scanRootElementHook() |
|
throws IOException, XNIException { |
|
|
|
if (scanStartElement()) { |
|
setScannerState(SCANNER_STATE_TRAILING_MISC); |
|
setDriver(fTrailingMiscDriver); |
|
return true; |
|
} |
|
return false; |
|
|
|
} // scanRootElementHook():boolean |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
protected void endOfFileHook(EOFException e) |
|
throws IOException, XNIException { |
|
|
|
reportFatalError("PrematureEOF", null); |
|
// in case continue-after-fatal-error set, should not do this... |
|
//throw e; |
|
|
|
} // endOfFileHook() |
|
|
|
protected void resolveExternalSubsetAndRead() |
|
throws IOException, XNIException { |
|
|
|
fDTDDescription.setValues(null, null, fEntityManager.getCurrentResourceIdentifier().getExpandedSystemId(), null); |
|
fDTDDescription.setRootName(fElementQName.rawname); |
|
XMLInputSource src = fExternalSubsetResolver.getExternalSubset(fDTDDescription); |
|
|
|
if (src != null) { |
|
fDoctypeName = fElementQName.rawname; |
|
fDoctypePublicId = src.getPublicId(); |
|
fDoctypeSystemId = src.getSystemId(); |
|
|
|
if (fDocumentHandler != null) { |
|
// This inserts a doctypeDecl event into the stream though no |
|
|
|
fDocumentHandler.doctypeDecl(fDoctypeName, fDoctypePublicId, fDoctypeSystemId, null); |
|
} |
|
try { |
|
fDTDScanner.setInputSource(src); |
|
while (fDTDScanner.scanDTDExternalSubset(true)); |
|
} finally { |
|
fEntityManager.setEntityHandler(XMLDocumentScannerImpl.this); |
|
} |
|
} |
|
} // resolveExternalSubsetAndRead() |
|
|
|
|
|
|
|
} // class ContentDriver |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
protected final class TrailingMiscDriver |
|
implements Driver { |
|
|
|
// |
|
// Driver methods |
|
|
|
public int next() throws IOException, XNIException{ |
|
//this could for cases like <foo/> |
|
|
|
if(fEmptyElement){ |
|
fEmptyElement = false; |
|
return XMLEvent.END_ELEMENT; |
|
} |
|
|
|
try { |
|
if(fScannerState == SCANNER_STATE_TERMINATED){ |
|
return XMLEvent.END_DOCUMENT ;} |
|
do { |
|
switch (fScannerState) { |
|
case SCANNER_STATE_TRAILING_MISC: { |
|
|
|
fEntityScanner.skipSpaces(); |
|
//we should have reached the end of the document in |
|
|
|
if(fScannerState == SCANNER_STATE_TERMINATED ){ |
|
return XMLEvent.END_DOCUMENT ; |
|
} |
|
if (fEntityScanner.skipChar('<', null)) { |
|
setScannerState(SCANNER_STATE_START_OF_MARKUP); |
|
} else { |
|
setScannerState(SCANNER_STATE_CONTENT); |
|
} |
|
break; |
|
} |
|
case SCANNER_STATE_START_OF_MARKUP: { |
|
fMarkupDepth++; |
|
if (fEntityScanner.skipChar('?', null)) { |
|
setScannerState(SCANNER_STATE_PI); |
|
} else if (fEntityScanner.skipChar('!', null)) { |
|
setScannerState(SCANNER_STATE_COMMENT); |
|
} else if (fEntityScanner.skipChar('/', null)) { |
|
reportFatalError("MarkupNotRecognizedInMisc", |
|
null); |
|
} else if (isValidNameStartChar(fEntityScanner.peekChar()) || |
|
isValidNameStartHighSurrogate(fEntityScanner.peekChar())) { |
|
reportFatalError("MarkupNotRecognizedInMisc", |
|
null); |
|
scanStartElement(); |
|
setScannerState(SCANNER_STATE_CONTENT); |
|
} else { |
|
reportFatalError("MarkupNotRecognizedInMisc", |
|
null); |
|
} |
|
break; |
|
} |
|
} |
|
} while(fScannerState == SCANNER_STATE_START_OF_MARKUP || |
|
fScannerState == SCANNER_STATE_TRAILING_MISC); |
|
|
|
switch (fScannerState){ |
|
case SCANNER_STATE_PI: { |
|
fContentBuffer.clear(); |
|
scanPI(fContentBuffer); |
|
setScannerState(SCANNER_STATE_TRAILING_MISC); |
|
return XMLEvent.PROCESSING_INSTRUCTION ; |
|
} |
|
case SCANNER_STATE_COMMENT: { |
|
if (!fEntityScanner.skipString(COMMENTSTRING)) { |
|
reportFatalError("InvalidCommentStart", null); |
|
} |
|
scanComment(); |
|
setScannerState(SCANNER_STATE_TRAILING_MISC); |
|
return XMLEvent.COMMENT; |
|
} |
|
case SCANNER_STATE_CONTENT: { |
|
int ch = fEntityScanner.peekChar(); |
|
if (ch == -1) { |
|
setScannerState(SCANNER_STATE_TERMINATED); |
|
return XMLEvent.END_DOCUMENT ; |
|
} else{ |
|
reportFatalError("ContentIllegalInTrailingMisc", |
|
null); |
|
fEntityScanner.scanChar(null); |
|
setScannerState(SCANNER_STATE_TRAILING_MISC); |
|
return XMLEvent.CHARACTERS; |
|
} |
|
|
|
} |
|
case SCANNER_STATE_REFERENCE: { |
|
reportFatalError("ReferenceIllegalInTrailingMisc", |
|
null); |
|
setScannerState(SCANNER_STATE_TRAILING_MISC); |
|
return XMLEvent.ENTITY_REFERENCE ; |
|
} |
|
case SCANNER_STATE_TERMINATED: { |
|
//there can't be any element after SCANNER_STATE_TERMINATED or when the parser |
|
|
|
setScannerState(SCANNER_STATE_NO_SUCH_ELEMENT_EXCEPTION); |
|
|
|
return XMLEvent.END_DOCUMENT ; |
|
} |
|
case SCANNER_STATE_NO_SUCH_ELEMENT_EXCEPTION:{ |
|
throw new java.util.NoSuchElementException("No more events to be parsed"); |
|
} |
|
default: throw new XNIException("Scanner State " + fScannerState + " not Recognized "); |
|
}//switch |
|
// encoding errors |
|
} catch (MalformedByteSequenceException e) { |
|
fErrorReporter.reportError(e.getDomain(), e.getKey(), |
|
e.getArguments(), XMLErrorReporter.SEVERITY_FATAL_ERROR, e); |
|
return -1; |
|
} catch (CharConversionException e) { |
|
fErrorReporter.reportError( |
|
XMLMessageFormatter.XML_DOMAIN, |
|
"CharConversionFailure", |
|
null, |
|
XMLErrorReporter.SEVERITY_FATAL_ERROR, e); |
|
return -1; |
|
} catch (EOFException e) { |
|
// NOTE: This is the only place we're allowed to reach |
|
// the real end of the document stream. Unless the |
|
|
|
if (fMarkupDepth != 0) { |
|
reportFatalError("PrematureEOF", null); |
|
return -1; |
|
//throw e; |
|
} |
|
|
|
setScannerState(SCANNER_STATE_TERMINATED); |
|
} |
|
|
|
return XMLEvent.END_DOCUMENT; |
|
|
|
}//next |
|
|
|
} // class TrailingMiscDriver |
|
|
|
/** |
|
* Implements XMLBufferListener interface. |
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public void refresh(int refreshPosition){ |
|
super.refresh(refreshPosition); |
|
if(fReadingDTD){ |
|
Entity entity = fEntityScanner.getCurrentEntity(); |
|
if(entity instanceof Entity.ScannedEntity){ |
|
fEndPos=((Entity.ScannedEntity)entity).position; |
|
} |
|
fDTDDecl.append(((Entity.ScannedEntity)entity).ch,fStartPos , fEndPos-fStartPos); |
|
fStartPos = refreshPosition; |
|
} |
|
} |
|
|
|
} // class XMLDocumentScannerImpl |