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

All declarations with the same name are reported

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      1.2.3
    • CPU:
      generic, sparc
    • OS:
      generic, solaris_8

      Description

      Name: dkR10031 Date: 07/31/2002


        
      All attribute and entity declarations with the same name are reported
      during the parsing an xml document (see DeclHandlerTest.java below). But
      descriptions of the corresponding event methods read:

          org.xml.sax.ext.DeclHandler.attributeDecl()
            "Only the effective (first) declaration for an attribute will be reported."

          org.xml.sax.ext.DeclHandler.internalEntityDecl()
          org.xml.sax.ext.DeclHandler.externalEntityDecl()
            "Only the effective (first) declaration for each entity will be reported."

      This issue is found in jaxp-1.2.0-fcs-b21 with help of the new JCK 1.4a
      tests:
      api/org_xml/sax/ext/DeclHandler/index.html#Decl[Decl113],
      api/org_xml/sax/ext/DeclHandler/index.html#EntityDecl[EntityDecl006],
      api/org_xml/sax/ext/DeclHandler/index.html#EntityDecl[EntityDecl104].


      ------------------- DeclHandlerTest.java ----------------------------------
      import java.io.IOException;
      import java.io.ByteArrayInputStream;
      import java.io.StringReader;

      import org.xml.sax.ext.DeclHandler;
      import org.xml.sax.InputSource;
      import org.xml.sax.SAXException;
      import org.xml.sax.SAXNotRecognizedException;
      import org.xml.sax.SAXNotSupportedException;
      import org.xml.sax.XMLReader;

      import javax.xml.parsers.ParserConfigurationException;
      import javax.xml.parsers.SAXParserFactory;


      class StubHl implements DeclHandler {
              public void elementDecl(String name, String model) throws SAXException {
      System.out.println("Element Declaration "+name+"\t"+model);
              }
              public void attributeDecl(String eName, String aName, String type, String valueDefault, String value) throws SAXException {
                  System.out.println("Attribute Declaration: Element Name is "+eName+
      "\tAttribute name is "+aName+"\tType is "+type+
      "\tValue Default is "+valueDefault+"\t Value is "+value);
              }
              public void internalEntityDecl(String name, String value) throws SAXException {
      System.out.println("Internal Entity Declaration Name is "+name+"\t Value is "+value);
              }
              public void externalEntityDecl(String name, String publicId, String systemId) throws SAXException{
      System.out.println("External Entity Declaration Name is "+name+
      "\t PublicId is "+publicId+"\t SystemId is "+systemId);
              }
      }


      class XMLParser {
          protected XMLReader parser;

          public XMLParser(boolean valFlag) throws SAXException, ParserConfigurationException {
              SAXParserFactory sfact = SAXParserFactory.newInstance();
              sfact.setValidating(valFlag);
              parser = sfact.newSAXParser().getXMLReader();
          }

          public void setProperty(String property, Object obj) throws SAXNotRecognizedException, SAXNotSupportedException {
              if (parser != null) {
                  parser.setProperty(property, obj);
              }
          }

          public void parse(String[] xmlData) throws IOException, SAXException {
              StringBuffer sb = new StringBuffer();

              for (int i = 0; i < xmlData.length; i++) {
                  sb.append(xmlData[i]).append("\n");
              }
              this.parseXMLString(sb.toString());
          }

          public void parseXMLString(String xmlData) throws IOException, SAXException {
              StringReader in = new StringReader(xmlData);

              if (parser != null) {
                  parser.parse(new InputSource(in));
              }
          }
      }


      public class DeclHandlerTest {
          public static void main(String argv[]) {
      String[] xmlDoc = {"<?xml version=\"1.0\" ?>",
                      "<!DOCTYPE root [",
                                      "ELEMENT root ANY",
                                      "ELEMENT root EMPTY",
              "ENTITY inEntity 'internal' ",
                      "ENTITY inEntity 'throwEx' ",
                              "ENTITY exEntity PUBLIC 'internal' 'http://www.nsu.ru/lalala&#39;",
                                      "ENTITY exEntity PUBLIC 'throwEx' 'http://www.nsu.ru/lalala&#39;",
                                      "ATTLIST root name CDATA 'first default value'",
                                      "ATTLIST root name CDATA 'second default value'",
      "]>",
      "<root>", "data and 5 whitespaces etc",
               "</root>" };

      try {
      XMLParser parser = new XMLParser(false);
                      StubHl handler = new StubHl();
      parser.setProperty("http://xml.org/sax/properties/declaration-handler", handler);
      parser.parse(xmlDoc);
      } catch (org.xml.sax.SAXException saxEx) {
                  System.out.println("SAXException: "+saxEx.getMessage());
      } catch (java.io.IOException ioEx) {
                  System.out.println("IO Exception: "+ioEx.getMessage());
      } catch (javax.xml.parsers.ParserConfigurationException pceEx){
                  System.out.println("Parser Configuration Exception: "+pceEx.getMessage());
              }
          }
      }
      ------------------ test run result -----------------------------
       % java DeclHandlerTest
      Element Declaration root ANY
      Element Declaration root EMPTY
      Internal Entity Declaration Name is inEntity Value is internal
      Internal Entity Declaration Name is inEntity Value is throwEx
      External Entity Declaration Name is exEntity PublicId is internal SystemId is http://www.nsu.ru/lalala
      External Entity Declaration Name is exEntity PublicId is throwEx SystemId is http://www.nsu.ru/lalala
      Attribute Declaration: Element Name is root Attribute name is name Type is CDATA Value Default is null Value is first default value
      Attribute Declaration: Element Name is root Attribute name is name Type is CDATA Value Default is null Value is second default value".

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


      ###@###.### 2003-04-14

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              nbajajsunw Neeraj Bajaj (Inactive)
              Reporter:
              dimasunw Dima Dima (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: