org.milyn.fixedlength
Class FixedLengthReader
java.lang.Object
org.milyn.fixedlength.FixedLengthReader
- All Implemented Interfaces:
- ContentHandler, VisitorAppender, SmooksXMLReader, org.xml.sax.XMLReader
public class FixedLengthReader
- extends java.lang.Object
- implements SmooksXMLReader, VisitorAppender
Fixed Length Reader.
This Fixed Length Reader can be plugged into the Smooks (for example) in order to convert a
Fixed Length record 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:fl="http://www.milyn.org/xsd/smooks/fixed-length-1.3.xsd">
<fl:reader fields="" separator="" quote="" skipLines="" lineNumber="" rootElementName="" recordElementName="" lineNumberAttributeName="" truncatedAttributeName="">
<fl:singleBinding beanId="" class="" />
</fl: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:fl="http://www.milyn.org/xsd/smooks/fixed-length-1.3.xsd">
<fl:reader fields="" separator="" quote="" skipLines="" lineNumber="" rootElementName="" recordElementName="" lineNumberAttributeName="" truncatedAttributeName="">
<fl:listBinding beanId="" class="" />
</fl: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:fl="http://www.milyn.org/xsd/smooks/fixed-length-1.3.xsd">
<fl:reader fields="" separator="" quote="" skipLines="" lineNumber="" rootElementName="" recordElementName="" lineNumberAttributeName="" truncatedAttributeName="">
<fl:mapBinding beanId="" class="" keyField="" />
</fl:reader>
</smooks-resource-list>
Field definition
The field definition is a comma separated list of fieldnames. After each fieldname the length is set between brackets. So a field
definition could look like this: firstname[10],lastname[10],gender[1]
Strict parsing
You can choose if the data is read strictly or not. When strict is to true then the line which doesn't contain enough characters is skipped
else the fields that don't have enough characters are empty and those records and fields have the 'truncated' attribute set to true.
By default strict is set to false.
Ignoring Fields
To ignore a field in a fixed length record set, just insert the string "$ignore$[10]" for that field in the fields attribute. You still
need to set the field length between the brackets
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 length definition and are optionally separated with a question mark. So a field
definition with string functions could look like this: firstname[10]?trim,lastname[10]?right_trim,gender[1]?upper_case
Take a look in the Smooks manual for a list of all available functions.
Simple Java Bindings
A simple java binding can be configured on the reader configuration. This allows quick binding configuration where the
fixed length 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 fixed length stream into
a stream of SAX events:
<csv:reader fields="name[20]?trim,address[50]?trim,$ignore$[5],item[5],quantity[3].trim" />
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:
<set>
<record number="1">
<name>Tom Fennelly</name>
<address>Ireland</address>
<item>V1234</item>
<quantity>3</quantity>
<record>
<record number="2">
<name>Joe Bloggs</name>
<address>England</address>
<item>D9123</item>
<quantity>7</quantity>
<record>
</set>
Other profile based transformations can then be used to transform the CSV records in accordance with the requirements
of the consuming entities.
- Author:
- Cedric Rathgeb, maurice.zeijen@smies.com
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
initialized
public boolean initialized
FixedLengthReader
public FixedLengthReader()
addVisitors
public void addVisitors(VisitorConfigMap visitorMap)
- Specified by:
addVisitors in interface VisitorAppender
setExecutionContext
public void setExecutionContext(ExecutionContext request)
- Specified by:
setExecutionContext in interface SmooksXMLReader
initialize
@Initialize
public void initialize()
parse
public void parse(org.xml.sax.InputSource flInputSource)
throws java.io.IOException,
org.xml.sax.SAXException
- Specified by:
parse in interface org.xml.sax.XMLReader
- Throws:
java.io.IOException
org.xml.sax.SAXException
setContentHandler
public void setContentHandler(org.xml.sax.ContentHandler contentHandler)
- Specified by:
setContentHandler in interface org.xml.sax.XMLReader
getContentHandler
public org.xml.sax.ContentHandler getContentHandler()
- Specified by:
getContentHandler in interface org.xml.sax.XMLReader
parse
public void parse(java.lang.String systemId)
throws java.io.IOException,
org.xml.sax.SAXException
- The following methods are currently unimplemented...
- Specified by:
parse in interface org.xml.sax.XMLReader
- Throws:
java.io.IOException
org.xml.sax.SAXException
getFeature
public boolean getFeature(java.lang.String name)
throws org.xml.sax.SAXNotRecognizedException,
org.xml.sax.SAXNotSupportedException
- Specified by:
getFeature in interface org.xml.sax.XMLReader
- Throws:
org.xml.sax.SAXNotRecognizedException
org.xml.sax.SAXNotSupportedException
setFeature
public void setFeature(java.lang.String name,
boolean value)
throws org.xml.sax.SAXNotRecognizedException,
org.xml.sax.SAXNotSupportedException
- Specified by:
setFeature in interface org.xml.sax.XMLReader
- Throws:
org.xml.sax.SAXNotRecognizedException
org.xml.sax.SAXNotSupportedException
getDTDHandler
public org.xml.sax.DTDHandler getDTDHandler()
- Specified by:
getDTDHandler in interface org.xml.sax.XMLReader
setDTDHandler
public void setDTDHandler(org.xml.sax.DTDHandler arg0)
- Specified by:
setDTDHandler in interface org.xml.sax.XMLReader
getEntityResolver
public org.xml.sax.EntityResolver getEntityResolver()
- Specified by:
getEntityResolver in interface org.xml.sax.XMLReader
setEntityResolver
public void setEntityResolver(org.xml.sax.EntityResolver arg0)
- Specified by:
setEntityResolver in interface org.xml.sax.XMLReader
getErrorHandler
public org.xml.sax.ErrorHandler getErrorHandler()
- Specified by:
getErrorHandler in interface org.xml.sax.XMLReader
setErrorHandler
public void setErrorHandler(org.xml.sax.ErrorHandler arg0)
- Specified by:
setErrorHandler in interface org.xml.sax.XMLReader
getProperty
public java.lang.Object getProperty(java.lang.String name)
throws org.xml.sax.SAXNotRecognizedException,
org.xml.sax.SAXNotSupportedException
- Specified by:
getProperty in interface org.xml.sax.XMLReader
- Throws:
org.xml.sax.SAXNotRecognizedException
org.xml.sax.SAXNotSupportedException
setProperty
public void setProperty(java.lang.String name,
java.lang.Object value)
throws org.xml.sax.SAXNotRecognizedException,
org.xml.sax.SAXNotSupportedException
- Specified by:
setProperty in interface org.xml.sax.XMLReader
- Throws:
org.xml.sax.SAXNotRecognizedException
org.xml.sax.SAXNotSupportedException
Copyright © 2011. All Rights Reserved.