You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xmlbeans-cvs@xml.apache.org by da...@apache.org on 2003/10/06 23:08:39 UTC
cvs commit: xml-xmlbeans/v2/src/xmlinputstream/weblogic/utils NestedThrowable.java
davidbau 2003/10/06 14:08:39
Modified: v1/external/lib oldxbean.jar
v1/src/common/org/apache/xmlbeans/impl/common
QNameHelper.java SniffedXmlInputStream.java
XMLNameHelper.java
v1/src/typeimpl/org/apache/xmlbeans/impl/values
JavaBase64Holder.java JavaHexBinaryHolder.java
v1/src/xmlinputstream/weblogic/utils NestedThrowable.java
v2/external/lib oldxbean.jar
v2/src/common/org/apache/xmlbeans/impl/common
QNameHelper.java SniffedXmlInputStream.java
XMLNameHelper.java
v2/src/typeimpl/org/apache/xmlbeans/impl/values
JavaBase64Holder.java JavaHexBinaryHolder.java
v2/src/xmlinputstream/weblogic/utils NestedThrowable.java
Log:
Patch submitted by Lawrence Jones.
This change eliminates all the calls to string.getBytes() in XBeans code
in favor of string.getBytes("UTF-8"), so that we work correctly in I18Ned
environemnts.
In particular, if you had an app that was built on a machine whose system
default encoding was, e.g., Shift-JIS, and you tried to run it on a system
with a different default encoding, e.g., MS-932, then you could run into
problems when trying to compute an .xsb filename.
DRT: passed
Code review: David Bau, Lawrence Jones
Revision Changes Path
1.3 +2198 -2385xml-xmlbeans/v1/external/lib/oldxbean.jar
<<Binary file>>
1.3 +66 -46 xml-xmlbeans/v1/src/common/org/apache/xmlbeans/impl/common/QNameHelper.java
Index: QNameHelper.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v1/src/common/org/apache/xmlbeans/impl/common/QNameHelper.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- QNameHelper.java 24 Sep 2003 23:31:05 -0000 1.2
+++ QNameHelper.java 6 Oct 2003 21:08:39 -0000 1.3
@@ -2,7 +2,7 @@
* The Apache Software License, Version 1.1
*
*
-* Copyright (c) 2003 The Apache Software Foundation. All rights
+* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -10,7 +10,7 @@
* are met:
*
* 1. Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
+* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
@@ -18,19 +18,19 @@
* distribution.
*
* 3. The end-user documentation included with the redistribution,
-* if any, must include the following acknowledgment:
+* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
-* 4. The names "Apache" and "Apache Software Foundation" must
+* 4. The names "Apache" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
-* software without prior written permission. For written
+* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
-* 5. Products derived from this software may not be called "Apache
-* XMLBeans", nor may "Apache" appear in their name, without prior
+* 5. Products derived from this software may not be called "Apache
+* XMLBeans", nor may "Apache" appear in their name, without prior
* written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
@@ -49,7 +49,7 @@
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
-* originally based on software copyright (c) 2000-2003 BEA Systems
+* originally based on software copyright (c) 2000-2003 BEA Systems
* Inc., <http://www.bea.com/>. For more information on the Apache Software
* Foundation, please see <http://www.apache.org/>.
*/
@@ -64,6 +64,7 @@
import java.util.Map;
import java.util.HashMap;
import java.util.Collections;
+import java.io.UnsupportedEncodingException;
import org.apache.xmlbeans.SchemaType;
import org.apache.xmlbeans.SchemaField;
@@ -76,10 +77,10 @@
{
if (qname == null)
return null;
-
+
return XMLNameHelper.forLNS( qname.getLocalPart(), qname.getNamespaceURI() );
}
-
+
public static QName forLNS(String localname, String uri)
{
if (uri == null)
@@ -107,7 +108,7 @@
if (name.getNamespaceURI() == null || name.getNamespaceURI().length() == 0)
return name.getLocalPart();
-
+
return name.getLocalPart() + "@" + name.getNamespaceURI();
}
@@ -142,9 +143,9 @@
//
// The reason for the "shortening" is to avoid filenames longer than about
// 256 characters, which are prohibited on Windows NT.
-
+
public static final int MAX_NAME_LENGTH = 64;
-
+
public static String hexsafe(String s)
{
StringBuffer result = new StringBuffer();
@@ -157,25 +158,44 @@
}
else
{
- byte[] utf8 = s.substring(i, i + 1).getBytes();
- for (int j = 0; j < utf8.length; j++)
+ byte[] utf8 = null;
+ try
{
- result.append('_');
- result.append(hexdigits[(utf8[j] >> 4) & 0xF]);
- result.append(hexdigits[utf8[j] & 0xF]);
+ utf8 = s.substring(i, i + 1).getBytes("UTF-8");
+ for (int j = 0; j < utf8.length; j++)
+ {
+ result.append('_');
+ result.append(hexdigits[(utf8[j] >> 4) & 0xF]);
+ result.append(hexdigits[utf8[j] & 0xF]);
+ }
+ }
+ catch(UnsupportedEncodingException uee)
+ {
+ // should never happen - UTF-8 i always supported
+ result.append("_BAD_UTF8_CHAR");
}
}
}
-
+
// short enough? Done!
if (result.length() <= MAX_NAME_LENGTH)
return result.toString();
-
+
// too long? use SHA1
try
{
MessageDigest md = MessageDigest.getInstance("SHA");
- byte[] digest = md.digest(s.getBytes());
+ byte[] inputBytes = null;
+ try
+ {
+ inputBytes = s.getBytes("UTF-8");
+ }
+ catch(UnsupportedEncodingException uee)
+ {
+ // should never happen - UTF-8 is always supported
+ inputBytes = new byte[0];
+ }
+ byte[] digest = md.digest(inputBytes);
assert(digest.length == 20); // SHA1 160 bits == 20 bytes
result = new StringBuffer("URI_SHA_1_");
for (int j = 0; j < digest.length; j++)
@@ -221,25 +241,25 @@
{
return readable(sType.getName(), nsPrefix);
}
-
+
if (sType.isAttributeType())
{
return "attribute type " + readable(sType.getAttributeTypeAttributeName(), nsPrefix);
}
-
+
if (sType.isDocumentType())
{
return "document type " + readable(sType.getDocumentElementName(), nsPrefix);
}
-
+
if (sType.isNoType() || sType.getOuterType() == null)
{
return "invalid type";
}
-
+
SchemaType outerType = sType.getOuterType();
SchemaField container = sType.getContainerField();
-
+
if (outerType.isAttributeType())
{
return "type of attribute " + readable(container.getName(), nsPrefix);
@@ -248,7 +268,7 @@
{
return "type of element " + readable(container.getName(), nsPrefix);
}
-
+
if (container != null)
{
if (container.isAttribute())
@@ -260,7 +280,7 @@
return "type of " + container.getName().getLocalPart() + " element in " + readable(outerType, nsPrefix);
}
}
-
+
if (outerType.getBaseType() == sType)
return "base type of " + readable(outerType, nsPrefix);
else if (outerType.getSimpleVariety() == SchemaType.LIST)
@@ -268,9 +288,9 @@
else if (outerType.getSimpleVariety() == SchemaType.UNION)
return "member type " + sType.getAnonymousUnionMemberOrdinal() + " of " + readable(outerType, nsPrefix);
else
- return "inner type in " + readable(outerType, nsPrefix);
+ return "inner type in " + readable(outerType, nsPrefix);
}
-
+
public static String readable(QName name)
{
return readable(name, WELL_KNOWN_PREFIXES);
@@ -285,13 +305,13 @@
return prefix + ":" + name.getLocalPart();
return name.getLocalPart() + " in namespace " + name.getNamespaceURI();
}
-
+
public static String suggestPrefix(String namespace)
{
String result = (String)WELL_KNOWN_PREFIXES.get(namespace);
if (result != null)
return result;
-
+
int len = namespace.length();
int i = namespace.lastIndexOf('/');
if (i > 0 && i == namespace.length() - 1)
@@ -299,21 +319,21 @@
len = i;
i = namespace.lastIndexOf('/', i - 1);
}
-
+
i += 1; // skip '/', also covers -1 case.
-
+
if (namespace.startsWith("www.", i))
{
i += 4; // "www.".length()
}
-
+
while (i < len)
{
if (XMLChar.isNCNameStart(namespace.charAt(i)))
break;
i += 1;
}
-
+
for (int end = i + 1; end < len; end += 1)
{
if (!XMLChar.isNCName(namespace.charAt(end)) || !Character.isLetterOrDigit(namespace.charAt(end)))
@@ -322,7 +342,7 @@
break;
}
}
-
+
// prefixes starting with "xml" are forbidden, so change "xmls" -> "xs"
if (namespace.length() >= i + 3 && startsWithXml(namespace, i))
{
@@ -330,7 +350,7 @@
return "x" + Character.toLowerCase(namespace.charAt(i + 3));
return "ns";
}
-
+
if (len - i > 4) // four or less? leave it.
{
if (isVowel(namespace.charAt(i + 2)) && !isVowel(namespace.charAt(i + 3)))
@@ -338,30 +358,30 @@
else
len = i + 3; // more than four? truncate to 3.
}
-
+
int n;
-
+
if (len - i == 0)
return "ns";
-
+
return namespace.substring(i, len).toLowerCase();
}
-
+
private static boolean startsWithXml(String s, int i)
{
if (s.length() < i + 3)
return false;
-
+
if (s.charAt(i) != 'X' && s.charAt(i) != 'x')
return false;
if (s.charAt(i + 1) != 'M' && s.charAt(i + 1) != 'm')
return false;
if (s.charAt(i + 2) != 'L' && s.charAt(i + 2) != 'l')
return false;
-
+
return true;
}
-
+
private static boolean isVowel(char ch)
{
switch (ch)
@@ -381,7 +401,7 @@
return false;
}
}
-
+
public static String namespace(SchemaType sType)
{
while (sType != null)
1.3 +10 -4 xml-xmlbeans/v1/src/common/org/apache/xmlbeans/impl/common/SniffedXmlInputStream.java
Index: SniffedXmlInputStream.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v1/src/common/org/apache/xmlbeans/impl/common/SniffedXmlInputStream.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SniffedXmlInputStream.java 24 Sep 2003 23:31:05 -0000 1.2
+++ SniffedXmlInputStream.java 6 Oct 2003 21:08:39 -0000 1.3
@@ -227,7 +227,7 @@
/* package */ static String extractXmlDeclEncoding(char[] buf, int offset, int size)
{
int limit = offset + size;
- int xmlpi = firstIndexOfAscii("<?xml", buf, offset, limit);
+ int xmlpi = firstIndexOf("<?xml", buf, offset, limit);
if (xmlpi >= 0)
{
int i = xmlpi + 5;
@@ -244,21 +244,27 @@
return null;
}
- private static int firstIndexOfAscii(String s, char[] buf, int startAt, int limit)
+ private static int firstIndexOf(String s, char[] buf, int startAt, int limit)
{
assert(s.length() > 0);
- byte[] lookFor = s.getBytes();
- int firstchar = lookFor[0];
+ char[] lookFor = s.toCharArray();
+
+ char firstchar = lookFor[0];
searching: for (limit -= lookFor.length; startAt < limit; startAt++)
{
if (buf[startAt] == firstchar)
{
for (int i = 1; i < lookFor.length; i++)
+ {
if (buf[startAt + i] != lookFor[i])
+ {
continue searching;
+ }
+ }
return startAt;
}
}
+
return -1;
}
1.3 +26 -16 xml-xmlbeans/v1/src/common/org/apache/xmlbeans/impl/common/XMLNameHelper.java
Index: XMLNameHelper.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v1/src/common/org/apache/xmlbeans/impl/common/XMLNameHelper.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- XMLNameHelper.java 24 Sep 2003 23:31:05 -0000 1.2
+++ XMLNameHelper.java 6 Oct 2003 21:08:39 -0000 1.3
@@ -2,7 +2,7 @@
* The Apache Software License, Version 1.1
*
*
-* Copyright (c) 2003 The Apache Software Foundation. All rights
+* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -10,7 +10,7 @@
* are met:
*
* 1. Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
+* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
@@ -18,19 +18,19 @@
* distribution.
*
* 3. The end-user documentation included with the redistribution,
-* if any, must include the following acknowledgment:
+* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
-* 4. The names "Apache" and "Apache Software Foundation" must
+* 4. The names "Apache" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
-* software without prior written permission. For written
+* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
-* 5. Products derived from this software may not be called "Apache
-* XMLBeans", nor may "Apache" appear in their name, without prior
+* 5. Products derived from this software may not be called "Apache
+* XMLBeans", nor may "Apache" appear in their name, without prior
* written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
@@ -49,7 +49,7 @@
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
-* originally based on software copyright (c) 2000-2003 BEA Systems
+* originally based on software copyright (c) 2000-2003 BEA Systems
* Inc., <http://www.bea.com/>. For more information on the Apache Software
* Foundation, please see <http://www.apache.org/>.
*/
@@ -58,6 +58,7 @@
import weblogic.xml.stream.XMLName;
import javax.xml.namespace.QName;
+import java.io.UnsupportedEncodingException;
public class XMLNameHelper
{
@@ -65,10 +66,10 @@
{
if (xmlName == null)
return null;
-
+
return QNameHelper.forLNS( xmlName.getLocalName(), xmlName.getNamespaceUri() );
}
-
+
public static XMLName forLNS(String localname, String uri)
{
if (uri == null)
@@ -96,7 +97,7 @@
if (name.getNamespaceUri() == null || name.getNamespaceUri().length() == 0)
return name.getLocalName();
-
+
return name.getLocalName() + "@" + name.getNamespaceUri();
}
@@ -126,12 +127,21 @@
}
else
{
- byte[] utf8 = s.substring(i, i + 1).getBytes();
- for (int j = 0; j < utf8.length; j++)
+ byte[] utf8 = null;
+ try
+ {
+ utf8 = s.substring(i, i + 1).getBytes("UTF-8");
+ for (int j = 0; j < utf8.length; j++)
+ {
+ result.append('_');
+ result.append(hexdigits[(utf8[j] >> 4) & 0xF]);
+ result.append(hexdigits[utf8[j] & 0xF]);
+ }
+ }
+ catch(UnsupportedEncodingException uee)
{
- result.append('_');
- result.append(hexdigits[(utf8[j] >> 4) & 0xF]);
- result.append(hexdigits[utf8[j] & 0xF]);
+ // should never happen - UTF-8 is always supported
+ result.append("_BAD_UTF8_CHAR");
}
}
}
1.3 +11 -1 xml-xmlbeans/v1/src/typeimpl/org/apache/xmlbeans/impl/values/JavaBase64Holder.java
Index: JavaBase64Holder.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v1/src/typeimpl/org/apache/xmlbeans/impl/values/JavaBase64Holder.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- JavaBase64Holder.java 24 Sep 2003 23:31:08 -0000 1.2
+++ JavaBase64Holder.java 6 Oct 2003 21:08:39 -0000 1.3
@@ -68,6 +68,7 @@
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
+import java.io.UnsupportedEncodingException;
public abstract class JavaBase64Holder extends XmlObjectBase
{
@@ -99,7 +100,16 @@
public static byte[] lex(String v, ValidationContext c)
{
- final byte[] bytes = Base64.decode(v.getBytes());
+ byte[] vBytes = null;
+ try
+ {
+ vBytes = v.getBytes("UTF-8");
+ }
+ catch(UnsupportedEncodingException uee)
+ {
+ // should never happen - UTF-8 is always supported
+ }
+ final byte[] bytes = Base64.decode(vBytes);
if (bytes == null)
{
1.3 +11 -1 xml-xmlbeans/v1/src/typeimpl/org/apache/xmlbeans/impl/values/JavaHexBinaryHolder.java
Index: JavaHexBinaryHolder.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v1/src/typeimpl/org/apache/xmlbeans/impl/values/JavaHexBinaryHolder.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- JavaHexBinaryHolder.java 24 Sep 2003 23:31:08 -0000 1.2
+++ JavaHexBinaryHolder.java 6 Oct 2003 21:08:39 -0000 1.3
@@ -68,6 +68,7 @@
import java.security.NoSuchAlgorithmException;
import java.security.MessageDigest;
import java.util.Arrays;
+import java.io.UnsupportedEncodingException;
public abstract class JavaHexBinaryHolder extends XmlObjectBase
{
@@ -99,7 +100,16 @@
public static byte[] lex(String v, ValidationContext context)
{
- byte[] bytes = HexBin.decode(v.getBytes());
+ byte[] vBytes = null;
+ try
+ {
+ vBytes = v.getBytes("UTF-8");
+ }
+ catch(UnsupportedEncodingException uee)
+ {
+ // should never happen - UTF-8 is always supported
+ }
+ byte[] bytes = HexBin.decode(vBytes);
if (bytes == null)
{
1.3 +13 -13 xml-xmlbeans/v1/src/xmlinputstream/weblogic/utils/NestedThrowable.java
Index: NestedThrowable.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v1/src/xmlinputstream/weblogic/utils/NestedThrowable.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- NestedThrowable.java 24 Sep 2003 23:31:12 -0000 1.2
+++ NestedThrowable.java 6 Oct 2003 21:08:39 -0000 1.3
@@ -2,7 +2,7 @@
* The Apache Software License, Version 1.1
*
*
-* Copyright (c) 2003 The Apache Software Foundation. All rights
+* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -10,7 +10,7 @@
* are met:
*
* 1. Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
+* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
@@ -18,19 +18,19 @@
* distribution.
*
* 3. The end-user documentation included with the redistribution,
-* if any, must include the following acknowledgment:
+* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
-* 4. The names "Apache" and "Apache Software Foundation" must
+* 4. The names "Apache" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
-* software without prior written permission. For written
+* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
-* 5. Products derived from this software may not be called "Apache
-* XMLBeans", nor may "Apache" appear in their name, without prior
+* 5. Products derived from this software may not be called "Apache
+* XMLBeans", nor may "Apache" appear in their name, without prior
* written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
@@ -49,7 +49,7 @@
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
-* originally based on software copyright (c) 2000-2003 BEA Systems
+* originally based on software copyright (c) 2000-2003 BEA Systems
* Inc., <http://www.bea.com/>. For more information on the Apache Software
* Foundation, please see <http://www.apache.org/>.
*/
@@ -63,7 +63,7 @@
*
* @deprecated use JDK 1.4 style nested throwables where possible.
*
- * @author Copyright (c) 1997 by WebLogic, Inc. All Rights Reserved.
+ * @author WebLogic
*/
import java.io.PrintWriter;
@@ -98,7 +98,7 @@
if (nested == null) {
return nt.superToString();
} else {
- return nt.superToString() + " - with nested exception:" +
+ return nt.superToString() + " - with nested exception:" +
EOL + "[" + nestedToString(nested) + "]";
}
}
@@ -106,7 +106,7 @@
private static String nestedToString(Throwable nested) {
if (nested instanceof InvocationTargetException) {
InvocationTargetException ite = (InvocationTargetException) nested;
- return nested.toString() + " - with target exception:" +
+ return nested.toString() + " - with target exception:" +
EOL + "[" + ite.getTargetException().toString() +
"]";
}
@@ -119,7 +119,7 @@
*
* @param s PrintStream
*/
- public static void printStackTrace(NestedThrowable nt, PrintStream s) {
+ public static void printStackTrace(NestedThrowable nt, PrintStream s) {
Throwable nested = nt.getNested();
if (nested != null) {
nested.printStackTrace(s);
@@ -134,7 +134,7 @@
*
* @param w PrintWriter
*/
- public static void printStackTrace(NestedThrowable nt, PrintWriter w) {
+ public static void printStackTrace(NestedThrowable nt, PrintWriter w) {
Throwable nested = nt.getNested();
if (nested != null) {
nested.printStackTrace(w);
1.2 +2539 -2385xml-xmlbeans/v2/external/lib/oldxbean.jar
<<Binary file>>
1.2 +22 -2 xml-xmlbeans/v2/src/common/org/apache/xmlbeans/impl/common/QNameHelper.java
Index: QNameHelper.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/common/org/apache/xmlbeans/impl/common/QNameHelper.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- QNameHelper.java 26 Sep 2003 21:23:26 -0000 1.1
+++ QNameHelper.java 6 Oct 2003 21:08:39 -0000 1.2
@@ -64,6 +64,7 @@
import java.util.Map;
import java.util.HashMap;
import java.util.Collections;
+import java.io.UnsupportedEncodingException;
import org.apache.xmlbeans.SchemaType;
import org.apache.xmlbeans.SchemaField;
@@ -157,7 +158,10 @@
}
else
{
- byte[] utf8 = s.substring(i, i + 1).getBytes();
+ byte[] utf8 = null;
+ try
+ {
+ utf8 = s.substring(i, i + 1).getBytes("UTF-8");
for (int j = 0; j < utf8.length; j++)
{
result.append('_');
@@ -165,6 +169,12 @@
result.append(hexdigits[utf8[j] & 0xF]);
}
}
+ catch(UnsupportedEncodingException uee)
+ {
+ // should never happen - UTF-8 i always supported
+ result.append("_BAD_UTF8_CHAR");
+ }
+ }
}
// short enough? Done!
@@ -175,7 +185,17 @@
try
{
MessageDigest md = MessageDigest.getInstance("SHA");
- byte[] digest = md.digest(s.getBytes());
+ byte[] inputBytes = null;
+ try
+ {
+ inputBytes = s.getBytes("UTF-8");
+ }
+ catch(UnsupportedEncodingException uee)
+ {
+ // should never happen - UTF-8 is always supported
+ inputBytes = new byte[0];
+ }
+ byte[] digest = md.digest(inputBytes);
assert(digest.length == 20); // SHA1 160 bits == 20 bytes
result = new StringBuffer("URI_SHA_1_");
for (int j = 0; j < digest.length; j++)
1.2 +10 -4 xml-xmlbeans/v2/src/common/org/apache/xmlbeans/impl/common/SniffedXmlInputStream.java
Index: SniffedXmlInputStream.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/common/org/apache/xmlbeans/impl/common/SniffedXmlInputStream.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SniffedXmlInputStream.java 26 Sep 2003 21:23:26 -0000 1.1
+++ SniffedXmlInputStream.java 6 Oct 2003 21:08:39 -0000 1.2
@@ -227,7 +227,7 @@
/* package */ static String extractXmlDeclEncoding(char[] buf, int offset, int size)
{
int limit = offset + size;
- int xmlpi = firstIndexOfAscii("<?xml", buf, offset, limit);
+ int xmlpi = firstIndexOf("<?xml", buf, offset, limit);
if (xmlpi >= 0)
{
int i = xmlpi + 5;
@@ -244,21 +244,27 @@
return null;
}
- private static int firstIndexOfAscii(String s, char[] buf, int startAt, int limit)
+ private static int firstIndexOf(String s, char[] buf, int startAt, int limit)
{
assert(s.length() > 0);
- byte[] lookFor = s.getBytes();
- int firstchar = lookFor[0];
+ char[] lookFor = s.toCharArray();
+
+ char firstchar = lookFor[0];
searching: for (limit -= lookFor.length; startAt < limit; startAt++)
{
if (buf[startAt] == firstchar)
{
for (int i = 1; i < lookFor.length; i++)
+ {
if (buf[startAt + i] != lookFor[i])
+ {
continue searching;
+ }
+ }
return startAt;
}
}
+
return -1;
}
1.2 +11 -1 xml-xmlbeans/v2/src/common/org/apache/xmlbeans/impl/common/XMLNameHelper.java
Index: XMLNameHelper.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/common/org/apache/xmlbeans/impl/common/XMLNameHelper.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XMLNameHelper.java 26 Sep 2003 21:23:26 -0000 1.1
+++ XMLNameHelper.java 6 Oct 2003 21:08:39 -0000 1.2
@@ -58,6 +58,7 @@
import weblogic.xml.stream.XMLName;
import javax.xml.namespace.QName;
+import java.io.UnsupportedEncodingException;
public class XMLNameHelper
{
@@ -126,12 +127,21 @@
}
else
{
- byte[] utf8 = s.substring(i, i + 1).getBytes();
+ byte[] utf8 = null;
+ try
+ {
+ utf8 = s.substring(i, i + 1).getBytes("UTF-8");
for (int j = 0; j < utf8.length; j++)
{
result.append('_');
result.append(hexdigits[(utf8[j] >> 4) & 0xF]);
result.append(hexdigits[utf8[j] & 0xF]);
+ }
+ }
+ catch(UnsupportedEncodingException uee)
+ {
+ // should never happen - UTF-8 is always supported
+ result.append("_BAD_UTF8_CHAR");
}
}
}
1.2 +11 -1 xml-xmlbeans/v2/src/typeimpl/org/apache/xmlbeans/impl/values/JavaBase64Holder.java
Index: JavaBase64Holder.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/typeimpl/org/apache/xmlbeans/impl/values/JavaBase64Holder.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JavaBase64Holder.java 26 Sep 2003 21:23:29 -0000 1.1
+++ JavaBase64Holder.java 6 Oct 2003 21:08:39 -0000 1.2
@@ -68,6 +68,7 @@
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
+import java.io.UnsupportedEncodingException;
public abstract class JavaBase64Holder extends XmlObjectBase
{
@@ -99,7 +100,16 @@
public static byte[] lex(String v, ValidationContext c)
{
- final byte[] bytes = Base64.decode(v.getBytes());
+ byte[] vBytes = null;
+ try
+ {
+ vBytes = v.getBytes("UTF-8");
+ }
+ catch(UnsupportedEncodingException uee)
+ {
+ // should never happen - UTF-8 is always supported
+ }
+ final byte[] bytes = Base64.decode(vBytes);
if (bytes == null)
{
1.2 +11 -1 xml-xmlbeans/v2/src/typeimpl/org/apache/xmlbeans/impl/values/JavaHexBinaryHolder.java
Index: JavaHexBinaryHolder.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/typeimpl/org/apache/xmlbeans/impl/values/JavaHexBinaryHolder.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JavaHexBinaryHolder.java 26 Sep 2003 21:23:29 -0000 1.1
+++ JavaHexBinaryHolder.java 6 Oct 2003 21:08:39 -0000 1.2
@@ -68,6 +68,7 @@
import java.security.NoSuchAlgorithmException;
import java.security.MessageDigest;
import java.util.Arrays;
+import java.io.UnsupportedEncodingException;
public abstract class JavaHexBinaryHolder extends XmlObjectBase
{
@@ -99,7 +100,16 @@
public static byte[] lex(String v, ValidationContext context)
{
- byte[] bytes = HexBin.decode(v.getBytes());
+ byte[] vBytes = null;
+ try
+ {
+ vBytes = v.getBytes("UTF-8");
+ }
+ catch(UnsupportedEncodingException uee)
+ {
+ // should never happen - UTF-8 is always supported
+ }
+ byte[] bytes = HexBin.decode(vBytes);
if (bytes == null)
{
1.2 +1 -1 xml-xmlbeans/v2/src/xmlinputstream/weblogic/utils/NestedThrowable.java
Index: NestedThrowable.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/xmlinputstream/weblogic/utils/NestedThrowable.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- NestedThrowable.java 26 Sep 2003 21:23:33 -0000 1.1
+++ NestedThrowable.java 6 Oct 2003 21:08:39 -0000 1.2
@@ -63,7 +63,7 @@
*
* @deprecated use JDK 1.4 style nested throwables where possible.
*
- * @author Copyright (c) 1997 by WebLogic, Inc. All Rights Reserved.
+ * @author WebLogic
*/
import java.io.PrintWriter;
---------------------------------------------------------------------
To unsubscribe, e-mail: xmlbeans-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-cvs-help@xml.apache.org