A "Smooks Resource" is anything that can be used by Smooks in the process of analyzing or transforming a data stream. They could be pieces of Java logic (DOMElementVisitor), some text or script resource, or perhaps simply a configuration parameter.
Resource Configuration Properties
- selector: Selector string. Used by Smooks to "lookup" a resource configuration. This is typically the message fragment name, but as mentioned above, not all resources are transformation/analysis resources targeted at a message fragment - this is why we didn't call this attribute "target-fragment".
- selector-namespace: The XML namespace of the selector target for this resource. This is used to target ContentDeliveryUnits at XML elements from a specific XML namespace e.g. "http://www.w3.org/2002/xforms". If not defined, the resource is targeted at all namespces.
- target-profile: A list of 1 or more profile targeting expressions. (supports wildcards "*").
Example selectors:
- The target fragment name (e.g. for HTML - table, tr, pre etc). This type of selector can be contextual in a similar way to contextual selectors in CSS e.g. "td ol li" will target the resource at all "li" elements nested inside an "ol" element, which is in turn nested inside a "td" element. See sample configurations above. Also supports wildcard based fragment selection ("*").
- "$document" is a special selector that targets a resource at the "document" fragment i.e. the whole document, or document root node fragment.
- Targeting a specific SmooksXMLReader at a specific profile. See the csv-to-xml and edi-to-xml tutorials.
XML Based Configuration
Smooks can be manually configured (through code), but the easiest way of working is through XML.
Basic Sample:
Note that it is not using any profiling. The resource-config element maps directly to an instance of this class.
<?xml version='1.0'?>
<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.0.xsd">
<resource-config selector="order order-header">
<resource type="xsl">/com/acme/transform/OrderHeaderTransformer.xsl</resource>
</resource-config>
<resource-config selector="order-items order-item">
<resource>com.acme.transform.MyJavaOrderItemTransformer</resource>
</resource-config>
</smooks-resource-list>
More Complex Sample:
This sample uses profiling. So resource 1 is targeted at both "message-exchange-1" and "message-exchange-2", whereas resource 2 is only targeted at "message-exchange-1" and resource 3 at "message-exchange-2" (see Smooks.createExecutionContext(String)).
<?xml version='1.0'?>
<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.0.xsd">
<profiles>
<profile base-profile="message-exchange-1" sub-profiles="message-producer-A, message-consumer-B" />
<profile base-profile="message-exchange-2" sub-profiles="message-producer-A, message-consumer-C" />
</profiles>
(1) <resource-config selector="order order-header" target-profile="message-producer-A">
<resource>com.acme.transform.AddIdentityInfo</resource>
</resource-config>
(2) <resource-config selector="order-items order-item" target-profile="message-consumer-B">
<resource>com.acme.transform.MyJavaOrderItemTransformer</resource>
<param name="execution-param-X">param-value-forB</param>
</resource-config>
(3) <resource-config selector="order-items order-item" target-profile="message-consumer-C">
<resource>com.acme.transform.MyJavaOrderItemTransformer</resource>
<param name="execution-param-X">param-value-forC</param>
</resource-config>
</smooks-resource-list>
For more examples, check out the tutorials.
Java Based Configuration
TODO!!