Class MimetypeRegistryService
java.lang.Object
org.nuxeo.runtime.model.DefaultComponent
org.nuxeo.ecm.platform.mimetype.service.MimetypeRegistryService
- All Implemented Interfaces:
MimetypeRegistry
,Adaptable
,Component
,Extensible
,TimestampedService
MimetypeEntry registry service.
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.
- Author:
- Julien Anguenot
-
Field Summary
Modifier and TypeFieldDescriptionprotected Map<String,
ExtensionDescriptor> static final long
protected Map<String,
MimetypeEntry> protected Map<String,
MimetypeEntry> static final String
static final ComponentName
static final String
Fields inherited from class org.nuxeo.runtime.model.DefaultComponent
lastModified, name
Fields inherited from interface org.nuxeo.ecm.platform.mimetype.interfaces.MimetypeRegistry
DEFAULT_MIMETYPE, PDF_EXTENSION, PDF_MIMETYPE, UNDEFINED_MIMETYPE, XML_MIMETYPE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
activate
(ComponentContext context) Activates the component.void
deactivate
(ComponentContext context) Deactivates the component.getExtensionsFromMimetypeName
(String mimetypeName) Returns the extension for given mime type.getMimetypeEntryByMimeType
(String mimetype) Gets theMimetypeEntry
for a given mime type.getMimetypeEntryByName
(String name) Gets a mime type entry by name.getMimetypeFromBlob
(Blob blob) Returns the mime type from a given stream.getMimetypeFromBlobWithDefault
(Blob blob, String defaultMimetype) Finds the mime type of a Blob content and returns provided default if not possible.getMimetypeFromExtension
(String extension) Returns the mime type from a given extension.getMimetypeFromFile
(File file) Returns the mime type from a given file.getMimetypeFromFilename
(String filename) Returns the mime type from a given filename.getMimetypeFromFilenameAndBlobWithDefault
(String filename, Blob blob, String defaultMimetype) Finds the mime type of some content according to its filename and / or binary content.getMimetypeFromFilenameWithBlobMimetypeFallback
(String filename, Blob blob, String defaultMimetype) Finds the mime type of some content according to its filename or binary mime type or binary content.getNormalizedMimeType
(String mimeType) Retrieves the normalized mime type for the givenmimeType
.protected void
protected boolean
isMimetypeEntry
(String mimetypeName) Deprecated, for removal: This API element is subject to removal in a future version.since 11.1.boolean
isMimeTypeNormalized
(String mimeType) Checks if the givenmimeType
is a normalized one.protected boolean
isTemporaryFile
(String filename) 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) updateMimetype
(Blob blob) Updates the mime type field of a Blob based on the embedded filename with fallback to binary sniffing.updateMimetype
(Blob blob, String filename) Updates the mime type field of a Blob based on the provided filename with fallback to binary sniffing.updateMimetype
(Blob blob, String filename, Boolean withBlobMimetypeFallback) Updates the mime type field of a Blob based on the provided filename with fallback to binary.Methods inherited from class org.nuxeo.runtime.model.DefaultComponent
addRuntimeMessage, addRuntimeMessage, getAdapter, getDescriptor, getDescriptors, getLastModified, getRegistry, register, registerContribution, setLastModified, setModifiedNow, setName, start, stop, unregister, unregisterContribution
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.nuxeo.runtime.model.Component
getApplicationStartedOrder
-
Field Details
-
NAME
-
MAX_SIZE_FOR_SCAN
public static final long MAX_SIZE_FOR_SCAN- See Also:
-
TMP_EXTENSION
- See Also:
-
MSOFFICE_TMP_PREFIX
- See Also:
-
mimetypeByNormalisedRegistry
-
mimetypeByExtensionRegistry
-
extensionRegistry
-
-
Constructor Details
-
MimetypeRegistryService
public MimetypeRegistryService()
-
-
Method Details
-
initializeRegistries
protected void initializeRegistries() -
isMimetypeEntry
Deprecated, for removal: This API element is subject to removal in a future version.since 11.1. UseisMimeTypeNormalized(String)
instead. -
activate
Description copied from interface:Component
Activates the component.This method is called by the runtime when a component is activated.
- Specified by:
activate
in interfaceComponent
- Overrides:
activate
in classDefaultComponent
- Parameters:
context
- the runtime context
-
deactivate
Description copied from interface:Component
Deactivates the component.This method is called by the runtime when a component is deactivated.
- Specified by:
deactivate
in interfaceComponent
- Overrides:
deactivate
in classDefaultComponent
- Parameters:
context
- the runtime context
-
registerExtension
Description copied from interface:Extensible
Registers the given extension.- Specified by:
registerExtension
in interfaceExtensible
- Overrides:
registerExtension
in classDefaultComponent
- Parameters:
extension
- the extension to register
-
registerMimetype
-
registerFileExtension
-
unregisterExtension
Description copied from interface:Extensible
Unregisters the given extension.- Specified by:
unregisterExtension
in interfaceExtensible
- Overrides:
unregisterExtension
in classDefaultComponent
- Parameters:
extension
- the extension to unregister
-
unregisterMimetype
-
unregisterFileExtension
-
getContext
-
getExtensionsFromMimetypeName
Description copied from interface:MimetypeRegistry
Returns the extension for given mime type.- Specified by:
getExtensionsFromMimetypeName
in interfaceMimetypeRegistry
- Parameters:
mimetypeName
- the mime type name.- Returns:
- a list of strings containing the possible extensions.
-
getMimetypeEntryByName
Description copied from interface:MimetypeRegistry
Gets a mime type entry by name.- Specified by:
getMimetypeEntryByName
in interfaceMimetypeRegistry
- Parameters:
name
- the mime type name- Returns:
- the mime type entry that matches the mime type name if it exists,
null
otherwise
-
getMimetypeFromFile
Description copied from interface:MimetypeRegistry
Returns the mime type from a given file.- Specified by:
getMimetypeFromFile
in interfaceMimetypeRegistry
- Returns:
- the mime type of the given file
-
getMimetypeFromExtension
Description copied from interface:MimetypeRegistry
Returns the mime type from a given extension.- Specified by:
getMimetypeFromExtension
in interfaceMimetypeRegistry
- Parameters:
extension
- the extension for which we are looking for the mime type- Returns:
- the mime type for the given extension if it exists
-
getMimetypeFromFilename
Description copied from interface:MimetypeRegistry
Returns the mime type from a given filename.- Specified by:
getMimetypeFromFilename
in interfaceMimetypeRegistry
- Parameters:
filename
- the file name for which we are looking for the mime type- Returns:
- the mime type that matches the
filename
-
isTemporaryFile
-
getMimetypeFromBlob
Description copied from interface:MimetypeRegistry
Returns the mime type from a given stream.- Specified by:
getMimetypeFromBlob
in interfaceMimetypeRegistry
- Returns:
- String mime type name.
-
getMimetypeEntryByMimeType
Description copied from interface:MimetypeRegistry
Gets theMimetypeEntry
for a given mime type.- Specified by:
getMimetypeEntryByMimeType
in interfaceMimetypeRegistry
- Parameters:
mimetype
- the mime type for which we are looking for the mime type entry- Returns:
- the mime type entry if it exists,
MimetypeRegistry.DEFAULT_MIMETYPE
otherwise
-
getMimetypeFromBlobWithDefault
Description copied from interface:MimetypeRegistry
Finds the mime type of a Blob content and returns provided default if not possible.- Specified by:
getMimetypeFromBlobWithDefault
in interfaceMimetypeRegistry
- Parameters:
blob
- content to be analyzeddefaultMimetype
- defaultMimeType to be used if no found- Returns:
- the mime type for the given blob if it exists, otherwise it returns
defaultMimetype
-
getMimetypeFromFilenameAndBlobWithDefault
public String getMimetypeFromFilenameAndBlobWithDefault(String filename, Blob blob, String defaultMimetype) Description copied from interface:MimetypeRegistry
Finds the mime type of some content according to its filename and / or binary content.- Specified by:
getMimetypeFromFilenameAndBlobWithDefault
in interfaceMimetypeRegistry
- Parameters:
filename
- extension to analyzeblob
- content to be analyzed if filename is ambiguousdefaultMimetype
- defaultMimeType to be used if no found- Returns:
- the mime type
-
getMimetypeFromFilenameWithBlobMimetypeFallback
public String getMimetypeFromFilenameWithBlobMimetypeFallback(String filename, Blob blob, String defaultMimetype) Description copied from interface:MimetypeRegistry
Finds the mime type of some content according to its filename or binary mime type or binary content.- Specified by:
getMimetypeFromFilenameWithBlobMimetypeFallback
in interfaceMimetypeRegistry
- Parameters:
filename
- extension to analyzeblob
- content to be analyzed if filename is ambiguousdefaultMimetype
- defaultMimeType to be used if no found- Returns:
- the mime type
-
updateMimetype
Description copied from interface:MimetypeRegistry
Updates the mime type field of a Blob based on the provided filename with fallback to binary. If the embedded filename isnull
, the provided filename is embedded into the blob as well.- Specified by:
updateMimetype
in interfaceMimetypeRegistry
- Parameters:
blob
- content to be analyzed if filename is ambiguousfilename
- with extension to analyzewithBlobMimetypeFallback
- to consider blob mime type as fallback or not- Returns:
- updated blob (persisted if necessary)
-
updateMimetype
Description copied from interface:MimetypeRegistry
Updates the mime type field of a Blob based on the provided filename with fallback to binary sniffing. If the embedded filename isnull
, the provided filename is embedded into the blob as well.- Specified by:
updateMimetype
in interfaceMimetypeRegistry
- Parameters:
blob
- content to be analyzed if filename is ambiguousfilename
- with extension to analyze- Returns:
- updated blob (persisted if necessary)
-
updateMimetype
Description copied from interface:MimetypeRegistry
Updates the mime type field of a Blob based on the embedded filename with fallback to binary sniffing. This method should not be called if the embedded filename isnull
for performance reasons (+ the fact that binary sniffing is no very reliable).- Specified by:
updateMimetype
in interfaceMimetypeRegistry
- Parameters:
blob
- content to be analyzed if filename is ambiguous- Returns:
- updated blob (persisted if necessary)
-
getNormalizedMimeType
Description copied from interface:MimetypeRegistry
Retrieves the normalized mime type for the givenmimeType
.- Specified by:
getNormalizedMimeType
in interfaceMimetypeRegistry
- Parameters:
mimeType
- the mime for which we are looking for the normalized one- Returns:
- an
Optional
with a present value if the normalized mime type can be found, otherwise an emptyOptional
-
isMimeTypeNormalized
Description copied from interface:MimetypeRegistry
Checks if the givenmimeType
is a normalized one.- Specified by:
isMimeTypeNormalized
in interfaceMimetypeRegistry
- Parameters:
mimeType
- the mime type to check- Returns:
true
ifmimeType
is normalized,false
otherwise
-