org.sakaiproject.component.legacy.calendar.readers
Class Reader

java.lang.Object
  extended byorg.sakaiproject.component.legacy.calendar.readers.Reader
Direct Known Subclasses:
CSVReader, MeetingMakerReader

public abstract class Reader
extends Object

This class provides common functionality for parsers of various calendar import formats.


Nested Class Summary
 class Reader.ColumnHeader
          Contains header information such as the text label used for the header and the calendar event property with which it is associated.
static class Reader.ReaderImportCell
          This class contains the information for a single cell in a given row/column.
static interface Reader.ReaderImportRowHandler
          Users of this class need to define a callback that will be handled for each row.
 
Field Summary
protected  Map columnHeaderMap
           
protected  TimeService timeService
           
 
Constructor Summary
Reader()
          Default Constructor
 
Method Summary
protected  Reader.ColumnHeader[] buildColumnDescriptionArray(String[] columns)
          Create meta-information from the first line of the "file" (actually stream) that contains the names of the columns.
abstract  List filterEvents(List events, String[] customFieldNames)
          Each derived class must implement this filter to convert the properties as set by the reader into a common set of properties that will be used to create calendar events.
 Map getColumnHeaderMap()
          Gets the mapping of text column header labels in the import file to calendar event properties.
abstract  Map getDefaultColumnMap()
          Derived classes must provide a default mapping of text column header labels in the import file to calendar event properties.
protected  BufferedReader getReader(InputStream stream)
          Utility routine to get a BufferedReader
 TimeService getTimeService()
           
abstract  void importStreamFromDelimitedFile(InputStream stream, Reader.ReaderImportRowHandler handler)
          Import a CSV file from a stream and callback on each row.
protected  Iterator processLine(Reader.ColumnHeader[] columnDescriptionArray, int lineNumber, String[] columns)
          Split a line into a list of CSVReaderImportCell objects.
 void setColumnHeaderToAtributeMapping(Map columnHeaderMap)
          Users of this class must define a map where the keys are the column headers that will appear in the first line of the CSV file (stream) and the values are the associated property names that the callback will receive.
 void setTimeService(TimeService service)
           
protected  void trimLeadingTrailingQuotes(String[] columnsReadFromFile)
          Remove leading/trailing quotes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

columnHeaderMap

protected Map columnHeaderMap

timeService

protected TimeService timeService
Constructor Detail

Reader

public Reader()
Default Constructor

Method Detail

buildColumnDescriptionArray

protected Reader.ColumnHeader[] buildColumnDescriptionArray(String[] columns)
Create meta-information from the first line of the "file" (actually stream) that contains the names of the columns.

Parameters:
columns -

trimLeadingTrailingQuotes

protected void trimLeadingTrailingQuotes(String[] columnsReadFromFile)
Remove leading/trailing quotes

Parameters:
columnsReadFromFile -

setColumnHeaderToAtributeMapping

public void setColumnHeaderToAtributeMapping(Map columnHeaderMap)
Users of this class must define a map where the keys are the column headers that will appear in the first line of the CSV file (stream) and the values are the associated property names that the callback will receive.


processLine

protected Iterator processLine(Reader.ColumnHeader[] columnDescriptionArray,
                               int lineNumber,
                               String[] columns)
Split a line into a list of CSVReaderImportCell objects.

Parameters:
columnDescriptionArray -
lineNumber -
columns -

getReader

protected BufferedReader getReader(InputStream stream)
Utility routine to get a BufferedReader

Parameters:
stream -

importStreamFromDelimitedFile

public abstract void importStreamFromDelimitedFile(InputStream stream,
                                                   Reader.ReaderImportRowHandler handler)
                                            throws ImportException
Import a CSV file from a stream and callback on each row.

Parameters:
stream - Stream of CSV (or other delimited data)
handler - Callback for each row.
Throws:
ImportException

getColumnHeaderMap

public Map getColumnHeaderMap()
Gets the mapping of text column header labels in the import file to calendar event properties.


filterEvents

public abstract List filterEvents(List events,
                                  String[] customFieldNames)
                           throws ImportException
Each derived class must implement this filter to convert the properties as set by the reader into a common set of properties that will be used to create calendar events. Notably, this filter must create a ScheduleImporterService.ACTUAL_TIMERANGE property that will define the actual start time/date of the event.

Parameters:
customFieldNames -
Throws:
ImportException

getDefaultColumnMap

public abstract Map getDefaultColumnMap()
Derived classes must provide a default mapping of text column header labels in the import file to calendar event properties.

Throws:
ImportException

getTimeService

public TimeService getTimeService()

setTimeService

public void setTimeService(TimeService service)
Parameters:
service -