Package rife.engine

Class AbstractResponse

java.lang.Object
rife.engine.AbstractResponse
All Implemented Interfaces:
Response
Direct Known Subclasses:
HttpResponse, MockResponse

public abstract class AbstractResponse extends Object implements Response
This abstract class implements parts of the Response interface to provide behaviour that is specific to RIFE2.

Additional abstract methods have been provided to integrate with the concrete back-end classes that extend AbstractResponse.

Since:
1.0
  • Field Details

    • contentType_

      protected String contentType_
    • lastElement_

      protected Element lastElement_
    • textBufferEnabled_

      protected boolean textBufferEnabled_
    • textBuffer_

      protected ArrayList<CharSequence> textBuffer_
    • responseOutputStream_

      protected OutputStream responseOutputStream_
    • gzipByteOutputStream_

      protected ByteArrayOutputStream gzipByteOutputStream_
    • gzipOutputStream_

      protected GZIPOutputStream gzipOutputStream_
    • outputStream_

      protected OutputStream outputStream_
  • Constructor Details

    • AbstractResponse

      protected AbstractResponse(Request request)
      Constructor that needs to be called by all the constructors of the extending classes.
      Parameters:
      request - the Request that is associated with this response
      Since:
      1.0
  • Method Details

    • _setContentType

      protected abstract void _setContentType(String contentType)
      This method needs to be implemented by the extending back-end class and will be called by AbstractResponse during the RIFE2-specific additional behaviour. It behaves exactly like its counter-part in the Response interface.
      Since:
      1.0
      See Also:
    • _getOutputStream

      protected abstract OutputStream _getOutputStream() throws IOException
      This method needs to be implemented by the extending back-end class and will be called by AbstractResponse during the RIFE2-specific additional behaviour. It behaves exactly like its counter-part in the Request interface.
      Throws:
      IOException
      Since:
      1.0
      See Also:
    • getRequest

      public Request getRequest()
      Retrieves the request that is associated with this response.
      Returns:
      the associated request
      Since:
      1.0
    • setLastElement

      public void setLastElement(Element element)
      Description copied from interface: Response
      Sets the latest target element of this response. This method is called repeatedly by the engine to make it possible to trace which elements have been processed.
      Specified by:
      setLastElement in interface Response
      Parameters:
      element - an element that has been executed in the context of this response
    • getLastElement

      public Element getLastElement()
      Description copied from interface: Response
      Retrieves the element that was last processed with
      Specified by:
      getLastElement in interface Response
      Returns:
      the last element
    • isContentTypeSet

      public boolean isContentTypeSet()
      Description copied from interface: Response
      Indicates whether this response's content type has been explicitly set.
      Specified by:
      isContentTypeSet in interface Response
      Returns:
      true if it has been set; or

      false otherwise

      See Also:
    • getContentType

      public String getContentType()
      Description copied from interface: Response
      Retrieves the content type that was explicitly set for this response.
      Specified by:
      getContentType in interface Response
      Returns:
      the content type as a String; or

      null if the content type wasn't set

      See Also:
    • setContentType

      public void setContentType(String contentType)
      Description copied from interface: Response
      Specified by:
      setContentType in interface Response
    • enableTextBuffer

      public void enableTextBuffer(boolean enabled)
      Description copied from interface: Response
      Enables or disabled the text output buffer.

      The buffer is enabled by default and its buffered contents will be flushed when the buffer is disabled.

      Specified by:
      enableTextBuffer in interface Response
      Parameters:
      enabled - true to enable the text buffer; or

      false to disable it

    • isTextBufferEnabled

      public boolean isTextBufferEnabled()
      Description copied from interface: Response
      Indicates whether the text output buffer is enabled.
      Specified by:
      isTextBufferEnabled in interface Response
      Returns:
      true when the text buffer is enabled; or

      false when it is disabled.

    • print

      public void print(Template template) throws EngineException
      Description copied from interface: Response
      Prints the content of a template to the request text output.
      Specified by:
      print in interface Response
      Parameters:
      template - the template that will be printed
      Throws:
      EngineException - if an error occurs during the output of the template content
      See Also:
    • print

      public void print(Collection<CharSequence> deferredContent) throws EngineException
      Description copied from interface: Response
      Prints a list of text snippets to the request text output.
      Specified by:
      print in interface Response
      Parameters:
      deferredContent - the text snippets that will be printed
      Throws:
      EngineException - if an error occurs during the output of the text snippets // * @see #print(Template)
      See Also:
    • print

      public void print(Object value) throws EngineException
      Description copied from interface: Response
      Prints the string representation of an object to the request text output. The string representation will be created through a String.valueOf(value) call.
      Specified by:
      print in interface Response
      Parameters:
      value - the object that will be output
      Throws:
      EngineException - if an error occurs during the output of the content // * @see #print(Template)
      See Also:
    • clearBuffer

      public void clearBuffer()
      Description copied from interface: Response
      Clears the text buffer is it's enabled.

      If the text buffer is disabled, this method does nothing.

      Specified by:
      clearBuffer in interface Response
    • flush

      public void flush() throws EngineException
      Description copied from interface: Response
      Forces all the streamed content to be output to the client.

      If the text buffer is enabled, this will flush its content to the output stream first.

      Specified by:
      flush in interface Response
      Throws:
      EngineException
    • close

      public void close() throws EngineException
      Description copied from interface: Response
      Closed the content output stream.

      All content is flushed first.

      Specified by:
      close in interface Response
      Throws:
      EngineException
    • getOutputStream

      public OutputStream getOutputStream() throws EngineException
      Description copied from interface: Response
      Specified by:
      getOutputStream in interface Response
      Throws:
      EngineException