Package com.vaadin.util
Class FileTypeResolver
- java.lang.Object
-
- com.vaadin.util.FileTypeResolver
-
public class FileTypeResolver extends java.lang.ObjectUtility 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
- Author:
- Vaadin Ltd.
-
-
Field Summary
Fields Modifier and Type Field Description static ResourceDEFAULT_ICONDefault icon given if no icon is specified for a mime-type.static java.lang.StringDEFAULT_MIME_TYPEDefault mime-type.
-
Constructor Summary
Constructors Modifier Constructor Description protectedFileTypeResolver()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddExtension(java.lang.String extension, java.lang.String mimeType)Adds a mime-type mapping for the given filename extension.static java.util.Map<java.lang.String,java.lang.String>getExtensionToMIMETypeMapping()Gets the internal file extension to mime-type mapping.static java.lang.StringgetMIMEType(java.io.File file)Gets the mime-type for a file.static java.lang.StringgetMIMEType(java.lang.String fileName)Gets the mime-type of a file.
-
-
-
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 java.lang.String DEFAULT_MIME_TYPE
Default mime-type.
-
-
Method Detail
-
getMIMEType
public static java.lang.String getMIMEType(java.lang.String fileName)
Gets the mime-type of a file. Currently the mime-type is resolved based only on the file name extension.- Parameters:
fileName- the name of the file whose mime-type is requested.- Returns:
- mime-type
Stringfor the given filename
-
getMIMEType
public static java.lang.String getMIMEType(java.io.File file)
Gets the mime-type for a file. Currently the returned file type is resolved by the filename extension only.- Parameters:
file- the file whose mime-type is requested.- Returns:
- the files mime-type
String
-
addExtension
public static void addExtension(java.lang.String extension, java.lang.String mimeType)Adds a mime-type mapping for the given filename extension. If the extension is already in the internal mapping it is overwritten.- Parameters:
extension- the filename extension to be associated withMIMEType.mimeType- the new mime-type forextension.
-
getExtensionToMIMETypeMapping
public static java.util.Map<java.lang.String,java.lang.String> getExtensionToMIMETypeMapping()
Gets the internal file extension to mime-type mapping.- Returns:
- unmodifiable map containing the current file extension to mime-type mapping
-
-