xml-rpc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject cvs commit: xml-rpc/src/java/org/apache/xmlrpc XmlWriter.java
Date Tue, 20 Aug 2002 16:48:50 GMT
dlr         2002/08/20 09:48:50

  Modified:    src/java/org/apache/xmlrpc XmlWriter.java
  Log:
  writeObject(): Noted new exception thrown.
  
  chardata(): Characters out of range for the XML spec won't be written
  as XML to avoid parse errors on the client side.  Instead, and
  exception will be thrown.  This was originally noted by John Wilson
  <tug@wilson.co.uk>, with this follow up by Adam Megacz
  <adam@megacz.com>:
  
  > Ah, the joys of the self-contradictory XML-RPC spec ;)
  >
  >   "<string> [is an] ASCII string"
  >
  >   "Any characters are allowed in a string except < and &... A string can
  >    be used to encode binary data."
  >
  > Dave absolutely refuses to fix or clarify this.
  
  Revision  Changes    Path
  1.4       +15 -6     xml-rpc/src/java/org/apache/xmlrpc/XmlWriter.java
  
  Index: XmlWriter.java
  ===================================================================
  RCS file: /home/cvs/xml-rpc/src/java/org/apache/xmlrpc/XmlWriter.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -u -r1.3 -r1.4
  --- XmlWriter.java	19 Aug 2002 21:09:16 -0000	1.3
  +++ XmlWriter.java	20 Aug 2002 16:48:49 -0000	1.4
  @@ -146,12 +146,14 @@
        * Writes the XML representation of a supported Java object type.
        *
        * @param obj The <code>Object</code> to write.
  +     * @exception XmlRpcException Unsupported character data found.
        * @exception IOException Problem writing data.
        * @throws IllegalArgumentException If a <code>null</code>
        * parameter is passed to this method (not supported by the <a
        * href="http://xml-rpc.com/spec">XML-RPC specification</a>).
        */
  -    public void writeObject(Object obj) throws IOException
  +    public void writeObject(Object obj)
  +        throws XmlRpcException, IOException
       {
           startElement("value");
           if (obj == null)
  @@ -296,9 +298,11 @@
        * Writes text as <code>PCDATA</code>.
        *
        * @param text The data to write.
  -     * @throws IOException
  +     * @exception XmlRpcException Unsupported character data found.
  +     * @exception IOException Problem writing data.
        */
  -    protected void chardata(String text) throws IOException
  +    protected void chardata(String text)
  +        throws XmlRpcException, IOException
       {
           int l = text.length ();
           for (int i = 0; i < l; i++)
  @@ -323,9 +327,14 @@
               default:
                   if (c < 0x20 || c > 0xff)
                   {
  -                    write("&#");
  -                    write(String.valueOf((int)c));
  -                    write(';');
  +                    // Though the XML-RPC spec allows any ASCII
  +                    // characters except '<' and '&', the XML spec
  +                    // does not allow this range of characters,
  +                    // resulting in a parse error from most XML
  +                    // parsers.
  +                    throw new XmlRpcException(0, "Invalid character data " +
  +                                              "corresponding to XML entity &#" +
  +                                              String.valueOf((int) c) + ';');
                   }
                   else
                   {
  
  
  

Mime
View raw message