Class MimetypeRegistryService

    • Constructor Detail

      • MimetypeRegistryService

        public MimetypeRegistryService()
    • Method Detail

      • initializeRegistries

        protected void initializeRegistries()
      • 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
      • registerMimetype

        public void registerMimetype​(MimetypeEntry mimetype)
      • registerFileExtension

        public void registerFileExtension​(ExtensionDescriptor extensionDescriptor)
      • unregisterMimetype

        public void unregisterMimetype​(String mimetypeName)
      • unregisterFileExtension

        public void unregisterFileExtension​(ExtensionDescriptor extensionDescriptor)
      • 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
      • 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)
      • 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