org.norther.tammi.core.locale
Class DefaultContentTypeMap

java.lang.Object
  extended by org.norther.tammi.core.base.Adaptee
      extended by org.norther.tammi.core.locale.DefaultContentTypeMap
All Implemented Interfaces:
Serializable, NotificationBroadcaster, NotificationEmitter, Manageable, MBeanDelegate, ContentTypeMap

public class DefaultContentTypeMap
extends Adaptee
implements ContentTypeMap

A default implementation of ContentTypeMap.

Author:
Ilkka Priha
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.norther.tammi.core.base.Adaptee
ADAPTEE_NOTIF_DESCRIPTION, ADAPTEE_NOTIFICATIONS
 
Fields inherited from interface org.norther.tammi.core.base.MBeanDelegate
ARRAY_TYPE, OBJECT_TYPE, PRIMITIVE_TYPE, STRING_TYPE
 
Constructor Summary
DefaultContentTypeMap()
          Constructs a new map.
 
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.
protected  CharSetMap getCharSetMap()
          Gets the char set map to use.
 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.
protected  MimeTypeMap getMimeTypeMap()
          Gets the MIME type map to use.
 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.
 
Methods inherited from class org.norther.tammi.core.base.Adaptee
addAdaptee, addNotificationListener, getAttributeSupport, getBroker, getCanonicalName, getDomain, getFactory, getLoader, getLog, getLog, getMBean, getMBeanServer, getNotificationInfo, getObjectName, getRegistrationTime, getSequenceNumber, hasListeners, isRegistered, postmanaged, premanaged, removeNotificationListener, removeNotificationListener, sendNotification, sendNotification, sendNotification, sendNotification, unmanaged, unregister
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultContentTypeMap

public DefaultContentTypeMap()
Constructs a new map.

Method Detail

getConfigKey

public String getConfigKey()
Description copied from interface: ContentTypeMap
Gets the path finder key for resolving configuration paths.

Specified by:
getConfigKey in interface ContentTypeMap
Returns:
the path finder key.

setConfigKey

public void setConfigKey(String key)
Description copied from interface: ContentTypeMap
Sets the path finder key for resolving configuration paths. The default key is PathFinderMBean.CONFIG.

Specified by:
setConfigKey in interface ContentTypeMap
Parameters:
key - the path finder key.

setContentType

public void setContentType(String spec)
Description copied from interface: ContentTypeMap
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.

Specified by:
setContentType in interface ContentTypeMap
Parameters:
spec - a MIME type extension specification to add.

getContentType

public String getContentType(File file)
Description copied from interface: ContentTypeMap
Gets the MIME content type for a file as a string.

Specified by:
getContentType in interface ContentTypeMap
Parameters:
file - the file.
Returns:
the MIME type string.

getContentType

public String getContentType(String name)
Description copied from interface: ContentTypeMap
Gets the MIME content type for a named file as a string.

Specified by:
getContentType in interface ContentTypeMap
Parameters:
name - the name of the file.
Returns:
the MIME type string.

getContentType

public String getContentType(String ext,
                             String def)
Description copied from interface: ContentTypeMap
Gets the MIME content type for a file name extension as a string.

Specified by:
getContentType in interface ContentTypeMap
Parameters:
ext - the file name extension.
def - the default type if none is found.
Returns:
the MIME type string.

getContentTypes

public String[] getContentTypes(String ext)
Description copied from interface: ContentTypeMap
Gets the MIME content types for a file name extension.

Specified by:
getContentTypes in interface ContentTypeMap
Parameters:
ext - the file name extension.
Returns:
an array of MIME type strings or null.

getMimeType

public MimeType getMimeType(File file)
Description copied from interface: ContentTypeMap
Gets the MIME content type for a file.

Specified by:
getMimeType in interface ContentTypeMap
Parameters:
file - the file.
Returns:
the MIME type.

getMimeType

public MimeType getMimeType(String name)
Description copied from interface: ContentTypeMap
Gets the MIME type for a named file.

Specified by:
getMimeType in interface ContentTypeMap
Parameters:
name - the name of the file.
Returns:
the MIME type.

getMimeType

