org.apache.xml.serializer
Class Encodings

java.lang.Object
  extended by org.apache.xml.serializer.Encodings

public final class Encodings
extends java.lang.Object

Provides information about encodings. Depends on the Java runtime to provides writers for the different encodings.

This class is not a public API. It is only public because it is used outside of this package.


Field Summary
private static EncodingInfo[] _encodings
           
private static java.util.Hashtable _encodingTableKeyJava
           
private static java.util.Hashtable _encodingTableKeyMime
           
(package private) static java.lang.String DEFAULT_MIME_ENCODING
          The default encoding, ISO style, ISO style.
private static java.lang.String ENCODINGS_FILE
          Standard filename for properties file with encodings data.
 
Constructor Summary
Encodings()
           
 
Method Summary
private static java.lang.String convertJava2MimeEncoding(java.lang.String encoding)
          Try the best we can to convert a Java encoding to a XML-style encoding.
static java.lang.String convertMime2JavaEncoding(java.lang.String encoding)
          Try the best we can to convert a Java encoding to a XML-style encoding.
(package private) static EncodingInfo getEncodingInfo(java.lang.String encoding)
          Returns the EncodingInfo object for the specified encoding, never null, although the encoding name inside the returned EncodingInfo object will be if we can't find a "real" EncodingInfo for the encoding.
static char getHighChar(java.lang.String encoding)
          Characters with values at or below the high code point are in the encoding.
(package private) static java.lang.String getMimeEncoding(java.lang.String encoding)
          Get the proper mime encoding.
(package private) static java.io.Writer getWriter(java.io.OutputStream output, java.lang.String encoding)
          Returns a writer for the specified encoding based on an output stream.
(package private) static boolean isHighUTF16Surrogate(char ch)
          Return true if the character is the high member of a surrogate pair.
(package private) static boolean isLowUTF16Surrogate(char ch)
          Return true if the character is the low member of a surrogate pair.
static boolean isRecognizedEncoding(java.lang.String encoding)
          Determines if the encoding specified was recognized by the serializer or not.
private static int lengthOfMimeNames(java.lang.String val)
          Get the length of the Mime names within the property value
private static EncodingInfo[] loadEncodingInfo()
          Load a list of all the supported encodings.
(package private) static int toCodePoint(char ch)
          Return the unicode code point represented by the char.
(package private) static int toCodePoint(char highSurrogate, char lowSurrogate)
          Return the unicode code point represented by the high/low surrogate pair.
private static java.lang.String toUpperCaseFast(java.lang.String s)
          A fast and cheap way to uppercase a String that is only made of printable ASCII characters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ENCODINGS_FILE

private static final java.lang.String ENCODINGS_FILE
Standard filename for properties file with encodings data.


DEFAULT_MIME_ENCODING

static final java.lang.String DEFAULT_MIME_ENCODING
The default encoding, ISO style, ISO style.

See Also:
Constant Field Values

_encodingTableKeyJava

private static final java.util.Hashtable _encodingTableKeyJava

_encodingTableKeyMime

private static final java.util.Hashtable _encodingTableKeyMime

_encodings

private static final EncodingInfo[] _encodings
Constructor Detail

Encodings

public Encodings()
Method Detail

getWriter

static java.io.Writer getWriter(java.io.OutputStream output,
                                java.lang.String encoding)
                         throws java.io.UnsupportedEncodingException
Returns a writer for the specified encoding based on an output stream.

This is not a public API.

Parameters:
output - The output stream
encoding - The encoding MIME name, not a Java name for the encoding.
Returns:
A suitable writer
Throws:
java.io.UnsupportedEncodingException - There is no convertor to support this encoding

getEncodingInfo

static EncodingInfo getEncodingInfo(java.lang.String encoding)
Returns the EncodingInfo object for the specified encoding, never null, although the encoding name inside the returned EncodingInfo object will be if we can't find a "real" EncodingInfo for the encoding.

