org.apache.xalan.serialize
Class Encodings

java.lang.Object
  extended byorg.apache.xalan.serialize.Encodings

public class Encodings
extends Object

Provides information about encodings. Depends on the Java runtime to provides writers for the different encodings, but can be used to override encoding names and provide the last printable character for each encoding.

Author:
Assaf Arkin

Field Summary
private static EncodingInfo[] _encodings
           
static String DEFAULT_MIME_ENCODING
          The default encoding, ISO style, ISO style.
(package private) static String ENCODINGS_FILE
          Standard filename for properties file with encodings data.
(package private) static int m_defaultLastPrintable
          The last printable character for unknown encodings.
private static Class[] NO_CLASSES
          a zero length Class array used in loadPropertyFile()
private static Object[] NO_OBJS
          a zero length Object array used in loadPropertyFile()
 
Constructor Summary
Encodings()
           
 
Method Summary
static String convertJava2MimeEncoding(String encoding)
          Try the best we can to convert a Java encoding to a XML-style encoding.
static String convertMime2JavaEncoding(String encoding)
          Try the best we can to convert a Java encoding to a XML-style encoding.
static Object getCharToByteConverter(String encoding)
          Returns an opaque CharToByte converter for the specified encoding.
static int getLastPrintable()
          Returns the last printable character for an unspecified encoding.
static int getLastPrintable(String encoding)
          Returns the last printable character for the specified encoding.
static String getMimeEncoding(String encoding)
          Get the proper mime encoding.
static Writer getWriter(OutputStream output, String encoding)
          Returns a writer for the specified encoding based on an output stream.
private static EncodingInfo[] loadEncodingInfo()
          Load a list of all the supported encodings.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_defaultLastPrintable

static final int m_defaultLastPrintable
The last printable character for unknown encodings.

See Also:
Constant Field Values

ENCODINGS_FILE

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

See Also:
Constant Field Values

NO_CLASSES

private static final Class[] NO_CLASSES
a zero length Class array used in loadPropertyFile()


NO_OBJS

private static final Object[] NO_OBJS
a zero length Object array used in loadPropertyFile()


DEFAULT_MIME_ENCODING

public static final String DEFAULT_MIME_ENCODING
The default encoding, ISO style, ISO style.

See Also:
Constant Field Values

_encodings

private static final EncodingInfo[] _encodings
Constructor Detail

Encodings

public Encodings()
Method Detail

getWriter

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

Parameters:
output - The output stream
encoding - The encoding
Returns:
A suitable writer
Throws:
UnsupportedEncodingException - There is no convertor to support this encoding

getCharToByteConverter

public static Object getCharToByteConverter(String encoding)
Returns an opaque CharToByte converter for the specified encoding.

Parameters:
encoding - The encoding
Returns:
An object which should be a sun.io.CharToByteConverter, or null.

getLastPrintable

public static int getLastPrintable(String encoding)
Returns the last printable character for the specified encoding.

Parameters:
encoding - The encoding
Returns:
The last printable character

getLastPrintable

public static int getLastPrintable()
Returns the last printable character for an unspecified encoding.

Returns:
the default size

getMimeEncoding

public static String getMimeEncoding(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."

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

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

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

convertMime2JavaEncoding

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

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

loadEncodingInfo

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