com.arsdigita.mimetypes
Class MimeType

java.lang.Object
  extended bycom.arsdigita.domain.DomainObject
      extended bycom.arsdigita.mimetypes.MimeType
Direct Known Subclasses:
ImageMimeType, TextMimeType

public class MimeType
extends DomainObject

Provides information about a single mime type, such as "image/gif" or "text/plain". The mime-type itself may be accessed by calling getMimeType(); the user-readable label can be accessed by calling getLabel().

This class is a member of each com.arsdigita.cms.Asset; it is used in (among other places) com.arsdigita.cms.ui.authoring.TextPageBody and com.arsdigita.cms.ui.authoring.ArticleImage in order to properly handle uploaded files.

Version:
$Revision: #9 $ $DateTime: 2004/04/07 16:07:11 $
Author:
Jack Chung, Stanislav Freidin

Field Summary
static String ALL_FILE_EXTENSIONS
           
static String BASE_DATA_OBJECT_TYPE
           
static String FILE_EXTENSION
           
static String JAVA_CLASS
           
static String LABEL
           
static String MIME_TYPE
           
static String OBJECT_TYPE
           
 
Fields inherited from class com.arsdigita.domain.DomainObject
versionId
 
Constructor Summary
MimeType(DataObject obj)
          Construct a new MimeType from the given DataObject.
MimeType(OID oid)
          Load an existing MimeType.
MimeType(String type, String mimeType)
          Construct a new MimeType with a given object type.
 
Method Summary
protected  void beforeSave()
          Save this mime type and remember the correct java class
static MimeType createMimeType(String mimeTypeName, String javaClass, String objectType)
          Create a new instance of the specified Java subclass of MimeType.
 MimeTypeExtensionCollection getAllFileExtensions()
          this returns a collection of Strings representing all of the file extensions associated with this mime type
static MimeTypeCollection getAllMimeTypes()
          Get all mime types in the system
 String getBaseDataObjectType()
          Return the base data object type for this mime-type
 String getFileExtension()
          Get the canonical file extension for the files of this mime type, f.ex.
 String getJavaClass()
          Return the name of the proper Java subclass of this mime type
 String getLabel()
          Get the user-readable label for this mime-type, such as "Plain Text"
 String getMimeType()
          Get the actual mime-type, such as "text/plain" or "image/gif"
 String getPrefix()
          Return the prefix of this mime type; the prefix is everything before the "/".
 String getSpecificObjectType()
          Return the name of the specific object type of this mime type
static MimeType guessMimeType(String fileExtension)
          Guess the mime type from a file extension.
static MimeType guessMimeTypeFromFile(String fileName)
          Guess the mime type from the given file name.
 boolean hasFileExtension(String fileExtension)
          this tells you if a particular extension is part of the mime type
static MimeType loadMimeType(String mimeTypeName)
          Return an instance of the specified mime type.
static MimeTypeCollection searchMimeTypes(String startsWith)
          Search all the mime types that starts with "startsWith".
 void setFileExtension(String value)
          Set the the canonical file extension for the files of this mime type
 void setJavaClass(String javaClassName)
          Set the name of the proper Java subclass of this mime type
 void setLabel(String value)
          Set the user-readable label
 void setMimeType(String value)
          Set the mime-type
 void setSpecificObjectType(String objectType)
          Set the name of the specific object type of this mime type
 MimeType specialize()
          Return a specific Java subclass of this mime type
 
Methods inherited from class com.arsdigita.domain.DomainObject
add, add, addToAssociation, afterDelete, afterSave, beforeDelete, clear, delete, disconnect, equals, get, getObjectType, getOID, getSession, hashCode, initialize, isDeleted, isDisconnected, isModified, isNew, isPropertyModified, isValid, remove, remove, remove, removeFromAssociation, save, set, setAssociation, setAssociation, specializeDataObject, specializeDataObject, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

BASE_DATA_OBJECT_TYPE

public static final String BASE_DATA_OBJECT_TYPE
See Also:
Constant Field Values

MIME_TYPE

public static final String MIME_TYPE
See Also:
Constant Field Values

LABEL

public static final String LABEL
See Also:
Constant Field Values

FILE_EXTENSION

public static final String FILE_EXTENSION
See Also:
Constant Field Values

ALL_FILE_EXTENSIONS

public static final String ALL_FILE_EXTENSIONS
See Also:
Constant Field Values