public MimeType getMimeType(String ext,
                            String def)
Description copied from interface: ContentTypeMap
Gets the MIME type for a file name extension.

Specified by:
getMimeType in interface ContentTypeMap
Parameters:
ext - the file name extension.
def - the default type if none is found.
Returns:
the MIME type.

getDefaultExtension

public String getDefaultExtension(String type)
Description copied from interface: ContentTypeMap
Gets the default file name extension for a MIME type.

Specified by:
getDefaultExtension in interface ContentTypeMap
Parameters:
type - the MIME type as a string.
Returns:
the file name extension or null.

getDefaultExtension

public String getDefaultExtension(MimeType mime)
Description copied from interface: ContentTypeMap
Gets the default file name extension for a MIME type.

Specified by:
getDefaultExtension in interface ContentTypeMap
Parameters:
mime - the MIME type.
Returns:
the file name extension or null.

getExtensions

public String[] getExtensions(String type)
Description copied from interface: ContentTypeMap
Gets the file name extensions for a MIME type.

Specified by:
getExtensions in interface ContentTypeMap
Parameters:
type - the MIME type as a string.
Returns:
an array of file name extensions or null.

getCharSet

public String getCharSet(String path)
Description copied from interface: ContentTypeMap
Gets the charset for a localized file path.

Specified by:
getCharSet in interface ContentTypeMap
Parameters:
path - the localized path.
Returns:
the found charset.

setCharSet

public void setCharSet(String key,
                       String charset)
Description copied from interface: ContentTypeMap
Sets a locale-charset mapping.

Specified by:
setCharSet in interface ContentTypeMap
Parameters:
key - the key for the charset.
charset - the corresponding charset.

getCharSet

public String getCharSet(Locale locale)
Description copied from interface: ContentTypeMap
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.

Specified by:
getCharSet in interface ContentTypeMap
Parameters:
locale - the locale.
Returns:
the charset.

getCharSet

public String getCharSet(Locale locale,
                         String variant)
Description copied from interface: ContentTypeMap
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.

Specified by:
getCharSet in interface ContentTypeMap
Parameters:
locale - the locale.
variant - an optional variant.
Returns:
the charset of the locale.

getCharSet

public String getCharSet(Locale locale,
                         List accepted)
Description copied from interface: ContentTypeMap
Gets the accepted charset for a locale.

Specified by:
getCharSet in interface ContentTypeMap
Parameters:
locale - the locale.
accepted - a list of accepted charsets.
Returns:
the charset.

getCharSet

public String getCharSet(Locale locale,
                         String variant,
                         List accepted)
Description copied from interface: ContentTypeMap
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.

Specified by:
getCharSet in interface ContentTypeMap
Parameters:
locale - the locale.
variant - the variant.
accepted - a list of accepted charsets.
Returns:
the charset.

getMimeTypePath

public String getMimeTypePath()
Description copied from interface: ContentTypeMap
Gets the pathname of the MIME type file.

Specified by:
getMimeTypePath in interface ContentTypeMap
Returns:
the pathname of the MIME type file or null.

setMimeTypePath

public void setMimeTypePath(String path)
Description copied from interface: ContentTypeMap
Sets the pathname of the MIME type file.

Specified by:
setMimeTypePath in interface ContentTypeMap
Parameters:
path - the pathname of the MIME type file.

getCharSetPath

public String getCharSetPath()
Description copied from interface: ContentTypeMap
Gets the pathname of the charset file.

Specified by:
getCharSetPath in interface ContentTypeMap
Returns:
the pathname of the charset file.

setCharSetPath

public void setCharSetPath(String path)
Description copied from interface: ContentTypeMap
Sets the pathname of the charset file.

Specified by:
setCharSetPath in interface ContentTypeMap
Parameters:
path - the pathname of the charset file.

getMimeTypeMap

protected MimeTypeMap getMimeTypeMap()
Gets the MIME type map to use.

Returns:
the MIME type map.

getCharSetMap

protected CharSetMap getCharSetMap()
Gets the char set map to use.

Returns:
the char set map.


Copyright © 2004 The Norther Organization. All rights reserved.