You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by mm...@locus.apache.org on 2000/03/08 21:11:25 UTC
cvs commit: xml-xalan/src/org/apache/xalan/xpath/xml FormatterToXML.java
mmidy 00/03/08 12:11:25
Modified: src/org/apache/xalan/xpath/res XPATHErrorResources.java
src/org/apache/xalan/xpath/xml FormatterToXML.java
Log:
Check for valid encoding. If it is a java supported encoding, let it through.
Revision Changes Path
1.17 +8 -1 xml-xalan/src/org/apache/xalan/xpath/res/XPATHErrorResources.java
Index: XPATHErrorResources.java
===================================================================
RCS file: /home/cvs/xml-xalan/src/org/apache/xalan/xpath/res/XPATHErrorResources.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- XPATHErrorResources.java 2000/03/06 20:13:42 1.16
+++ XPATHErrorResources.java 2000/03/08 20:11:24 1.17
@@ -76,7 +76,7 @@
public static final String ERROR_SUFFIX = "ER";
public static final String WARNING_SUFFIX = "WR";
- public static final int MAX_CODE = 47; // this is needed to keep track of the number of messages
+ public static final int MAX_CODE = 48; // this is needed to keep track of the number of messages
public static final int MAX_WARNING = 10; // this is needed to keep track of the number of warnings
public static final int MAX_OTHERS = 20;
public static final int MAX_MESSAGES = MAX_CODE + MAX_WARNING +1;
@@ -446,6 +446,13 @@
{
contents[ER_COULDNOT_FIND_FUNCTION ][1]
= "Could not find function: {0}";
+ }
+
+ public static final int ER_UNSUPPORTED_ENCODING = 48;
+ static
+ {
+ contents[ER_UNSUPPORTED_ENCODING ][1]
+ = "Unsupported encoding: {0}";
}
1.31 +40 -2 xml-xalan/src/org/apache/xalan/xpath/xml/FormatterToXML.java
Index: FormatterToXML.java
===================================================================
RCS file: /home/cvs/xml-xalan/src/org/apache/xalan/xpath/xml/FormatterToXML.java,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- FormatterToXML.java 2000/03/06 20:13:44 1.30
+++ FormatterToXML.java 2000/03/08 20:11:24 1.31
@@ -69,6 +69,7 @@
import java.util.Hashtable;
import org.apache.xml.serialize.Serializer;
import org.apache.xml.serialize.OutputFormat;
+import org.apache.xalan.xpath.res.XPATHErrorResources;
/**
* <meta name="usage" content="general"/>
@@ -1741,6 +1742,30 @@
}
/**
+ * Try to determine if a given encoding is supported
+ * by the Java VM. (If folks know of a better
+ * way to do this, then please do tell...)
+ * @param enc Name of encoding (can not be null).
+ * @return true if VM can support the encoding, false otherwise.
+ */
+ static boolean isSupportedJavaEncoding(String enc)
+ {
+ try
+ {
+ java.io.ByteArrayOutputStream os = new java.io.ByteArrayOutputStream();
+ os.write(32);
+ String s = os.toString(enc);
+ // Just in case it doesn't throw an exception...
+ if(null != s)
+ return true;
+ }
+ catch (java.io.UnsupportedEncodingException e)
+ {
+ }
+ return false;
+ }
+
+ /**
* Convert a MIME charset name, also known as an XML encoding name, to a Java encoding name.
* @param mimeCharsetName Case insensitive MIME charset name: <code>UTF-8, US-ASCII, ISO-8859-1,
* ISO-8859-2, ISO-8859-3, ISO-8859-4, ISO-8859-5, ISO-8859-6,
@@ -1755,14 +1780,27 @@
* is unknown.
* @see #reverse
*/
- public static String convertMime2JavaEncoding(String mimeCharsetName)
+ public static String convertMime2JavaEncoding(String mimeCharsetName)
+ throws UnsupportedEncodingException
{
if(null == s_enchash)
initEncodings();
if(null == mimeCharsetName)
return "UTF8";
- return javaEncodingIsISO ? mimeCharsetName :
+ String encoding = javaEncodingIsISO ? mimeCharsetName :
(String)s_enchash.get(mimeCharsetName.toUpperCase());
+
+ // Since we're serializing out, if they hand in a Java encoding name
+ // for whatever reason, it's probably good and OK, so just use that.
+ if((null == encoding) && isSupportedJavaEncoding(mimeCharsetName))
+ {
+ encoding = mimeCharsetName;
+ }
+
+ if (null == encoding)
+ throw new UnsupportedEncodingException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_UNSUPPORTED_ENCODING, new Object[] {mimeCharsetName}));
+ else
+ return encoding;
}
/**