public class MimeTypeServiceImpl extends Object implements MimeTypeService, org.osgi.framework.BundleListener
MimeTypeServiceImpl
is the official implementation of the
MimeTypeService
interface.Modifier and Type | Class and Description |
---|---|
static interface |
MimeTypeServiceImpl.Config |
Modifier and Type | Field and Description |
---|---|
static String |
CORE_MIME_TYPES |
static String |
MIME_TYPES |
Constructor and Description |
---|
MimeTypeServiceImpl() |
Modifier and Type | Method and Description |
---|---|
protected void |
activate(org.osgi.framework.BundleContext context,
MimeTypeServiceImpl.Config config) |
protected void |
bindMimeTypeProvider(MimeTypeProvider mimeTypeProvider) |
void |
bundleChanged(org.osgi.framework.BundleEvent event) |
protected void |
deactivate(org.osgi.framework.BundleContext context) |
String |
getExtension(String mimeType)
Returns the primary name extension to which the given
mimeType maps. |
Map<String,String> |
getExtensionMap() |
Map<String,String> |
getMimeMap() |
String |
getMimeType(String name)
Returns the MIME type of the extension of the given
name . |
void |
registerMimeType(InputStream mimeTabStream)
Register MIME types stored in the given input stream formatted as a
regular MIME type file format: One entry per line.
|
void |
registerMimeType(String mimeType,
String... extensions)
Dynamically register a new mime type with one or more file name
extensions.
|
protected void |
unbindMimeTypeProvider(MimeTypeProvider mimeTypeProvider) |
public static final String CORE_MIME_TYPES
public static final String MIME_TYPES
public String getMimeType(String name)
MimeTypeService
name
.
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.getMimeType
in interface MimeTypeService
name
- The name for which the MIME type is to be returned.name
is
null
, null
is returned.MimeTypeService.getExtension(String)
public String getExtension(String mimeType)
MimeTypeService
mimeType
maps. The returned extension must map to the given
mimeType
when fed to the MimeTypeService.getMimeType(String)
method. In other words, the expression
mimeType.equals(getMimeType(getExtension(mimeType)))
must
always be true
for any non-null
MIME type.
A MIME type may be mapped to multiple extensions (e.g.
text/plain
to txt
, 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.
getExtension
in interface MimeTypeService
mimeType
- The MIME type whose primary extension is requested.null
if no such mapping exists.MimeTypeService.getMimeType(String)
public void registerMimeType(String mimeType, String... extensions)
MimeTypeService
This registration is dynamic and not persisted.
registerMimeType
in interface MimeTypeService
mimeType
- The MIME type to registerextensions
- One or more file name extensions (without leading dot)
to register for the MIME type.public void registerMimeType(InputStream mimeTabStream) throws IOException
MimeTypeService
#
) are ignored.
The stream is assumed to contain string data encoded with "ISO-8859-1".
This method reads the stream until an IOException
occurs or
until it has been fully read. The stream is not closed, though, by this
method.
registerMimeType
in interface MimeTypeService
mimeTabStream
- The stream to read the MIME type mappings fromIOException
- If an error occurs reading from the streamprotected void activate(org.osgi.framework.BundleContext context, MimeTypeServiceImpl.Config config)
protected void deactivate(org.osgi.framework.BundleContext context)
protected void bindMimeTypeProvider(MimeTypeProvider mimeTypeProvider)
protected void unbindMimeTypeProvider(MimeTypeProvider mimeTypeProvider)
public void bundleChanged(org.osgi.framework.BundleEvent event)
bundleChanged
in interface org.osgi.framework.BundleListener
public Map<String,String> getMimeMap()
getMimeMap
in interface MimeTypeService
public Map<String,String> getExtensionMap()
getExtensionMap
in interface MimeTypeService
Copyright © 2007–2018 The Apache Software Foundation. All rights reserved.