# HG changeset patch # User lana # Date 1340685454 25200 # Node ID 54a86b897fe8e077de491e71615a1417a0b3eec6 # Parent a5c1047a05e95723c367a8bdcc7951a4a9701f53# Parent a079926a6d815256266163af52cff38be084474b Merge diff -r a5c1047a05e9 -r 54a86b897fe8 src/com/sun/org/apache/xerces/internal/impl/XMLDocumentFragmentScannerImpl.java --- a/src/com/sun/org/apache/xerces/internal/impl/XMLDocumentFragmentScannerImpl.java Thu Jun 21 17:07:57 2012 -0700 +++ b/src/com/sun/org/apache/xerces/internal/impl/XMLDocumentFragmentScannerImpl.java Mon Jun 25 21:37:34 2012 -0700 @@ -286,12 +286,13 @@ //STAX related properties //defaultValues. + protected boolean fSupportDTD = true; protected boolean fReplaceEntityReferences = true; protected boolean fSupportExternalEntities = false; protected boolean fReportCdataEvent = false ; protected boolean fIsCoalesce = false ; protected String fDeclaredEncoding = null; - /** Disallow doctype declaration. */ + /** Xerces Feature: Disallow doctype declaration. */ protected boolean fDisallowDoctype = false; // drivers @@ -1847,7 +1848,7 @@ // start general entity if (!fEntityStore.isDeclaredEntity(name)) { //SUPPORT_DTD=false && ReplaceEntityReferences should throw exception - if (fDisallowDoctype && fReplaceEntityReferences) { + if (!fSupportDTD && fReplaceEntityReferences) { reportFatalError("EntityNotDeclared", new Object[]{name}); return; } diff -r a5c1047a05e9 -r 54a86b897fe8 src/com/sun/org/apache/xerces/internal/impl/XMLDocumentScannerImpl.java --- a/src/com/sun/org/apache/xerces/internal/impl/XMLDocumentScannerImpl.java Thu Jun 21 17:07:57 2012 -0700 +++ b/src/com/sun/org/apache/xerces/internal/impl/XMLDocumentScannerImpl.java Mon Jun 25 21:37:34 2012 -0700 @@ -278,7 +278,7 @@ fDoctypeSystemId = null; fSeenDoctypeDecl = false; fNamespaceContext.reset(); - fDisallowDoctype = !((Boolean)propertyManager.getProperty(XMLInputFactory.SUPPORT_DTD)).booleanValue(); + fSupportDTD = ((Boolean)propertyManager.getProperty(XMLInputFactory.SUPPORT_DTD)).booleanValue(); // xerces features fLoadExternalDTD = !((Boolean)propertyManager.getProperty(Constants.ZEPHYR_PROPERTY_PREFIX + Constants.IGNORE_EXTERNAL_DTD)).booleanValue(); @@ -628,7 +628,7 @@ // scanning methods /** Scans a doctype declaration. */ - protected boolean scanDoctypeDecl(boolean ignore) throws IOException, XNIException { + protected boolean scanDoctypeDecl(boolean supportDTD) throws IOException, XNIException { // spaces if (!fEntityScanner.skipSpaces()) { @@ -653,7 +653,7 @@ fHasExternalDTD = fDoctypeSystemId != null; // Attempt to locate an external subset with an external subset resolver. - if (!ignore && !fHasExternalDTD && fExternalSubsetResolver != null) { + if (supportDTD && !fHasExternalDTD && fExternalSubsetResolver != null) { fDTDDescription.setValues(null, null, fEntityManager.getCurrentResourceIdentifier().getExpandedSystemId(), null); fDTDDescription.setRootName(fDoctypeName); fExternalSubsetSource = fExternalSubsetResolver.getExternalSubset(fDTDDescription); @@ -661,7 +661,7 @@ } // call handler - if (!ignore && fDocumentHandler != 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 @@ -916,6 +916,10 @@ } case SCANNER_STATE_DOCTYPE: { + if (fDisallowDoctype) { + reportFatalError("DoctypeNotAllowed", null); + } + if (fSeenDoctypeDecl) { reportFatalError("AlreadySeenDoctype", null); @@ -924,7 +928,7 @@ // scanDoctypeDecl() sends XNI doctypeDecl event that // in SAX is converted to startDTD() event. - if (scanDoctypeDecl(fDisallowDoctype)) { + if (scanDoctypeDecl(fSupportDTD)) { //allow parsing of entity decls to continue in order to stay well-formed setScannerState(SCANNER_STATE_DTD_INTERNAL_DECLS); fSeenInternalSubset = true; @@ -934,8 +938,6 @@ setDriver(fContentDriver); //always return DTD event, the event however, will not contain any entities return fDTDDriver.next(); - // If no DTD support, ignore and continue parsing - //return fDisallowDoctype ? next() : dtdEvent; } if(fSeenDoctypeDecl){ @@ -950,7 +952,7 @@ if (fDoctypeSystemId != null) { if (((fValidation || fLoadExternalDTD) && (fValidationManager == null || !fValidationManager.isCachedDTD()))) { - if (!fDisallowDoctype) + if (fSupportDTD) setScannerState(SCANNER_STATE_DTD_EXTERNAL); else setScannerState(SCANNER_STATE_PROLOG); @@ -967,7 +969,7 @@ // This handles the case of a DOCTYPE that had neither an internal subset or an external subset. fDTDScanner.setInputSource(fExternalSubsetSource); fExternalSubsetSource = null; - if (!fDisallowDoctype) + if (fSupportDTD) setScannerState(SCANNER_STATE_DTD_EXTERNAL_DECLS); else setScannerState(SCANNER_STATE_PROLOG); @@ -1113,7 +1115,7 @@ } fMarkupDepth--; - if (fDisallowDoctype) { + if (!fSupportDTD) { //simply reset the entity store without having to mess around //with the DTD Scanner code fEntityStore = fEntityManager.getEntityStore(); diff -r a5c1047a05e9 -r 54a86b897fe8 src/com/sun/xml/internal/stream/XMLEventReaderImpl.java --- a/src/com/sun/xml/internal/stream/XMLEventReaderImpl.java Thu Jun 21 17:07:57 2012 -0700 +++ b/src/com/sun/xml/internal/stream/XMLEventReaderImpl.java Mon Jun 25 21:37:34 2012 -0700 @@ -248,8 +248,11 @@ object = nextEvent(); }catch(XMLStreamException streamException){ fLastEvent = null ; - //xxx: what should be done in this case ? - throw new NoSuchElementException(); + //don't swallow the cause + NoSuchElementException e = new NoSuchElementException(streamException.getMessage()); + e.initCause(streamException.getCause()); + throw e; + } return object; }