org.jSyncManager.API.Conduit.Tools

Class JSCSVDocument

Known Direct Subclasses:
DLPRecordCSV

public class JSCSVDocument
extends java.lang.Object

A JSCSVDocument class to hold a CSV delimited document for use. Each "cell" in the record will be a double-quoted String, escaped if necessary.
See Also:
JSCSVCell, DLPRecordCSV

Field Summary

static int
DATATYPE_ROW
static int
DLPRECORD_COLS
static int
TITLE_ROW

Constructor Summary

JSCSVDocument()
Create a default empty JSCSVDocument type.
JSCSVDocument(InputStreamReader inputfile)
Create new JSCSVDocument from an InputStreamReader stream.
JSCSVDocument(java.io.File document)
Create new JSCSVDocument with java.io.File document instance.

Method Summary

protected JSCSVCell
elementAt(int row, int col)
Get a JSCSVCell object at the row,col given.
String
escape(String in)
Escapes any html characters in the input string.
String
escape(byte in)
Escapes any html characters in the input byte.
String
escape(char in)
Escapes any html characters in the input char.
String
escape(double in)
Escapes any html characters in the input double value.
String
escape(float in)
Escapes any html characters in the input float value.
String[]
escape(in[] )
Escapes any html characters in the input byte array.
String[]
escape(in[] )
Escapes any html characters in the input char array.
String[]
escape(in[] )
Escapes any html characters in the input int array.
String[]
escape(in[] )
Escapes any html characters in the input long array.
String[]
escape(in[] )
Escapes any html characters in the input float array value.
String[]
escape(in[] )
Escapes any html characters in the input double array value.
String
escape(int in)
Escapes any html characters in the input int.
String
escape(long in)
Escapes any html characters in the input long value.
JSCSVCell
getCell(int row, int col)
Retrieve the JSCSVCell object from the given row and column.
Vector
getDocument()
Getter for property document.
int
getHeaderrows()
Getter for property headerrows.
java.io.BufferedReader
getReader()
Getter for property reader.
int
getRowNo(int recordno)
Get current internal Row number taken from given record number plus the number of header rows.
java.lang.String
getSeparator()
Getter for property separator which separates the columns in each row in the document.
String
getValue(int row, int col)
Retrieve the String value from the JSCSVCell at the given row and column.
boolean
isShowtitles()
Get boolean value showing whether the titles should be shown in the output document or not.
protected void
parse()
Parse the document and insert elements as needed.
void
parse(BufferedReader input)
Parse the document from the input BufferedReader stream and insert elements as needed.
void
parse(File input)
Parse the document from the input java.io.File and insert elements as needed.
void
parse(InputStreamReader input)
Parse a CSV style document from the input InputStreamReader stream and insert elements as needed.
protected void
parseRow(String line)
Parse the data values for the next row.
protected void
parseTitleRow(String line)
Parse the titles for the TITLE_ROW row of the document.
protected void
parseTypeRow(String line)
Parse the data types from the DATATYPE_ROW row String given.
boolean
readBooleanCell(JSCSVCell node)
Get boolean value of node JSCSVCell object.
byte[]
readByteArrayCell(JSCSVCell node)
Get byte array value of node JSCSVCell object.
byte
readByteCell(JSCSVCell node)
Get byte value of node JSCSVCell object.
GregorianCalendar
readCalendarCell(JSCSVCell node)
Get GregorianCalendar value of node JSCSVCell object.
char[]
readCharArrayCell(JSCSVCell node)
Get char array value of node JSCSVCell object.
char
readCharCell(JSCSVCell node)
Get char value of node JSCSVCell object.
void
readDocument(InputStreamReader inputfile)
Read and parse the contents from an InputStreamReader stream.
double[]
readDoubleArrayCell(JSCSVCell node)
Get double array value of node JSCSVCell object.
double
readDoubleCell(JSCSVCell node)
Get double value of node JSCSVCell object.
float[]
readFloatArrayCell(JSCSVCell node)
Get float array value of node JSCSVCell object.
float
readFloatCell(JSCSVCell node)
Get float value of node JSCSVCell object.
int[]
readIntArrayCell(JSCSVCell node)
Get int array value of node JSCSVCell object.
int
readIntCell(JSCSVCell node)
Get int value of node JSCSVCell object.
long[]
readLongArrayCell(JSCSVCell node)
Get long array value of node JSCSVCell object.
long
readLongCell(JSCSVCell node)
Get long value of node JSCSVCell object.
String[]
readStringArrayCell(JSCSVCell node)
Get String array value of node JSCSVCell object.
String
readStringCell(JSCSVCell node)
Get String value of node JSCSVCell object.
void
setDocument(Vector document)
Setter for property document.
protected void
setElementAt(JSCSVCell cell, String title, int row, int col)
Set a JSCSVCell object at the row,col given with the given title String.
protected void
setElementAt(JSCSVCell cell, int row, int col)
Set a JSCSVCell object at the row,col given.
void
setHeaderrows()
Setter for property headerrows.
void
setReader(java.io.BufferedReader reader)
Setter for property reader.
void
setReader(java.io.File file)
Setter for property reader from java.io.File instance.
void
setReader(java.io.InputStreamReader reader)
Setter for property reader.
void
setSeparator(java.lang.String separator)
Setter for property separator which separates the columns in each row in the document.
void
setShowtitles(boolean showtitles)
Setter for property showtitles with boolean value showing whether the titles should be shown in the output document or not.
void
writeDataRow(BufferedWriter outputfile, int row)
Write the document row at the given index row to the given BufferedWriter stream.
void
writeDocument(BufferedWriter outputfile)
Write the current document to the given BufferedWriter stream.
void
writeDocument(OutputStreamWriter outputfile)
Write the current document to the given OutputStreamWriter stream.

