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
public class MimetypeRegistryService extends DefaultComponent implements MimetypeRegistry
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
Fields Modifier and Type Field Description protected Map<String,ExtensionDescriptor>
extensionRegistry
static long
MAX_SIZE_FOR_SCAN
protected Map<String,MimetypeEntry>
mimetypeByExtensionRegistry
protected Map<String,MimetypeEntry>
mimetypeByNormalisedRegistry
static String
MSOFFICE_TMP_PREFIX
static ComponentName
NAME
static String
TMP_EXTENSION
-
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
Constructors Constructor Description MimetypeRegistryService()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method 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 mime type.MimetypeEntry
getMimetypeEntryByMimeType(String mimetype)
Gets theMimetypeEntry
for a given mime type.MimetypeEntry
getMimetypeEntryByName(String name)
Gets a mime type entry by name.String
getMimetypeFromBlob(Blob blob)
Returns the mime type from a given stream.String
getMimetypeFromBlobWithDefault(Blob blob, String defaultMimetype)
Finds the mime type 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 from a given file.String
getMimetypeFromFilename(String filename)
Returns the mime type from a given filename.String
getMimetypeFromFilenameAndBlobWithDefault(String filename, Blob blob, String defaultMimetype)
Finds the mime type of some content according to its filename and / or binary content.String
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.Optional<String>
getNormalizedMimeType(String mimeType)
Retrieves the normalized mime type for the givenmimeType
.protected void
initializeRegistries()
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)
Blob
updateMimetype(Blob blob)
Updates the mime type field of a Blob based on the embedded filename with fallback to binary sniffing.Blob
updateMimetype(Blob blob, String filename)
Updates the mime type field of a Blob based on the provided filename with fallback to binary sniffing.Blob
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
applicationStarted, getApplicationStartedOrder
-
-
-
-
Field Detail
-
NAME
public static final ComponentName NAME
-
MAX_SIZE_FOR_SCAN
public static final long MAX_SIZE_FOR_SCAN
- See Also:
- Constant Field Values
-
TMP_EXTENSION
public static final String TMP_EXTENSION
- See Also:
- Constant Field Values
-
MSOFFICE_TMP_PREFIX
public static final String MSOFFICE_TMP_PREFIX
- See Also:
- Constant Field Values
-
mimetypeByNormalisedRegistry
protected Map<String,MimetypeEntry> mimetypeByNormalisedRegistry
-
mimetypeByExtensionRegistry
protected Map<String,MimetypeEntry> mimetypeByExtensionRegistry
-
extensionRegistry
protected Map<String,ExtensionDescriptor> extensionRegistry
-
-
Method Detail
-
initializeRegistries
protected void initializeRegistries()
-
isMimetypeEntry
@Deprecated(since="11.1", forRemoval=true) protected boolean isMimetypeEntry(String mimetypeName)
Deprecated, for removal: This API element is subject to removal in a future version.since 11.1. UseisMimeTypeNormalized(String)
instead.
-
activate
public void activate(ComponentContext context)
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
public void deactivate(ComponentContext context)
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
public void registerExtension(Extension extension)
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
public void registerMimetype(MimetypeEntry mimetype)
-
registerFileExtension
public void registerFileExtension(ExtensionDescriptor extensionDescriptor)
-
unregisterExtension
public void unregisterExtension(Extension extension)
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
public void unregisterMimetype(String mimetypeName)
-
unregisterFileExtension
public void unregisterFileExtension(ExtensionDescriptor extensionDescriptor)
-
getContext
public RuntimeContext getContext()
-
getExtensionsFromMimetypeName
public List<String> getExtensionsFromMimetypeName(String mimetypeName)
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
public MimetypeEntry getMimetypeEntryByName(String name)
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
public String getMimetypeFromFile(File file)
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
public String getMimetypeFromExtension(String extension)
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
public String getMimetypeFromFilename(String filename)
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
protected boolean isTemporaryFile(String filename)
-
getMimetypeFromBlob
public String getMimetypeFromBlob(Blob blob)
Description copied from interface:MimetypeRegistry
Returns the mime type from a given stream.- Specified by:
getMimetypeFromBlob
in interfaceMimetypeRegistry
- Returns:
- String mime type name.
-
getMimetypeEntryByMimeType
public MimetypeEntry getMimetypeEntryByMimeType(String mimetype)
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
public String getMimetypeFromBlobWithDefault(Blob blob, String defaultMimetype)
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
public Blob updateMimetype(Blob blob, String filename, Boolean withBlobMimetypeFallback)
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
public Blob updateMimetype(Blob blob, String filename)
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
public Blob updateMimetype(Blob blob)
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
public Optional<String> getNormalizedMimeType(String mimeType)
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
public boolean isMimeTypeNormalized(String mimeType)
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
-
-