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 Details

  • Constructor Details

    • MimetypeRegistryService

      public MimetypeRegistryService()
  • Method Details

    • 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. Use isMimeTypeNormalized(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 interface Component
      Overrides:
      activate in class DefaultComponent
      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 interface Component
      Overrides:
      deactivate in class DefaultComponent
      Parameters:
      context - the runtime context
    • registerExtension

      public void registerExtension(Extension extension)
      Description copied from interface: Extensible
      Registers the given extension.
      Specified by:
      registerExtension in interface Extensible
      Overrides:
      registerExtension in class DefaultComponent
      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 interface Extensible
      Overrides:
      unregisterExtension in class DefaultComponent
      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 interface MimetypeRegistry
      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 interface MimetypeRegistry
      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 interface MimetypeRegistry
      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 interface MimetypeRegistry
      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 interface MimetypeRegistry
      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 interface MimetypeRegistry
      Returns:
      String mime type name.
    • getMimetypeEntryByMimeType

      public MimetypeEntry getMimetypeEntryByMimeType(String mimetype)
      Description copied from interface: MimetypeRegistry
      Gets the MimetypeEntry for a given mime type.
      Specified by:
      getMimetypeEntryByMimeType in interface MimetypeRegistry
      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 interface MimetypeRegistry
      Parameters:
      blob - content to be analyzed
      defaultMimetype - 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 interface MimetypeRegistry
      Parameters:
      filename - extension to analyze
      blob - content to be analyzed if filename is ambiguous
      defaultMimetype - 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 interface MimetypeRegistry
      Parameters:
      filename - extension to analyze
      blob - content to be analyzed if filename is ambiguous
      defaultMimetype - 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 is null, the provided filename is embedded into the blob as well.
      Specified by:
      updateMimetype in interface MimetypeRegistry
      Parameters:
      blob - content to be analyzed if filename is ambiguous
      filename - with extension to analyze
      withBlobMimetypeFallback - 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 is null, the provided filename is embedded into the blob as well.
      Specified by:
      updateMimetype in interface MimetypeRegistry
      Parameters:
      blob - content to be analyzed if filename is ambiguous
      filename - 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 is null for performance reasons (+ the fact that binary sniffing is no very reliable).
      Specified by:
      updateMimetype in interface MimetypeRegistry
      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 given mimeType.
      Specified by:
      getNormalizedMimeType in interface MimetypeRegistry
      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 empty Optional
    • isMimeTypeNormalized

      public boolean isMimeTypeNormalized(String mimeType)
      Description copied from interface: MimetypeRegistry
      Checks if the given mimeType is a normalized one.
      Specified by:
      isMimeTypeNormalized in interface MimetypeRegistry
      Parameters:
      mimeType - the mime type to check
      Returns:
      true if mimeType is normalized, false otherwise