Package org.smooks.io

Class AbstractOutputStreamResource

  • All Implemented Interfaces:
    org.smooks.api.delivery.ContentHandler, org.smooks.api.delivery.ordering.Consumer, org.smooks.api.lifecycle.PostExecutionLifecycle, org.smooks.api.lifecycle.PostFragmentLifecycle, org.smooks.api.resource.visitor.dom.DOMVisitBefore, org.smooks.api.resource.visitor.dom.DOMVisitor, org.smooks.api.resource.visitor.sax.ng.BeforeVisitor, org.smooks.api.resource.visitor.sax.ng.SaxNgVisitor, org.smooks.api.resource.visitor.Visitor

    public abstract class AbstractOutputStreamResource
    extends Object
    implements org.smooks.api.resource.visitor.dom.DOMVisitBefore, org.smooks.api.delivery.ordering.Consumer, org.smooks.api.lifecycle.PostFragmentLifecycle, org.smooks.api.lifecycle.PostExecutionLifecycle, org.smooks.api.resource.visitor.sax.ng.BeforeVisitor
    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.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 class
    • resourceName: the name of this resouce. Will be used to identify this resource
    • writerEncoding: (Optional) the encoding to be used by any writers opened on this resource (Default is "UTF-8")
    Author:
    Daniel Bevenius
    • Field Detail

      • resourceName

        @Inject
        protected String resourceName
      • writerEncoding

        @Inject
        protected Charset writerEncoding
    • Constructor Detail

      • AbstractOutputStreamResource

        public AbstractOutputStreamResource()
    • Method Detail

      • getOutputStream

        public abstract OutputStream getOutputStream​(org.smooks.api.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)
        Specified by:
        consumes in interface org.smooks.api.delivery.ordering.Consumer
      • setResourceName

        public AbstractOutputStreamResource setResourceName​(String resourceName)
        Set the name of this resource
        Parameters:
        resourceName - The name of the resource
      • getWriterEncoding

        public Charset getWriterEncoding()
      • visitBefore

        public void visitBefore​(Element element,
                                org.smooks.api.ExecutionContext executionContext)
                         throws org.smooks.api.SmooksException
        Specified by:
        visitBefore in interface org.smooks.api.resource.visitor.sax.ng.BeforeVisitor
        Specified by:
        visitBefore in interface org.smooks.api.resource.visitor.dom.DOMVisitBefore
        Throws:
        org.smooks.api.SmooksException
      • onPostFragment

        public void onPostFragment​(org.smooks.api.delivery.fragment.Fragment<?> fragment,
                                   org.smooks.api.ExecutionContext executionContext)
        Specified by:
        onPostFragment in interface org.smooks.api.lifecycle.PostFragmentLifecycle
      • onPostExecution

        public void onPostExecution​(org.smooks.api.ExecutionContext executionContext)
        Specified by:
        onPostExecution in interface org.smooks.api.lifecycle.PostExecutionLifecycle
      • closeCondition

        protected boolean closeCondition​(org.smooks.api.ExecutionContext executionContext)
      • closeResource

        protected void closeResource​(org.smooks.api.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
      • bind

        protected void bind​(org.smooks.api.ExecutionContext executionContext)
      • close

        protected void close​(Closeable closeable)