com.vaadin.service.
Class FileTypeResolver
java.lang.Object
com.vaadin.service.FileTypeResolver
All Implemented Interfaces:
- extends Object
- implements Serializable
public class FileTypeResolver
Utility class that can figure out mime-types and icons related to files.
Note : The icons are associated purely to mime-types, so a file may not have a custom icon accessible with this class.
Since:
3.0
Version:
6.8.18
Author:
Vaadin Ltd.
See Also:
Field Summary | |
---|---|
static Resource |
DEFAULT_ICON
Default icon given if no icon is specified for a mime-type. |
static String |
DEFAULT_MIME_TYPE
Default mime-type. |
Constructor Summary | |
---|---|
FileTypeResolver()
|
Method Summary | |
---|---|
static void |
addExtension(String extension,
String MIMEType)
Adds a mime-type mapping for the given filename extension. |
static void |
addIcon(String MIMEType,
Resource icon)
Adds a icon for the given mime-type. |
static Map<String,String> |
getExtensionToMIMETypeMapping()
Gets the internal file extension to mime-type mapping. |
static Resource |
getIcon(File file)
Gets the descriptive icon representing a file. |
static Resource |
getIcon(String fileName)
Gets the descriptive icon representing file, based on the filename. |
static String |
getMIMEType(File file)
Gets the mime-type for a file. |
static String |
getMIMEType(String fileName)
Gets the mime-type of a file. |
static Map<String,Resource> |
getMIMETypeToIconMapping()
Gets the internal mime-type to icon mapping. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
DEFAULT_ICON
public static Resource DEFAULT_ICON
Default icon given if no icon is specified for a mime-type.
DEFAULT_MIME_TYPE
public static String DEFAULT_MIME_TYPE
Default mime-type.
Constructor Detail |
---|
FileTypeResolver
public FileTypeResolver()
Method Detail |
---|
getMIMEType
public static String getMIMEType(String fileName)
- Parameters:
fileName
- the name of the file whose mime-type is requested.- Returns:
- mime-type
String
for the given filename
Gets the mime-type of a file. Currently the mime-type is resolved based only on the file name extension.
getIcon
public static Resource getIcon(String fileName)
- Parameters:
fileName
- the name of the file whose icon is requested.- Returns:
- the icon corresponding to the given file
Gets the descriptive icon representing file, based on the filename. First the mime-type for the given filename is resolved, and then the corresponding icon is fetched from the internal icon storage. If it is not found the default icon is returned.
getIcon
public static Resource getIcon(File file)
- Parameters:
file
- the file whose icon is requested.- Returns:
- the icon corresponding to the given file
Gets the descriptive icon representing a file. First the mime-type for the given file name is resolved, and then the corresponding icon is fetched from the internal icon storage. If it is not found the default icon is returned.
getMIMEType
public static String getMIMEType(File file)
- Parameters:
file
- the file whose mime-type is requested.- Returns:
- the files mime-type
String
Gets the mime-type for a file. Currently the returned file type is resolved by the filename extension only.
addExtension
public static void addExtension(String extension,
String MIMEType)
- Parameters:
extension
- the filename extension to be associated withMIMEType
.MIMEType
- the new mime-type forextension
.
Adds a mime-type mapping for the given filename extension. If the extension is already in the internal mapping it is overwritten.
addIcon
public static void addIcon(String MIMEType,
Resource icon)
- Parameters:
MIMEType
- the mime-type whose icon is to be changed.icon
- the new icon to be associated withMIMEType
.
Adds a icon for the given mime-type. If the mime-type also has a corresponding icon, it is replaced with the new icon.
getExtensionToMIMETypeMapping
public static Map<String,String> getExtensionToMIMETypeMapping()
- Returns:
- unmodifiable map containing the current file extension to mime-type mapping
Gets the internal file extension to mime-type mapping.
getMIMETypeToIconMapping
public static Map<String,Resource> getMIMETypeToIconMapping()
- Returns:
- unmodifiable map containing the current mime-type to icon mapping
Gets the internal mime-type to icon mapping.