org.vivoweb.harvester.util.repo
Class TextFileRecordHandler

java.lang.Object
  extended by org.vivoweb.harvester.util.repo.RecordHandler
      extended by org.vivoweb.harvester.util.repo.TextFileRecordHandler
All Implemented Interfaces:
java.lang.Iterable<Record>

public class TextFileRecordHandler
extends RecordHandler

Record Handler that stores each record as a file in a directory

Author:
Christopher Haines (hainesc@ctrip.ufl.edu)

Field Summary
protected  org.apache.commons.vfs.FileObject fileDirObj
          The directory to store record files in
protected static org.slf4j.Logger log
          SLF4J Logger
 
Constructor Summary
protected TextFileRecordHandler()
          Default Constructor
  TextFileRecordHandler(java.lang.String fileDir)
          Constructor
 
Method Summary
protected  void addMetaData(Record rec, RecordMetaData rmd)
          Adds a metadata record
 boolean addRecord(Record rec, java.lang.Class<?> operator, boolean overwrite)
          Adds a record to the RecordHandler
 void close()
          Closes the recordhandler
protected  void delMetaData(java.lang.String recID)
          Deletes all metadata for a record
 void delRecord(java.lang.String recID)
          Delete the specified Record
 java.util.Set<java.lang.String> find(java.lang.String idText)
          Find records with idText in their id
 java.lang.String getRecordData(java.lang.String recID)
          Retrieve the data for a given record
protected  java.util.SortedSet<RecordMetaData> getRecordMetaData(java.lang.String recID)
          Retrieves all metadata for a given record
 java.util.Iterator<Record> iterator()
           
 void setParams(java.util.Map<java.lang.String,java.lang.String> params)
          Sets parameters from param list
 
Methods inherited from class org.vivoweb.harvester.util.repo.RecordHandler
addMetaData, addRecord, addRecord, addRecord, getLastMetaData, getParam, getRecord, isOverwriteDefault, needsProcessed, needsUpdated, parseConfig, parseConfig, parseConfig, parseConfig, parseConfig, parseConfig, parseConfig, setOverwriteDefault, setProcessed, setWritten
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static org.slf4j.Logger log
SLF4J Logger


fileDirObj

protected org.apache.commons.vfs.FileObject fileDirObj
The directory to store record files in

Constructor Detail

TextFileRecordHandler

protected TextFileRecordHandler()
Default Constructor


TextFileRecordHandler

public TextFileRecordHandler(java.lang.String fileDir)
                      throws java.io.IOException
Constructor

Parameters:
fileDir - directory to store records in
Throws:
java.io.IOException - error accessing directory
Method Detail

setParams

public void setParams(java.util.Map<java.lang.String,java.lang.String> params)
               throws java.lang.IllegalArgumentException,
                      java.io.IOException
Description copied from class: RecordHandler
Sets parameters from param list

Specified by:
setParams in class RecordHandler
Parameters:
params - map of parameters
Throws:
java.lang.IllegalArgumentException - invalid parameters
java.io.IOException - error

addRecord

public boolean addRecord(Record rec,
                         java.lang.Class<?> operator,
                         boolean overwrite)
                  throws java.io.IOException
Description copied from class: RecordHandler
Adds a record to the RecordHandler

Specified by:
addRecord in class RecordHandler
Parameters:
rec - record to add
operator - the creator
overwrite - when set to true, will automatically overwrite existing records
Returns:
true if added, false if not needed (aka record already existed and was the same)
Throws:
java.io.IOException - error adding

delRecord

public void delRecord(java.lang.String recID)
               throws java.io.IOException
Description copied from class: RecordHandler
Delete the specified Record

Specified by:
delRecord in class RecordHandler
Parameters:
recID - id of record to delete
Throws:
java.io.IOException - i/o error

getRecordData

public java.lang.String getRecordData(java.lang.String recID)
                               throws java.lang.IllegalArgumentException,
                                      java.io.IOException
Description copied from class: RecordHandler
Retrieve the data for a given record

Specified by:
getRecordData in class RecordHandler
Parameters:
recID - id of record to retrieve
Returns:
data from record
Throws:
java.lang.IllegalArgumentException - id not found
java.io.IOException - error reading

delMetaData

protected void delMetaData(java.lang.String recID)
                    throws java.io.IOException
Description copied from class: RecordHandler
Deletes all metadata for a record

Specified by:
delMetaData in class RecordHandler
Parameters:
recID - record id to delete metadata for
Throws:
java.io.IOException - error deleting metadata

addMetaData

protected void addMetaData(Record rec,
                           RecordMetaData rmd)
                    throws java.io.IOException
Description copied from class: RecordHandler
Adds a metadata record

Specified by:
addMetaData in class RecordHandler
Parameters:
rec - record to add metadata for
rmd - the metadata record
Throws:
java.io.IOException - error adding meta data

getRecordMetaData

protected java.util.SortedSet<RecordMetaData> getRecordMetaData(java.lang.String recID)
                                                         throws java.io.IOException
Description copied from class: RecordHandler
Retrieves all metadata for a given record

Specified by:
getRecordMetaData in class RecordHandler
Parameters:
recID - id of record to retrieve metadata for
Returns:
the metadata map
Throws:
java.io.IOException - error retrieving record metadata

iterator

public java.util.Iterator<Record> iterator()

close

public void close()
           throws java.io.IOException
Description copied from class: RecordHandler
Closes the recordhandler

Specified by:
close in class RecordHandler
Throws:
java.io.IOException - error closing

find

public java.util.Set<java.lang.String> find(java.lang.String idText)
Description copied from class: RecordHandler
Find records with idText in their id

Specified by:
find in class RecordHandler
Parameters:
idText - the text to find
Returns:
list of ids that match