org.milyn.io
Class AbstractOutputStreamResource

java.lang.Object
  extended by org.milyn.io.AbstractOutputStreamResource
All Implemented Interfaces:
ContentHandler, DOMVisitBefore, DOMVisitor, ExecutionLifecycleCleanable, Consumer, SAXVisitBefore, SAXVisitor, VisitLifecycleCleanable, Visitor

public abstract class AbstractOutputStreamResource
extends Object
implements SAXVisitBefore, DOMVisitBefore, Consumer, VisitLifecycleCleanable, ExecutionLifecycleCleanable

AbstractOuputStreamResource is the base class for handling output stream resources in Smooks.

Note that a Writer can also be opened on a stream resource. If a Writer has been opened on a resource, an OutputStream cannot also be opened (and visa versa).

Example configuration:

 <resource-config selector="#document">
    <resource>org.milyn.io.ConcreateImpl</resource>
    <param name="resourceName">resourceName</param>
    <param name="writerEncoding">UTF-8</param> <!-- Optional -->
 </resource-config>
 
Description of configuration properties:

Author:
Daniel Bevenius

Field Summary
protected static String RESOURCE_CONTEXT_KEY_PREFIX
           
 
Constructor Summary
AbstractOutputStreamResource()
           
 
Method Summary
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.
 void executeExecutionLifecycleCleanup(ExecutionContext executionContext)
          Cleanup the resources allocated by this resource for the specified ExecutionContext.
 void executeVisitLifecycleCleanup(ExecutionContext executionContext)
          Cleanup the resources allocated by this resource for the specified ExecutionContext.
abstract  OutputStream getOutputStream(ExecutionContext executionContext)
          Retrieve/create an output stream that is appropriate for the concreate implementation
static OutputStream getOutputStream(String resourceName, ExecutionContext executionContext)
          Get an OutputStream to the named Resource.
static Writer getOutputWriter(String resourceName, ExecutionContext executionContext)
          Get a Writer to the named OutputStream Resource.
 String getResourceName()
          Get the name of this resource
 Charset getWriterEncoding()
           
 AbstractOutputStreamResource setResourceName(String resourceName)
          Set the name of this resource
 AbstractOutputStreamResource setWriterEncoding(Charset writerEncoding)
           
 void visitBefore(Element element, ExecutionContext executionContext)
          Visit the supplied element before visiting its child elements.
 void visitBefore(SAXElement element, ExecutionContext executionContext)
          Visit the supplied element before visiting its child elements.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RESOURCE_CONTEXT_KEY_PREFIX

protected static final String RESOURCE_CONTEXT_KEY_PREFIX
Constructor Detail

AbstractOutputStreamResource

public AbstractOutputStreamResource()
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 a Producer that is executing on the same element. The consumer should only return false 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.

Specified by:
consumes in interface Consumer
Parameters:
object - The product representation
Returns:
True if the consumer consumes the specified product, otherwise false.

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(SAXElement element,
                        ExecutionContext executionContext)
                 throws SmooksException,
                        IOException
Description copied from interface: SAXVisitBefore
Visit the supplied element before visiting its child elements.

Specified by:
visitBefore in interface SAXVisitBefore
Parameters:
element - The SAX element being visited.
executionContext - Execution context.
Throws:
SmooksException - Event processing failure.
IOException - Error writing event to output writer.

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 interface DOMVisitBefore
Parameters:
element - The DOM element being visited.
executionContext - Request relative instance.
Throws:
SmooksException - Element processing failure.

executeVisitLifecycleCleanup

public void executeVisitLifecycleCleanup(ExecutionContext executionContext)
Description copied from interface: VisitLifecycleCleanable
Cleanup the resources allocated by this resource for the specified ExecutionContext.

Executes the cleanup at the end of the fragment visit.

Specified by:
executeVisitLifecycleCleanup in interface VisitLifecycleCleanable
Parameters:
executionContext - The ExecutionContext.

executeExecutionLifecycleCleanup

public void executeExecutionLifecycleCleanup(ExecutionContext executionContext)
Description copied from interface: ExecutionLifecycleCleanable
Cleanup the resources allocated by this resource for the specified ExecutionContext.

Executes the cleanup at the end of the filter execution.

Specified by:
executeExecutionLifecycleCleanup in interface ExecutionLifecycleCleanable
Parameters:
executionContext - The ExecutionContext.

closeCondition

protected boolean closeCondition(ExecutionContext executionContext)

getOutputStream

public static OutputStream getOutputStream(String resourceName,
                                           ExecutionContext executionContext)
                                    throws SmooksException
Get an OutputStream to the named Resource.

Parameters:
resourceName - The resource name.
executionContext - The current ExececutionContext.
Returns:
An OutputStream to the named Resource.
Throws:
SmooksException - Unable to access OutputStream.

getOutputWriter

public static Writer getOutputWriter(String resourceName,
                                     ExecutionContext executionContext)
                              throws SmooksException
Get a Writer to the named OutputStream Resource.

Wraps the OutputStream in a Writer. Uses the "writerEncoding" param to set the encoding on the Writer.

Parameters:
resourceName - The resource name.
executionContext - The current ExececutionContext.
Returns:
A Writer to the named OutputStream Resource.
Throws:
SmooksException - Unable to access OutputStream.

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


Copyright © 2009. All Rights Reserved.