mrglavas 2004/03/19 15:18:33 Modified: java/src/org/apache/xerces/parsers AbstractSAXParser.java java/src/org/apache/xerces/impl Constants.java Log: Support the SAX feature: lexical-handler/parameter-entities.
This should now complete support for all features defined for SAX 2.0. This particular feature controls whether the beginning and end of parameter entities will be reported to the LexicalHandler. Revision Changes Path 1.52 +54 -5 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.51 retrieving revision 1.52 diff -u -r1.51 -r1.52 --- AbstractSAXParser.java 3 Mar 2004 21:24:15 -0000 1.51 +++ AbstractSAXParser.java 19 Mar 2004 23:18:33 -0000 1.52 @@ -139,6 +139,9 @@ /** Namespace prefixes. */ protected boolean fNamespacePrefixes = false; + + /** Lexical handler parameter entities. */ + protected boolean fLexicalHandlerParameterEntities = true; // parser handlers @@ -350,7 +353,24 @@ String encoding, Augmentations augs) throws XNIException { - startParameterEntity(name, identifier, encoding, augs); + try { + // 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) { + throw new XNIException(e); + } } // startGeneralEntity(String,String,String,String,String) @@ -375,7 +395,18 @@ */ public void endGeneralEntity(String name, Augmentations augs) throws XNIException { - endParameterEntity(name, augs); + try { + // 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) { + throw new XNIException(e); + } } // endEntity(String) @@ -755,7 +786,7 @@ } else { // SAX2 extension - if (fLexicalHandler != null) { + if (fLexicalHandler != null && fLexicalHandlerParameterEntities) { fLexicalHandler.startEntity(name); } } @@ -792,7 +823,7 @@ // 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) { + if (fLexicalHandler != null && fLexicalHandlerParameterEntities) { fLexicalHandler.endEntity(name); } } @@ -1457,6 +1488,15 @@ } return; } + // http://xml.org/sax/features/lexical-handler/parameter-entities + // controls whether the beginning and end of parameter entities + // will be reported to the LexicalHandler. + // + if (suffixLength == Constants.LEXICAL_HANDLER_PARAMETER_ENTITIES_FEATURE.length() && + featureId.endsWith(Constants.LEXICAL_HANDLER_PARAMETER_ENTITIES_FEATURE)) { + fLexicalHandlerParameterEntities = state; + return; + } // // Drop through and perform default processing @@ -1541,6 +1581,15 @@ if (suffixLength == Constants.STRING_INTERNING_FEATURE.length() && featureId.endsWith(Constants.STRING_INTERNING_FEATURE)) { return true; + } + + // http://xml.org/sax/features/lexical-handler/parameter-entities + // controls whether the beginning and end of parameter entities + // will be reported to the LexicalHandler. + // + if (suffixLength == Constants.LEXICAL_HANDLER_PARAMETER_ENTITIES_FEATURE.length() && + featureId.endsWith(Constants.LEXICAL_HANDLER_PARAMETER_ENTITIES_FEATURE)) { + return fLexicalHandlerParameterEntities; } // 1.40 +4 -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.39 retrieving revision 1.40 diff -u -r1.39 -r1.40 --- Constants.java 27 Feb 2004 20:36:07 -0000 1.39 +++ Constants.java 19 Mar 2004 23:18:33 -0000 1.40 @@ -57,6 +57,9 @@ /** External parameter entities feature ("external-parameter-entities "). */ public static final String EXTERNAL_PARAMETER_ENTITIES_FEATURE = "external-parameter-entities"; + + /** Lexical handler parameter entities feature ("lexical-handler/parameter-entities"). */ + public static final String LEXICAL_HANDLER_PARAMETER_ENTITIES_FEATURE = "lexical-handler/parameter-entities"; /** Allow unparsed entity and notation declaration events to be sent after the end DTD event ("allow-dtd-events-after-endDTD") */ public static final String ALLOW_DTD_EVENTS_AFTER_ENDDTD_FEATURE = "allow-dtd-events-after-endDTD"; --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]