org.milyn.csv
Class CSVReader

java.lang.Object
  extended by org.milyn.csv.CSVReader
All Implemented Interfaces:
org.milyn.delivery.ContentHandler, org.milyn.delivery.VisitorAppender, org.milyn.xml.SmooksXMLReader, XMLReader

Deprecated. Use the FlatFileReader configured with the CSVRecordParserFactory.

public class CSVReader
extends Object
implements org.milyn.xml.SmooksXMLReader, org.milyn.delivery.VisitorAppender

CSV Reader.

This CSV Reader can be plugged into the Smooks (for example) in order to convert a CSV based message stream into a stream of SAX events to be consumed by the DOMBuilder.

Configuration

To maintain a single binding instance in memory:
 <?xml version="1.0"?>
 <smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd" xmlns:csv="http://www.milyn.org/xsd/smooks/csv-1.2.xsd">

     <csv:reader fields="" separator="" quote="" skipLines="" rootElementName="" recordElementName="">
         <csv:singleBinding beanId="" class="" />
     </csv:reader>

 </smooks-resource-list>

To maintain a List of binding instances in memory:

 <?xml version="1.0"?>
 <smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd" xmlns:csv="http://www.milyn.org/xsd/smooks/csv-1.2.xsd">

     <csv:reader fields="" separator="" quote="" skipLines="" rootElementName="" recordElementName="">
         <csv:listBinding beanId="" class="" />
     </csv:reader>

 </smooks-resource-list>

To maintain a Map of binding instances in memory:

 <?xml version="1.0"?>
 <smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd" xmlns:csv="http://www.milyn.org/xsd/smooks/csv-1.2.xsd">

     <csv:reader fields="" separator="" quote="" skipLines="" rootElementName="" recordElementName="">
         <csv:mapBinding beanId="" class="" keyField="" />
     </csv:reader>

 </smooks-resource-list>

Strict parsing

Strict parsing was the only option until Smooks 1.2.x, whereby lines that would not comply with the provided tokens (that it where the tokens present in the line is less than the number of tokens expected) would be garbled and a WARN log statement was provided. Now, you can decide if you want those lines to be parsed too, this is accomplished by setting strict="false" on the config.

String manipulation functions

String manipulation functions can be defined per field. These functions are executed before that the data is converted into SAX events. The functions are defined after the field name, separated with a question mark. So a field definition with string functions could look like this: firstname?trim,lastname?right_trim,gender?upper_case Take a look in the Smooks manual for a list of all available functions.

Ignoring Fields

To ignore a field in a CSV record set, just insert the string "$ignore$" for that field in the fields attribute.

Simple Java Bindings

A simple java binding can be configured on the reader configuration. This allows quick binding configuration where the CSV records map cleanly to the target bean. For more complex bindings, use the Java Binging Framework.

Example Usage

So the following configuration could be used to parse a CSV stream into a stream of SAX events:
 <csv:reader fields="name,address,$ignore$,item,quantity" />

Within Smooks, the stream of SAX events generated by the "Acme-Order-List" message (and this parser) will generate an event stream equivalent to the following:

 <csv-set>
        <csv-record number="1">
                <name>Tom Fennelly</name>
                <address>Ireland</address>
                <item>V1234</item>
                <quantity>3</quantity>
        <csv-record>
        <csv-record number="2">
                <name>Joe Bloggs</name>
                <address>England</address>
                <item>D9123</item>
                <quantity>7</quantity>
        <csv-record>
 </csv-set>

Other profile based transformations can then be used to transform the CSV records in accordance with the requirements of the consuming entities.

Author:
tfennelly

Constructor Summary
CSVReader()
          Deprecated.  
 
