Package org.smooks.io
Class AbstractOutputStreamResource
- java.lang.Object
-
- org.smooks.io.AbstractOutputStreamResource
-
- All Implemented Interfaces:
ContentHandler
,Consumer
,PostExecutionLifecycle
,PostFragmentLifecycle
,DOMVisitBefore
,DOMVisitor
,BeforeVisitor
,SaxNgVisitor
,Visitor
public abstract class AbstractOutputStreamResource extends Object implements DOMVisitBefore, Consumer, PostFragmentLifecycle, PostExecutionLifecycle, BeforeVisitor
AbstractOuputStreamResource is the base class for handling output stream resources in Smooks. Note that aWriter
can also be opened on a stream resource. If aWriter
has been opened on a resource, anOutputStream
cannot also be opened (and visa versa). Example configuration:<resource-config selector="#document"> <resource>org.smooks.io.ConcreateImpl</resource> <param name="resourceName">resourceName</param> <param name="writerEncoding">UTF-8</param> <!-- Optional --> </resource-config>
Description of configuration properties:
resource
: should be a concreate implementation of this classresourceName
: the name of this resouce. Will be used to identify this resourcewriterEncoding
: (Optional) the encoding to be used by any writers opened on this resource (Default is "UTF-8")
- Author:
- Daniel Bevenius
-
-
Constructor Summary
Constructors Constructor Description AbstractOutputStreamResource()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected boolean
closeCondition(ExecutionContext executionContext)
protected void
closeResource(ExecutionContext executionContext)
Close the resource output stream.boolean
consumes(Object object)
Does this consumer consume the specified named object.abstract OutputStream
getOutputStream(ExecutionContext executionContext)
Retrieve/create an output stream that is appropriate for the concreate implementationString
getResourceName()
Get the name of this resourceCharset
getWriterEncoding()
void
onPostExecution(ExecutionContext executionContext)
Cleanup the resources allocated by this resource for the specified ExecutionContext.void
onPostFragment(Fragment<?> fragment, ExecutionContext executionContext)
Cleanup the resources allocated by this resource for the specified ExecutionContext.AbstractOutputStreamResource
setResourceName(String resourceName)
Set the name of this resourceAbstractOutputStreamResource
setWriterEncoding(Charset writerEncoding)
void
visitBefore(Element element, ExecutionContext executionContext)
Visit the supplied element before visiting its child elements.
-
-
-
Method Detail
-
getOutputStream
public abstract OutputStream getOutputStream(ExecutionContext executionContext) throws IOException
Retrieve/create an output stream that is appropriate for the concreate implementation- Parameters:
executionContext
- Execution Context.- Returns:
- OutputStream specific to the concreate implementation
- Throws:
IOException
-
getResourceName
public String getResourceName()
Get the name of this resource- Returns:
- The name of the resource
-
consumes
public boolean consumes(Object object)
Description copied from interface:Consumer
Does this consumer consume the specified named object. The named object would be a product of aProducer
that is executing on the same element. The consumer should only returnfalse
if it knows for certain that it doesn't consumer the specified named object. If uncertain, it should error on the side of saying that it does consume the object.
-
setResourceName
public AbstractOutputStreamResource setResourceName(String resourceName)
Set the name of this resource- Parameters:
resourceName
- The name of the resource
-
setWriterEncoding
public AbstractOutputStreamResource setWriterEncoding(Charset writerEncoding)
-
getWriterEncoding
public Charset getWriterEncoding()
-
visitBefore
public void visitBefore(Element element, ExecutionContext executionContext) throws SmooksException
Description copied from interface:DOMVisitBefore
Visit the supplied element before visiting its child elements.- Specified by:
visitBefore
in interfaceBeforeVisitor
- Specified by:
visitBefore
in interfaceDOMVisitBefore
- Parameters:
element
- The DOM element being visited.executionContext
- Request relative instance.- Throws:
SmooksException
- Element processing failure.
-
onPostFragment
public void onPostFragment(Fragment<?> fragment, ExecutionContext executionContext)
Description copied from interface:PostFragmentLifecycle
Cleanup the resources allocated by this resource for the specified ExecutionContext. Executes the cleanup at the end of the fragment visit.- Specified by:
onPostFragment
in interfacePostFragmentLifecycle
- Parameters:
fragment
- The fragment.executionContext
- The ExecutionContext.
-
onPostExecution
public void onPostExecution(ExecutionContext executionContext)
Description copied from interface:PostExecutionLifecycle
Cleanup the resources allocated by this resource for the specified ExecutionContext. Executes the cleanup at the end of the filter execution.- Specified by:
onPostExecution
in interfacePostExecutionLifecycle
- Parameters:
executionContext
- The ExecutionContext.
-
closeCondition
protected boolean closeCondition(ExecutionContext executionContext)
-
closeResource
protected void closeResource(ExecutionContext executionContext)
Close the resource output stream. Classes overriding this method must call super on this method. This will probably need to be done before performing any aditional cleanup.- Parameters:
executionContext
- Smooks ExecutionContext
-
-