public class MimetypeRegistryService extends DefaultComponent implements MimetypeRegistry
Singleton holding a registry of mimetype entries and exposes an API to grab information related to these mimetypes. As well, this is possible to ask for a mimetype magic detection from a stream or file using the API.
| Modifier and Type | Field and Description |
|---|---|
static long |
MAX_SIZE_FOR_SCAN |
static ComponentName |
NAME |
DEFAULT_MIMETYPE| Constructor and Description |
|---|
MimetypeRegistryService() |
| Modifier and Type | Method and Description |
|---|---|
void |
activate(ComponentContext context)
Activates the component.
|
void |
deactivate(ComponentContext context)
Deactivates the component.
|
RuntimeContext |
getContext() |
List<String> |
getExtensionsFromMimetypeName(String mimetypeName)
Returns the extension for given mimetype.
|
MimetypeEntry |
getMimetypeEntryByMimeType(String mimetype)
Gets a mimetype entry given the normalized mimetype.
|
MimetypeEntry |
getMimetypeEntryByName(String name)
Gets a mimetype entry by name.
|
String |
getMimetypeFromBlob(Blob blob)
Returns the mime type from a given stream.
|
String |
getMimetypeFromBlobWithDefault(Blob blob,
String defaultMimetype)
Finds the mimetype of a Blob content and returns provided default if not
possible.
|
String |
getMimetypeFromExtension(String extension) |
String |
getMimetypeFromFile(File file)
Returns the mime type given a file.
|
String |
getMimetypeFromFilename(String filename) |
String |
getMimetypeFromFilenameAndBlobWithDefault(String filename,
Blob blob,
String defaultMimetype)
Finds the mimetype of some content according to its filename and / or
binary content.
|
String |
getMimetypeFromStream(InputStream stream)
Deprecated.
|
String |
getMimetypeFromStreamWithDefault(InputStream is,
String defaultMimetype)
Deprecated.
|
void |
registerExtension(Extension extension)
Registers the given extension.
|
void |
registerFileExtension(ExtensionDescriptor extensionDescriptor) |
void |
registerMimetype(MimetypeEntry mimetype) |
void |
unregisterExtension(Extension extension)
Unregisters the given extension.
|
void |
unregisterFileExtension(ExtensionDescriptor extensionDescriptor) |
void |
unregisterMimetype(String mimetypeName) |
Blob |
updateMimetype(Blob blob)
Update the mimetype field of a Blob based on the embedded filename with
fallback to binary sniffing.
|
Blob |
updateMimetype(Blob blob,
String filename)
Update the mimetype field of a Blob based on the provided filename with
fallback to binary sniffing.
|
applicationStarted, getAdapter, getApplicationStartedOrder, getLastModified, registerContribution, setLastModified, unregisterContributionpublic static final ComponentName NAME
public static final long MAX_SIZE_FOR_SCAN
public void activate(ComponentContext context)
ComponentThis method is called by the runtime when a component is activated.
activate in interface Componentactivate in class DefaultComponentcontext - the runtime contextpublic void deactivate(ComponentContext context)
ComponentThis method is called by the runtime when a component is deactivated.
deactivate in interface Componentdeactivate in class DefaultComponentcontext - the runtime contextpublic void registerExtension(Extension extension)
ExtensibleregisterExtension in interface ExtensibleregisterExtension in class DefaultComponentextension - the extension to registerpublic void registerMimetype(MimetypeEntry mimetype)
public void registerFileExtension(ExtensionDescriptor extensionDescriptor)
public void unregisterExtension(Extension extension)
ExtensibleunregisterExtension in interface ExtensibleunregisterExtension in class DefaultComponentextension - the extension to unregisterpublic void unregisterMimetype(String mimetypeName)
public void unregisterFileExtension(ExtensionDescriptor extensionDescriptor)
public RuntimeContext getContext()
public List<String> getExtensionsFromMimetypeName(String mimetypeName)
MimetypeRegistrygetExtensionsFromMimetypeName in interface MimetypeRegistrymimetypeName - the mimetype name.public MimetypeEntry getMimetypeEntryByName(String name)
MimetypeRegistrygetMimetypeEntryByName in interface MimetypeRegistryname - the mimetype name.public String getMimetypeFromFile(File file) throws MimetypeNotFoundException, MimetypeDetectionException
MimetypeRegistrygetMimetypeFromFile in interface MimetypeRegistryMimetypeNotFoundException - if mimetype sniffing failedMimetypeDetectionException - if unexpected problem prevent the
detection to work as expectedpublic String getMimetypeFromExtension(String extension) throws MimetypeNotFoundException
MimetypeNotFoundExceptionpublic String getMimetypeFromFilename(String filename) throws MimetypeNotFoundException
MimetypeNotFoundException@Deprecated public String getMimetypeFromStream(InputStream stream) throws MimetypeNotFoundException, MimetypeDetectionException
MimetypeRegistrygetMimetypeFromStream in interface MimetypeRegistryMimetypeNotFoundException - if mimetype sniffing failed to identify
a registered mime typeMimetypeDetectionException - if unexpected problem prevent the
detection to work as expected@Deprecated public String getMimetypeFromStreamWithDefault(InputStream is, String defaultMimetype) throws MimetypeDetectionException
getMimetypeFromStreamWithDefault in interface MimetypeRegistryis - content to be analyzeddefaultMimetype - default mimetype to be used if no foundMimetypeDetectionExceptionpublic String getMimetypeFromBlob(Blob blob) throws MimetypeNotFoundException, MimetypeDetectionException
MimetypeRegistrygetMimetypeFromBlob in interface MimetypeRegistryMimetypeNotFoundException - if mimetype sniffing failed to identify
a registered mime typeMimetypeDetectionException - if unexpected problem prevent the
detection to work as expectedpublic MimetypeEntry getMimetypeEntryByMimeType(String mimetype)
MimetypeRegistrygetMimetypeEntryByMimeType in interface MimetypeRegistrymimetype - the normalized mimetypepublic String getMimetypeFromBlobWithDefault(Blob blob, String defaultMimetype) throws MimetypeDetectionException
getMimetypeFromBlobWithDefault in interface MimetypeRegistryblob - content to be analyzeddefaultMimetype - defaultMimeType to be used if no foundMimetypeDetectionExceptionpublic String getMimetypeFromFilenameAndBlobWithDefault(String filename, Blob blob, String defaultMimetype) throws MimetypeDetectionException
getMimetypeFromFilenameAndBlobWithDefault in interface MimetypeRegistryfilename - extension to analyzeblob - content to be analyzed if filename is ambiguousdefaultMimetype - defaultMimeType to be used if no foundMimetypeDetectionExceptionpublic Blob updateMimetype(Blob blob, String filename) throws MimetypeDetectionException
MimetypeRegistryupdateMimetype in interface MimetypeRegistryblob - content to be analyzed if filename is ambiguousfilename - with extension to analyzeMimetypeDetectionExceptionpublic Blob updateMimetype(Blob blob) throws MimetypeDetectionException
MimetypeRegistryupdateMimetype in interface MimetypeRegistryblob - content to be analyzed if filename is ambiguousMimetypeDetectionExceptionCopyright © 2014 Nuxeo SA. All Rights Reserved.