org.mycore.datamodel.ifs
Class MCRSimpleFCTDetector

java.lang.Object
  extended by org.mycore.datamodel.ifs.MCRSimpleFCTDetector
All Implemented Interfaces:
MCRFileContentTypeDetector

public class MCRSimpleFCTDetector
extends Object
implements MCRFileContentTypeDetector

A simple implementation of an MCRFileContentTypeDetector, detects the file type based on the filename extension and a magic bytes pattern at some offset in the header of the file's content. The rules for detecting each file type are embedded in the <rules> element of the file content types definition XML file.

Version:
$Revision: 13085 $ $Date: 2008-02-06 18:27:24 +0100 (Mi, 06 Feb 2008) $
Author:
Frank Lützenkirchen
See Also:
MCRFileContentTypeDetector, MCRFileContentType, MCRFileContentTypeFactory

Nested Class Summary
(package private)  class MCRSimpleFCTDetector.MCRDetectionRule
          Common superclass of different kinds of detection rules
(package private)  class MCRSimpleFCTDetector.MCRDoctypeRule
          A rule that decides based on the doctype of a xml file
(package private)  class MCRSimpleFCTDetector.MCRExtensionRule
          A rule that decides based on the file extension
(package private)  class MCRSimpleFCTDetector.MCRPatternRule
          A rule that decides based on a magic bytes pattern that has to occur in the file header at a given offset
(package private)  class MCRSimpleFCTDetector.MCRStringRule
          A rule that decides based on a String at any position in the head of the file
 
Constructor Summary
MCRSimpleFCTDetector()
          Creates a new detector
 
Method Summary
 void addRule(MCRFileContentType type, Element xRules)
          Adds a detection rule from the file content type definition XML file.
 MCRFileContentType detectType(String filename, byte[] header)
          Detects the file content type from filename and/or file header.
protected  String parseDocumentType(InputStream in)
          Copy from MCRLayoutServlet, messages changed from MCRLayoutServlet to MCRSimpleFCTDetector Try to detect doctype of xml data
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MCRSimpleFCTDetector

public MCRSimpleFCTDetector()
Creates a new detector

Method Detail

addRule

public void addRule(MCRFileContentType type,
                    Element xRules)
Adds a detection rule from the file content type definition XML file. The detector parses the <rules> element provided with each content type in the file content types XML definition.

Specified by:
addRule in interface MCRFileContentTypeDetector
Parameters:
type - the file content type the rule is for
xRules - the rules XML element containing the rules for detecting that type

detectType

public MCRFileContentType detectType(String filename,
                                     byte[] header)
Description copied from interface: MCRFileContentTypeDetector
Detects the file content type from filename and/or file header.

Specified by:
detectType in interface MCRFileContentTypeDetector
Parameters:
filename - the name of the file
header - the first bytes of the file content
Returns:
the file content type detected, or null if detection was not possible

parseDocumentType

protected String parseDocumentType(InputStream in)
Copy from MCRLayoutServlet, messages changed from MCRLayoutServlet to MCRSimpleFCTDetector Try to detect doctype of xml data

Parameters:
in - xml data
Returns:
detected doctype