mrglavas 2004/02/27 12:36:07 Modified: java/src/org/apache/xerces/parsers AbstractSAXParser.java java/src/org/apache/xerces/impl XMLVersionDetector.java XMLEntityHandler.java XMLDocumentScannerImpl.java XMLEntityManager.java XMLDTDScannerImpl.java Constants.java XMLDocumentFragmentScannerImpl.java XMLScanner.java Log: Fixing Bug #26685:
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=26685 SAX requires that when an entity is skipped that it be reported to ContentHandler.skippedEntity. From the API spec for ContentHandler: "The Parser will invoke this method each time the entity is skipped. Non-validating processors may skip entities if they have not seen the declarations (because, for example, the entity was declared in an external DTD subset). All processors may skip external entities, depending on the values of the http://xml.org/sax/features/external-general-entities and the http://xml.org/sax/features/external-parameter-entities properties." XNI (which isn't going to change) has no built-in method for communicating skipped entities. XMLEntityManager needed some method to communicate that an entity has been skipped so I've added Augmentations to our internal interface XMLEntityHandler. This is consistent with interfaces in XNI. Revision Changes Path 1.50 +19 -7 xml-xerces/java/src/org/apache/xerces/parsers/AbstractSAXParser.java Index: AbstractSAXParser.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/AbstractSAXParser.java,v retrieving revision 1.49 retrieving revision 1.50 diff -u -r1.49 -r1.50 --- AbstractSAXParser.java 24 Feb 2004 23:15:56 -0000 1.49 +++ AbstractSAXParser.java 27 Feb 2004 20:36:06 -0000 1.50 @@ -746,9 +746,18 @@ throws XNIException { try { - // SAX2 extension - if (fLexicalHandler != null) { - fLexicalHandler.startEntity(name); + // Only report startEntity if this entity was actually read. + if (augs != null && Boolean.TRUE.equals(augs.getItem(Constants.ENTITY_SKIPPED))) { + // report skipped entity to content handler + if (fContentHandler != null) { + fContentHandler.skippedEntity(name); + } + } + else { + // SAX2 extension + if (fLexicalHandler != null) { + fLexicalHandler.startEntity(name); + } } } catch (SAXException e) { @@ -780,9 +789,12 @@ public void endParameterEntity(String name, Augmentations augs) throws XNIException { try { - // SAX2 extension - if (fLexicalHandler != null) { - fLexicalHandler.endEntity(name); + // Only report endEntity if this entity was actually read. + if (augs == null || !Boolean.TRUE.equals(augs.getItem(Constants.ENTITY_SKIPPED))) { + // SAX2 extension + if (fLexicalHandler != null) { + fLexicalHandler.endEntity(name); + } } } catch (SAXException e) { 1.12 +2 -2 xml-xerces/java/src/org/apache/xerces/impl/XMLVersionDetector.java Index: XMLVersionDetector.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/XMLVersionDetector.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- XMLVersionDetector.java 24 Feb 2004 23:03:46 -0000 1.11 +++ XMLVersionDetector.java 27 Feb 2004 20:36:07 -0000 1.12 @@ -126,7 +126,7 @@ // fEntityManager.setEntityHandler(scanner); - scanner.startEntity(fXMLSymbol, fEntityManager.getCurrentResourceIdentifier(), fEncoding); + scanner.startEntity(fXMLSymbol, fEntityManager.getCurrentResourceIdentifier(), fEncoding, null); } 1.9 +8 -5 xml-xerces/java/src/org/apache/xerces/impl/XMLEntityHandler.java Index: XMLEntityHandler.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/XMLEntityHandler.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- XMLEntityHandler.java 24 Feb 2004 23:03:46 -0000 1.8 +++ XMLEntityHandler.java 27 Feb 2004 20:36:07 -0000 1.9 @@ -16,6 +16,7 @@ package org.apache.xerces.impl; +import org.apache.xerces.xni.Augmentations; import org.apache.xerces.xni.XMLResourceIdentifier; import org.apache.xerces.xni.XNIException; @@ -47,12 +48,13 @@ * where the entity encoding is not auto-detected (e.g. * internal entities or a document entity that is * parsed from a java.io.Reader). - * + * @param augs Additional information that may include infoset augmentations + * * @throws XNIException Thrown by handler to signal an error. */ public void startEntity(String name, XMLResourceIdentifier identifier, - String encoding) throws XNIException; + String encoding, Augmentations augs) throws XNIException; /** * This method notifies the end of an entity. The DTD has the pseudo-name @@ -60,9 +62,10 @@ * are just specified by their name. * * @param name The name of the entity. - * + * @param augs Additional information that may include infoset augmentations + * * @throws XNIException Thrown by handler to signal an error. */ - public void endEntity(String name) throws XNIException; + public void endEntity(String name, Augmentations augs) throws XNIException; } // interface XMLEntityHandler 1.40 +6 -5 xml-xerces/java/src/org/apache/xerces/impl/XMLDocumentScannerImpl.java Index: XMLDocumentScannerImpl.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/XMLDocumentScannerImpl.java,v retrieving revision 1.39 retrieving revision 1.40 diff -u -r1.39 -r1.40 --- XMLDocumentScannerImpl.java 24 Feb 2004 23:03:46 -0000 1.39 +++ XMLDocumentScannerImpl.java 27 Feb 2004 20:36:07 -0000 1.40 @@ -24,6 +24,7 @@ import org.apache.xerces.util.XMLChar; import org.apache.xerces.util.XMLResourceIdentifierImpl; import org.apache.xerces.util.XMLStringBuffer; +import org.apache.xerces.xni.Augmentations; import org.apache.xerces.xni.NamespaceContext; import org.apache.xerces.xni.XMLResourceIdentifier; import org.apache.xerces.xni.XMLString; @@ -478,9 +479,9 @@ */ public void startEntity(String name, XMLResourceIdentifier identifier, - String encoding) throws XNIException { + String encoding, Augmentations augs) throws XNIException { - super.startEntity(name, identifier, encoding); + super.startEntity(name, identifier, encoding, augs); // prepare to look for a TextDecl if external general entity if (!name.equals("[xml]") && fEntityScanner.isExternal()) { @@ -503,9 +504,9 @@ * * @throws XNIException Thrown by handler to signal an error. */ - public void endEntity(String name) throws XNIException { + public void endEntity(String name, Augmentations augs) throws XNIException { - super.endEntity(name); + super.endEntity(name, augs); // call handler if (fDocumentHandler != null && name.equals("[xml]")) { 1.76 +26 -9 xml-xerces/java/src/org/apache/xerces/impl/XMLEntityManager.java Index: XMLEntityManager.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/XMLEntityManager.java,v retrieving revision 1.75 retrieving revision 1.76 diff -u -r1.75 -r1.76 --- XMLEntityManager.java 24 Feb 2004 23:03:46 -0000 1.75 +++ XMLEntityManager.java 27 Feb 2004 20:36:07 -0000 1.76 @@ -33,12 +33,14 @@ import org.apache.xerces.impl.io.UTF8Reader; import org.apache.xerces.impl.msg.XMLMessageFormatter; import org.apache.xerces.impl.validation.ValidationManager; +import org.apache.xerces.util.AugmentationsImpl; import org.apache.xerces.util.EncodingMap; import org.apache.xerces.util.SecurityManager; import org.apache.xerces.util.SymbolTable; import org.apache.xerces.util.URI; import org.apache.xerces.util.XMLChar; import org.apache.xerces.util.XMLResourceIdentifierImpl; +import org.apache.xerces.xni.Augmentations; import org.apache.xerces.xni.XMLResourceIdentifier; import org.apache.xerces.xni.XNIException; import org.apache.xerces.xni.parser.XMLComponent; @@ -338,6 +340,9 @@ /** Resource identifer. */ private final XMLResourceIdentifierImpl fResourceIdentifier = new XMLResourceIdentifierImpl(); + + /** Augmentations for entities. */ + private final Augmentations fEntityAugs = new AugmentationsImpl(); // // Constructors @@ -687,8 +692,12 @@ if (fEntityHandler != null) { String encoding = null; fResourceIdentifier.clear(); - fEntityHandler.startEntity(entityName, fResourceIdentifier, encoding); - fEntityHandler.endEntity(entityName); + fEntityAugs.removeAllItems(); + fEntityAugs.putItem(Constants.ENTITY_SKIPPED, Boolean.TRUE); + fEntityHandler.startEntity(entityName, fResourceIdentifier, encoding, fEntityAugs); + fEntityAugs.removeAllItems(); + fEntityAugs.putItem(Constants.ENTITY_SKIPPED, Boolean.TRUE); + fEntityHandler.endEntity(entityName, fEntityAugs); } return; } @@ -714,8 +723,12 @@ fResourceIdentifier.setValues( (externalEntity.entityLocation != null ? externalEntity.entityLocation.getPublicId() : null), extLitSysId, extBaseSysId, expandedSystemId); - fEntityHandler.startEntity(entityName, fResourceIdentifier, encoding); - fEntityHandler.endEntity(entityName); + fEntityAugs.removeAllItems(); + fEntityAugs.putItem(Constants.ENTITY_SKIPPED, Boolean.TRUE); + fEntityHandler.startEntity(entityName, fResourceIdentifier, encoding, fEntityAugs); + fEntityAugs.removeAllItems(); + fEntityAugs.putItem(Constants.ENTITY_SKIPPED, Boolean.TRUE); + fEntityHandler.endEntity(entityName, fEntityAugs); } return; } @@ -752,8 +765,12 @@ (externalEntity.entityLocation != null ? externalEntity.entityLocation.getPublicId() : null), extLitSysId, extBaseSysId, expandedSystemId); } - fEntityHandler.startEntity(entityName, fResourceIdentifier, encoding); - fEntityHandler.endEntity(entityName); + fEntityAugs.removeAllItems(); + fEntityAugs.putItem(Constants.ENTITY_SKIPPED, Boolean.TRUE); + fEntityHandler.startEntity(entityName, fResourceIdentifier, encoding, fEntityAugs); + fEntityAugs.removeAllItems(); + fEntityAugs.putItem(Constants.ENTITY_SKIPPED, Boolean.TRUE); + fEntityHandler.endEntity(entityName, null); } return; } @@ -856,7 +873,7 @@ // call handler if (fEntityHandler != null) { - fEntityHandler.startEntity(name, fResourceIdentifier, encoding); + fEntityHandler.startEntity(name, fResourceIdentifier, encoding, null); } } // startEntity(String,XMLInputSource) @@ -1678,7 +1695,7 @@ System.out.println(); } if (fEntityHandler != null) { - fEntityHandler.endEntity(fCurrentEntity.name); + fEntityHandler.endEntity(fCurrentEntity.name, null); } // Close the reader for the current entity once we're 1.49 +10 -7 xml-xerces/java/src/org/apache/xerces/impl/XMLDTDScannerImpl.java Index: XMLDTDScannerImpl.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/XMLDTDScannerImpl.java,v retrieving revision 1.48 retrieving revision 1.49 diff -u -r1.48 -r1.49 --- XMLDTDScannerImpl.java 24 Feb 2004 23:03:46 -0000 1.48 +++ XMLDTDScannerImpl.java 27 Feb 2004 20:36:07 -0000 1.49 @@ -23,6 +23,7 @@ import org.apache.xerces.util.XMLAttributesImpl; import org.apache.xerces.util.XMLChar; import org.apache.xerces.util.XMLStringBuffer; +import org.apache.xerces.xni.Augmentations; import org.apache.xerces.xni.XMLDTDContentModelHandler; import org.apache.xerces.xni.XMLDTDHandler; import org.apache.xerces.xni.XMLResourceIdentifier; @@ -476,14 +477,15 @@ * where the entity encoding is not auto-detected (e.g. * internal entities or a document entity that is * parsed from a java.io.Reader). + * @param augs Additional information that may include infoset augmentations * * @throws XNIException Thrown by handler to signal an error. */ public void startEntity(String name, XMLResourceIdentifier identifier, - String encoding) throws XNIException { + String encoding, Augmentations augs) throws XNIException { - super.startEntity(name, identifier, encoding); + super.startEntity(name, identifier, encoding, augs); boolean dtdEntity = name.equals("[dtd]"); if (dtdEntity) { @@ -506,7 +508,7 @@ // call handler if (fDTDHandler != null && !dtdEntity && fReportEntity) { - fDTDHandler.startParameterEntity(name, identifier, encoding, null); + fDTDHandler.startParameterEntity(name, identifier, encoding, augs); } } // startEntity(String,XMLResourceIdentifier,String) @@ -517,13 +519,14 @@ * are just specified by their name. * * @param name The name of the entity. + * @param augs Additional information that may include infoset augmentations * * @throws XNIException Thrown by handler to signal an error. */ - public void endEntity(String name) + public void endEntity(String name, Augmentations augs) throws XNIException { - super.endEntity(name); + super.endEntity(name, augs); // if there is no data after the doctype // @@ -564,7 +567,7 @@ // call handler boolean dtdEntity = name.equals("[dtd]"); if (fDTDHandler != null && !dtdEntity && reportEntity) { - fDTDHandler.endParameterEntity(name, null); + fDTDHandler.endParameterEntity(name, augs); } // end DTD 1.39 +9 -1 xml-xerces/java/src/org/apache/xerces/impl/Constants.java Index: Constants.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/Constants.java,v retrieving revision 1.38 retrieving revision 1.39 diff -u -r1.38 -r1.39 --- Constants.java 24 Feb 2004 23:03:46 -0000 1.38 +++ Constants.java 27 Feb 2004 20:36:07 -0000 1.39 @@ -328,6 +328,14 @@ * augmentation indicates that the attribute was not declared in the DTD. */ public final static String ATTRIBUTE_DECLARED = "ATTRIBUTE_DECLARED"; + + /** + * Boolean indicating whether an entity referenced in the document has + * not been read is stored in augmentations using string "ENTITY_SKIPPED". + * The absence of this augmentation indicates that the entity had a + * declaration and was expanded. + */ + public final static String ENTITY_SKIPPED = "ENTITY_SKIPPED"; // XML version constants public final static short XML_VERSION_1_0 = 1; 1.48 +9 -7 xml-xerces/java/src/org/apache/xerces/impl/XMLDocumentFragmentScannerImpl.java Index: XMLDocumentFragmentScannerImpl.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/XMLDocumentFragmentScannerImpl.java,v retrieving revision 1.47 retrieving revision 1.48 diff -u -r1.47 -r1.48 --- XMLDocumentFragmentScannerImpl.java 24 Feb 2004 23:03:46 -0000 1.47 +++ XMLDocumentFragmentScannerImpl.java 27 Feb 2004 20:36:07 -0000 1.48 @@ -509,12 +509,13 @@ * where the entity encoding is not auto-detected (e.g. * internal entities or a document entity that is * parsed from a java.io.Reader). + * @param augs Additional information that may include infoset augmentations * * @throws XNIException Thrown by handler to signal an error. */ public void startEntity(String name, XMLResourceIdentifier identifier, - String encoding) throws XNIException { + String encoding, Augmentations augs) throws XNIException { // keep track of this entity before fEntityDepth is increased if (fEntityDepth == fEntityStack.length) { @@ -524,7 +525,7 @@ } fEntityStack[fEntityDepth] = fMarkupDepth; - super.startEntity(name, identifier, encoding); + super.startEntity(name, identifier, encoding, augs); // WFC: entity declared in external subset in standalone doc if(fStandalone && fEntityManager.isEntityDeclInExternalSubset(name)) { @@ -535,7 +536,7 @@ // call handler if (fDocumentHandler != null && !fScanningAttribute) { if (!name.equals("[xml]")) { - fDocumentHandler.startGeneralEntity(name, identifier, encoding, null); + fDocumentHandler.startGeneralEntity(name, identifier, encoding, augs); } } @@ -547,10 +548,11 @@ * are just specified by their name. * * @param name The name of the entity. + * @param augs Additional information that may include infoset augmentations * * @throws XNIException Thrown by handler to signal an error. */ - public void endEntity(String name) throws XNIException { + public void endEntity(String name, Augmentations augs) throws XNIException { // flush possible pending output buffer - see scanContent if (fInScanContent && fStringBuffer.length != 0 @@ -559,7 +561,7 @@ fStringBuffer.length = 0; // make sure we know it's been flushed } - super.endEntity(name); + super.endEntity(name, augs); // make sure markup is properly balanced if (fMarkupDepth != fEntityStack[fEntityDepth]) { @@ -569,7 +571,7 @@ // call handler if (fDocumentHandler != null && !fScanningAttribute) { if (!name.equals("[xml]")) { - fDocumentHandler.endGeneralEntity(name, null); + fDocumentHandler.endGeneralEntity(name, augs); } } 1.47 +6 -3 xml-xerces/java/src/org/apache/xerces/impl/XMLScanner.java Index: XMLScanner.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/XMLScanner.java,v retrieving revision 1.46 retrieving revision 1.47 diff -u -r1.46 -r1.47 --- XMLScanner.java 24 Feb 2004 23:03:46 -0000 1.46 +++ XMLScanner.java 27 Feb 2004 20:36:07 -0000 1.47 @@ -23,6 +23,7 @@ import org.apache.xerces.util.XMLChar; import org.apache.xerces.util.XMLResourceIdentifierImpl; import org.apache.xerces.util.XMLStringBuffer; +import org.apache.xerces.xni.Augmentations; import org.apache.xerces.xni.XMLAttributes; import org.apache.xerces.xni.XMLResourceIdentifier; import org.apache.xerces.xni.XMLString; @@ -1129,12 +1130,13 @@ * where the entity encoding is not auto-detected (e.g. * internal entities or a document entity that is * parsed from a java.io.Reader). + * @param augs Additional information that may include infoset augmentations * * @throws XNIException Thrown by handler to signal an error. */ public void startEntity(String name, XMLResourceIdentifier identifier, - String encoding) throws XNIException { + String encoding, Augmentations augs) throws XNIException { // keep track of the entity depth fEntityDepth++; @@ -1150,10 +1152,11 @@ * specified by their name. * * @param name The name of the entity. + * @param augs Additional information that may include infoset augmentations * * @throws XNIException Thrown by handler to signal an error. */ - public void endEntity(String name) throws XNIException { + public void endEntity(String name, Augmentations augs) throws XNIException { // keep track of the entity depth fEntityDepth--; --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]