Nuxeo ECM Projects 5.4.3-SNAPSHOT

org.nuxeo.ecm.platform.mimetype.service
Class MimetypeRegistryService

java.lang.Object
  extended by org.nuxeo.runtime.model.DefaultComponent
      extended by org.nuxeo.ecm.platform.mimetype.service.MimetypeRegistryService
All Implemented Interfaces:
MimetypeRegistry, Adaptable, Component, Extensible

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
static ComponentName NAME
           
 
Fields inherited from interface org.nuxeo.ecm.platform.mimetype.interfaces.MimetypeRegistry
DEFAULT_MIMETYPE
 
Constructor Summary
MimetypeRegistryService()
           
 
Method Summary
 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 mimetype.
 MimetypeEntry getMimetypeEntryByMimeType(String mimetype)
          Gets a mimetype entry given the normalized mimetype.
 MimetypeEntry getMimetypeEntryByName(String name)
          Gets a mimetype entry by name.
 String getMimetypeFromBlob(Blob blob)
          Returns the mime type from a given stream.
 String getMimetypeFromBlobWithDefault(Blob blob, String defaultMimetype)
          Finds the mimetype of a Blob content and returns provided default if not possible.
 String getMimetypeFromExtension(String extension)
           
 String getMimetypeFromFile(File file)
          Returns the mime type given a file.
 String getMimetypeFromFilename(String filename)
           
 String getMimetypeFromFilenameAndBlobWithDefault(String filename, Blob blob, String defaultMimetype)
          Finds the mimetype of some content according to its filename and / or binary content.
 String getMimetypeFromStream(InputStream stream)
          Deprecated. 
 String getMimetypeFromStreamWithDefault(InputStream is, String defaultMimetype)
          Deprecated. 
 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)
          Update the mimetype field of a Blob based on the embedded filename with fallback to binary sniffing.
 Blob updateMimetype(Blob blob, String filename)
          Update the mimetype field of a Blob based on the provided filename with fallback to binary sniffing.
 
Methods inherited from class org.nuxeo.runtime.model.DefaultComponent
applicationStarted, getAdapter, registerContribution, unregisterContribution
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NAME

public static final ComponentName NAME
Constructor Detail

MimetypeRegistryService

public MimetypeRegistryService()
Method Detail

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 mimetype.

Specified by:
getExtensionsFromMimetypeName in interface MimetypeRegistry
Parameters:
mimetypeName - the mimetype name.
Returns:
a list of strings containing the possible extensions.

getMimetypeEntryByName

public MimetypeEntry getMimetypeEntryByName(String name)
Description copied from interface: MimetypeRegistry
Gets a mimetype entry by name.

Specified by:
getMimetypeEntryByName in interface MimetypeRegistry
Parameters:
name - the mimetype name.
Returns:
mimetype instance

getMimetypeFromFile

public String getMimetypeFromFile(File file)
                           throws MimetypeNotFoundException,
                                  MimetypeDetectionException
Description copied from interface: MimetypeRegistry
Returns the mime type given a file.

Specified by:
getMimetypeFromFile in interface MimetypeRegistry
Returns:
string containing the mime type
Throws:
MimetypeNotFoundException - if mimetype sniffing failed
MimetypeDetectionException - if unexpected problem prevent the detection to work as expected

getMimetypeFromExtension

public String getMimetypeFromExtension(String extension)
                                throws MimetypeNotFoundException
Throws:
MimetypeNotFoundException

getMimetypeFromFilename

public String getMimetypeFromFilename(String filename)
                               throws MimetypeNotFoundException
Throws:
MimetypeNotFoundException

getMimetypeFromStream

@Deprecated
public String getMimetypeFromStream(InputStream stream)
                             throws MimetypeNotFoundException,
                                    MimetypeDetectionException
Deprecated. 

Description copied from interface: MimetypeRegistry
Returns the mime type from a given stream.

Specified by:
getMimetypeFromStream in interface MimetypeRegistry
Returns:
String mimetype name.
Throws:
MimetypeNotFoundException - if mimetype sniffing failed to identify a registered mime type
MimetypeDetectionException - if unexpected problem prevent the detection to work as expected

getMimetypeFromStreamWithDefault

@Deprecated
public String getMimetypeFromStreamWithDefault(InputStream is,
                                                          String defaultMimetype)
                                        throws MimetypeDetectionException
Deprecated. 

Finds the mimetype of a stream content and returns provided default if not possible.

Specified by:
getMimetypeFromStreamWithDefault in interface MimetypeRegistry
Parameters:
is - content to be analyzed
defaultMimetype - default mimetype to be used if no found
Returns:
the string mimetype
Throws:
MimetypeDetectionException

getMimetypeFromBlob

public String getMimetypeFromBlob(Blob blob)
                           throws MimetypeNotFoundException,
                                  MimetypeDetectionException
Description copied from interface: MimetypeRegistry
Returns the mime type from a given stream.

Specified by:
getMimetypeFromBlob in interface MimetypeRegistry
Returns:
String mimetype name.
Throws:
MimetypeNotFoundException - if mimetype sniffing failed to identify a registered mime type
MimetypeDetectionException - if unexpected problem prevent the detection to work as expected

getMimetypeEntryByMimeType

public MimetypeEntry getMimetypeEntryByMimeType(String mimetype)
Description copied from interface: MimetypeRegistry
Gets a mimetype entry given the normalized mimetype.

Specified by:
getMimetypeEntryByMimeType in interface MimetypeRegistry
Parameters:
mimetype - the normalized mimetype
Returns:
mimetype instance

getMimetypeFromBlobWithDefault

public String getMimetypeFromBlobWithDefault(Blob blob,
                                             String defaultMimetype)
                                      throws MimetypeDetectionException
Finds the mimetype 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 string mimetype
Throws:
MimetypeDetectionException

getMimetypeFromFilenameAndBlobWithDefault

public String getMimetypeFromFilenameAndBlobWithDefault(String filename,
                                                        Blob blob,
                                                        String defaultMimetype)
                                                 throws MimetypeDetectionException
Finds the mimetype 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 string mimetype
Throws:
MimetypeDetectionException

updateMimetype

public Blob updateMimetype(Blob blob,
                           String filename)
                    throws MimetypeDetectionException
Description copied from interface: MimetypeRegistry
Update the mimetype 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)
Throws:
MimetypeDetectionException

updateMimetype

public Blob updateMimetype(Blob blob)
                    throws MimetypeDetectionException
Description copied from interface: MimetypeRegistry
Update the mimetype 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)
Throws:
MimetypeDetectionException

Nuxeo ECM Projects 5.4.3-SNAPSHOT

Copyright © 2011 Nuxeo SAS. All Rights Reserved.