public class Smooks extends Object
Smooks
instance
through the SmooksUtil
class.
The basic usage scenario for this class might be as follows:
DOMElementVisitor
/SAXElementVisitor
to
perform some transformation/analysis operation on a message. There are a number of prebuilt
and reuseable implemntations available as
"Smooks Cartridges".resource configuration
to target the DOMElementVisitor
/SAXElementVisitor
implementation at the target fragment of the message being processed.Smooks smooks =new Smooks
("smooks-config.xml");ExecutionContext
execContext; execContext = smooks.createExecutionContext
(); smooks.filter
(newStreamSource
(...), newStreamResult
(...), execContext);
DOMElementVisitors
/SAXElementVisitor
within the context of a single filtering operation. You can also target
DOMElementVisitors
/SAXElementVisitor
based on target profiles, and so use a single
configuration to process multiple messages by sharing profiles across your message set.
See Smooks Tutorials.Constructor and Description |
---|
Smooks()
Public Default Constructor.
|
Smooks(InputStream resourceConfigStream)
Public constructor.
|
Smooks(StandaloneApplicationContext context)
Public Default Constructor.
|
Smooks(String resourceURI)
Public constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addConfiguration(SmooksResourceConfiguration resourceConfig)
Add a resource configuration to this Smooks instance.
|
void |
addConfigurations(InputStream resourceConfigStream)
Add a set of resource configurations to this Smooks instance.
|
void |
addConfigurations(String resourceURI)
Add a set of resource configurations to this Smooks instance.
|
void |
addConfigurations(String baseURI,
InputStream resourceConfigStream)
Add a set of resource configurations to this Smooks instance.
|
SmooksResourceConfiguration |
addVisitor(Visitor visitor)
Add a visitor instance to
this Smooks instance. |
void |
addVisitor(VisitorAppender appender)
Add a visitor instances to
this Smooks instance
via a VisitorAppender . |
SmooksResourceConfiguration |
addVisitor(Visitor visitor,
String targetSelector)
Add a visitor instance to
this Smooks instance. |
SmooksResourceConfiguration |
addVisitor(Visitor visitor,
String targetSelector,
String targetSelectorNS)
Add a visitor instance to
this Smooks instance. |
void |
close()
Close this Smooks instance and all associated resources.
|
ExecutionContext |
createExecutionContext()
Create a
ExecutionContext instance for use on this Smooks instance. |
ExecutionContext |
createExecutionContext(String targetProfile)
Create a
ExecutionContext instance for use on this Smooks instance. |
void |
filterSource(ExecutionContext executionContext,
Source source,
Result... results)
|
void |
filterSource(Source source)
Filter the content in the supplied
Source instance. |
void |
filterSource(Source source,
Result... results)
|
ApplicationContext |
getApplicationContext()
Get the Smooks
ApplicationContext associated with
this Smooks instance. |
ClassLoader |
getClassLoader()
Get the ClassLoader associated with this Smooks instance.
|
void |
setClassLoader(ClassLoader classLoader)
Set the ClassLoader 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.
|
public Smooks()
addConfigurations(String)
or addConfigurations(String,java.io.InputStream)
.public Smooks(StandaloneApplicationContext context)
addConfigurations(String)
or addConfigurations(String,java.io.InputStream)
.public Smooks(String resourceURI) throws IOException, SAXException
resources
via the addConfigurations(String)
method,
which resolves the resourceURI parameter using a URIResourceLocator
.
Additional resource configurations can be added through calls to
addConfigurations(String)
or addConfigurations(String,java.io.InputStream)
.resourceURI
- XML resource configuration stream URI.IOException
- Error reading resource stream.SAXException
- Error parsing the resource stream.SmooksResourceConfiguration
public Smooks(InputStream resourceConfigStream) throws IOException, SAXException
resources
via the addConfigurations(java.io.InputStream)
.
Additional resource configurations can be added through calls to
addConfigurations
method set.resourceConfigStream
- XML resource configuration stream.IOException
- Error reading resource stream.SAXException
- Error parsing the resource stream.SmooksResourceConfiguration
public ClassLoader getClassLoader()
public void setClassLoader(ClassLoader classLoader)
classLoader
- The ClassLoader instance.public void setFilterSettings(FilterSettings filterSettings)
filterSettings
- The filter settings to be used.public Smooks setExports(Exports exports)
exports
- The exports that will be created by this Smooks instance.public void setReaderConfig(ReaderConfigurator readerConfigurator)
readerConfigurator
- ReaderConfigurator
instance.public void setNamespaces(Properties namespaces)
namespaces
- The namespace prefix-to-uri mappings.public SmooksResourceConfiguration addVisitor(Visitor visitor)
this
Smooks instance.
This Visitor will be targeted at the root (#document) fragment.visitor
- The visitor implementation.public SmooksResourceConfiguration addVisitor(Visitor visitor, String targetSelector)
this
Smooks instance.visitor
- The visitor implementation.targetSelector
- The message fragment target selector.public SmooksResourceConfiguration addVisitor(Visitor visitor, String targetSelector, String targetSelectorNS)
this
Smooks instance.visitor
- The visitor implementation.targetSelector
- The message fragment target selector.targetSelectorNS
- The message fragment target selector namespace.public void addVisitor(VisitorAppender appender)
this
Smooks instance
via a VisitorAppender
.appender
- The visitor appender.public void addConfiguration(SmooksResourceConfiguration resourceConfig)
resourceConfig
- The resource configuration to be added.public void addConfigurations(String resourceURI) throws IOException, SAXException
URIResourceLocator
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.resourceURI
- The URI string for the resource configuration list. See
URIResourceLocator
.IOException
- Error reading resource stream.SAXException
- Error parsing the resource stream.public void addConfigurations(String baseURI, InputStream resourceConfigStream) throws SAXException, IOException
baseURI
- The base URI string for the resource configuration list. See
URIResourceLocator
.resourceConfigStream
- The resource configuration stream.IOException
- Error reading resource stream.SAXException
- Error parsing the resource stream.public void addConfigurations(InputStream resourceConfigStream) throws SAXException, IOException
addConfigurations(String, java.io.InputStream)
with a baseURI of "./",
which is the default base URI on all URIResourceLocator
instances.resourceConfigStream
- The resource configuration stream.IOException
- Error reading resource stream.SAXException
- Error parsing the resource stream.public ExecutionContext createExecutionContext()
ExecutionContext
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 to
filterSource(org.milyn.container.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 data
bound
to the execution context (before and after the calls), providing the
caller with a mechanism for interacting with the content filtering
phases.public ExecutionContext createExecutionContext(String targetProfile) throws UnknownProfileMemberException
ExecutionContext
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 to
filterSource(org.milyn.container.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 data
bound
to the execution context (before and after the calls), providing the
caller with a mechanism for interacting with the content filtering
phases.targetProfile
- The target profile (base profile
) on behalf of whom the filtering/serialisation
filter is to be executed.UnknownProfileMemberException
- Unknown target profile.public void filterSource(Source source) throws SmooksException
source
- The content Source.SmooksException
- Failed to filter.public void filterSource(Source source, Result... results) throws SmooksException
Source
instance, outputing data
to the supplied Result
instances.source
- The filter Source.results
- The filter Results.SmooksException
- Failed to filter.public void filterSource(ExecutionContext executionContext, Source source, Result... results) throws SmooksException
Source
instance, outputing data
to the supplied Result
instances.executionContext
- The ExecutionContext
for this filter operation. See
createExecutionContext(String)
.source
- The filter Source.results
- The filter Results.SmooksException
- Failed to filter.public ApplicationContext getApplicationContext()
ApplicationContext
associated with
this Smooks instance.ApplicationContext
.public void close()
uninitialization
of all allocated ContentHandler
instances.Copyright © 2020. All rights reserved.