Class MimeTypeServiceImpl
- java.lang.Object
-
- org.apache.sling.commons.mime.internal.MimeTypeServiceImpl
-
- All Implemented Interfaces:
java.util.EventListener,MimeTypeService,org.osgi.framework.BundleListener
public class MimeTypeServiceImpl extends java.lang.Object implements MimeTypeService, org.osgi.framework.BundleListener
TheMimeTypeServiceImplis the official implementation of theMimeTypeServiceinterface.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceMimeTypeServiceImpl.Config
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCORE_MIME_TYPESstatic java.lang.StringMIME_TYPES
-
Constructor Summary
Constructors Constructor Description MimeTypeServiceImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidactivate(org.osgi.framework.BundleContext context, MimeTypeServiceImpl.Config config)protected voidbindMimeTypeProvider(MimeTypeProvider mimeTypeProvider)voidbundleChanged(org.osgi.framework.BundleEvent event)protected voiddeactivate(org.osgi.framework.BundleContext context)java.lang.StringgetExtension(java.lang.String mimeType)Returns the primary name extension to which the givenmimeTypemaps.java.util.Map<java.lang.String,java.lang.String>getExtensionMap()java.util.Map<java.lang.String,java.lang.String>getMimeMap()java.lang.StringgetMimeType(java.lang.String name)Returns the MIME type of the extension of the givenname.voidregisterMimeType(java.io.InputStream mimeTabStream)Register MIME types stored in the given input stream formatted as a regular MIME type file format: One entry per line.voidregisterMimeType(java.lang.String mimeType, java.lang.String... extensions)Dynamically register a new mime type with one or more file name extensions.protected voidunbindMimeTypeProvider(MimeTypeProvider mimeTypeProvider)
-
-
-
Field Detail
-
CORE_MIME_TYPES
public static final java.lang.String CORE_MIME_TYPES
- See Also:
- Constant Field Values
-
MIME_TYPES
public static final java.lang.String MIME_TYPES
- See Also:
- Constant Field Values
-
-
Method Detail
-
getMimeType
public java.lang.String getMimeType(java.lang.String name)
Description copied from interface:MimeTypeServiceReturns the MIME type of the extension of the givenname. The extension is the part of the name after the last dot. If the name does not contain a dot, the name as a whole is assumed to be the extension.- Specified by:
getMimeTypein interfaceMimeTypeService- Parameters:
name- The name for which the MIME type is to be returned.- Returns:
- The MIME type for the extension of the name. If the extension
cannot be mapped to a MIME type or
nameisnull,nullis returned. - See Also:
MimeTypeService.getExtension(String)
-
getExtension
public java.lang.String getExtension(java.lang.String mimeType)
Description copied from interface:MimeTypeServiceReturns the primary name extension to which the givenmimeTypemaps. The returned extension must map to the givenmimeTypewhen fed to theMimeTypeService.getMimeType(String)method. In other words, the expressionmimeType.equals(getMimeType(getExtension(mimeType)))must always betruefor any non-nullMIME type.A MIME type may be mapped to multiple extensions (e.g.
text/plaintotxt,log, ...). This method is expected to returned one of those extensions. It is up to the implementation to select an appropriate extension if multiple mappings exist for a single MIME type.- Specified by:
getExtensionin interfaceMimeTypeService- Parameters:
mimeType- The MIME type whose primary extension is requested.- Returns:
- A extension which maps to the given MIME type or
nullif no such mapping exists. - See Also:
MimeTypeService.getMimeType(String)
-
registerMimeType
public void registerMimeType(java.lang.String mimeType, java.lang.String... extensions)Description copied from interface:MimeTypeServiceDynamically register a new mime type with one or more file name extensions. The first of those extensions is assumed to be default file name extension.This registration is dynamic and not persisted.
- Specified by:
registerMimeTypein interfaceMimeTypeService- Parameters:
mimeType- The MIME type to registerextensions- One or more file name extensions (without leading dot) to register for the MIME type.
-
registerMimeType
public void registerMimeType(java.io.InputStream mimeTabStream) throws java.io.IOExceptionDescription copied from interface:MimeTypeServiceRegister MIME types stored in the given input stream formatted as a regular MIME type file format: One entry per line. Each entry consists of two or more whitespace delimited fields where the first field is the MIME type and the rest of the fields are the file extensions. The first of the extensions is considered the default extension. Empty lines and lines starting with a hash sign (#) are ignored.The stream is assumed to contain string data encoded with "ISO-8859-1".
This method reads the stream until an
IOExceptionoccurs or until it has been fully read. The stream is not closed, though, by this method.- Specified by:
registerMimeTypein interfaceMimeTypeService- Parameters:
mimeTabStream- The stream to read the MIME type mappings from- Throws:
java.io.IOException- If an error occurs reading from the stream
-
activate
protected void activate(org.osgi.framework.BundleContext context, MimeTypeServiceImpl.Config config)
-
deactivate
protected void deactivate(org.osgi.framework.BundleContext context)
-
bindMimeTypeProvider
protected void bindMimeTypeProvider(MimeTypeProvider mimeTypeProvider)
-
unbindMimeTypeProvider
protected void unbindMimeTypeProvider(MimeTypeProvider mimeTypeProvider)
-
bundleChanged
public void bundleChanged(org.osgi.framework.BundleEvent event)
- Specified by:
bundleChangedin interfaceorg.osgi.framework.BundleListener
-
getMimeMap
public java.util.Map<java.lang.String,java.lang.String> getMimeMap()
- Specified by:
getMimeMapin interfaceMimeTypeService
-
getExtensionMap
public java.util.Map<java.lang.String,java.lang.String> getExtensionMap()
- Specified by:
getExtensionMapin interfaceMimeTypeService
-
-