Class StreamingCsvToXml
- All Implemented Interfaces:
AdaptrisComponent
,ComponentLifecycle
,ComponentLifecycleExtension
,MessageEventGenerator
,Service
,StateManagedComponent
net.sf.supercsv:super-csv
via XMLStreamWriter
This transformation uses net.sf.supercsv:super-csv
as the parsing engine for a CSV file
and uses XMLStreamWriter
via com.adaptris:interlok-stax
to write each row as part
of an XML document. It may have better performance characteristics with large CSV files compared
to CsvToXml
. It also reduces the number of configuration options that are available.
Element names are always generated from the first line; so a header line is always assumed; Note
that if your header rows contains characters that would not be allowed in an standard XML element
name then it will be replaced with an '_', so "Order Date" becomes "Order_Date". Additionally
illegal XML characters are always stripped (illegal characters would cause an exception
regardless in the XMLStreamWriter
).
For example, given an input document :
Event Name,Order Date,Ticket Type,Date Attending,Total Paid
Glastonbury,"Sep 15, 2012",Free entry,"Jun 26, 2014 at 6:00 PM",0
Reading Festival,"Sep 16, 2012",Free entry,"Aug 30, 2014 at 6:00 PM",0
Then the output (without a header row) would be
<csv-xml>
<record line="1">
<Event_Name>Glastonbury</Event_Name>
<Order_Date>Sep 15, 2012</Order_Date>
<Ticket_Type>Free entry</Ticket_Type>
<Date_Attending>Jun 26, 2014 at 6:00 PM</Date_Attending>
<Total_Paid>0</Total_Paid>
</record>
<record line="2">
<Event_Name>Reading Festival</Event_Name>
<Order_Date>Sep 16, 2012</Order_Date>
<Ticket_Type>Free entry</Ticket_Type>
<Date_Attending>Aug 30, 2014 at 6:00 PM</Date_Attending>
<Total_Paid>0</Total_Paid>
</record>
In the adapter configuration file this class is aliased as streaming-csv-to-xml-transform which is the preferred alternative to the fully qualified classname when building your configuration.
-
Field Summary
Fields inherited from class com.adaptris.csv.transform.CsvXmlTransformImpl
CSV_FIELD_NAME, CSV_RECORD_NAME, XML_ROOT_ELEMENT
Fields inherited from class com.adaptris.core.ServiceImp
log
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
void
doService
(AdaptrisMessage msg) protected void
void
prepare()
void
void
setStreamWriter
(StreamWriterFactory factory) Set the stream writer factory to use.Methods inherited from class com.adaptris.csv.transform.CsvXmlTransformImpl
evaluateEncoding, getIncludeLineNumberAttribute, getOutputMessageEncoding, includeLineNumberAttribute, safeElementNames, safeElementNames, setIncludeLineNumberAttribute, setOutputMessageEncoding
Methods inherited from class com.adaptris.core.ServiceImp
changeState, close, continueOnFailure, createName, createQualifier, getContinueOnFail, getIsTrackingEndpoint, getUniqueId, init, isBranching, isTrackingEndpoint, requestClose, requestInit, requestStart, requestStop, retrieveComponentState, setContinueOnFail, setIsTrackingEndpoint, setUniqueId, start, stop
-
Constructor Details
-
StreamingCsvToXml
public StreamingCsvToXml() -
StreamingCsvToXml
-
-
Method Details
-
doService
- Throws:
ServiceException
-
prepare
- Specified by:
prepare
in interfaceComponentLifecycleExtension
- Overrides:
prepare
in classCsvXmlTransformImpl
- Throws:
CoreException
-
initService
- Overrides:
initService
in classCsvXmlTransformImpl
- Throws:
CoreException
-
closeService
protected void closeService()- Overrides:
closeService
in classCsvXmlTransformImpl
-
getPreferenceBuilder
-
setPreferenceBuilder
-
getStreamWriter
- Returns:
- the streamWriterFactory
-
setStreamWriter
Set the stream writer factory to use.- Parameters:
factory
- the streamWriterFactory to set, default isDefaultWriterFactory
if not specified.
-