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 |
lastModifiedDEFAULT_MIMETYPE, PDF_EXTENSION, PDF_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 |
getMimetypeFromFilenameWithBlobMimetypeFallback(String filename,
Blob blob,
String defaultMimetype)
Finds the mimetype of some content according to its filename or binary mime type or binary content.
|
protected void |
initializeRegistries() |
protected boolean |
isMimetypeEntry(String mimetypeName) |
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.
|
Blob |
updateMimetype(Blob blob,
String filename,
Boolean withBlobMimetypeFallback)
Update the mimetype field of a Blob based on the provided filename with fallback to binary.
|
getAdapter, getLastModified, registerContribution, setLastModified, setModifiedNow, start, stop, unregisterContributionclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitapplicationStarted, getApplicationStartedOrderpublic 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()
protected boolean isMimetypeEntry(String mimetypeName)
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
MimetypeRegistrygetMimetypeFromExtension in interface MimetypeRegistryMimetypeNotFoundExceptionpublic String getMimetypeFromFilename(String filename) throws MimetypeNotFoundException
MimetypeRegistrygetMimetypeFromFilename in interface MimetypeRegistryMimetypeNotFoundExceptionpublic 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
MimetypeRegistrygetMimetypeFromBlobWithDefault in interface MimetypeRegistryblob - content to be analyzeddefaultMimetype - defaultMimeType to be used if no foundMimetypeDetectionExceptionpublic String getMimetypeFromFilenameAndBlobWithDefault(String filename, Blob blob, String defaultMimetype) throws MimetypeDetectionException
MimetypeRegistrygetMimetypeFromFilenameAndBlobWithDefault in interface MimetypeRegistryfilename - extension to analyzeblob - content to be analyzed if filename is ambiguousdefaultMimetype - defaultMimeType to be used if no foundMimetypeDetectionExceptionpublic String getMimetypeFromFilenameWithBlobMimetypeFallback(String filename, Blob blob, String defaultMimetype) throws MimetypeDetectionException
MimetypeRegistrygetMimetypeFromFilenameWithBlobMimetypeFallback 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, Boolean withBlobMimetypeFallback) throws MimetypeDetectionException
MimetypeRegistryupdateMimetype in interface MimetypeRegistryblob - content to be analyzed if filename is ambiguousfilename - with extension to analyzewithBlobMimetypeFallback - to consider blob mimetype as fallback or notMimetypeDetectionExceptionpublic 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 © 2018 Nuxeo. All rights reserved.