[jdom-interest] SAXHandler skipped entity patch

Elliotte Rusty Harold elharo at metalab.unc.edu
Wed Feb 6 09:18:45 PST 2002


The following patch will add support for skipped entities to SAXHandler
in the event that the parser is not resolving external entities. I''ve 
verified
that it compiles and doesn't break any tests. However, I'm not totally
fluent on the current logic of SAXHandler and org.jdom.input, so please
double check my skippedEntity() method for any obvious mistakes.

I also made some corrections to the JavaDoc for processsingInstruction().

? build
? saxhandlerdiff.txt
Index: src/java/org/jdom/input/SAXHandler.java
===================================================================
RCS file: /home/cvspublic/jdom/src/java/org/jdom/input/SAXHandler.java,v
retrieving revision 1.34
diff -d -u -r1.34 SAXHandler.java
--- src/java/org/jdom/input/SAXHandler.java    2002/02/06 02:11:42    1.34
+++ src/java/org/jdom/input/SAXHandler.java    2002/02/07 01:15:44
@@ -153,7 +153,8 @@
      * <p>
      * Class initializer: Populate a table to translate SAX attribute
      * type names into JDOM attribute type value (integer).
-     * </p><p>
+     * </p>
+     * <p>
      * <b>Note that all the mappings defined below are compliant with
      * the SAX 2.0 specification exception for "ENUMERATION" with is
      * specific to Crinsom 1.1.X and Xerces 2.0.0-betaX which report
@@ -448,12 +449,13 @@
 
     /**
      * <p>
-     * This will indicate that a processing instruction (other than
-     *   the XML declaration) has been encountered.
+     * This will indicate that a processing instruction has been 
encountered.
+     * (The XML declaration is not a processing instrcution and will not
+     *  be reported.)
      * </p>
      *
      * @param target <code>String</code> target of PI
-     * @param data <code>String</code containing all data sent to the PI.
+     * @param data <code>String</code> containing all data sent to the PI.
      *             This typically looks like one or more attribute value
      *             pairs.
      * @throws SAXException when things go wrong
@@ -475,6 +477,28 @@
 
     /**
      * <p>
+     * This indicates that an unresolvable entity reference has been 
encountered,
+     * normally because the external DTD subset has not been
+     * read.
+     * </p>
+     *
+     * @param name <code>String</code> name of entity
+     * @throws SAXException when things go wrong
+     */
+    public void skippedEntity(String name)
+        throws SAXException {
+
+        // We don't handle parameter entity references.
+        if (name.startsWith("%")) return; 
+       
+        flushCharacters();
+
+        getCurrentElement().addContent(factory.entityRef(name));
+       
+    }
+
+    /**
+     * <p>
      * This will add the prefix mapping to the JDOM
      *   <code>Document</code> object.
      * </p>
@@ -1067,4 +1091,5 @@
     public Locator getDocumentLocator() {
         return locator;
     }
+   
 }




More information about the jdom-interest mailing list