jSyncManager

org.jSyncManager.API.Protocol.Util
Class JSCSVDocument

java.lang.Object
  |
  +--org.jSyncManager.API.Protocol.Util.JSCSVDocument
Direct Known 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.

Version:
$Revision: 1.13 $
Author:
David A. Bartmess <dingodave@edingo.net>
Last modified by: $Author: dingodave $ on $Date: 2003/06/18 05:32:16 $.
See Also:
JSCSVCell, DLPRecordCSV

Field Summary
static int DATATYPE_ROW
           
static int DLPRECORD_COLS
           
(package private)  int headerrows
           
static int TITLE_ROW
           
 
Constructor Summary
JSCSVDocument()
          Create a default empty JSCSVDocument type.
JSCSVDocument(java.io.File document)
          Create new JSCSVDocument with java.io.File document instance.
JSCSVDocument(java.io.InputStreamReader inputfile)
          Create new JSCSVDocument from an InputStreamReader stream.
 
Method Summary
protected  JSCSVCell elementAt(int row, int col)
          Get a JSCSVCell object at the row,col given.
 java.lang.String escape(byte in)
          Escapes any html characters in the input byte.
 java.lang.String[] escape(byte[] in)
          Escapes any html characters in the input byte array.
 java.lang.String escape(char in)
          Escapes any html characters in the input char.
 java.lang.String[] escape(char[] in)
          Escapes any html characters in the input char array.
 java.lang.String escape(double in)
          Escapes any html characters in the input double value.
 java.lang.String[] escape(double[] in)
          Escapes any html characters in the input double array value.
 java.lang.String escape(float in)
          Escapes any html characters in the input float value.
 java.lang.String[] escape(float[] in)
          Escapes any html characters in the input float array value.
 java.lang.String escape(int in)
          Escapes any html characters in the input int.
 java.lang.String[] escape(int[] in)
          Escapes any html characters in the input int array.
 java.lang.String escape(long in)
          Escapes any html characters in the input long value.
 java.lang.String[] escape(long[] in)
          Escapes any html characters in the input long array.
 java.lang.String escape(java.lang.String in)
          Escapes any html characters in the input string.
 JSCSVCell getCell(int row, int col)
          Retrieve the JSCSVCell object from the given row and column.
 java.util.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.
 java.lang.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(java.io.BufferedReader input)
          Parse the document from the input BufferedReader stream and insert elements as needed.
 void parse(java.io.File input)
          Parse the document from the input java.io.File and insert elements as needed.
 void parse(java.io.InputStreamReader input)
          Parse a CSV style document from the input InputStreamReader stream and insert elements as needed.
protected  void parseRow(java.lang.String line)
          Parse the data values for the next row.
protected  void parseTitleRow(java.lang.String line)
          Parse the titles for the TITLE_ROW row of the document.
