LBS logics Logo welcome to the AMORPH project. Logo

Amorph Usage Examples

Amorph usage from within Java code:

First you have to "grab" the definition for the amorph engine "what to do" - the so called recipe - into a JDOM Element (the XML node). The recipe tells amorph which DataGetter to use, which transformations should be applied, which DataPutter should be invoked. In this case we grab the recipe node by applying a XPath expression to our XML config file.

For examples of how recipes look like, see the file "docs/examples/example.rcp.xml" within the amorph distribution (or directly look at the CVS file here:

A short example of a recipe that is needed for parsing and transforming a .CSV file could look like this:
			<!-- type "builtin" allows ommiting the
				 default package: com.lbslogics.amorph.input. -->
			<prepare type="builtin" class="CsvPreparator">	
				<param name="delimiter" value=";"/>	
			<!-- there can exist multiple transform-elements 
				 specifying a stylesheet to applicate -->
			<transform type="xslt" file="docs\\example\\xslt\\example-xmlout.xslt" />
			<!-- postprocess node is optional: if it would be required
				 to transform the resulting XML to a specific format (like
				 CSV or something else), a PostProcessor would have be
				 to configured at this place  -->
			<!-- simple output of the result 
				 to the specified output stream (file) -->
			<putter type="builtin" class="StreamPutter"/>
This is all the amorph engine needs to know. The actual transformation Java code is only some lines:
Element recipe = (Element) xprec.selectSingleNode(recipeDoc);

/** now instantiate the amorph Recipe an pass the XML node
 * and a map representing the runtime context (can be empty 
 * by default) */
Recipe rec = new DefaultXMLRecipe(recipe, new HashMap());

/** the "chopper" is the amorph transformation engine, it cooks your
*	data as you specified it in your recipe: 
Chopper chop = new Chopper(rec);

// now set the input/output stuff, even if null
// the chopper has to handle that:

// now do the work:
Thats it: your data has been transformed as you wanted
  • - mails were downloaded and attachments saved
  • - the attached files have been parsed by the preprocessor
  • - numerous XSLT transformations where applied onto the parsed basic-xml format
  • - optional dataputters and postprocessors refined and delivered the resulting data