This example illustrates how to hook the EdiSax (http://milyn.codehaus.org/EdiSax) EDI parser into a Smooks based transform (filter operation). It's another example of how non-XML streams can be processed by Smooks (see the "csv-to-xml" example).
In this example, we simply configure in the EdiSax parser to process the EDI stream into XML. We don't perform any other transforms on the underlying data. For an example of how other transform operations can be built on top of this edi-to-xml transform, see the edi-to-java example.
So here's the source edi file that is to be transformed:
HDR*1*0*59.97*64.92*4.95*Wed Nov 15 13:45:28 EST 2006
ORD*1*1*364*The 40-Year-Old Virgin*29.98
And this is the expected result of our transformation:
In order to apply this transformer to a message fragment, a Smooks Configurationneeds to be created. This configuration will target the transformer at a particular message fragment. For more information on configuring XSLT resources, see XslContentDeliveryUnitCreator.
Here's the configuration ("smooks-config.xml"):
<!-- Configure the EDI Parser to parse the message stream into a stream of SAX events. -->
Here's the edi mapping ("/src/main/java/example/edi-to-xml-order-mapping.xml"):
Again, it's exactly the same as with the java-basic tutorial:
// Instantiate Smooks with the config...
Smooks smooks = new Smooks("smooks-config.xml");
// Create an exec context - no profiles....
StandaloneExecutionContext executionContext = smooks.createExecutionContext();
// Filter the input message to the outputWriter, using the execution context...
DOMResult domResult = new DOMResult();
smooks.filter(new StreamSource(new ByteArrayInputStream(messageIn)), domResult, executionContext);
Of course, you'd typically cache the Smooks instance.