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 |
---|---|
protected Map<String,ExtensionDescriptor> |
extensionRegistry |
static long |
MAX_SIZE_FOR_SCAN |
protected Map<String,MimetypeEntry> |
mimetypeByExtensionRegistry |
protected Map<String,MimetypeEntry> |
mimetypeByNormalisedRegistry |
static ComponentName |
NAME |
lastModified
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)
Returns the mime type from a given extension.
|
String |
getMimetypeFromFile(File file)
Returns the mime type given a file.
|
String |
getMimetypeFromFilename(String filename)
Returns the mime type from a given 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.
|
protected void |
initializeRegistries() |
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, setModifiedNow, unregisterContribution
public static final ComponentName NAME
public static final long MAX_SIZE_FOR_SCAN
protected Map<String,MimetypeEntry> mimetypeByNormalisedRegistry
protected Map<String,MimetypeEntry> mimetypeByExtensionRegistry
protected Map<String,ExtensionDescriptor> extensionRegistry
public MimetypeRegistryService()
protected void initializeRegistries()
public void activate(ComponentContext context)
Component
This method is called by the runtime when a component is activated.
activate
in interface Component
activate
in class DefaultComponent
context
- the runtime contextpublic void deactivate(ComponentContext context)
Component
This method is called by the runtime when a component is deactivated.
deactivate
in interface Component
deactivate
in class DefaultComponent
context
- the runtime contextpublic void registerExtension(Extension extension)
Extensible
registerExtension
in interface Extensible
registerExtension
in class DefaultComponent
extension
- the extension to registerpublic void registerMimetype(MimetypeEntry mimetype)
public void registerFileExtension(ExtensionDescriptor extensionDescriptor)
public void unregisterExtension(Extension extension)
Extensible
unregisterExtension
in interface Extensible
unregisterExtension
in class DefaultComponent
extension
- the extension to unregisterpublic void unregisterMimetype(String mimetypeName)
public void unregisterFileExtension(ExtensionDescriptor extensionDescriptor)
public RuntimeContext getContext()
public List<String> getExtensionsFromMimetypeName(String mimetypeName)
MimetypeRegistry
getExtensionsFromMimetypeName
in interface MimetypeRegistry
mimetypeName
- the mimetype name.public MimetypeEntry getMimetypeEntryByName(String name)
MimetypeRegistry
getMimetypeEntryByName
in interface MimetypeRegistry
name
- the mimetype name.public String getMimetypeFromFile(File file) throws MimetypeNotFoundException, MimetypeDetectionException
MimetypeRegistry
getMimetypeFromFile
in interface MimetypeRegistry
MimetypeNotFoundException
- if mimetype sniffing failedMimetypeDetectionException
- if unexpected problem prevent the detection to work as expectedpublic String getMimetypeFromExtension(String extension) throws MimetypeNotFoundException
MimetypeRegistry
getMimetypeFromExtension
in interface MimetypeRegistry
MimetypeNotFoundException
public String getMimetypeFromFilename(String filename) throws MimetypeNotFoundException
MimetypeRegistry
getMimetypeFromFilename
in interface MimetypeRegistry
MimetypeNotFoundException
@Deprecated public String getMimetypeFromStream(InputStream stream) throws MimetypeNotFoundException, MimetypeDetectionException
MimetypeRegistry
getMimetypeFromStream
in interface MimetypeRegistry
MimetypeNotFoundException
- 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 MimetypeRegistry
is
- content to be analyzeddefaultMimetype
- default mimetype to be used if no foundMimetypeDetectionException
public String getMimetypeFromBlob(Blob blob) throws MimetypeNotFoundException, MimetypeDetectionException
MimetypeRegistry
getMimetypeFromBlob
in interface MimetypeRegistry
MimetypeNotFoundException
- if mimetype sniffing failed to identify a registered mime typeMimetypeDetectionException
- if unexpected problem prevent the detection to work as expectedpublic MimetypeEntry getMimetypeEntryByMimeType(String mimetype)
MimetypeRegistry
getMimetypeEntryByMimeType
in interface MimetypeRegistry
mimetype
- the normalized mimetypepublic String getMimetypeFromBlobWithDefault(Blob blob, String defaultMimetype) throws MimetypeDetectionException
getMimetypeFromBlobWithDefault
in interface MimetypeRegistry
blob
- content to be analyzeddefaultMimetype
- defaultMimeType to be used if no foundMimetypeDetectionException
public String getMimetypeFromFilenameAndBlobWithDefault(String filename, Blob blob, String defaultMimetype) throws MimetypeDetectionException
getMimetypeFromFilenameAndBlobWithDefault
in interface MimetypeRegistry
filename
- extension to analyzeblob
- content to be analyzed if filename is ambiguousdefaultMimetype
- defaultMimeType to be used if no foundMimetypeDetectionException
public Blob updateMimetype(Blob blob, String filename) throws MimetypeDetectionException
MimetypeRegistry
updateMimetype
in interface MimetypeRegistry
blob
- content to be analyzed if filename is ambiguousfilename
- with extension to analyzeMimetypeDetectionException
public Blob updateMimetype(Blob blob) throws MimetypeDetectionException
MimetypeRegistry
updateMimetype
in interface MimetypeRegistry
blob
- content to be analyzed if filename is ambiguousMimetypeDetectionException
Copyright © 2015 Nuxeo SA. All rights reserved.