net.sf.xbus.protocol.csv
Class CSVParser

java.lang.Object
  extended by net.sf.xbus.protocol.csv.CSVParser

public class CSVParser
extends java.lang.Object

The CSVParser class contains all methods necessary for parsing CSV format into an XML representation.

This parser supports all CSV format content which satisfies the rules indicated in this CSV definition .

The parsing result is a DOM tree with the following structure:

<InterfaceName>

<+ Header +> <+ heading +>+ FieldValue +</+ heading +>
...
</+ Header +>
<Records> <+ Record +> <+ FieldName +>+ FieldValue +</+ FieldName +>
...
</+ Record +>
...
</Records>
</InterfaceName>

The header is optional. For every entry a Record tag structure is created.

The information for the names and values of the DOM entities are taken out of the CSV source text and the optional Description file. A description file must be valid (InterfaceSpecCSV.dtd).

The following table gives an overview, how the Header information and the names of the entry tags are selected:

*
CSV file Description file Result
has header does not contain header No description file does not contain any information contains only Header information contains only Records information contains Header and Records information Header information taken from: Tag names of entries taken from:
X   X         CSV header CSV header
X     X       CSV header CSV header
X       X     Description file Header information in description file
X         X   CSV header Records information in description file
X           X Description file Records information in description file
  X X         No header Tag name = "field"
  X   X       No header Tag name = "field"
  X     X     Description file Header information in description file
  X       X   No header Records information in description file
  X         X Description file Records information in description file


Constructor Summary
CSVParser(java.lang.String system)
          Constructor of the parser.
 
Method Summary
 org.w3c.dom.Document getDescriptionTree()
           
 java.util.Vector getFieldNames()
           
 java.lang.String getFieldSeparator()
           
protected static CSVParser getInstance(java.lang.String sourceType)
          Returns an instance of CSVParser
 java.lang.String getLineSeparator()
           
 java.lang.String getQuoteChar()
           
 boolean isHasHeader()
           
 org.w3c.dom.Document parse(java.lang.String text, java.lang.String systemName)
          Parses the passed CSV format text into a DOM tree and returns it.
 void setDescriptionTree(org.w3c.dom.Document descriptionTree)
           
 void setFieldNames(java.util.Vector fieldNames)
           
 void setFieldSeparator(java.lang.String fieldSeparator)
           
 void setHasHeader(boolean hasHeader)
           
 void setLineSeparator(java.lang.String lineSeparator)
           
 void setQuoteChar(java.lang.String quoteChar)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CSVParser

public CSVParser(java.lang.String system)
          throws XException
Constructor of the parser. Starts the initialization which loads the configuration values.

Parameters:
system - the name of the process
Throws:
XException
Method Detail

setQuoteChar

public void setQuoteChar(java.lang.String quoteChar)
Parameters:
quoteChar - The quoteChar to set.

getQuoteChar

public java.lang.String getQuoteChar()
Returns:
Returns the quoteChar.

isHasHeader

public boolean isHasHeader()
Returns:
Returns the hasHeader.

setHasHeader

public void setHasHeader(boolean hasHeader)
Parameters:
hasHeader - The hasHeader to set.

setFieldSeparator

public void setFieldSeparator(java.lang.String fieldSeparator)
Parameters:
fieldSeparator - The fieldSeparator to set.

getFieldSeparator

public java.lang.String getFieldSeparator()
Returns:
Returns the fieldSeparator.

setLineSeparator

public void setLineSeparator(java.lang.String lineSeparator)
Parameters:
lineSeparator - The lineSeparator to set.

getLineSeparator

public java.lang.String getLineSeparator()
Returns:
Returns the lineSeparator.

getDescriptionTree

public org.w3c.dom.Document getDescriptionTree()
Returns:
Returns the descriptionTree.

setDescriptionTree

public void setDescriptionTree(org.w3c.dom.Document descriptionTree)
Parameters:
descriptionTree - The descriptionTree to set.

getFieldNames

public java.util.Vector getFieldNames()
Returns:
Returns the headerArray.

setFieldNames

public void setFieldNames(java.util.Vector fieldNames)
Parameters:
fieldNames -

getInstance

protected static CSVParser getInstance(java.lang.String sourceType)
                                throws XException
Returns an instance of CSVParser

Parameters:
sourceType - The name of the process
Returns:
An instance of the CSVSerializer class
Throws:
XException

parse

public org.w3c.dom.Document parse(java.lang.String text,
                                  java.lang.String systemName)
                           throws XException
Parses the passed CSV format text into a DOM tree and returns it.

Parameters:
text - The source text to parse. Has to be CSV format.
systemName - The name of the process - used as root tag
Returns:
The parsed DOM tree.
Throws:
XException