APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.sun.org.apache.xml.internal.serializer

public final Class Encodings

extends Object
Class Inheritance
Imports
java.io.BufferedWriter, .IOException, .InputStream, .OutputStream, .OutputStreamWriter, .UnsupportedEncodingException, .Writer, java.net.MalformedURLException, .URL, java.nio.charset.Charset, .IllegalCharsetNameException, .UnsupportedCharsetException, java.util.Collections, .Enumeration, .HashMap, .Map.Entry, .Map, .Properties, .StringTokenizer, jdk.xml.internal.SecuritySupport

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

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static final Encodings.EncodingInfos
pack-priv static final String
DEFAULT_MIME_ENCODING

The default encoding, ISO style, ISO style.

private static final String
ENCODINGS_FILE

Standard filename for properties file with encodings data.

private static final String
ENCODINGS_PROP

Standard filename for properties file with encodings data.

private static final int
m_defaultLastPrintable

The last printable character for unknown encodings.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static String

Returns:

ISO-style encoding string.
convertJava2MimeEncoding
(String
non-null reference to encoding string, java style.
encoding
)

Try the best we can to convert a Java encoding to a XML-style encoding.

public static String

Returns:

ISO-style encoding string.
convertMime2JavaEncoding
(String
non-null reference to encoding string, java style.
encoding
)

Try the best we can to convert a Java encoding to a XML-style encoding.

pack-priv static EncodingInfo

Returns:

The object that is used to determine if characters are in the given encoding.
getEncodingInfo
(String
The encoding
encoding
)

Returns the EncodingInfo object for the specified encoding.

public static int

Returns:

the default size
getLastPrintable
()

Returns the last printable character for an unspecified encoding.

pack-priv static String

Returns:

The ISO-style encoding string, or null if failure.
getMimeEncoding
(String
Reference to java-style encoding string, which may be null, in which case a default will be found.
encoding
)

Get the proper mime encoding.

pack-priv static Writer

Returns:

A suitable writer
getWriter
(OutputStream
The output stream
output
,
String
The encoding
encoding
)

Returns a writer for the specified encoding based on an output stream.

pack-priv static boolean
isHighUTF16Surrogate(char
the character to test
ch
)

Return true if the character is the high member of a surrogate pair.

pack-priv static boolean
isLowUTF16Surrogate(char
the character to test
ch
)

Return true if the character is the low member of a surrogate pair.

public static boolean

Returns:

boolean - true if the encoding was recognized else false
isRecognizedEncoding
(String
The encoding
encoding
)

Determines if the encoding specified was recognized by the serializer or not.

pack-priv static int
toCodePoint(char
the high char of the high/low pair
highSurrogate
,
char
the low char of the high/low pair
lowSurrogate
)

Return the unicode code point represented by the high/low surrogate pair.

pack-priv static int
toCodePoint(char
the char.
ch
)

Return the unicode code point represented by the char.

private static String

Returns:

an uppercased version of the input String, possibly the same String.
toUpperCaseFast
(final String
a String of ASCII characters
s
)

A fast and cheap way to uppercase a String that is only made of printable ASCII characters.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_encodingInfosback to summary
private static final Encodings.EncodingInfos _encodingInfos
DEFAULT_MIME_ENCODINGback to summary
pack-priv static final String DEFAULT_MIME_ENCODING

The default encoding, ISO style, ISO style.

ENCODINGS_FILEback to summary
private static final String ENCODINGS_FILE

Standard filename for properties file with encodings data.

ENCODINGS_PROPback to summary
private static final String ENCODINGS_PROP

Standard filename for properties file with encodings data.

m_defaultLastPrintableback to summary
private static final int m_defaultLastPrintable

The last printable character for unknown encodings.

Constructor Detail

Encodingsback to summary
public Encodings()

Method Detail

convertJava2MimeEncodingback to summary
private static String convertJava2MimeEncoding(String encoding)

Try the best we can to convert a Java encoding to a XML-style encoding.

Parameters
encoding:String

non-null reference to encoding string, java style.

Returns:String

ISO-style encoding string.

convertMime2JavaEncodingback to summary
public static String convertMime2JavaEncoding(String encoding)

