org.mycore.datamodel.ifs.extractors
Class MCRDataExtractor

java.lang.Object
  extended by org.mycore.common.events.MCREventHandlerBase
      extended by org.mycore.datamodel.ifs.extractors.MCRDataExtractor
All Implemented Interfaces:
MCREventHandler
Direct Known Subclasses:
MCRDataExtractorJPEG, MCRDataExtractorMP3, MCRDataExtractorPDF

public abstract class MCRDataExtractor
extends MCREventHandlerBase

Event handler that extracts data like technical metadata (ID3 from MP3, EXIF from JPEG etc.) whenever an MCRFile's content is changed. The extracted data is stored in MCRFile's additional xml data.

Version:
$Revision: 13085 $ $Date: 2008-02-06 18:27:24 +0100 (Mi, 06 Feb 2008) $
Author:
Frank Lützenkirchen
See Also:
org.mycore.datamodel.ifs.MCRFilesystemNode#getAdditionalData()

Constructor Summary
MCRDataExtractor()
           
 
Method Summary
protected  void addDataValue(Element parent, String name, String value)
          Adds extracted metadata value to the resulting XML output, if it is not null or empty.
protected abstract  void extractData(Element container, InputStream in)
          Extracts metadata from a file.
protected abstract  String getSupportedContentTypeIDs()
          Returns the IDs of the FileContentTypes that are supported by this metadata extractor.
protected  void handleFileCreated(MCREvent evt, MCRFile file)
          Handles file created events.
protected  void handleFileUpdated(MCREvent evt, MCRFile file)
          Handles file updated events.
protected  String outputData(Element data)
          Returns the XML data element as a String
protected  void testLocalFile(String filePath)
          Convenience method that prints out extracted data of a local file
 
Methods inherited from class org.mycore.common.events.MCREventHandlerBase
doHandleEvent, doNothing, handleClassificationCreated, handleClassificationDeleted, handleClassificationRepaired, handleClassificationUpdated, handleDerivateCreated, handleDerivateDeleted, handleDerivateRepaired, handleDerivateUpdated, handleFileDeleted, handleFileRepaired, handleObjectCreated, handleObjectDeleted, handleObjectRepaired, handleObjectUpdated, undoClassificationCreated, undoClassificationDeleted, undoClassificationRepaired, undoClassificationUpdated, undoDerivateCreated, undoDerivateDeleted, undoDerivateRepaired, undoDerivateUpdated, undoFileCreated, undoFileDeleted, undoFileRepaired, undoFileUpdated, undoHandleEvent, undoObjectCreated, undoObjectDeleted, undoObjectRepaired, undoObjectUpdated
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MCRDataExtractor

public MCRDataExtractor()
Method Detail

testLocalFile

protected void testLocalFile(String filePath)
Convenience method that prints out extracted data of a local file

Parameters:
filePath - the path of the file to be tested

outputData

protected String outputData(Element data)
Returns the XML data element as a String

Parameters:
data - the extracted data as XML element
Returns:
the XML pretty-outputted as a String

handleFileCreated

protected void handleFileCreated(MCREvent evt,
                                 MCRFile file)
Description copied from class: MCREventHandlerBase
Handles file created events. This implementation does nothing and should be overwritted by subclasses.

Overrides:
handleFileCreated in class MCREventHandlerBase
Parameters:
evt - the event that occured
file - the MCRFile that caused the event

handleFileUpdated

protected void handleFileUpdated(MCREvent evt,
                                 MCRFile file)
Description copied from class: MCREventHandlerBase
Handles file updated events. This implementation does nothing and should be overwritted by subclasses.

Overrides:
handleFileUpdated in class MCREventHandlerBase
Parameters:
evt - the event that occured
file - the MCRFile that caused the event

extractData

protected abstract void extractData(Element container,
                                    InputStream in)
                             throws Exception
Extracts metadata from a file. This method must be overwritten by subclasses.

Parameters:
container - empty XML element that the extractor should fill with data
in - the InputStream to read the file's content from
Throws:
Exception

getSupportedContentTypeIDs

protected abstract String getSupportedContentTypeIDs()
Returns the IDs of the FileContentTypes that are supported by this metadata extractor. Only if the given file matches one of these types, metadata is extracted.

Returns:
a String of supported MCRFileContentType ID(s), separated by spaces

addDataValue

protected void addDataValue(Element parent,
                            String name,
                            String value)
Adds extracted metadata value to the resulting XML output, if it is not null or empty.