Last update: 2011-06-23

org.proteios.core
Class MimeType

java.lang.Object
  extended by org.proteios.core.BasicItem<MimeTypeData>
      extended by org.proteios.core.MimeType
All Implemented Interfaces:
AccessControlled, Identifiable, Nameable, Removable

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

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: 2010-01-02 22:12:32 +0100 (Sat, 02 Jan 2010) $

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 org.proteios.core.Nameable
MAX_DESCRIPTION_LENGTH, MAX_NAME_LENGTH
 
Method Summary
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.
 String getExtension()
          Get the extension for this MimeType item.
static List<MimeTypeData> getMimeTypeDataList(DbControl dc)
          Get a list of MimeTypeData items.
static String getMimeTypeStringByExtension(DbControl dc, String extension)
          Get a MimeType string when you know the file extension.
 String getName()
          Get the name of the 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.
 boolean isUsed()
          A MimeType is not used by other items.
 void setDescription(String description)
          Set the description for the item.
 void setExtension(String extension)
          Set the extension variable for this MimeType 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 org.proteios.core.BasicItem
checkPermission, equals, getDbControl, getId, getPermissions, getSessionControl, getVersion, hashCode, hasPermission, isDetached, isInDatabase, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.proteios.core.Identifiable
getId, getVersion
 
Methods inherited from interface org.proteios.core.AccessControlled
checkPermission, 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
Method Detail

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

getMimeTypeStringByExtension

public static String getMimeTypeStringByExtension(DbControl dc,
                                                  String extension)
                                           throws BaseException
Get a MimeType string when you know the file extension.

Parameters:
dc - The DbControl which will be used for database access.
extension - The extension of the mime type, do not include the dot in the extension.
Returns:
The MimeType string
Throws:
BaseException - If there is another error

getMimeTypeDataList

public static List<MimeTypeData> getMimeTypeDataList(DbControl dc)
                                              throws BaseException
Get a list of MimeTypeData items.

Parameters:
dc - The DbControl which will be used for database access.
Returns:
List A list of MimeTypeData items in the database.
Throws:
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

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

isUsed

public boolean isUsed()
               throws BaseException
A MimeType is not used by other items.

Specified by:
isUsed in class BasicItem<MimeTypeData>
Returns:
Allways false
Throws:
BaseException - If there is an error.

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

Last update: 2011-06-23