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>extensionRegistrystatic longMAX_SIZE_FOR_SCANprotected Map<String,MimetypeEntry>mimetypeByExtensionRegistryprotected Map<String,MimetypeEntry>mimetypeByNormalisedRegistrystatic StringMSOFFICE_TMP_PREFIXstatic ComponentNameNAMEstatic StringTMP_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
-
-
Constructor Summary
Constructors Constructor Description MimetypeRegistryService()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidactivate(ComponentContext context)Activates the component.voiddeactivate(ComponentContext context)Deactivates the component.RuntimeContextgetContext()List<String>getExtensionsFromMimetypeName(String mimetypeName)Returns the extension for given mime type.MimetypeEntrygetMimetypeEntryByMimeType(String mimetype)Gets theMimetypeEntryfor a given mime type.MimetypeEntrygetMimetypeEntryByName(String name)Gets a mime type entry by name.StringgetMimetypeFromBlob(Blob blob)Returns the mime type from a given stream.StringgetMimetypeFromBlobWithDefault(Blob blob, String defaultMimetype)Finds the mime type of a Blob content and returns provided default if not possible.StringgetMimetypeFromExtension(String extension)Returns the mime type from a given extension.StringgetMimetypeFromFile(File file)Returns the mime type from a given file.StringgetMimetypeFromFilename(String filename)Returns the mime type from a given filename.StringgetMimetypeFromFilenameAndBlobWithDefault(String filename, Blob blob, String defaultMimetype)Finds the mime type of some content according to its filename and / or binary content.StringgetMimetypeFromFilenameWithBlobMimetypeFallback(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 voidinitializeRegistries()protected booleanisMimetypeEntry(String mimetypeName)Deprecated, for removal: This API element is subject to removal in a future version.since 11.1.booleanisMimeTypeNormalized(String mimeType)Checks if the givenmimeTypeis a normalized one.protected booleanisTemporaryFile(String filename)voidregisterExtension(Extension extension)Registers the given extension.voidregisterFileExtension(ExtensionDescriptor extensionDescriptor)voidregisterMimetype(MimetypeEntry mimetype)voidunregisterExtension(Extension extension)Unregisters the given extension.voidunregisterFileExtension(ExtensionDescriptor extensionDescriptor)voidunregisterMimetype(String mimetypeName)BlobupdateMimetype(Blob blob)Updates the mime type field of a Blob based on the embedded filename with fallback to binary sniffing.BlobupdateMimetype(Blob blob, String filename)Updates the mime type field of a Blob based on the provided filename with fallback to binary sniffing.BlobupdateMimetype(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
-
-
Constructor Detail
-
MimetypeRegistryService
public MimetypeRegistryService()
-
-
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:ComponentActivates the component.This method is called by the runtime when a component is activated.
- Specified by:
activatein interfaceComponent- Overrides:
activatein classDefaultComponent- Parameters:
context- the runtime context
-
deactivate
public void deactivate(ComponentContext context)
Description copied from interface:ComponentDeactivates the component.This method is called by the runtime when a component is deactivated.
- Specified by:
deactivatein interfaceComponent- Overrides:
deactivatein classDefaultComponent- Parameters:
context- the runtime context
-
registerExtension
public void registerExtension(Extension extension)
Description copied from interface:ExtensibleRegisters the given extension.- Specified by:
registerExtensionin interfaceExtensible- Overrides:
registerExtensionin 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:ExtensibleUnregisters the given extension.- Specified by:
unregisterExtensionin interfaceExtensible- Overrides:
unregisterExtensionin 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:MimetypeRegistryReturns the extension for given mime type.- Specified by:
getExtensionsFromMimetypeNamein 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:MimetypeRegistryGets a mime type entry by name.- Specified by:
getMimetypeEntryByNamein interfaceMimetypeRegistry- Parameters:
name- the mime type name- Returns:
- the mime type entry that matches the mime type name if it exists,
nullotherwise
-
getMimetypeFromFile
public String getMimetypeFromFile(File file)
Description copied from interface:MimetypeRegistryReturns the mime type from a given file.- Specified by:
getMimetypeFromFilein interfaceMimetypeRegistry- Returns:
- the mime type of the given file
-
getMimetypeFromExtension
public String getMimetypeFromExtension(String extension)
Description copied from interface:MimetypeRegistryReturns the mime type from a given extension.- Specified by:
getMimetypeFromExtensionin 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:MimetypeRegistryReturns the mime type from a given filename.- Specified by:
getMimetypeFromFilenamein 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:MimetypeRegistryReturns the mime type from a given stream.- Specified by:
getMimetypeFromBlobin interfaceMimetypeRegistry- Returns:
- String mime type name.
-
getMimetypeEntryByMimeType
public MimetypeEntry getMimetypeEntryByMimeType(String mimetype)
Description copied from interface:MimetypeRegistryGets theMimetypeEntryfor a given mime type.- Specified by:
getMimetypeEntryByMimeTypein 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_MIMETYPEotherwise
-
getMimetypeFromBlobWithDefault
public String getMimetypeFromBlobWithDefault(Blob blob, String defaultMimetype)
Description copied from interface:MimetypeRegistryFinds the mime type of a Blob content and returns provided default if not possible.- Specified by:
getMimetypeFromBlobWithDefaultin 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:MimetypeRegistryFinds the mime type of some content according to its filename and / or binary content.- Specified by:
getMimetypeFromFilenameAndBlobWithDefaultin 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:MimetypeRegistryFinds the mime type of some content according to its filename or binary mime type or binary content.- Specified by:
getMimetypeFromFilenameWithBlobMimetypeFallbackin 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:MimetypeRegistryUpdates 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:
updateMimetypein 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:MimetypeRegistryUpdates 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:
updateMimetypein 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:MimetypeRegistryUpdates 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 isnullfor performance reasons (+ the fact that binary sniffing is no very reliable).- Specified by:
updateMimetypein 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:MimetypeRegistryRetrieves the normalized mime type for the givenmimeType.- Specified by:
getNormalizedMimeTypein interfaceMimetypeRegistry- Parameters:
mimeType- the mime for which we are looking for the normalized one- Returns:
- an
Optionalwith a present value if the normalized mime type can be found, otherwise an emptyOptional
-
isMimeTypeNormalized
public boolean isMimeTypeNormalized(String mimeType)
Description copied from interface:MimetypeRegistryChecks if the givenmimeTypeis a normalized one.- Specified by:
isMimeTypeNormalizedin interfaceMimetypeRegistry- Parameters:
mimeType- the mime type to check- Returns:
trueifmimeTypeis normalized,falseotherwise
-
-