org.modeshape.graph.mimetype
Class MimeTypeDetectors

java.lang.Object
  extended by org.modeshape.graph.mimetype.MimeTypeDetectors
All Implemented Interfaces:
MimeTypeDetector

@ThreadSafe
public final class MimeTypeDetectors
extends Object
implements MimeTypeDetector

Facility for managing MimeTypeDetectorConfigs.


Constructor Summary
MimeTypeDetectors()
           
 
Method Summary
 boolean addDetector(MimeTypeDetectorConfig config)
          Adds the configuration for a MIME-type detector before any previously added configurations, or updates any existing one that represents the same configuration
 ClassLoaderFactory getClassLoaderFactory()
          Gets the class loader factory that should be used to load MIME-type detectors.
 Logger getLogger()
          Gets the logger for this system
 String mimeTypeOf(String name, InputStream content)
          Returns the first non-null result of iterating over the registered MIME-type detectors in the reverse order in which they were registered to determine the MIME-type of a data source, using its supplied content and/or its supplied name, depending upon the implementation.
 boolean removeDetector(MimeTypeDetectorConfig config)
          Removes the configuration for a MIME-type detector.
 void setClassLoaderFactory(ClassLoaderFactory classLoaderFactory)
          Sets the Maven Repository that should be used to load the MIME-type detectors.
 void setLogger(Logger logger)
          Sets the logger for this system.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MimeTypeDetectors

public MimeTypeDetectors()
Method Detail

addDetector

public boolean addDetector(MimeTypeDetectorConfig config)
Adds the configuration for a MIME-type detector before any previously added configurations, or updates any existing one that represents the same configuration

Parameters:
config - the new configuration; must not be null.
Returns:
true if the detector was added, or false if there already was an existing detector configuration.
See Also:
removeDetector(MimeTypeDetectorConfig)

getClassLoaderFactory

public ClassLoaderFactory getClassLoaderFactory()
Gets the class loader factory that should be used to load MIME-type detectors. By default, this service uses a factory that will return either the current thread's context class loader, or if null the class loader for this class.

Returns:
the class loader factory; never null
See Also:
setClassLoaderFactory(ClassLoaderFactory)

getLogger

public Logger getLogger()
Gets the logger for this system

Returns:
the logger

mimeTypeOf

public String mimeTypeOf(String name,
                         InputStream content)
                  throws IOException
Returns the first non-null result of iterating over the registered MIME-type detectors in the reverse order in which they were registered to determine 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 by any registered detector, "text/plain" or "application/octet-stream" will be returned, the former only if it is determined the stream contains no nulls.

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; never null.
Throws:
IOException - If an error occurs reading the supplied content.

removeDetector

public boolean removeDetector(MimeTypeDetectorConfig config)
Removes the configuration for a MIME-type detector.

Parameters:
config - the configuration to be removed; must not be null.
Returns:
true if the configuration was removed, or false if there was no existing configuration
See Also:
addDetector(MimeTypeDetectorConfig)

setClassLoaderFactory

public void setClassLoaderFactory(ClassLoaderFactory classLoaderFactory)
Sets the Maven Repository that should be used to load the MIME-type detectors. By default, this service uses a factory that will return either the current thread's context class loader, or if null the class loader for this class.

Parameters:
classLoaderFactory - the class loader factory, or null if the default class loader factory should be used.
See Also:
getClassLoaderFactory()

setLogger

public void setLogger(Logger logger)
Sets the logger for this system.

Parameters:
logger - the logger, or null if the standard logging should be used


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