Method Summary
 void addVisitors(org.milyn.delivery.VisitorConfigMap visitorMap)
          Deprecated.  
 ContentHandler getContentHandler()
          Deprecated.  
 DTDHandler getDTDHandler()
          Deprecated.  
 EntityResolver getEntityResolver()
          Deprecated.  
 ErrorHandler getErrorHandler()
          Deprecated.  
 boolean getFeature(String name)
          Deprecated.  
 Object getProperty(String name)
          Deprecated.  
 void initialize()
          Deprecated.  
 void parse(InputSource csvInputSource)
          Deprecated.  
 void parse(String systemId)
          Deprecated. The following methods are currently unimplemnted...
 void setContentHandler(ContentHandler contentHandler)
          Deprecated.  
 void setDTDHandler(DTDHandler arg0)
          Deprecated.  
 void setEntityResolver(EntityResolver arg0)
          Deprecated.  
 void setErrorHandler(ErrorHandler arg0)
          Deprecated.  
 void setExecutionContext(org.milyn.container.ExecutionContext request)
          Deprecated.  
 void setFeature(String name, boolean value)
          Deprecated.  
 void setProperty(String name, Object value)
          Deprecated.  
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CSVReader

public CSVReader()
Deprecated. 
Method Detail

initialize

@Initialize
public void initialize()
Deprecated. 

addVisitors

public void addVisitors(org.milyn.delivery.VisitorConfigMap visitorMap)
Deprecated. 
Specified by:
addVisitors in interface org.milyn.delivery.VisitorAppender

setExecutionContext

public void setExecutionContext(org.milyn.container.ExecutionContext request)
Deprecated. 
Specified by:
setExecutionContext in interface org.milyn.xml.SmooksXMLReader

parse

public void parse(InputSource csvInputSource)
           throws IOException,
                  SAXException
Deprecated. 
Specified by:
parse in interface XMLReader
Throws:
IOException
SAXException

setContentHandler

public void setContentHandler(ContentHandler contentHandler)
Deprecated. 
Specified by:
setContentHandler in interface XMLReader

getContentHandler

public ContentHandler getContentHandler()
Deprecated. 
Specified by:
getContentHandler in interface XMLReader

parse

public void parse(String systemId)
           throws IOException,
                  SAXException
Deprecated. 
The following methods are currently unimplemnted...

Specified by:
parse in interface XMLReader
Throws:
IOException
SAXException

getFeature

public boolean getFeature(String name)
                   throws SAXNotRecognizedException,
                          SAXNotSupportedException
Deprecated. 
Specified by:
getFeature in interface XMLReader
Throws:
SAXNotRecognizedException
SAXNotSupportedException

setFeature

public void setFeature(String name,
                       boolean value)
                throws SAXNotRecognizedException,
                       SAXNotSupportedException
Deprecated. 
Specified by:
setFeature in interface XMLReader
Throws:
SAXNotRecognizedException
SAXNotSupportedException

getDTDHandler

public DTDHandler getDTDHandler()
Deprecated. 
Specified by:
getDTDHandler in interface XMLReader

setDTDHandler

public void setDTDHandler(DTDHandler arg0)
Deprecated. 
Specified by:
setDTDHandler in interface XMLReader

getEntityResolver

public EntityResolver getEntityResolver()
Deprecated. 
Specified by:
getEntityResolver in interface XMLReader

setEntityResolver

public void setEntityResolver(EntityResolver arg0)
Deprecated. 
Specified by:
setEntityResolver in interface XMLReader

getErrorHandler

public ErrorHandler getErrorHandler()
Deprecated. 
Specified by:
getErrorHandler in interface XMLReader

setErrorHandler

public void setErrorHandler(ErrorHandler arg0)
Deprecated. 
Specified by:
setErrorHandler in interface XMLReader

getProperty

public Object getProperty(String name)
                   throws SAXNotRecognizedException,
                          SAXNotSupportedException
Deprecated. 
Specified by:
getProperty in interface XMLReader
Throws:
SAXNotRecognizedException
SAXNotSupportedException

setProperty

public void setProperty(String name,
                        Object value)
                 throws SAXNotRecognizedException,
                        SAXNotSupportedException
Deprecated. 
Specified by:
setProperty in interface XMLReader
Throws:
SAXNotRecognizedException
SAXNotSupportedException


Copyright © 2018. All rights reserved.