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

SAXParser allows Schema and the 'schemaLanguage' prop to be set

    Details

    • Subcomponent:
    • Resolved In Build:
      b49
    • CPU:
      generic
    • OS:
      generic

      Description

      Name: inR10064 Date: 04/02/2004




      The
           javax.xml.parsers.SAXParser.setProperty()

      does not throw exception when a Schema object was set for the SAXParser's
      factory and the
           http://java.sun.com/xml/jaxp/properties/schemaSource

      property and/or the
           http://java.sun.com/xml/jaxp/properties/schemaLanguage

      property are set for this SAXParser (please see log and the SetSchema402.java
      source below).

      The spec for the method
           SAXParserFactory.setSchema(Schema)

      requires that the exception is thrown in such configuration :
          "It is an error to use the http://java.sun.com/xml/jaxp/properties/schemaSource
          property and/or the http://java.sun.com/xml/jaxp/properties/schemaLanguage
          property in conjunction with a non-null Schema object."


      The bug affects new tests in JCK 1.5:
        api/javax_xml/parsers/SAXParserFactory/index.html#SetSchema[SetSchema401]
        api/javax_xml/parsers/SAXParserFactory/index.html#SetSchema[SetSchema402]

      The bug is reproducible with the JDK 1.5.0-beta-b45. Similar bug #4967002 was
      reported against DocumentBuilderFactory and the bug is fixed/integrated.

      ------------------------------- SetSchema402.java
      package tests;

      import java.io.StringReader;
      import javax.xml.XMLConstants;
      import javax.xml.parsers.SAXParser;
      import javax.xml.parsers.SAXParserFactory;
      import javax.xml.parsers.ParserConfigurationException;
      import javax.xml.transform.stream.StreamSource;
      import javax.xml.validation.Schema;
      import javax.xml.validation.SchemaFactory;
      import org.xml.sax.InputSource;
      import org.xml.sax.SAXException;

      public class SetSchema402 {

          String schemaSource =
                            "<?xml version='1.0'?>\n"
                            + "<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema&#39;>\n"
                            + " <xsd:element name='test101'>\n"
                            + " <xsd:complexType>\n"
                            + " <xsd:attribute name='attr'/>\n"
                            + " <xsd:attribute name='attr2' default='DEF'/>\n"
                            + " </xsd:complexType>\n"
                            + " </xsd:element>\n"
                            + "</xsd:schema>\n";

          Schema createSchema() {
              SchemaFactory schFactory = SchemaFactory.newInstance(
      XMLConstants.W3C_XML_SCHEMA_NS_URI);
      try {
      Schema sch = schFactory.newSchema(
      new StreamSource(
      new StringReader(schemaSource)
      ));
      return sch;
      } catch (Exception se) {
      throw new IllegalStateException("No Schema : " + se);
      }
          }

          void setAttr(boolean setSrc) {
              Schema sch = createSchema();
              SAXParserFactory spFactory = SAXParserFactory.newInstance();
              spFactory.setNamespaceAware(true);
              spFactory.setValidating(true);
              spFactory.setSchema(sch);

              SAXParser sParser = null;
              try {
                  sParser = spFactory.newSAXParser();
              } catch (Exception pce) {
                  pce.printStackTrace();
                  return;
              }

              final String aSchemaLanguage =
      "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
      final String aSchemaSource = "http://java.sun.com/xml/jaxp/properties/schemaSource";

              try {
                  sParser.setProperty(aSchemaLanguage, "http://www.w3.org/2001/XMLSchema");
      System.out.println("---- Set schemaLanguage: "+
      sParser.getProperty(aSchemaLanguage));
              } catch (SAXException e) {
                  System.out.println("== "+ e);
              }

      if (! setSrc)
      return;

              try {
                 sParser.setProperty(aSchemaSource,
                                          new InputSource(new StringReader(schemaSource)));
      System.out.println("---- Set schemaSource: "+ sParser.getProperty(aSchemaSource));
              } catch (SAXException e) {
                  System.out.println("== "+ e);
              }
          }

          public static void main(String argv[]) {
      SetSchema402 test = new SetSchema402();
      test.setAttr(false);
      test.setAttr(true);
          }

      }

      --------------------------------------------------------------------------
      % java -showversion -cp . tests.SetSchema402
      java version "1.5.0-beta2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b45)
      Java HotSpot(TM) Server VM (build 1.5.0-beta2-b45, mixed mode)

      ---- Set schemaLanguage: http://www.w3.org/2001/XMLSchema
      ---- Set schemaLanguage: http://www.w3.org/2001/XMLSchema
      ---- Set schemaSource: org.xml.sax.InputSource@3901c6

      --------------------------------------------------------------------------

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

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                kkawagucsunw Kohsuke Kawaguchi (Inactive)
                Reporter:
                inevsunw Inev Inev (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: