org.mycore.datamodel.ifs
Class MCRFileContentTypeFactory

java.lang.Object
  extended by org.mycore.datamodel.ifs.MCRFileContentTypeFactory

public class MCRFileContentTypeFactory
extends Object

Provides methods to get the file content type with a given ID, or to detect the file content type by providing file content header and filename. The list of known file content types is defined in an XML file that is specified in the property MCR.IFS.FileContentTypes.DefinitionFile, and that file is searched in the CLASSPATH directories or JAR files. The class that implements the file content type detector must be specified by the configuration property MCR.IFS.FileContentTypes.DetectorClass.

Author:
Frank Lützenkirchen

Field Summary
protected static MCRFileContentType defaultType
          The default file content type if unknown
protected static MCRFileContentTypeDetector detector
          The file content type detector implementation that is used
protected static Hashtable typesTable
          Table for looking up all file content types by ID
 
Constructor Summary
MCRFileContentTypeFactory()
           
 
Method Summary
static MCRFileContentType detectType(String filename, byte[] header)
          Detects the file content type from filename and file content header.
static MCRFileContentType getDefaultType()
          Returns the default file content type to be used if content type is unknown
static MCRFileContentType getType(String ID)
          Returns the file content type with the given ID
static boolean isTypeAvailable(String ID)
          Returns true if the file content type with the given ID is configured
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

typesTable

protected static Hashtable typesTable
Table for looking up all file content types by ID


defaultType

protected static MCRFileContentType defaultType
The default file content type if unknown


detector

protected static MCRFileContentTypeDetector detector
The file content type detector implementation that is used

Constructor Detail

MCRFileContentTypeFactory

public MCRFileContentTypeFactory()
Method Detail

getType

public static MCRFileContentType getType(String ID)
                                  throws MCRConfigurationException
Returns the file content type with the given ID

Parameters:
ID - The non-null ID of the content type that should be returned
Returns:
The file content type with the given ID
Throws:
MCRConfigurationException - if no such file content type is known in the system

isTypeAvailable

public static boolean isTypeAvailable(String ID)
                               throws MCRConfigurationException
Returns true if the file content type with the given ID is configured

Parameters:
ID - The non-null ID of the content type that should be returned
Returns:
true if content type is available, else false
Throws:
MCRConfigurationException

getDefaultType

public static MCRFileContentType getDefaultType()
Returns the default file content type to be used if content type is unknown


detectType

public static MCRFileContentType detectType(String filename,
                                            byte[] header)
Detects the file content type from filename and file content header.

Parameters:
filename - the name of the file, may be null
header - the first bytes of the file header, may be null or empty
Returns:
the file content type detected, or the default file content type if detection was not possible