Field Details

DATATYPE_ROW

public static final int DATATYPE_ROW
Field Value:
0

DLPRECORD_COLS

public static final int DLPRECORD_COLS
Field Value:
5

TITLE_ROW

public static final int TITLE_ROW
Field Value:
1

Constructor Details

JSCSVDocument

public JSCSVDocument()
Create a default empty JSCSVDocument type.

JSCSVDocument

public JSCSVDocument(InputStreamReader inputfile)
            throws java.io.IOException
Create new JSCSVDocument from an InputStreamReader stream.
Parameters:
inputfile - InputStreamReader stream to parse the document contents from.

JSCSVDocument

public JSCSVDocument(java.io.File document)
            throws java.io.IOException
Create new JSCSVDocument with java.io.File document instance.
Parameters:
document - External File object to be parsed into the document.

Method Details

elementAt

protected JSCSVCell elementAt(int row,
                              int col)
            throws ArrayIndexOutOfBoundsException
Get a JSCSVCell object at the row,col given.
Parameters:
row - Row number (index starts at 0) to insert the cell.
col - Column number (index starts at 0) to insert the cell.
Returns:
cell JSCSVCell type value to insert into the document.

escape

public String escape(String in)
Escapes any html characters in the input string.
Parameters:
in - String value to replace escape values for.
Returns:
String value of escaped input string

escape

public String escape(byte in)
Escapes any html characters in the input byte.
Parameters:
in - byte value to replace escape values for.
Returns:
String value of escaped input byte.

escape

public String escape(char in)
Escapes any html characters in the input char.
Parameters:
in - char value to replace escape values for.
Returns:
String value of escaped input char array

escape

public String escape(double in)
Escapes any html characters in the input double value.
Parameters:
in - double value to replace escape values for.
Returns:
String value of escaped input double value.

escape

public String escape(float in)
Escapes any html characters in the input float value.
Parameters:
in - float value to replace escape values for.
Returns:
String value of escaped input float value.

escape

public String[] escape(in[] )
Escapes any html characters in the input byte array.
Parameters:
Returns:
String[] Array value of escaped input byte array

escape

public String[] escape(in[] )
Escapes any html characters in the input char array.
Parameters:
Returns:
String[] Array value of escaped input char array

escape

public String[] escape(in[] )
Escapes any html characters in the input int array.
Parameters:
Returns:
String[] Array value of escaped input int array

escape

public String[] escape(in[] )
Escapes any html characters in the input long array.
Parameters:
Returns:
String[] Array value of escaped input long array

escape

public String[] escape(in[] )
Escapes any html characters in the input float array value.
Parameters:
Returns:
String[] value of escaped input float array value.

escape

public String[] escape(in[] )
Escapes any html characters in the input double array value.
Parameters:
Returns:
String[] Array value of escaped input double array value.

escape

