|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.norther.tammi.acorn.mime.CharSetMap
public class CharSetMap
CharSetMap maintains a set of mappers defining mappings between locales and the corresponding charsets. The mappings are defined as properties between locale and charset names. The definitions can be listed in property files located in user's home directory, Java home directory or the current class jar. In addition, this class maintains static default mappings and constructors support application specific mappings.
More than one charset can be specified for a locale separated by commas. The first one always the default one.
| Field Summary | |
|---|---|
static String |
ANY_KEY
The wildcard key. |
static String |
CHARSET_RESOURCE
The name for charset mapper resources. |
static String |
DEFAULT_ENCODING
The default encoding if UTF-8 cannot be applied. |
| Constructor Summary | |
|---|---|
CharSetMap()
Constructs a new charset map with default mappers. |
|
CharSetMap(File file)
Contructs a charset map read from a property file. |
|
CharSetMap(InputStream input)
Contructs a charset map read from a stream. |
|
CharSetMap(Properties props)
Contructs a charset map from properties. |
|
CharSetMap(String path)
Contructs a charset map read from a property file path. |
|
| Method Summary | |
|---|---|
String |
getCharSet(Locale locale)
Gets the charset for a locale. |
String |
getCharSet(Locale locale,
List accepted)
Gets the accepted charset for a locale. |
String |
getCharSet(Locale locale,
String variant)
Gets the charset for a locale with an additional variant. |
String |
getCharSet(Locale locale,
String variant,
List accepted)
Gets the accepted charset for a locale with an optional variant. |
String |
getCharSet(String path)
Gets the charset for a localized file path. |
protected static Map |
loadFile(File file)
Loads mappings from a file. |
protected static Map |
loadPath(String path)
Loads mappings from a file path. |
protected static Map |
loadResource(String name)
Loads mappings from a resource. |
protected static Map |
loadStream(InputStream input)
Loads mappings from a stream. |
void |
setCharSet(String key,
String charset)
Sets a locale-charset mapping. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String CHARSET_RESOURCE
public static final String DEFAULT_ENCODING
public static final String ANY_KEY
| Constructor Detail |
|---|
public CharSetMap()
public CharSetMap(Properties props)
props - charset mapping propeties.
public CharSetMap(InputStream input)
throws IOException
input - an input stream.
IOException - for an incorrect stream.
public CharSetMap(File file)
throws IOException
file - a property file.
IOException - for an incorrect property file.
public CharSetMap(String path)
throws IOException
path - a property file path.
IOException - for an incorrect property file.| Method Detail |
|---|
protected static Map loadStream(InputStream input)
throws IOException
input - an input stream.
IOException - for an incorrect stream.
protected static Map loadFile(File file)
throws IOException
file - a file.
IOException - for an incorrect file.
protected static Map loadPath(String path)
throws IOException
path - a file path.
IOException - for an incorrect file.protected static Map loadResource(String name)
name - a resource name.
public String getCharSet(String path)
path - the localized path.
public void setCharSet(String key,
String charset)
key - the key for the charset.charset - the corresponding charset.public String getCharSet(Locale locale)
locale - the locale.
public String getCharSet(Locale locale,
String variant)
locale - the locale.variant - the variant.
public String getCharSet(Locale locale,
List accepted)
locale - the locale.accepted - a list of accepted charsets.
public String getCharSet(Locale locale,
String variant,
List accepted)
The search is performed in the following order:
The found charsets are compared with the list of accepted ones and the first accepted charset is returned. If none of the above is accepted but UTF-8 is, UTF-8 is returned. Otherwise the first found charset is returned.
locale - the locale.variant - the variant.accepted - a list of accepted charsets.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||