JAVA_CLASS

public static final String JAVA_CLASS
See Also:
Constant Field Values

OBJECT_TYPE

public static final String OBJECT_TYPE
See Also:
Constant Field Values
Constructor Detail

MimeType

public MimeType(OID oid)
         throws DataObjectNotFoundException
Load an existing MimeType.


MimeType

public MimeType(DataObject obj)
Construct a new MimeType from the given DataObject. All subclasses must implement this constructor.


MimeType

public MimeType(String type,
                String mimeType)
Construct a new MimeType with a given object type. All subclasses must implement this constructor.

Method Detail

getMimeType

public String getMimeType()
Get the actual mime-type, such as "text/plain" or "image/gif"


setMimeType

public void setMimeType(String value)
Set the mime-type


getLabel

public String getLabel()
Get the user-readable label for this mime-type, such as "Plain Text"


setLabel

public void setLabel(String value)
Set the user-readable label


getFileExtension

public String getFileExtension()
Get the canonical file extension for the files of this mime type, f.ex. "jpeg" or "txt"


getAllFileExtensions

public MimeTypeExtensionCollection getAllFileExtensions()
this returns a collection of Strings representing all of the file extensions associated with this mime type


hasFileExtension

public boolean hasFileExtension(String fileExtension)
this tells you if a particular extension is part of the mime type


setFileExtension

public void setFileExtension(String value)
Set the the canonical file extension for the files of this mime type


getJavaClass

public String getJavaClass()
Return the name of the proper Java subclass of this mime type


setJavaClass

public void setJavaClass(String javaClassName)
Set the name of the proper Java subclass of this mime type


getSpecificObjectType

public String getSpecificObjectType()
Return the name of the specific object type of this mime type


setSpecificObjectType

public void setSpecificObjectType(String objectType)
Set the name of the specific object type of this mime type


specialize

public MimeType specialize()
Return a specific Java subclass of this mime type

Returns:
the specific Java subclass of this mime type (could be the same as "this")

getBaseDataObjectType

public String getBaseDataObjectType()
Return the base data object type for this mime-type

Overrides:
getBaseDataObjectType in class DomainObject
Returns:
The fully qualified name ("modelName.typeName") of the base data object type for this domain object class, or null if there is no restriction on the data object type for the primary data object encapsulated by this class.

getPrefix

public String getPrefix()
Return the prefix of this mime type; the prefix is everything before the "/".

Returns:
the prefix of this mime type

loadMimeType

public static MimeType loadMimeType(String mimeTypeName)
Return an instance of the specified mime type. If no such mime type exists, return null. Will return an appropriate java subclass of MimeType

Parameters:
mimeTypeName - The name of the mime type to load, such as "text/html" or "image/jpeg"
Returns:
a proper subclass of MimeType, or null if no such mime type exists

createMimeType

public static MimeType createMimeType(String mimeTypeName,
                                      String javaClass,
                                      String objectType)
Create a new instance of the specified Java subclass of MimeType.

Parameters:
mimeTypeName - The name of the mime type to create, such as "text/html" or "image/jpeg"
javaClass - The Java class of the new mime type
objectType - The PDL object type of the new mime type
Returns:
a proper subclass of MimeType

guessMimeType

public static MimeType guessMimeType(String fileExtension)
Guess the mime type from a file extension.

Parameters:
fileExtension - the extension associated with a mime type
Returns:
the guessed mime type, or null if there is no corresponding mime type in the database.

guessMimeTypeFromFile

public static MimeType guessMimeTypeFromFile(String fileName)
Guess the mime type from the given file name. Computes the file extension as the substring following the last '.' and calls guessMimeType(java.lang.String) to lookup the corresponding type. If the file has no extension, this will always return null.

Parameters:
fileName - the file name
Returns:
the guessed mime type, or null if there is no corresponding mime type in the database.

beforeSave

protected void beforeSave()
Save this mime type and remember the correct java class

Overrides:
beforeSave in class DomainObject

getAllMimeTypes

public static MimeTypeCollection getAllMimeTypes()
Get all mime types in the system


searchMimeTypes

public static MimeTypeCollection searchMimeTypes(String startsWith)
Search all the mime types that starts with "startsWith".



Copyright (c) 2004 Red Hat, Inc. Corporation. All Rights Reserved. Generated at July 20 2004:2337 UTC