Class StreamingCsvToXml
- java.lang.Object
-
- com.adaptris.core.ServiceImp
-
- com.adaptris.csv.transform.CsvXmlTransformImpl
-
- com.adaptris.csv.transform.StreamingCsvToXml
-
- All Implemented Interfaces:
AdaptrisComponent
,ComponentLifecycle
,ComponentLifecycleExtension
,MessageEventGenerator
,Service
,StateManagedComponent
@ComponentProfile(summary="Transform CSV to XML using the XML streaming API (STaX).", tag="service,transform,csv,xml", since="3.11.0") public class StreamingCsvToXml extends CsvXmlTransformImpl
CSV to XML usingnet.sf.supercsv:super-csv
viaXMLStreamWriter
This transformation uses
net.sf.supercsv:super-csv
as the parsing engine for a CSV file and usesXMLStreamWriter
viacom.adaptris:interlok-stax
to write each row as part of an XML document. It may have better performance characteristics with large CSV files compared toCsvToXml
. 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
<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 Constructor Description StreamingCsvToXml()
StreamingCsvToXml(PreferenceBuilder prefs, StreamWriterFactory fact)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
closeService()
void
doService(AdaptrisMessage msg)
PreferenceBuilder
getPreferenceBuilder()
StreamWriterFactory
getStreamWriter()
protected void
initService()
void
prepare()
void
setPreferenceBuilder(PreferenceBuilder b)
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 Detail
-
StreamingCsvToXml
public StreamingCsvToXml()
-
StreamingCsvToXml
public StreamingCsvToXml(PreferenceBuilder prefs, StreamWriterFactory fact)
-
-
Method Detail
-
doService
public void doService(AdaptrisMessage msg) throws ServiceException
- Throws:
ServiceException
-
prepare
public void prepare() throws CoreException
- Specified by:
prepare
in interfaceComponentLifecycleExtension
- Overrides:
prepare
in classCsvXmlTransformImpl
- Throws:
CoreException
-
initService
protected void initService() throws CoreException
- Overrides:
initService
in classCsvXmlTransformImpl
- Throws:
CoreException
-
closeService
protected void closeService()
- Overrides:
closeService
in classCsvXmlTransformImpl
-
getPreferenceBuilder
public PreferenceBuilder getPreferenceBuilder()
-
setPreferenceBuilder
public void setPreferenceBuilder(PreferenceBuilder b)
-
getStreamWriter
public StreamWriterFactory getStreamWriter()
- Returns:
- the streamWriterFactory
-
setStreamWriter
public void setStreamWriter(StreamWriterFactory factory)
Set the stream writer factory to use.- Parameters:
factory
- the streamWriterFactory to set, default isDefaultWriterFactory
if not specified.
-
-