public String escape(int in)
Escapes any html characters in the input int.
Parameters:
in - int value to replace escape values for.
Returns:
String value of escaped input int.

escape

public String escape(long in)
Escapes any html characters in the input long value.
Parameters:
in - long value to replace escape values for.
Returns:
String value of escaped input long value.

getCell

public JSCSVCell getCell(int row,
                         int col)
Retrieve the JSCSVCell object from the given row and column.
Parameters:
row - Row number of the desired cell.
col - Column number of the desired cell.
Returns:
JSCSVCell JSCSVCell object at the given row and column.

getDocument

public Vector getDocument()
Getter for property document.
Returns:
Vector value of property document.

getHeaderrows

public int getHeaderrows()
Getter for property headerrows.
Returns:
Number of header rows included.

getReader

public java.io.BufferedReader getReader()
Getter for property reader.
Returns:
Value of property reader.

getRowNo

public int getRowNo(int recordno)
Get current internal Row number taken from given record number plus the number of header rows.
Returns:
Number of the given record's row in the document.

getSeparator

public java.lang.String getSeparator()
Getter for property separator which separates the columns in each row in the document.
Returns:
Value of property separator.

getValue

public String getValue(int row,
                       int col)
Retrieve the String value from the JSCSVCell at the given row and column.
Parameters:
row - Row number of the desired cell.
col - Column number of the desired cell.
Returns:
String String value of the contents of the JSCSVCell object at the given row and column.

isShowtitles

public boolean isShowtitles()
Get boolean value showing whether the titles should be shown in the output document or not.
Returns:
Value of property showtitles.

parse

protected void parse()
            throws java.io.IOException
Parse the document and insert elements as needed.

parse

public void parse(BufferedReader input)
            throws java.io.IOException
Parse the document from the input BufferedReader stream and insert elements as needed.
Parameters:
input - BufferedReader stream to be parsed.

parse

public void parse(File input)
            throws java.io.FileNotFoundException,
                   java.io.IOException
Parse the document from the input java.io.File and insert elements as needed.
Parameters:
input - File object to be parsed.

parse

public void parse(InputStreamReader input)
            throws java.io.IOException
Parse a CSV style document from the input InputStreamReader stream and insert elements as needed.
Parameters:
input - InputStreamReader stream to be parsed.

parseRow

protected void parseRow(String line)
Parse the data values for the next row. This gives the values of the various columns.
Parameters:
line - String value of the row values separated by commas.

parseTitleRow

protected void parseTitleRow(String line)
Parse the titles for the TITLE_ROW row of the document. This gives the titles of the various columns for the document.
Parameters:
line - String value of the TITLE_ROW.

parseTypeRow

