The primary goals of this example are to introduce you to the following:
- A very basic Fragment Transformer written in Java.
- The Smooks configuration file.
- Executing a Smooks Transformation.
The Fragment Transformer
Smooks is a Fragment based Transformation Framework. That means you can write (or reuse) Transformers that apply transformations on message fragments, as opposed to the message as a whole.
In this example we build a very simple (silly) fragment transformer in raw Java. Smooks supports applying transformations through a number of technologies (not just Java). However, underpinning all of these is the element Visitor. All transformation technologies supported by Smooks are hooked into the transformation process through an implementation of an element Visitor.
In this example, we implement a very simple DOMElementVisitor that simply renames the DOM Element of the fragment at which it is "targeted".
As you can see from the code, the implementation gets the new name for the targeted fragment via the configuration (in the setConfiguration method). It doesn't apply any transformation on the visitBefore event. On the visitAfter event, it applies the rename transformation on the targeted Element (message fragment) (See DomUtils.html.renameElement).
The Smooks Configuration
In order to apply this transformer to a message fragment, a Smooks Configuration needs to be created. This configuration will target the transformer at a particular message fragment.
Here's the configuration: