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

Method DOMSerializer.write() raise an error without error type as specified in A

XMLWordPrintable

    • rc
    • sparc
    • solaris_2.6

      Name: apR10229 Date: 10/09/2003


      Filed By : SPB JCK team (###@###.###)
      JDK : java full version "1.5.0-beta-b22"
      JCK : 1.5
      Platform[s] : Linux
      switch/Mode :
      JCK test owner : http://javaweb.eng/jct/sqe/JCK-tck/usr/owners.jto
      Failing Test [s] : N/A


      Specification excerpt:
      ======================
      --------- J2SE API spec v.1.5 ---------
      ...
      public interface DOMSerializer
      ...
       While serializing, errors are reported to the application through the error handler (DOMSerializer.config's " error-handler" parameter). This specification does in no way try to define all possible errors that can occur while serializing a DOM node, but some common error cases are defined. The types (DOMError.type) of errors and warnings defined by this specification are:
      ...
       "no-output-specified" [fatal]
      Raised when writing to a DOMOutput if no output is specified in the DOMOutput.
      .........................

      public boolean write(Node node,
                           DOMOutput destination)
      ...
       If no output is specified in the DOMOutput, a "no-output-specified" error is raised.
      ...
      ---------- end-of-excerpt ---------------

      Problem description
      ===================
      API method org.w3c.dom.ls.DOMSerializer.write() raise an error when no output
      specified in the given DOMOutput, but it is unable to determine what kind of error is it.
      In other words, DOMError, received by DOMErrorHandler implementation has getType() method,
      that simply returns null. But API Doc says, that getType() method of DOMError should
      contain an explicit error name (i.e. "no-output-specified").

      Minimized test:
      ===============
      ------- Test.java -------
      import java.io.*;
      import org.w3c.dom.ls.*;
      import org.w3c.dom.*;
      import javax.xml.parsers.*;

      public class Test {
          public static void main(String[] argv) {
              Document doc = null;
              try {
                  DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
                  doc = parser.parse(new StringBufferInputStream("<ROOT><CHILD/></ROOT>"));
              } catch (Throwable e) {
                  e.printStackTrace();
              }
              DOMImplementation impl = doc.getImplementation();
              DOMImplementationLS implLS = (DOMImplementationLS) impl.getFeature("LS","3.0");
              LSSerializer writer = implLS.createLSSerializer();
              DOMErrorHandlerImpl eh = new DOMErrorHandlerImpl();
              writer.getDomConfig().setParameter("error-handler",eh);

              if (writer.write(doc,new Output())) {
                  System.out.println("FAILED: Expected result value - false");
              }
              if (!eh.NoOutputSpecifiedErrorReceived) {
                  System.out.println("FAILED: 'no-output-specified' error was expected ");
              }
          }
      }

      class DOMErrorHandlerImpl implements DOMErrorHandler {
          boolean NoOutputSpecifiedErrorReceived = false;
          public boolean handleError(DOMError error) {
              if ("no-output-specified".equalsIgnoreCase(error.getType())) {
                  NoOutputSpecifiedErrorReceived = true;
              } else {
                  System.out.println("RECEIVED ERROR TYPE: "+error.getType());
              }
              return true;
          }
      }

      class Output implements LSOutput {
          public OutputStream getByteStream() {
              return null;
          }
          public void setByteStream(OutputStream byteStream) {}
          public Writer getCharacterStream() {
              return null;
          }
          public void setCharacterStream(Writer characterStream) {}
          public String getSystemId() {
              return null;
          }
          public void setSystemId(String systemId) {}
          public String getEncoding() {
              return "UTF8";
          }
          public void setEncoding(String encoding) {}
      }
      ------- end-of-Test.java -------

      Minimized test output:
      ======================
      <pav@hammer(pts/11).270> java Test
      RECEIVER ERROR TYPE: null
      FAILED: 'no-output-specified' error was expected

      JCK test source location:
      ==========================
      /java/re/jck/1.5/promoted/latest/JCK-runtime-15/tests

      Specific Machine Info:
      =====================
      Linux hammer 2.4.21 #1 Wed Jun 25 20:18:22 MSD 2003 i686 unknown

      ======================================================================
      ###@###.### 2004-09-01

            jsuttorsunw Jeff Suttor (Inactive)
            pavsunw Pav Pav (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: