2.17.2: 2011-06-17

net.sf.basedb.core
Class MimeType

java.lang.Object
  extended by net.sf.basedb.core.BasicItem<MimeTypeData>
      extended by net.sf.basedb.core.MimeType
All Implemented Interfaces:
AccessControlled, Identifiable, Nameable, Registered, Removable

public class MimeType
extends BasicItem<MimeTypeData>
implements Nameable, Removable, Registered

This class is used to represent mime types. The mime types are important for file handling, for example when downloading a file on the web.

Version:
2.0
Author:
enell
Last modified
$Date: 2009-04-06 14:52:39 +0200 (Mon, 06 Apr 2009) $

Field Summary
static int MAX_EXTENSION_LENGTH
          The maximum length of the extension variable that can be stored in the database.
static Item TYPE
          The type of item represented by this class.
 
Fields inherited from interface net.sf.basedb.core.Nameable
MAX_DESCRIPTION_LENGTH, MAX_NAME_LENGTH
 
Constructor Summary
MimeType(MimeTypeData data)
          Creates a new mimetype item from the given data.
 
Method Summary
 boolean getAutoCompress()
          If files of this MIME type should automatically be compressed when they are uploaded to BASE.
static MimeType getByExtension(DbControl dc, String extension)
          Get a MimeType item when you know the file extension.
static MimeType getById(DbControl dc, int id)
          Get a MimeType object when you know the ID.
 String getDescription()
          Get the description for the item.
 Date getEntryDate()
          Get the date that the item was registered in the database.
 String getExtension()
          Get the extension for this MimeType item.
 FileType getFileType()
          Get the associated FileType item.
static String getMimeType(DbControl dc, String name, String defaultMimeType)
          Get the MIME type of a given file name or extension.
 String getName()
          Get the name of the item.
static MimeType getNew(DbControl dc)
          Create a new MimeType item.
static ItemQuery<MimeType> getQuery()
          Get a query configured to retrieve MIME types.
 Item getType()
          Get the type of item represented by the object.
 boolean isRemoved()
          Check if the removed flag is set for this item.
 void setAutoCompress(boolean autoCompress)
          Set if files of this MIME type should automatically be compressed when they are uploaded to BASE.
 void setDescription(String description)
          Set the description for the item.
 void setExtension(String extension)
          Set the extension variable for this MimeType item.
 void setFileType(FileType filetype)
          Set the filetype of this item.
 void setName(String name)
          Set the name of the item.
 void setRemoved(boolean removed)
          Set the removed flag for this item.
 
Methods inherited from class net.sf.basedb.core.BasicItem
addUsingItems, addUsingItems, checkPermission, equals, getData, getDbControl, getId, getPermissions, getPluginPermissions, getSessionControl, getUsingItems, getVersion, hashCode, hasPermission, initPermissions, isDetached, isInDatabase, isUsed, onAfterCommit, onAfterInsert, onBeforeCommit, onRollback, setDbControl, setProjectDefaults, toString, toTransferable, validate
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sf.basedb.core.Identifiable
getId, getVersion
 
Methods inherited from interface net.sf.basedb.core.AccessControlled
checkPermission, getPermissions, hasPermission
 

Field Detail

TYPE

public static final Item TYPE
The type of item represented by this class.

See Also:
Item.MIMETYPE, getType()

MAX_EXTENSION_LENGTH

public static final int MAX_EXTENSION_LENGTH
The maximum length of the extension variable that can be stored in the database. Check the length against this value before calling the setExtension(String) method to avoid exceptions.

See Also:
Constant Field Values
Constructor Detail

MimeType

MimeType(MimeTypeData data)
Creates a new mimetype item from the given data.

Parameters:
data - the data.
Method Detail

getNew

public static MimeType getNew(DbControl dc)
                       throws BaseException
Create a new MimeType item.

Parameters:
dc - The DbControl which will be used for permission checking and database access
Returns:
The new MimeType item
Throws:
BaseException - If there is an error

getById

public static MimeType getById(DbControl dc,
                               int id)
                        throws ItemNotFoundException,
                               PermissionDeniedException,
                               BaseException
Get a MimeType object when you know the ID.

Parameters:
dc - The DbControl which will be used for permission checking and database access.
id - The ID of the item to load
Returns:
The MimeType item
Throws:
ItemNotFoundException - If an item with the specified ID is not found
PermissionDeniedException - If the logged in user doesn't have Permission.READ permission to the items
BaseException - If there is another error

getByExtension

public static MimeType getByExtension(DbControl dc,
                                      String extension)
                               throws PermissionDeniedException,
                                      ItemNotFoundException,
                                      BaseException
Get a MimeType item when you know the file extension.

Parameters:
dc - The DbControl which will be used for permission checking and database access.
extension - The extension of the mime type, do not include the dot in the extension
Returns:
The MimeType item
Throws:
ItemNotFoundException - If an item with the specified ID is not found
PermissionDeniedException - If the logged in user doesn't have Permission.READ permission to the items
BaseException - If there is another error

getQuery

public static ItemQuery<MimeType> getQuery()
                                    throws BaseException
Get a query configured to retrieve MIME types.

Returns:
An ItemQuery object
Throws:
BaseException - If the query could not be created.

getMimeType

public static String getMimeType(DbControl dc,
                                 String name,
                                 String defaultMimeType)
                          throws BaseException
Get the MIME type of a given file name or extension. This method will check all registered MIME types even if the logged in user doesn't have read permission.

Parameters:
dc - The DbControl to use for database access
name - The file name or extension, if a dot exists in the name only the last part will be used for MIME type lookup
defaultMimeType - A default MIME type to return if none is found
Returns:
A MIME type or null
Throws:
BaseException - If there is an error
Since:
2.2

getType

public Item getType()
Description copied from interface: Identifiable
Get the type of item represented by the object. The returned value is one of the values defined in the Item enumeration.

Specified by:
getType in interface Identifiable
Returns:
A value indicating the type of item

getName

public String getName()
Description copied from interface: Nameable
Get the name of the item.

Specified by:
getName in interface Nameable
Returns:
A String with the name of the item

setName

public void setName(String name)
             throws PermissionDeniedException,
                    InvalidDataException
Description copied from interface: Nameable
Set the name of the item. The name cannot be null and mustn't be longer than the value specified by the Nameable.MAX_NAME_LENGTH constant.

Specified by:
setName in interface Nameable
Parameters:
name - The new name for the item
Throws:
PermissionDeniedException - If the logged in user doesn't have write permission
InvalidDataException - If the name is null or longer than specified by the Nameable.MAX_NAME_LENGTH constant

getDescription

public String getDescription()
Description copied from interface: Nameable
Get the description for the item.

Specified by:
getDescription in interface Nameable
Returns:
A String with a description of the item

setDescription

public void setDescription(String description)
                    throws PermissionDeniedException,
                           InvalidDataException
Description copied from interface: Nameable
Set the description for the item. The description can be null but mustn't be longer than the value specified by the Nameable.MAX_DESCRIPTION_LENGTH constant.

Specified by:
setDescription in interface Nameable
Parameters:
description - The new description for the item
Throws:
PermissionDeniedException - If the logged in user doesn't have write permission
InvalidDataException - If the description longer than specified by the Nameable.MAX_DESCRIPTION_LENGTH constant

isRemoved

public boolean isRemoved()
Description copied from interface: Removable
Check if the removed flag is set for this item.

Specified by:
isRemoved in interface Removable
Returns:
TRUE if the item is flagged as removed, FALSE otherwise

setRemoved

public void setRemoved(boolean removed)
                throws PermissionDeniedException
Description copied from interface: Removable
Set the removed flag for this item.

Specified by:
setRemoved in interface Removable
Parameters:
removed - TRUE if the item should be flagged as removed, FALSE otherwise
Throws:
PermissionDeniedException - If the logged in user doesn't have Permission.DELETE permission for setting the flag to TRUE or Permission.WRITE permission for setting the flag to FALSE

getEntryDate

public Date getEntryDate()
Description copied from interface: Registered
Get the date that the item was registered in the database.

Specified by:
getEntryDate in interface Registered
Returns:
A date or null if this is not known

setExtension

public void setExtension(String extension)
                  throws PermissionDeniedException,
                         InvalidDataException
Set the extension variable for this MimeType item.

Parameters:
extension - A string with the extension of this item. Note that this extension should be without leading dot.
Throws:
PermissionDeniedException - If the logged in user doesn't have Permission.WRITE permission to the mimetype.
InvalidDataException - If the new value is null or longer than MAX_EXTENSION_LENGTH

getExtension

public String getExtension()
Get the extension for this MimeType item.

Returns:
A string with the extension of this item

getFileType

public FileType getFileType()
                     throws PermissionDeniedException,
                            BaseException
Get the associated FileType item.

Returns:
The FileType item, or null if no type has been specified
Throws:
PermissionDeniedException - This exception is thrown if the logged in user doesn't have read permission to the item
BaseException - If there is another error

setFileType

public void setFileType(FileType filetype)
                 throws PermissionDeniedException
Set the filetype of this item.

Parameters:
filetype - The new FileType, or null
Throws:
PermissionDeniedException - If the logged in user doesn't have write permission

getAutoCompress

public boolean getAutoCompress()
If files of this MIME type should automatically be compressed when they are uploaded to BASE. Note! Auto-compression must be enabled. See Application.autoCompressionEnabled().

Returns:
TRUE to automatically compress files of this type
Since:
2.5

setAutoCompress

public void setAutoCompress(boolean autoCompress)
                     throws PermissionDeniedException
Set if files of this MIME type should automatically be compressed when they are uploaded to BASE. Note! Auto-compression must be enabled. See Application.autoCompressionEnabled().

Parameters:
autoCompress - TRUE to enable auto-compression
Throws:
PermissionDeniedException - If the logged in user doesn't have write permission
Since:
2.5

2.17.2: 2011-06-17