Package org.smooks
Class Smooks
- java.lang.Object
-
- org.smooks.Smooks
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
@ThreadSafe public class Smooks extends Object implements Closeable
Smooks executor class. Additional configurations can be carried out on theSmooks
instance through theSmooksUtil
class. The basic usage scenario for this class might be as follows:- Develop (or reuse) an implementation of
ElementVisitor
to perform some transformation/analysis operation on a message. There are a number of prebuilt and reuseable implemntations available as "Smooks Cartridges". - Write a
resource configuration
to target theElementVisitor
implementation at the target fragment of the message being processed. - Apply the logic as follows:
Smooks smooks =
new Smooks
("smooks-config.xml");ExecutionContext
execContext; execContext = smooks.createExecutionContext
(); smooks.filter
(newStreamSource
(...), newStreamResult
(...), execContext);
ElementVisitor
within the context of a single filtering operation. You can also targetDOMElementVisitors
/ElementVisitor
based on target profiles, and so use a single configuration to process multiple messages by sharing profiles across your message set. See Smooks Tutorials.- Author:
- tom.fennelly@gmail.com
-
-
Constructor Summary
Constructors Constructor Description Smooks()
Public Default Constructor.Smooks(InputStream inputStream)
Public constructor.Smooks(String resourceURI)
Public constructor.Smooks(ApplicationContext applicationContext)
Public Default Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addResourceConfig(ResourceConfig resourceConfig)
Add a resource configuration to this Smooks instance.void
addResourceConfigs(InputStream resourceConfigStream)
Add a set of resource configurations to this Smooks instance.void
addResourceConfigs(String resourceURI)
Add a set of resource configurations to this Smooks instance.void
addResourceConfigs(String baseURI, InputStream inputStream)
Add a set of resource configurations to this Smooks instance.ResourceConfig
addVisitor(Visitor visitor)
Add a visitor instance tothis
Smooks instance.ResourceConfig
addVisitor(Visitor visitor, String targetSelector)
Add a visitor instance tothis
Smooks instance.void
addVisitors(VisitorAppender visitorAppender)
void
close()
Close this Smooks instance and all associated resources.ExecutionContext
createExecutionContext()
Create aExecutionContext
instance for use on this Smooks instance.ExecutionContext
createExecutionContext(String targetProfile)
Create aExecutionContext
instance for use on this Smooks instance.void
filterSource(Source source)
Filter the content in the suppliedSource
instance.void
filterSource(Source source, Result... results)
void
filterSource(ExecutionContext executionContext, Source source, Result... results)
ApplicationContext
getApplicationContext()
Get the SmooksApplicationContext
associated with this Smooks instance.Smooks
setExports(Exports exports)
Set the Exports for this Smooks instance.void
setFilterSettings(FilterSettings filterSettings)
Set the filter settings for this Smooks instance.void
setNamespaces(Properties namespaces)
Set the namespace prefix-to-uri mappings to be used on this Smooks instance.void
setReaderConfig(ReaderConfigurator readerConfigurator)
Set the configuration for the reader to be used on this Smooks instance.
-
-
-
Constructor Detail
-
Smooks
public Smooks()
Public Default Constructor. Resource configurations can be added through calls toaddResourceConfigs(String)
oraddResourceConfigs(String, java.io.InputStream)
.
-
Smooks
public Smooks(ApplicationContext applicationContext)
Public Default Constructor. Resource configurations can be added through calls toaddResourceConfigs(String)
oraddResourceConfigs(String, java.io.InputStream)
.
-
Smooks
public Smooks(String resourceURI) throws IOException, SAXException
Public constructor. Adds the set ofresources
via theaddResourceConfigs(String)
method, which resolves the resourceURI parameter using aURIResourceLocator
. Additional resource configurations can be added through calls toaddResourceConfigs(String)
oraddResourceConfigs(String, java.io.InputStream)
.- Parameters:
resourceURI
- XML resource configuration stream URI.- Throws:
IOException
- Error reading resource stream.SAXException
- Error parsing the resource stream.- See Also:
ResourceConfig
-
Smooks
public Smooks(InputStream inputStream) throws IOException, SAXException
Public constructor. Adds the set ofresources
via theaddResourceConfigs(java.io.InputStream)
. Additional resource configurations can be added through calls toaddConfigurations
method set.- Parameters:
inputStream
- XML resource configuration stream.- Throws:
IOException
- Error reading resource stream.SAXException
- Error parsing the resource stream.- See Also:
ResourceConfig
-
-
Method Detail
-
setFilterSettings
public void setFilterSettings(FilterSettings filterSettings)
Set the filter settings for this Smooks instance.- Parameters:
filterSettings
- The filter settings to be used.
-
setExports
public Smooks setExports(Exports exports)
Set the Exports for this Smooks instance.- Parameters:
exports
- The exports that will be created by this Smooks instance.
-
setReaderConfig
public void setReaderConfig(ReaderConfigurator readerConfigurator)
Set the configuration for the reader to be used on this Smooks instance.- Parameters:
readerConfigurator
-ReaderConfigurator
instance.
-
setNamespaces
public void setNamespaces(Properties namespaces)
Set the namespace prefix-to-uri mappings to be used on this Smooks instance.- Parameters:
namespaces
- The namespace prefix-to-uri mappings.
-
addVisitor
public ResourceConfig addVisitor(Visitor visitor)
Add a visitor instance tothis
Smooks instance. This Visitor will be targeted at the root (#document) fragment.- Parameters:
visitor
- The visitor implementation.
-
addVisitor
public ResourceConfig addVisitor(Visitor visitor, String targetSelector)
Add a visitor instance tothis
Smooks instance.- Parameters:
visitor
- The visitor implementation.targetSelector
- The message fragment target selector.
-
addVisitors
public void addVisitors(VisitorAppender visitorAppender)
- Parameters:
visitorAppender
- theVisitorAppender
-
addResourceConfig
public void addResourceConfig(ResourceConfig resourceConfig)
Add a resource configuration to this Smooks instance. These configurations do not overwrite previously added configurations. They are added to the list of configurations on this Smooks instance.- Parameters:
resourceConfig
- The resource configuration to be added.
-
addResourceConfigs
public void addResourceConfigs(String resourceURI) throws IOException, SAXException
Add a set of resource configurations to this Smooks instance. Uses theURIResourceLocator
class to load the resource. These configurations do not overwrite previously added configurations. They are added to the list of configurations on this Smooks instance.- Parameters:
resourceURI
- The URI string for the resource configuration list. SeeURIResourceLocator
.- Throws:
IOException
- Error reading resource stream.SAXException
- Error parsing the resource stream.
-
addResourceConfigs
public void addResourceConfigs(String baseURI, InputStream inputStream) throws SAXException, IOException
Add a set of resource configurations to this Smooks instance. These configurations do not overwrite previously added configurations. They are added to the list of configurations on this Smooks instance. The base URI is required for resolving resource imports. Just specify the location of the resource file.- Parameters:
baseURI
- The base URI string for the resource configuration list. SeeURIResourceLocator
.inputStream
- The resource configuration stream.- Throws:
IOException
- Error reading resource stream.SAXException
- Error parsing the resource stream.
-
addResourceConfigs
public void addResourceConfigs(InputStream resourceConfigStream) throws SAXException, IOException
Add a set of resource configurations to this Smooks instance. CallsaddResourceConfigs(String, java.io.InputStream)
with a baseURI of "./", which is the default base URI on allURIResourceLocator
instances.- Parameters:
resourceConfigStream
- The resource configuration stream.- Throws:
IOException
- Error reading resource stream.SAXException
- Error parsing the resource stream.
-
createExecutionContext
public ExecutionContext createExecutionContext()
Create aExecutionContext
instance for use on this Smooks instance. The created context is profile agnostic and should be used where profile based targeting is not in use. The context returned from this method is used in subsequent calls tofilterSource(ExecutionContext, javax.xml.transform.Source, javax.xml.transform.Result...)
It allows access to the execution context instance before and after calls on this method. This means the caller has an opportunity to set and get databound
to the execution context (before and after the calls), providing the caller with a mechanism for interacting with the contentfiltering
phases.- Returns:
- Execution context instance.
-
createExecutionContext
public ExecutionContext createExecutionContext(String targetProfile) throws UnknownProfileMemberException
Create aExecutionContext
instance for use on this Smooks instance. The created context is profile aware and should be used where profile based targeting is in use. In this case, the transfromation/analysis resources must be configured with profile targeting information. The context returned from this method is used in subsequent calls tofilterSource(ExecutionContext, javax.xml.transform.Source, javax.xml.transform.Result...)
. It allows access to the execution context instance before and after calls on this method. This means the caller has an opportunity to set and get databound
to the execution context (before and after the calls), providing the caller with a mechanism for interacting with the contentfiltering
phases.- Parameters:
targetProfile
- The target profile (base profile
) on behalf of whom the filtering/serialisation filter is to be executed.- Returns:
- Execution context instance.
- Throws:
UnknownProfileMemberException
- Unknown target profile.
-
filterSource
public void filterSource(Source source) throws SmooksException
- Parameters:
source
- The content Source.- Throws:
SmooksException
- Failed to filter.
-
filterSource
public void filterSource(Source source, Result... results) throws SmooksException
Filter the content in the suppliedSource
instance, outputing data to the suppliedResult
instances.- Parameters:
source
- The filter Source.results
- The filter Results.- Throws:
SmooksException
- Failed to filter.
-
filterSource
public void filterSource(ExecutionContext executionContext, Source source, Result... results) throws SmooksException
Filter the content in the suppliedSource
instance, outputing data to the suppliedResult
instances.- Parameters:
executionContext
- TheExecutionContext
for this filter operation. SeecreateExecutionContext(String)
.source
- The filter Source.results
- The filter Results.- Throws:
SmooksException
- Failed to filter.
-
getApplicationContext
public ApplicationContext getApplicationContext()
Get the SmooksApplicationContext
associated with this Smooks instance.- Returns:
- The Smooks
ApplicationContext
.
-
close
public void close()
Close this Smooks instance and all associated resources. Should result in theuninitialization
of all allocatedContentHandler
instances.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
-