protected void parseTypeRow(String line)
Parse the data types from the DATATYPE_ROW row String given. This gives the types of the various columns (assuming the columns' values are the same type) and allows proper parsing of the cell values.
Parameters:
line - String value of the DATATYPE_ROW.

readBooleanCell

public boolean readBooleanCell(JSCSVCell node)
Get boolean value of node JSCSVCell object.
Parameters:
node - JSCSVCell to get value from.
Returns:
boolean value.

readByteArrayCell

public byte[] readByteArrayCell(JSCSVCell node)
Get byte array value of node JSCSVCell object.
Parameters:
node - JSCSVCell to get value from.
Returns:
byte[] value.

readByteCell

public byte readByteCell(JSCSVCell node)
Get byte value of node JSCSVCell object.
Parameters:
node - JSCSVCell to get value from.
Returns:
byte value.

readCalendarCell

public GregorianCalendar readCalendarCell(JSCSVCell node)
            throws java.text.ParseException
Get GregorianCalendar value of node JSCSVCell object.
Parameters:
node - JSCSVCell to get value from.
Returns:
GregorianCalendar value.

readCharArrayCell

public char[] readCharArrayCell(JSCSVCell node)
Get char array value of node JSCSVCell object.
Parameters:
node - JSCSVCell to get value from.
Returns:
char[] value.

readCharCell

public char readCharCell(JSCSVCell node)
Get char value of node JSCSVCell object.
Parameters:
node - JSCSVCell to get value from.
Returns:
char value.

readDocument

public void readDocument(InputStreamReader inputfile)
            throws java.io.IOException
Read and parse the contents from an InputStreamReader stream.
Parameters:
inputfile - InputStreamReader stream to parse the document contents from.

readDoubleArrayCell

public double[] readDoubleArrayCell(JSCSVCell node)
Get double array value of node JSCSVCell object.
Parameters:
node - JSCSVCell to get value from.
Returns:
double[] value.

readDoubleCell

public double readDoubleCell(JSCSVCell node)
Get double value of node JSCSVCell object.
Parameters:
node - JSCSVCell to get value from.
Returns:
double value.

readFloatArrayCell

public float[] readFloatArrayCell(JSCSVCell node)
Get float array value of node JSCSVCell object.
Parameters:
node - JSCSVCell to get value from.
Returns:
float[] value.

readFloatCell

public float readFloatCell(JSCSVCell node)
Get float value of node JSCSVCell object.
Parameters:
node - JSCSVCell to get value from.
Returns:
float value.

readIntArrayCell

public int[] readIntArrayCell(JSCSVCell node)
Get int array value of node JSCSVCell object.
Parameters:
node - JSCSVCell to get value from.
Returns:
int[] value.

readIntCell

public int readIntCell(JSCSVCell node)
Get int value of node JSCSVCell object.
Parameters:
node - JSCSVCell to get value from.
Returns:
int value.

readLongArrayCell

public long[] readLongArrayCell(JSCSVCell node)
Get long array value of node JSCSVCell object.
Parameters:
node - JSCSVCell to get value from.
Returns:
long[] value.

readLongCell

public long readLongCell(JSCSVCell node)
Get long value of node JSCSVCell object.
Parameters:
node - JSCSVCell to get value from.
Returns:
long value.

readStringArrayCell

public String[] readStringArrayCell(JSCSVCell node)
Get String array value of node JSCSVCell object.
Parameters:
node - JSCSVCell to get value from.
Returns:
String[] value.

readStringCell

public String readStringCell(JSCSVCell node)
Get String value of node JSCSVCell object.
Parameters:
node - JSCSVCell to get value from.
Returns:
String value.

setDocument

public void setDocument(Vector document)
Setter for property document.
Parameters:
document - New Vector value of property document contents.

setElementAt

protected void setElementAt(JSCSVCell cell,
                            String title,
                            int row,
                            int col)
Set a JSCSVCell object at the row,col given with the given title String.
Parameters:
cell - JSCSVCell type value to insert into the document.
title - String value of title row for this column.
row - Row number (index starts at 0) to insert the cell.
col - Column number (index starts at 0) to insert the cell.

setElementAt

protected void setElementAt(JSCSVCell cell,
                            int row,
                            int col)
Set a JSCSVCell object at the row,col given.
Parameters:
cell - JSCSVCell type value to insert into the document.
row - Row number (index starts at 0) to insert the cell.
col - Column number (index starts at 0) to insert the cell.

setHeaderrows

public void setHeaderrows()
Setter for property headerrows.

setReader

public void setReader(java.io.BufferedReader reader)
Setter for property reader.
Parameters:
reader - New value of property reader.

setReader

public void setReader(java.io.File file)
            throws java.io.FileNotFoundException
Setter for property reader from java.io.File instance.
Parameters:
file - New value of property reader.

setReader

public void setReader(java.io.InputStreamReader reader)
Setter for property reader.
Parameters:
reader - New value of property reader.

setSeparator

public void setSeparator(java.lang.String separator)
Setter for property separator which separates the columns in each row in the document.
Parameters:
separator - New value of property separator.

setShowtitles

public void setShowtitles(boolean showtitles)
Setter for property showtitles with boolean value showing whether the titles should be shown in the output document or not.
Parameters:
showtitles - New value of property showtitles.

writeDataRow

public void writeDataRow(BufferedWriter outputfile,
                         int row)
            throws java.io.IOException
Write the document row at the given index row to the given BufferedWriter stream.
Parameters:
outputfile - BufferedWriter to output the document to.

writeDocument

public void writeDocument(BufferedWriter outputfile)
            throws java.io.IOException
Write the current document to the given BufferedWriter stream.
Parameters:
outputfile - BufferedWriter to output the document to.

writeDocument

public void writeDocument(OutputStreamWriter outputfile)
            throws java.io.IOException
Write the current document to the given OutputStreamWriter stream.
Parameters:
outputfile - OutputStreamWriter to output the document to.