org.norther.tammi.core.locale
Interface ContentTypeMap

All Known Implementing Classes:
DefaultContentTypeMap

public interface ContentTypeMap

ContentTypeMap maintains mappings between MIME types and the corresponding file name extensions, and between locales and character encodings. The mappings are typically defined in properties or files located in user's home directory, Java home directory or the current class jar depending on the implementation.

Author:
Ilkka Priha

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 optional 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.
 String getCharSetPath()
          Gets the pathname of the charset file.
 String getConfigKey()
          Gets the path finder key for resolving configuration paths.
 String getContentType(File file)
          Gets the MIME content type for a file as a string.
 String getContentType(String name)
          Gets the MIME content type for a named file as a string.
 String getContentType(String ext, String def)
          Gets the MIME content type for a file name extension as a string.
 String[] getContentTypes(String ext)
          Gets the MIME content types for a file name extension.
 String getDefaultExtension(MimeType mime)
          Gets the default file name extension for a MIME type.
 String getDefaultExtension(String type)
          Gets the default file name extension for a MIME type.
 String[] getExtensions(String type)
          Gets the file name extensions for a MIME type.
 MimeType getMimeType(File file)
          Gets the MIME content type for a file.
 MimeType getMimeType(String name)
          Gets the MIME type for a named file.
 MimeType getMimeType(String ext, String def)
          Gets the MIME type for a file name extension.
 String getMimeTypePath()
          Gets the pathname of the MIME type file.
 void setCharSet(String key, String charset)
          Sets a locale-charset mapping.
 void setCharSetPath(String path)
          Sets the pathname of the charset file.
 void setConfigKey(String key)
          Sets the path finder key for resolving configuration paths.
 void setContentType(String spec)
          Sets a MIME content type mapping to extensions to the map.
 void setMimeTypePath(String path)
          Sets the pathname of the MIME type file.
 

Method Detail

getConfigKey

String getConfigKey()
Gets the path finder key for resolving configuration paths.

Returns:
the path finder key.

setConfigKey

void setConfigKey(String key)
Sets the path finder key for resolving configuration paths. The default key is PathFinderMBean.CONFIG.

Parameters:
key - the path finder key.

setContentType

void setContentType(String spec)
Sets a MIME content type mapping to extensions to the map. The extension is specified by a MIME type name followed by a list of file name extensions separated by a whitespace.

Parameters:
spec - a MIME type extension specification to add.

getContentType

String getContentType(File file)
Gets the MIME content type for a file as a string.

Parameters:
file - the file.
Returns:
the MIME type string.

getContentType

String getContentType(String name)
Gets the MIME content type for a named file as a string.

Parameters:
name - the name of the file.
Returns:
the MIME type string.

getContentType

String getContentType(String ext,
                      String def)
Gets the MIME content type for a file name extension as a string.

Parameters:
ext - the file name extension.
def - the default type if none is found.
Returns:
the MIME type string.

getContentTypes

String[] getContentTypes(String ext)
Gets the MIME content types for a file name extension.

Parameters:
ext - the file name extension.
Returns:
an array of MIME type strings or null.

getMimeType

MimeType getMimeType(File file)
Gets the MIME content type for a file.

Parameters:
file - the file.
Returns:
the MIME type.

getMimeType

MimeType getMimeType(String name)
Gets the MIME type for a named file.

Parameters:
name - the name of the file.
Returns:
the MIME type.

getMimeType

MimeType getMimeType(String ext,
                     String def)
Gets the MIME type for a file name extension.

Parameters:
ext - the file name extension.
def - the default type if none is found.
Returns:
the MIME type.

getDefaultExtension

String getDefaultExtension(String type)
Gets the default file name extension for a MIME type.

Parameters:
type - the MIME type as a string.
Returns:
the file name extension or null.

getDefaultExtension

String getDefaultExtension(MimeType mime)
Gets the default file name extension for a MIME type.

Parameters:
mime - the MIME type.
Returns:
the file name extension or null.

getExtensions

String[] getExtensions(String type)
Gets the file name extensions for a MIME type.

Parameters:
type - the MIME type as a string.
Returns:
an array of file name extensions or null.

getCharSet

String getCharSet(String path)
Gets the charset for a localized file path.

Parameters:
path - the localized path.
Returns:
the found charset.

setCharSet

void setCharSet(String key,
                String charset)
Sets a locale-charset mapping.

Parameters:
key - the key for the charset.
charset - the corresponding charset.

getCharSet

String getCharSet(Locale locale)
Gets the charset for a locale. First a locale specific charset is searched for, then a country specific one and lastly a language specific one. If a variant is included in the locale, it is applied to the search as well.

Parameters:
locale - the locale.
Returns:
the charset.

getCharSet

String getCharSet(Locale locale,
                  String variant)
Gets the charset for a locale with an optional variant. If the optional variant is not null and a variant is also included in the locale, the one in the locale is replaced by the given variant.

Parameters:
locale - the locale.
variant - an optional variant.
Returns:
the charset of the locale.

getCharSet

String getCharSet(Locale locale,
                  List accepted)
Gets the accepted charset for a locale.

Parameters:
locale - the locale.
accepted - a list of accepted charsets.
Returns:
the charset.

getCharSet

String getCharSet(Locale locale,
                  String variant,
                  List accepted)
Gets the accepted charset for a locale with an optional variant. If the optional variant is not null and a variant is also included in the locale, the one in the locale is replaced by the given variant.

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.

Parameters:
locale - the locale.
variant - the variant.
accepted - a list of accepted charsets.
Returns:
the charset.

getMimeTypePath

String getMimeTypePath()
Gets the pathname of the MIME type file.

Returns:
the pathname of the MIME type file or null.

setMimeTypePath

void setMimeTypePath(String path)
Sets the pathname of the MIME type file.

Parameters:
path - the pathname of the MIME type file.

getCharSetPath

String getCharSetPath()
Gets the pathname of the charset file.

Returns:
the pathname of the charset file.

setCharSetPath

void setCharSetPath(String path)
Sets the pathname of the charset file.

Parameters:
path - the pathname of the charset file.


Copyright © 2004 The Norther Organization. All rights reserved.