org.jboss.dna.graph.mimetype
Class ExtensionBasedMimeTypeDetector

java.lang.Object
  extended by org.jboss.dna.graph.mimetype.ExtensionBasedMimeTypeDetector
All Implemented Interfaces:
MimeTypeDetector

@Immutable
public class ExtensionBasedMimeTypeDetector
extends Object
implements MimeTypeDetector

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

Author:
Randall Hauch

Field Summary
static String MIME_TYPE_EXTENSIONS_RESOURCE_PATH
          The default location of the properties file containing the extension patterns to MIME types.
 
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 java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MIME_TYPE_EXTENSIONS_RESOURCE_PATH

public static final String MIME_TYPE_EXTENSIONS_RESOURCE_PATH
The default location of the properties file containing the extension patterns to MIME types.

See Also:
Constant Field Values
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 "org.jboss.dna.graph.MimeTypes.properties".


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 "org.jboss.dna.graph.MimeTypes.properties", 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 "org.jboss.dna.graph.MimeTypes.properties" 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-Present JBoss a division of Red Hat. All Rights Reserved.