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 theSmooksinstance through theSmooksUtilclass. The basic usage scenario for this class might be as follows:- Develop (or reuse) an implementation of
ElementVisitorto perform some transformation/analysis operation on a message. There are a number of prebuilt and reuseable implemntations available as "Smooks Cartridges". - Write a
resource configurationto target theElementVisitorimplementation at the target fragment of the message being processed. - Apply the logic as follows:
Smooks smooks =
new Smooks("smooks-config.xml");ExecutionContextexecContext; execContext = smooks.createExecutionContext(); smooks.filter(newStreamSource(...), newStreamResult(...), execContext);
ElementVisitorwithin the context of a single filtering operation. You can also targetDOMElementVisitors/ElementVisitorbased 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 voidaddResourceConfig(ResourceConfig resourceConfig)Add a resource configuration to this Smooks instance.voidaddResourceConfigs(InputStream resourceConfigStream)Add a set of resource configurations to this Smooks instance.voidaddResourceConfigs(String resourceURI)Add a set of resource configurations to this Smooks instance.voidaddResourceConfigs(String baseURI, InputStream inputStream)Add a set of resource configurations to this Smooks instance.ResourceConfigaddVisitor(Visitor visitor)Add a visitor instance tothisSmooks instance.ResourceConfigaddVisitor(Visitor visitor, String targetSelector)Add a visitor instance tothisSmooks instance.voidaddVisitors(VisitorAppender visitorAppender)voidclose()Close this Smooks instance and all associated resources.ExecutionContextcreateExecutionContext()Create aExecutionContextinstance for use on this Smooks instance.ExecutionContextcreateExecutionContext(String targetProfile)Create aExecutionContextinstance for use on this Smooks instance.voidfilterSource(Source source)Filter the content in the suppliedSourceinstance.voidfilterSource(Source source, Result... results)voidfilterSource(ExecutionContext executionContext, Source source, Result... results)ApplicationContextgetApplicationContext()Get the SmooksApplicationContextassociated with this Smooks instance.SmookssetExports(Exports exports)Set the Exports for this Smooks instance.voidsetFilterSettings(FilterSettings filterSettings)Set the filter settings for this Smooks instance.voidsetNamespaces(Properties namespaces)Set the namespace prefix-to-uri mappings to be used on this Smooks instance.voidsetReaderConfig(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 ofresourcesvia 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 ofresourcesvia theaddResourceConfigs(java.io.InputStream). Additional resource configurations can be added through calls toaddConfigurationsmethod 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-ReaderConfiguratorinstance.
-
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 tothisSmooks 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 tothisSmooks 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 theURIResourceLocatorclass 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 allURIResourceLocatorinstances.- Parameters:
resourceConfigStream- The resource configuration stream.- Throws:
IOException- Error reading resource stream.SAXException- Error parsing the resource stream.
-
createExecutionContext
public ExecutionContext createExecutionContext()
Create aExecutionContextinstance 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 databoundto the execution context (before and after the calls), providing the caller with a mechanism for interacting with the contentfilteringphases.- Returns:
- Execution context instance.
-
createExecutionContext
public ExecutionContext createExecutionContext(String targetProfile) throws UnknownProfileMemberException
Create aExecutionContextinstance 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 databoundto the execution context (before and after the calls), providing the caller with a mechanism for interacting with the contentfilteringphases.- 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 suppliedSourceinstance, outputing data to the suppliedResultinstances.- 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 suppliedSourceinstance, outputing data to the suppliedResultinstances.- Parameters:
executionContext- TheExecutionContextfor this filter operation. SeecreateExecutionContext(String).source- The filter Source.results- The filter Results.- Throws:
SmooksException- Failed to filter.
-
getApplicationContext
public ApplicationContext getApplicationContext()
Get the SmooksApplicationContextassociated with this Smooks instance.- Returns:
- The Smooks
ApplicationContext.
-
close
public void close()
Close this Smooks instance and all associated resources. Should result in theuninitializationof all allocatedContentHandlerinstances.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
-