Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4681389

externalEntityDecl() is called twice for external entity declaration

XMLWordPrintable



      Name: viR10068 Date: 05/07/2002



      The api doc for the interface DeclHandler the method
      public void externalEntityDecl(String name, String publicId, String systemId)
                              throws SAXException
      says:
      "Only the effective (first) declaration for each entity will be reported."

      But the xerces in JAXP 1.2 build b18 reports both entity declaration.
      Note, the crimson in JDK 1.4.1 reports only one.

      See the log below for details:

      % cat xml_ex2.xml
      <?xml version="1.0" ?>
      <!DOCTYPE root [
         <!ENTITY comment SYSTEM 'comment.txt'>
         <!ENTITY comment SYSTEM 'comment.txt'>
      ]>
      <root>data</root>

      % cat xml_ex.java
      import java.io.PrintStream;
      import java.io.File;
      import javax.xml.parsers.SAXParserFactory;
      import javax.xml.parsers.SAXParser;
      import org.xml.sax.helpers.DefaultHandler;
      import org.xml.sax.SAXException;
      import org.xml.sax.ext.DeclHandler;

      class StubHl implements DeclHandler {
          public void externalEntityDecl(String name, String publicId, String systemId) throws
      SAXException {
              System.out.println("externalEntityDecl: name is " + name);
              System.out.println("externalEntityDecl: publicId is " + publicId);
              System.out.println("externalEntityDecl: systemId is " + systemId);
          }
          public void attributeDecl(String eName, String aName, String type, String
      valueDefault, String value) throws SAXException {
          }
          public void elementDecl(String name, String model) throws SAXException {
          }
          public void internalEntityDecl(String name, String value) throws SAXException{
          }
          public void setIntEntDeclHook(String name, String value){
          }
      }

      public class xml_ex {

          public static void main(String [] args) {
              try {
                  // create and initialize the parser
                  SAXParserFactory spf = SAXParserFactory.newInstance();
                  spf.setNamespaceAware(true);
                  spf.setValidating(true);
                  SAXParser parser = spf.newSAXParser();

                  StubHl handler = new StubHl();
                  parser.setProperty("http://xml.org/sax/properties/declaration-handler",
      handler);

                  File xmlFile = new File(args[0]);
                  parser.parse(xmlFile, new DefaultHandler());
                  System.out.println("Passed.");
              } catch (Exception e) {
                  e.printStackTrace();
                  System.out.println("Failed.");
              }
          }
      }
       

      %echo $CLASSPATH && /export/ld25/java/dest/jdk1.3.1/solsparc/bin/java -showversion xml_ex
      xml_ex2.xml
      /export/ld25/java/dest/JAXP/jaxp-1.2.0-fcs-b18-24_apr_2002/xalan.jar:.:/export/ld25/java/d
      est/JAXP/jaxp-1.2.0-fcs-b18-24_apr_2002/jaxp-api.jar:/export/ld25/java/dest/JAXP/jaxp-1.2.
      0-fcs-b18-24_apr_2002/xercesImpl.jar:/export/ld25/java/dest/JAXP/jaxp-1.2.0-fcs-b18-24_apr
      _2002/sax.jar:
      java version "1.3.1"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
      Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)

      externalEntityDecl: name is comment
      externalEntityDecl: publicId is null
      externalEntityDecl: systemId is comment.txt
      externalEntityDecl: name is comment
      externalEntityDecl: publicId is null
      externalEntityDecl: systemId is comment.txt
      Passed.
      %

      ======================================================================

            nbajajsunw Neeraj Bajaj (Inactive)
            vivsunw Viv Viv (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: