org.milyn.io
Class AbstractOutputStreamResource

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

public abstract class AbstractOutputStreamResource
extends Object
implements SAXVisitBefore, SAXVisitAfter, DOMElementVisitor, 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  void closeResource(ExecutionContext executionContext)
          Close the resource output stream.
 void executeExecutionLifecycleCleanup(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()
          Return the name of this resource
 Charset getWriterEncoding()
           
 void visitAfter(Element element, ExecutionContext executionContext)
          Visit the supplied element after visiting its child elements.
 void visitAfter(SAXElement element, ExecutionContext executionContext)
          Visit the supplied element after visiting its child elements.
 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()
Return the name of this resource

Returns:
String - the name of the resource

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.

visitAfter

public void visitAfter(SAXElement element,
                       ExecutionContext executionContext)
                throws SmooksException,
                       IOException
Description copied from interface: SAXVisitAfter
Visit the supplied element after visiting its child elements.

Specified by:
visitAfter in interface SAXVisitAfter
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.

visitAfter

public void visitAfter(Element element,
                       ExecutionContext executionContext)
                throws SmooksException
Description copied from interface: DOMVisitAfter
Visit the supplied element after visiting its child elements.

Specified by:
visitAfter in interface DOMVisitAfter
Parameters:
element - The DOM element being visited.
executionContext - Request relative instance.
Throws:
SmooksException - Element processing failure.

executeExecutionLifecycleCleanup

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

Specified by:
executeExecutionLifecycleCleanup in interface ExecutionLifecycleCleanable
Parameters:
executionContext - The 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 © 2008. All Rights Reserved.