com.sas.servlet.util
Class StreamContent

com.sas.servlet.util.StreamContent

public class StreamContent

The StreamContent is a utility class that allows easier use of the StreamContentServlet.

 Example using img tag: 
<%@page import="com.sas.servlet.util.StreamContent"%> <% byte [] b = //get your image bytes here StreamContent s1 = new StreamContent(request, response); s1.setContentKey("testgif"); s1.setContentType("image/gif"); s1.setContentDisposition("inline;filename=test.gif"); s1.setContentBytes(b); %> <img src="<%=s1.getURL()%>"/> Example using jsp:forward tag:
<%@page import="com.sas.servlet.util.StreamContent"%> <% byte [] b = //get your image bytes here StreamContent s1 = new StreamContent(request, response); s1.setContentKey("testgif"); s1.setContentType("image/gif"); s1.setContentDisposition("inline;filename=test.gif"); s1.setContentBytes(b); %> <jsp:forward page="<%=s1.getURL(false)%>" />

See Also:
StreamContentServlet

Constructor Summary
StreamContent(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Constructor
 
Method Summary
 java.lang.String getAbsoluteURL()
          Gets the absolute StreamContentServlet URL.
 byte[] getContentBytes()
          Gets the current content bytes.
 java.lang.String getContentDisposition()
          Gets the current content disposition.
 java.lang.String getContentKey()
          Gets the current content key.
 java.lang.String getContentType()
          Gets the current content type.
 javax.servlet.http.HttpServletRequest getRequest()
          Gets the current request object.
 javax.servlet.http.HttpServletResponse getResponse()
          Gets the current response object.
 java.lang.String getServletMapping()
          Gets the current servlet mapping.
 java.lang.String getURL()
          Gets the complete StreamContentServlet URL.
 java.lang.String getURL(boolean includeContext)
          Gets the complete StreamContentServlet URL.
 boolean isDisposeContents()
          Gets the disposeContents boolean value.
 boolean isNoop()
          Gets the noop boolean value.
 boolean isPersistence()
          Gets the persistence boolean value.
 void setContentBytes(byte[] contentBytes)
          Sets the content bytes to be streamed back to the user.
 void setContentDisposition(java.lang.String contentDisposition)
          Sets the content disposition.
 void setContentKey(java.lang.String contentKey)
          Sets the content key that is used to define unique user parameters for request or session scope.
 void setContentType(java.lang.String contentType)
          Sets the content mime type, such as image/gif.
 void setDisposeContent(boolean disposeContents)
          Sets the disposeContents property.
 void setNoop(boolean noop)
          Set to true if the servlet is to do no operation.
 void setPersistence(boolean persistence)
          Set to true if the servlet is to send the content lenth (based on content bytes) back with the response.
 void setRequest(javax.servlet.http.HttpServletRequest request)
          Sets the request object.
 void setResponse(javax.servlet.http.HttpServletResponse response)
          Sets the response object.
 void setServletMapping(java.lang.String servletMapping)
          Sets the servlet mapping for the StreamContentServlet as defined in the web.xml.
 

Constructor Detail

StreamContent

public StreamContent(javax.servlet.http.HttpServletRequest request,
                     javax.servlet.http.HttpServletResponse response)
Constructor

Parameters:
request - The HttpServletRequest passed to the servlet.
response - The HttpServletResponse passed to the servlet.
Method Detail

setRequest

public void setRequest(javax.servlet.http.HttpServletRequest request)
Sets the request object.

Parameters:
request - The request object

getRequest

public javax.servlet.http.HttpServletRequest getRequest()
Gets the current request object.

Returns:
The request object

setResponse

public void setResponse(javax.servlet.http.HttpServletResponse response)
Sets the response object.

Parameters:
response - The response object

getResponse

public javax.servlet.http.HttpServletResponse getResponse()
Gets the current response object.

Returns:
The response object

setContentKey

public void setContentKey(java.lang.String contentKey)
Sets the content key that is used to define unique user parameters for request or session scope. When sent to the StreamContentServlet, this value is appended to the various StreamContentServlet attribute keys..

Parameters:
contentKey - The content key.

getContentKey

public java.lang.String getContentKey()
Gets the current content key.

Returns:
The content key.

setContentType

public void setContentType(java.lang.String contentType)
Sets the content mime type, such as image/gif.

Parameters:
contentType - The content type.

getContentType

public java.lang.String getContentType()
Gets the current content type.

Returns:
The content type.

setContentDisposition

public void setContentDisposition(java.lang.String contentDisposition)
Sets the content disposition. This is eventually used in the Content-Disposition in the header field.

Parameters:
contentDisposition - The content disposition.

getContentDisposition

public java.lang.String getContentDisposition()
Gets the current content disposition.

Returns:
The content disposition.

setContentBytes

public void setContentBytes(byte[] contentBytes)
Sets the content bytes to be streamed back to the user.

Parameters:
contentBytes - The content bytes.

getContentBytes

public byte[] getContentBytes()
Gets the current content bytes.

Returns:
The content bytes.

setServletMapping

public void setServletMapping(java.lang.String servletMapping)
Sets the servlet mapping for the StreamContentServlet as defined in the web.xml. The default is /StreamContentServlet.

Parameters:
servletMapping - The servlet mapping.

getServletMapping

public java.lang.String getServletMapping()
Gets the current servlet mapping. The default is /StreamContentServlet.

Returns:
The servlet mapping.

setNoop

public void setNoop(boolean noop)
Set to true if the servlet is to do no operation. The default is false.

Parameters:
noop - The boolean no operation value for the servlet.

isNoop

public boolean isNoop()
Gets the noop boolean value. The default is false.

Returns:
True if the servlet is to do no operation.

setPersistence

public void setPersistence(boolean persistence)
Set to true if the servlet is to send the content lenth (based on content bytes) back with the response. The default is true.

Parameters:
persistence - The boolean value for connection persistence.

isPersistence

public boolean isPersistence()
Gets the persistence boolean value. The default is true.

Returns:
True if the servlet reponse is going to set the content length.

getAbsoluteURL

public java.lang.String getAbsoluteURL()
Gets the absolute StreamContentServlet URL. This will add the scheme, server name and port to the URL. For most cases withing a web application, the getURL methods should be used.

Returns:
The absolute URL.

getURL

public java.lang.String getURL()
Gets the complete StreamContentServlet URL. This will call getURL(true).

Returns:
The URL.

getURL

public java.lang.String getURL(boolean includeContext)
Gets the complete StreamContentServlet URL. For URL's that require a context, such as those in a webapp that are using an <img> or <form> tag, you must use getURL() or getURL(true). Those not requiring a context, such as the page attribute in a <jsp:forward> tag must use getURL(false).

Parameters:
includeContext - Set to true if the webapp context is to be prepended to the URL.
Returns:
The URL.

setDisposeContent

public void setDisposeContent(boolean disposeContents)
Sets the disposeContents property. If set to true, the servlet will remove the session stored attributes after the content is delivered.

Parameters:
disposeContents - The content type.

isDisposeContents

public boolean isDisposeContents()
Gets the disposeContents boolean value.

Returns:
true if session stored attributes are to be removed.



Copyright © 2009 SAS Institute Inc. All Rights Reserved.