You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xmlrpc-dev@ws.apache.org by dl...@apache.org on 2005/05/02 05:58:46 UTC
cvs commit: ws-xmlrpc/src/java/org/apache/xmlrpc XmlWriter.java
dlr 2005/05/01 20:58:46
Modified: src/java/org/apache/xmlrpc Tag: XMLRPC_1_2_BRANCH
XmlWriter.java
Log:
* src/java/org/apache/xmlrpc/XmlWriter.java
(chardata): Removed exception thrown when characters outside
of the valid range for XML are encountered. Instead, pass these
characters along (valid for XML-RPC), either entity-encoding them
as &#xxx; if less than 0x20, or literally if greater than 0x7f.
This doesn't appear to cause complaints from the XML parsers used
in SourceCast, likely because the XML specification demands that
parsers support UTF-8 and UTF-16. This is a revision to the change
made in CVS rev 1.4 of XmlWriter.java.
Target release: 1.2
Branch: XMLRPC_1_2
Reviewed by: Jochen Wiedmann
Revision Changes Path
No revision
No revision
1.6.2.1 +32 -5 ws-xmlrpc/src/java/org/apache/xmlrpc/XmlWriter.java
Index: XmlWriter.java
===================================================================
RCS file: /home/cvs/ws-xmlrpc/src/java/org/apache/xmlrpc/XmlWriter.java,v
retrieving revision 1.6
retrieving revision 1.6.2.1
diff -u -u -r1.6 -r1.6.2.1
--- XmlWriter.java 21 Nov 2002 21:57:39 -0000 1.6
+++ XmlWriter.java 2 May 2005 03:58:46 -0000 1.6.2.1
@@ -312,6 +312,11 @@
throws XmlRpcException, IOException
{
int l = text.length ();
+ String enc = super.getEncoding();
+ boolean isUnicode = UTF8.equals(enc) || "UTF-16".equals(enc);
+ // ### TODO: Use a buffer rather than going character by
+ // ### character to scale better for large text sizes.
+ //char[] buf = new char[32];
for (int i = 0; i < l; i++)
{
char c = text.charAt (i);
@@ -332,16 +337,38 @@
write(AMPERSAND_ENTITY);
break;
default:
- if (c < 0x20 || c > 0xff)
+ if (c < 0x20 || c > 0x7f)
{
// 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) + ';');
+ // parsers. However, the XML spec does require
+ // XML parsers to support UTF-8 and UTF-16.
+ if (isUnicode)
+ {
+ if (c < 0x20)
+ {
+ // Entity escape the character.
+ write("&#");
+ // ### Do we really need the String conversion?
+ write(String.valueOf((int) c));
+ write(';');
+ }
+ else // c > 0x7f
+ {
+ // Write the character in our encoding.
+ write(new String(String.valueOf(c).getBytes(enc)));
+ }
+ }
+ else
+ {
+ throw new XmlRpcException(0, "Invalid character data "
+ + "corresponding to XML "
+ + "entity &#"
+ + String.valueOf((int) c)
+ + ';');
+ }
}
else
{