Package net.sf.basedb.core
Class MimeType
java.lang.Object
net.sf.basedb.core.BasicItem
net.sf.basedb.core.MimeType
- All Implemented Interfaces:
AccessControlled
,Identifiable
,Nameable
,Registered
,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: 2017-05-22 14:35:27 +0200 (må, 22 maj 2017) $
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
The maximum length of the extension variable that can be stored in the database.static final Item
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
ConstructorDescriptionMimeType
(MimeTypeData data) Creates a new mimetype item from the given data. -
Method Summary
Modifier and TypeMethodDescriptionboolean
If files of this MIME type should automatically be compressed when they are uploaded to BASE.static MimeType
getByExtension
(DbControl dc, String extension) Get aMimeType
item when you know the file extension.static MimeType
Get aMimeType
object when you know the ID.(package private) MimeTypeData
getData()
Get theBasicData
object that holds all data for this item.Get the description for the item.Get the date that the item was registered in the database.Get the extension for thisMimeType
item.Get the associated file subtype item.static String
getMimeType
(DbControl dc, String name, String defaultMimeType) Get the MIME type of a given file name or extension.getName()
Get the name of the item.static MimeType
Create a newMimeType
item.getQuery()
Get a query configured to retrieve MIME types.Get the user that flagged this item for removal.getType()
Get the type of item represented by the object.boolean
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
setEntryDate
(Date entryDate) Set the date the entry was registered in the database.void
setExtension
(String extension) Set the extension variable for thisMimeType
item.void
setFileType
(ItemSubtype filetype) Set the filetype of this item.void
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
addAnnotatableParents, addUsingItems, addUsingItems, breakCircularReferences, checkBatchAnnotatableUsage, checkPermission, equals, getBasicData, getDbControl, getId, getPermissions, getPluginPermissions, getSessionControl, getUsingItems, getVersion, hashCode, hasPermission, initPermissions, isDetached, isInDatabase, isUsed, onAfterCommit, onAfterInsert, onBeforeCommit, onRollback, setDbControl, setProjectDefaults, toString, validate
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface net.sf.basedb.core.AccessControlled
checkPermission, getPermissions, hasPermission
Methods inherited from interface net.sf.basedb.core.Identifiable
getId, getVersion
-
Field Details
-
TYPE
The type of item represented by this class.- See Also:
-
MAX_EXTENSION_LENGTH
public static final int MAX_EXTENSION_LENGTHThe maximum length of the extension variable that can be stored in the database. Check the length against this value before calling thesetExtension(String)
method to avoid exceptions.- See Also:
-
-
Constructor Details
-
MimeType
MimeType(MimeTypeData data) Creates a new mimetype item from the given data.- Parameters:
data
- the data.
-
-
Method Details
-
getNew
Create a newMimeType
item.- Parameters:
dc
- TheDbControl
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 aMimeType
object when you know the ID.- Parameters:
dc
- TheDbControl
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 foundPermissionDeniedException
- If the logged in user doesn't havePermission.READ
permission to the itemsBaseException
- If there is another error
-
getByExtension
public static MimeType getByExtension(DbControl dc, String extension) throws PermissionDeniedException, ItemNotFoundException, BaseException Get aMimeType
item when you know the file extension.- Parameters:
dc
- TheDbControl
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 foundPermissionDeniedException
- If the logged in user doesn't havePermission.READ
permission to the itemsBaseException
- If there is another error
-
getQuery
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 accessname
- The file name or extension, if a dot exists in the name only the last part will be used for MIME type lookupdefaultMimeType
- 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
-
getData
MimeTypeData getData()Description copied from class:BasicItem
Get theBasicData
object that holds all data for this 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 theItem
enumeration.- Specified by:
getType
in interfaceIdentifiable
- Returns:
- A value indicating the type of item
-
getName
Description copied from interface:Nameable
Get the name of the item. -
setName
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 theNameable.MAX_NAME_LENGTH
constant.- Specified by:
setName
in interfaceNameable
- Parameters:
name
- The new name for the item- Throws:
PermissionDeniedException
- If the logged in user doesn't have write permissionInvalidDataException
- If the name is null or longer than specified by theNameable.MAX_NAME_LENGTH
constant
-
getDescription
Description copied from interface:Nameable
Get the description for the item.- Specified by:
getDescription
in interfaceNameable
- 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 theNameable.MAX_DESCRIPTION_LENGTH
constant.- Specified by:
setDescription
in interfaceNameable
- Parameters:
description
- The new description for the item- Throws:
PermissionDeniedException
- If the logged in user doesn't have write permissionInvalidDataException
- If the description longer than specified by theNameable.MAX_DESCRIPTION_LENGTH
constant
-
isRemoved
public boolean isRemoved()Description copied from interface:Removable
Check if the removed flag is set for this item. -
setRemoved
Description copied from interface:Removable
Set the removed flag for this item.- Specified by:
setRemoved
in interfaceRemovable
- Parameters:
removed
- TRUE if the item should be flagged as removed, FALSE otherwise- Throws:
PermissionDeniedException
- If the logged in user doesn't havePermission.DELETE
permission for setting the flag to TRUE orPermission.WRITE
permission for setting the flag to FALSE
-
getRemovedBy
Description copied from interface:Removable
Get the user that flagged this item for removal.- Specified by:
getRemovedBy
in interfaceRemovable
- Returns:
- A User object, or null if this item has not been flagged
- Throws:
PermissionDeniedException
- If the logged in user doesn't havePermission.READ
permission for the userItemNotFoundException
- If the user that removed this item can't be found
-
getEntryDate
Description copied from interface:Registered
Get the date that the item was registered in the database.- Specified by:
getEntryDate
in interfaceRegistered
- Returns:
- A date or null if this is not known
-
setEntryDate
Description copied from interface:Registered
Set the date the entry was registered in the database. Implementations should only allow this property to be set before the item is first stored in the database. The intention of this method is to facilitate export/import of data between server.- Specified by:
setEntryDate
in interfaceRegistered
- Parameters:
entryDate
- A date or null to use today's date
-
setExtension
Set the extension variable for thisMimeType
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 havePermission.WRITE
permission to the mimetype.InvalidDataException
- If the new value is null or longer thanMAX_EXTENSION_LENGTH
-
getExtension
Get the extension for thisMimeType
item.- Returns:
- A string with the extension of this item
-
getFileType
Get the associated file subtype 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 itemBaseException
- If there is another error- Since:
- 3.0
-
setFileType
Set the filetype of this item.- Parameters:
filetype
- The new file subtype, 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. SeeApplication.autoCompressionEnabled()
.- Returns:
- TRUE to automatically compress files of this type
- Since:
- 2.5
-
setAutoCompress
Set if files of this MIME type should automatically be compressed when they are uploaded to BASE. Note! Auto-compression must be enabled. SeeApplication.autoCompressionEnabled()
.- Parameters:
autoCompress
- TRUE to enable auto-compression- Throws:
PermissionDeniedException
- If the logged in user doesn't have write permission- Since:
- 2.5
-