mrglavas    2004/05/27 20:31:43

  Modified:    java/src/org/apache/xerces/impl/msg
                        XMLSerializerMessages.properties
               java/src/org/apache/xml/serialize DOMSerializerImpl.java
  Log:
  Fixing Jira Bug #967:

  http://nagoya.apache.org/jira/browse/XERCESJ-967

  

  LSSerializer.writeToString should throw a LSException if a node

  is passed in other than Document, DocumentFragment or Element.

  Null was being returned instead. This is fixed thanks to the patch

  by Jonathan Au, modified so that it also reports the error to a

  registered error-handler.
  
  Revision  Changes    Path
  1.3       +5 -4      
xml-xerces/java/src/org/apache/xerces/impl/msg/XMLSerializerMessages.properties
  
  Index: XMLSerializerMessages.properties
  ===================================================================
  RCS file: 
/home/cvs/xml-xerces/java/src/org/apache/xerces/impl/msg/XMLSerializerMessages.properties,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- XMLSerializerMessages.properties  10 Feb 2004 17:25:27 -0000      1.2
  +++ XMLSerializerMessages.properties  28 May 2004 03:31:43 -0000      1.3
  @@ -24,6 +24,7 @@
       ResourceNotLoaded = The resource ''{0}'' could not be loaded. {1}
       SerializationStopped =  Serialization stopped at user request.
   
  -     #DOM Level 3 load and save messages
  -     no-output-specified = no-output-specified: The output destination for data to 
be written to was null.
  -     unsupported-encoding = unsupported-encoding: An unsupported encoding is 
encountered. 
  +    # DOM Level 3 load and save messages
  +    no-output-specified = no-output-specified: The output destination for data to 
be written to was null.
  +    unsupported-encoding = unsupported-encoding: An unsupported encoding is 
encountered.
  +    unable-to-serialize-node = unable-to-serialize-node: The node could not be 
serialized.
  
  
  
  1.25      +30 -16    
xml-xerces/java/src/org/apache/xml/serialize/DOMSerializerImpl.java
  
  Index: DOMSerializerImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xerces/java/src/org/apache/xml/serialize/DOMSerializerImpl.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- DOMSerializerImpl.java    14 May 2004 19:52:12 -0000      1.24
  +++ DOMSerializerImpl.java    28 May 2004 03:31:43 -0000      1.25
  @@ -449,12 +449,14 @@
        * this document, but that should be useful to a human for debugging or
        * diagnostic purposes.
        * @param wnode  The node to be written.
  -     * @return  Returns the serialized data, or <code>null</code> in case a
  -     *   failure occured and the failure wasn't canceled by the error
  -     *   handler.
  +     * @return  Returns the serialized data
        * @exception DOMException
        *    DOMSTRING_SIZE_ERR: The resulting string is too long to fit in a
        *   <code>DOMString</code>.
  +     * @exception LSException
  +     *    SERIALIZE_ERR: Unable to serialize the node.  DOM applications should
  +     *    attach a <code>DOMErrorHandler</code> using the parameter 
  +     *    &quot;<i>error-handler</i>&quot; to get details on error.
        */
       public String writeToString(Node wnode) throws DOMException, LSException {
           // determine which serializer to use:
  @@ -489,16 +491,28 @@
               prepareForSerialization(ser, wnode);
               ser._format.setEncoding("UTF-16");
               ser.setOutputCharStream(destination);
  -            if (wnode == null)
  -                return null;
  -            else if (wnode.getNodeType() == Node.DOCUMENT_NODE)
  +            if (wnode.getNodeType() == Node.DOCUMENT_NODE) {
                   ser.serialize((Document)wnode);
  -            else if (wnode.getNodeType() == Node.DOCUMENT_FRAGMENT_NODE)
  +            }
  +            else if (wnode.getNodeType() == Node.DOCUMENT_FRAGMENT_NODE) {
                   ser.serialize((DocumentFragment)wnode);
  -            else if (wnode.getNodeType() == Node.ELEMENT_NODE)
  +            }
  +            else if (wnode.getNodeType() == Node.ELEMENT_NODE) {
                   ser.serialize((Element)wnode);
  -            else
  -                return null;
  +            }
  +            else {
  +                String msg = DOMMessageFormatter.formatMessage(
  +                    DOMMessageFormatter.SERIALIZER_DOMAIN, 
  +                    "unable-to-serialize-node", null);
  +                if (ser.fDOMErrorHandler != null) {
  +                    DOMErrorImpl error = new DOMErrorImpl();
  +                    error.fType = "unable-to-serialize-node";
  +                    error.fMessage = msg;
  +                    error.fSeverity = DOMError.SEVERITY_FATAL_ERROR;
  +                    ser.fDOMErrorHandler.handleError(error);
  +                }
  +                throw new LSException(LSException.SERIALIZE_ERR, msg);
  +            }
           } catch (LSException lse) {
               // Rethrow LSException.
               throw lse;
  @@ -714,17 +728,17 @@
               if (writer == null) {
                   if (outputStream == null) {
                       if (uri == null) {
  +                        String msg = DOMMessageFormatter.formatMessage(
  +                            DOMMessageFormatter.SERIALIZER_DOMAIN, 
  +                            "no-output-specified", null);
                           if (ser.fDOMErrorHandler != null) {
                               DOMErrorImpl error = new DOMErrorImpl();
                               error.fType = "no-output-specified";
  -                            error.fMessage = "no-output-specified";
  +                            error.fMessage = msg;
                               error.fSeverity = DOMError.SEVERITY_FATAL_ERROR;
                               ser.fDOMErrorHandler.handleError(error);
                           }
  -                        throw new LSException(LSException.SERIALIZE_ERR, 
  -                            DOMMessageFormatter.formatMessage(
  -                                DOMMessageFormatter.SERIALIZER_DOMAIN, 
  -                                "no-output-specified", null));
  +                        throw new LSException(LSException.SERIALIZE_ERR, msg);
                       }
                       else {
                           // URI was specified. Handle relative URIs.
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to