Try the best we can to convert a Java encoding to a XML-style encoding.

Parameters
encoding:String

non-null reference to encoding string, java style.

Returns:String

ISO-style encoding string.

getEncodingInfoback to summary
pack-priv static EncodingInfo getEncodingInfo(String encoding)

Returns the EncodingInfo object for the specified encoding.

This is not a public API.

Parameters
encoding:String

The encoding

Returns:EncodingInfo

The object that is used to determine if characters are in the given encoding.

getLastPrintableback to summary
public static int getLastPrintable()

Returns the last printable character for an unspecified encoding.

Returns:int

the default size

getMimeEncodingback to summary
pack-priv 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:String

Reference to java-style encoding string, which may be null, in which case a default will be found.

Returns:String

The ISO-style encoding string, or null if failure.

getWriterback to summary
pack-priv static Writer getWriter(OutputStream output, String encoding) throws UnsupportedEncodingException

Returns a writer for the specified encoding based on an output stream.

Parameters
output:OutputStream

The output stream

encoding:String

The encoding

Returns:Writer

A suitable writer

Exceptions
UnsupportedEncodingException:
There is no convertor to support this encoding
isHighUTF16Surrogateback to summary
pack-priv 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:char

the character to test

isLowUTF16Surrogateback to summary
pack-priv 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:char

the character to test

isRecognizedEncodingback to summary
public static boolean isRecognizedEncoding(String encoding)

Determines if the encoding specified was recognized by the serializer or not.

Parameters
encoding:String

The encoding

Returns:boolean

boolean - true if the encoding was recognized else false

toCodePointback to summary
pack-priv 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:char

the high char of the high/low pair

lowSurrogate:char

the low char of the high/low pair

toCodePointback to summary
pack-priv 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:char

the char.

toUpperCaseFastback to summary
private static String toUpperCaseFast(final 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:String

a String of ASCII characters

Returns:String

an uppercased version of the input String, possibly the same String.

com.sun.org.apache.xml.internal.serializer back to summary

private final Class Encodings.EncodingInfos

extends Object
Class Inheritance
  • java.lang.Object
  • com.sun.org.apache.xml.internal.serializer.Encodings.EncodingInfos

Field Summary

Modifier and TypeField and Description
private final Map<String, EncodingInfo>
private final Map<String, EncodingInfo>
private final Map<String, EncodingInfo>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private String
private String
findCharsetNameFor(String javaName, String[] mimes)

pack-priv EncodingInfo
findEncoding(String normalizedEncoding)

pack-priv EncodingInfo
getEncodingFromJavaKey(String normalizedJavaName)

pack-priv EncodingInfo
getEncodingFromMimeKey(String normalizedMimeName)

private void
loadEncodingInfo()

Loads a list of all the supported encodings.

private Properties
private InputStream
private String[]
pack-priv void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_encodingDynamicTableback to summary
private final Map<String, EncodingInfo> _encodingDynamicTable
_encodingTableKeyJavaback to summary
private final Map<String, EncodingInfo> _encodingTableKeyJava
_encodingTableKeyMimeback to summary
private final Map<String, EncodingInfo> _encodingTableKeyMime

Constructor Detail

EncodingInfosback to summary
private EncodingInfos()

Method Detail

findCharsetNameForback to summary
private String findCharsetNameFor(String name)
findCharsetNameForback to summary
private String findCharsetNameFor(String javaName, String[] mimes)
findEncodingback to summary
pack-priv EncodingInfo findEncoding(String normalizedEncoding)
getEncodingFromJavaKeyback to summary
pack-priv EncodingInfo getEncodingFromJavaKey(String normalizedJavaName)
getEncodingFromMimeKeyback to summary
pack-priv EncodingInfo getEncodingFromMimeKey(String normalizedMimeName)
loadEncodingInfoback to summary
private void loadEncodingInfo()

Loads 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!

loadPropertiesback to summary
private Properties loadProperties() throws MalformedURLException, IOException
openEncodingsFileStreamback to summary
private InputStream openEncodingsFileStream() throws MalformedURLException, IOException
parseMimeTypesback to summary
private String[] parseMimeTypes(String val)
putEncodingback to summary
pack-priv void putEncoding(String key, EncodingInfo info)