protected  void parseTypeRow(java.lang.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.
 java.util.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(java.io.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.
 java.lang.String[] readStringArrayCell(JSCSVCell node)
          Get String array value of node JSCSVCell object.
 java.lang.String readStringCell(JSCSVCell node)
          Get String value of node JSCSVCell object.
 void setDocument(java.util.Vector document)
          Setter for property document.
protected  void setElementAt(JSCSVCell cell, int row, int col)
          Set a JSCSVCell object at the row,col given.
protected  void setElementAt(JSCSVCell cell, java.lang.String title, int row, int col)
          Set a JSCSVCell object at the row,col given with the given title String.
 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(java.io.BufferedWriter outputfile, int row)
          Write the document row at the given index row to the given BufferedWriter stream.
 void writeDocument(java.io.BufferedWriter outputfile)
          Write the current document to the given BufferedWriter stream.
 void writeDocument(java.io.OutputStreamWriter outputfile)
          Write the current document to the given OutputStreamWriter stream.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

headerrows

int headerrows

DATATYPE_ROW

public static final int DATATYPE_ROW

TITLE_ROW

public static final int TITLE_ROW

DLPRECORD_COLS

public static final int DLPRECORD_COLS
Constructor Detail

JSCSVDocument

public JSCSVDocument()
Create a default empty JSCSVDocument type.

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.
Throws:
java.io.IOException -  

JSCSVDocument

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

readDocument

public void readDocument(java.io.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.
Throws:
java.io.IOException -  

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.

setElementAt

protected void setElementAt(JSCSVCell cell,
                            java.lang.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.

elementAt

protected JSCSVCell elementAt(int row,
                              int col)
                       throws java.lang.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.
Throws:
ArraIndexOutOfBoundException - Thrown if the row,col given is outside the boundaries of the current document's values.

parse

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

parse

public void parse(java.io.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.
Throws:
java.io.IOException -  

parse

public void parse(java.io.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.
Throws:
java.io.IOException -  

parse

public void parse(java.io.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.
Throws:
java.io.FileNotFoundException -  
java.io.IOException -  

parseTypeRow

protected void parseTypeRow(java.lang.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.

parseTitleRow

protected void parseTitleRow(java.lang.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.

parseRow

protected void parseRow(java.lang.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.

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.

getValue

public java.lang.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.

writeDocument

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

writeDocument

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

writeDataRow

public void writeDataRow(java.io.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.
Throws:
java.io.IOException -  

getDocument

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

setDocument

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

readStringCell

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

readStringArrayCell

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

readCalendarCell

public java.util.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.
Throws:
java.text.ParseException - Thrown if the cell contents are NOT a Calendar type.

readBooleanCell

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

readByteCell

public byte readByteCell(JSCSVCell node)
Get byte value of node JSCSVCell object.
Parameters:
node - JSCSVCell to get value from.
Returns:
byte 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.

readCharCell

public char readCharCell(JSCSVCell node)
Get char value of node JSCSVCell object.
Parameters:
node - JSCSVCell to get value from.
Returns:
char 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.

readIntCell

public int readIntCell(JSCSVCell node)
Get int value of node JSCSVCell object.
Parameters:
node - JSCSVCell to get value from.
Returns:
int 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.

readLongCell

public long readLongCell(JSCSVCell node)
Get long value of node JSCSVCell object.
Parameters:
node - JSCSVCell to get value from.
Returns:
long 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.

readFloatCell

public float readFloatCell(JSCSVCell node)
Get float value of node JSCSVCell object.
Parameters:
node - JSCSVCell to get value from.
Returns:
float 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.

readDoubleCell

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

readDoubleArrayCell

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

escape

public java.lang.String escape(java.lang.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 java.lang.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 java.lang.String[] escape(byte[] in)
Escapes any html characters in the input byte array.
Parameters:
in - byte array value to replace escape values for.
Returns:
String[] Array value of escaped input byte array

escape

public java.lang.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 java.lang.String[] escape(char[] in)
Escapes any html characters in the input char array.
Parameters:
in - char array value to replace escape values for.
Returns:
String[] Array value of escaped input char array

escape

public java.lang.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 java.lang.String[] escape(int[] in)
Escapes any html characters in the input int array.
Parameters:
in - int array value to replace escape values for.
Returns:
String[] Array value of escaped input int array

escape

public java.lang.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.

escape

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

escape

public java.lang.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 java.lang.String[] escape(float[] in)
Escapes any html characters in the input float array value.
Parameters:
in - float array value to replace escape values for.
Returns:
String[] value of escaped input float array value.

escape

public java.lang.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 java.lang.String[] escape(double[] in)
Escapes any html characters in the input double array value.
Parameters:
in - double array value to replace escape values for.
Returns:
String[] Array value of escaped input double array value.

getReader

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

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.InputStreamReader 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:
reader - New value of property reader.

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.

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.

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.

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.

getHeaderrows

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

setHeaderrows

public void setHeaderrows()
Setter for property headerrows.
Parameters:
headerrows - Number of header rows to include.

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.

jSyncManager

Copyright (c) 1999 - 2003 Brad BARCLAY and others. All Rights Reserved.