This is not a public API.

Parameters:
encoding - The encoding
Returns:
The object that is used to determine if characters are in the given encoding.

isRecognizedEncoding

public static boolean isRecognizedEncoding(java.lang.String encoding)
Determines if the encoding specified was recognized by the serializer or not.

Parameters:
encoding - The encoding
Returns:
boolean - true if the encoding was recognized else false

toUpperCaseFast

private static java.lang.String toUpperCaseFast(java.lang.String s)
A fast and cheap way to uppercase a String that is only made of printable ASCII characters.

This is not a public API.

Parameters:
s - a String of ASCII characters
Returns:
an uppercased version of the input String, possibly the same String.

getMimeEncoding

static java.lang.String getMimeEncoding(java.lang.String encoding)
Get the proper mime encoding. From the XSLT recommendation: "The encoding attribute specifies the preferred encoding to use for outputting the result tree. XSLT processors are required to respect values of UTF-8 and UTF-16. For other values, if the XSLT processor does not support the specified encoding it may signal an error; if it does not signal an error it should use UTF-8 or UTF-16 instead. The XSLT processor must not use an encoding whose name does not match the EncName production of the XML Recommendation [XML]. If no encoding attribute is specified, then the XSLT processor should use either UTF-8 or UTF-16."

This is not a public API.

Parameters:
encoding - Reference to java-style encoding string, which may be null, in which case a default will be found.
Returns:
The ISO-style encoding string, or null if failure.

convertJava2MimeEncoding

private static java.lang.String convertJava2MimeEncoding(java.lang.String encoding)
Try the best we can to convert a Java encoding to a XML-style encoding.

This is not a public API.

Parameters:
encoding - non-null reference to encoding string, java style.
Returns:
ISO-style encoding string.

convertMime2JavaEncoding

public static java.lang.String convertMime2JavaEncoding(java.lang.String encoding)
Try the best we can to convert a Java encoding to a XML-style encoding.

This is not a public API.

Parameters:
encoding - non-null reference to encoding string, java style.
Returns:
ISO-style encoding string.

This method is not a public API.


loadEncodingInfo

private static EncodingInfo[] loadEncodingInfo()
Load a list of all the supported encodings. System property "encodings" formatted using URL syntax may define an external encodings list. Thanks to Sergey Ushakov for the code contribution!


lengthOfMimeNames

private static int lengthOfMimeNames(java.lang.String val)
Get the length of the Mime names within the property value

Parameters:
val - The value of the property, which should contain a comma separated list of Mime names, followed optionally by a space and the high char value
Returns:

isHighUTF16Surrogate

static boolean isHighUTF16Surrogate(char ch)
Return true if the character is the high member of a surrogate pair.

This is not a public API.

Parameters:
ch - the character to test

isLowUTF16Surrogate

static boolean isLowUTF16Surrogate(char ch)
Return true if the character is the low member of a surrogate pair.

This is not a public API.

Parameters:
ch - the character to test

toCodePoint

static int toCodePoint(char highSurrogate,
                       char lowSurrogate)
Return the unicode code point represented by the high/low surrogate pair.

This is not a public API.

Parameters:
highSurrogate - the high char of the high/low pair
lowSurrogate - the low char of the high/low pair

toCodePoint

static int toCodePoint(char ch)
Return the unicode code point represented by the char. A bit of a dummy method, since all it does is return the char, but as an int value.

This is not a public API.

Parameters:
ch - the char.

getHighChar

public static char getHighChar(java.lang.String encoding)
Characters with values at or below the high code point are in the encoding. Code point values above this one may or may not be in the encoding, but lower ones certainly are.

This is for performance.

Parameters:
encoding - The encoding
Returns:
The code point for which characters at or below this code point are in the encoding. Characters with higher code point may or may not be in the encoding. A value of zero is returned if the high code point is unknown.

This method is not a public API.