org.modeshape.graph.mimetype
Class ExtensionBasedMimeTypeDetector

java.lang.Object
  extended by org.modeshape.common.util.MimeTypeUtil
      extended by org.modeshape.graph.mimetype.ExtensionBasedMimeTypeDetector
All Implemented Interfaces:
MimeTypeDetector

@Immutable
public class ExtensionBasedMimeTypeDetector
extends MimeTypeUtil
implements MimeTypeDetector

A MimeTypeDetector that attempts to match the extension of the supplied name against a set of known file extensions.


Field Summary
 
Fields inherited from class org.modeshape.common.util.MimeTypeUtil
MIME_TYPE_EXTENSIONS_RESOURCE_PATH
 
Constructor Summary
ExtensionBasedMimeTypeDetector()
          Create a default instance of the extension-based MIME type detector.
ExtensionBasedMimeTypeDetector(Map<String,String> extensionsToMimeTypes)
          Create an instance of the extension-based MIME type detector by using the supplied mappings.
ExtensionBasedMimeTypeDetector(Map<String,String> extensionsToMimeTypes, boolean initWithDefaults)
          Create an instance of the extension-based MIME type detector by using the supplied mappings.
 
Method Summary
 String mimeTypeOf(String name, InputStream content)
          Returns the MIME-type of a data source, using its supplied content and/or its supplied name, depending upon the implementation.
 
Methods inherited from class org.modeshape.common.util.MimeTypeUtil
load, mimeTypeOf, mimeTypeOf
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExtensionBasedMimeTypeDetector

public ExtensionBasedMimeTypeDetector()
Create a default instance of the extension-based MIME type detector. The set of extension patterns to MIME-types is loaded from the "org/modeshape/graph/mime.types" classpath resource.


ExtensionBasedMimeTypeDetector

public ExtensionBasedMimeTypeDetector(Map<String,String> extensionsToMimeTypes)
Create an instance of the extension-based MIME type detector by using the supplied mappings. The set of extension patterns to MIME-types is loaded from the "org/modeshape/graph/mime.types" classpath resource, but the supplied extension mappings override any default mappings.

Parameters:
extensionsToMimeTypes - the mapping of extension patterns to MIME types, which will override the default mappings; may be null if the default mappings are to be used

ExtensionBasedMimeTypeDetector

public ExtensionBasedMimeTypeDetector(Map<String,String> extensionsToMimeTypes,
                                      boolean initWithDefaults)
Create an instance of the extension-based MIME type detector by using the supplied mappings. If requested, the set of extension patterns to MIME-types is loaded from the "org/modeshape/graph/mime.types" classpath resource and any supplied extension mappings override any default mappings.

Parameters:
extensionsToMimeTypes - the mapping of extension patterns to MIME types, which will override the default mappings; may be null if the default mappings are to be used
initWithDefaults - true if the default mappings are to be loaded first
Method Detail

mimeTypeOf

public String mimeTypeOf(String name,
                         InputStream content)
Returns the MIME-type of a data source, using its supplied content and/or its supplied name, depending upon the implementation. If the MIME-type cannot be determined, either a "default" MIME-type or null may be returned, where the former will prevent earlier registered MIME-type detectors from being consulted.

Note that detector implementations should not close the supplied input stream.

Specified by:
mimeTypeOf in interface MimeTypeDetector
Parameters:
name - The name of the data source; may be null.
content - The content of the data source; may be null.
Returns:
The MIME-type of the data source, or optionally null if the MIME-type could not be determined.
See Also:
MimeTypeDetector.mimeTypeOf(java.lang.String, java.io.InputStream)


Copyright © 2008-2010 JBoss, a division of Red Hat. All Rights Reserved.