|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjavax.servlet.GenericServlet
javax.servlet.http.HttpServlet
org.glassfish.admingui.common.servlet.DownloadServlet
public class DownloadServlet
This Servlet provides the ability to download information from the
Server to the client. It provides the ability to set the content type
of the downloaded file, if not specified, it will attempt to guess
based on the extension (if possible). It requires the
DownloadServlet#ContentSource of the data to download to be
specified by passing in a ServletRequest parameter named
CONTENT_SOURCE_ID. The
DownloadServlet.ContentSource provides a plugable means
of obtaining data from an arbitrary source (i.e. the filesystem,
generated on the fly, from some network location, etc.). The available
DownloadServlet.ContentSource implemenatations must be
specified via a Servlet init parameter named
CONTENT_SOURCES.
| Nested Class Summary | |
|---|---|
static interface |
DownloadServlet.ContentSource
Implement this interface to provide an Object that is capable of providing data to DownloadServlet. |
static class |
DownloadServlet.Context
This class provides information about the request that may be necessary for the DownloadServlet.ContentSource to
provide content. |
| Field Summary | |
|---|---|
static String |
CONTENT_SOURCE_ID
This is the ServletRequest Parameter that should be provided to identify the DownloadServlet.ContentSource
implementation that should be used. |
static String |
CONTENT_SOURCES
This String ("ContentSources") is the name if the Servlet Init Parameter that should be used to register all available DownloadServlet#ContentSource implementations. |
static String |
CONTENT_TYPE
The Content-type ("ContentType"). |
static String |
DEFAULT_CONTENT_TYPE
The Default Content-type ("application/octet-stream"). |
static String |
DOWNLOAD_CONTEXT
This String ("downloadContext") is the name if the ServletRequest Attribute used to store the DownloadServlet#Context object for this request. |
static String |
EXTENSION
This is the DownloadServlet#Context attribute name used to
specify the filename extension of the content. |
static String |
HEADERS
This is the DownloadServlet#Context attribute name used to
specify optional additional headers. |
| Constructor Summary | |
|---|---|
DownloadServlet()
Default Constructor. |
|
| Method Summary | |
|---|---|
void |
doGet(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
This method delegates to the #doPost() method. |
void |
doPost(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
This method is the main method for this class when used in an HttpServlet environment. |
protected DownloadServlet.ContentSource |
getContentSource(javax.servlet.ServletRequest request)
This method locates the appropriate DownloadServlet#ContentSource for this request. |
DownloadServlet.ContentSource |
getContentSource(String id)
This method looks up a DownloadServlet.ContentSource given its id. |
protected DownloadServlet.Context |
getDownloadContext(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
This method instantiates a DownloadServlet.Context and
initializes it with the Servlet, ServletConfig, ServletRequest,
and ServletResponse. |
protected long |
getLastModified(javax.servlet.http.HttpServletRequest request)
This method gets called before the doGet/doPost method. |
void |
init(javax.servlet.ServletConfig config)
Servlet initialization method. |
void |
registerContentSource(Class cls)
This method registers the given class name as a DownloadServlet#ContentSource. |
void |
registerContentSource(String className)
This method registers the given class name as a DownloadServlet#ContentSource. |
protected void |
writeContent(DownloadServlet.ContentSource source,
DownloadServlet.Context context)
This method is responsible for copying the data from the given InputStream to the ServletResponse's
OutputStream. |
protected void |
writeHeader(DownloadServlet.ContentSource source,
DownloadServlet.Context context)
This method is responsible for setting the response header information. |
| Methods inherited from class javax.servlet.http.HttpServlet |
|---|
doDelete, doHead, doOptions, doPut, doTrace, service, service |
| Methods inherited from class javax.servlet.GenericServlet |
|---|
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String DOWNLOAD_CONTEXT
This String ("downloadContext") is the name if the
ServletRequest Attribute used to store the
DownloadServlet#Context object for this request.
public static final String CONTENT_SOURCES
This String ("ContentSources") is the name if the Servlet Init
Parameter that should be used to register all available
DownloadServlet#ContentSource implementations.
public static final String CONTENT_SOURCE_ID
This is the ServletRequest Parameter that should be provided
to identify the DownloadServlet.ContentSource
implementation that should be used. This value must match the
value returned by the DownloadServlet.ContentSource
implementation's getId() method.
public static final String CONTENT_TYPE
The Content-type ("ContentType"). This is the
DownloadServlet#Context attribute used to specify an
explicit "Content-type". It may be set by the
DownloadServlet#ContentSource, or may be passed in via a
request parameter. If not specified, the EXTENSION will
be used. If that fails, the DEFAULT_CONTENT_TYPE will
apply.
public static final String DEFAULT_CONTENT_TYPE
The Default Content-type ("application/octet-stream").
public static final String EXTENSION
This is the DownloadServlet#Context attribute name used to
specify the filename extension of the content. It is the
responsibility of the DownloadServlet#ContentSource to set
this value. The value should represent the filename extension of
the content if it were saved to a filesystem.
public static final String HEADERS
This is the DownloadServlet#Context attribute name used to
specify optional additional headers. It must be set to
| Constructor Detail |
|---|
public DownloadServlet()
Default Constructor.
| Method Detail |
|---|
public void init(javax.servlet.ServletConfig config)
throws javax.servlet.ServletException
Servlet initialization method.
init in interface javax.servlet.Servletinit in class javax.servlet.GenericServletjavax.servlet.ServletExceptionpublic void registerContentSource(String className)
This method registers the given class name as a
DownloadServlet#ContentSource. This method will attempt
to resolve and instantiate the class using the current
classloader.
public void registerContentSource(Class cls)
This method registers the given class name as a
DownloadServlet#ContentSource. This method will attempt
to instantiate the class via the default constructor.
public DownloadServlet.ContentSource getContentSource(String id)
This method looks up a DownloadServlet.ContentSource given its id.
The DownloadServlet#ContentSource must be previously
registered.
public void doGet(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
throws javax.servlet.ServletException,
IOException
This method delegates to the #doPost() method.
doGet in class javax.servlet.http.HttpServletjavax.servlet.ServletException
IOException
public void doPost(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
throws javax.servlet.ServletException,
IOException
This method is the main method for this class when used in an
HttpServlet environment. It drives the process, which
includes creating a DownloadServet#Context, choosing the
appropriate DownloadServlet#ContentSource, and copying the
output of the DownloadServlet#ContentSource to the
ServletResponse's OutputStream.
doPost in class javax.servlet.http.HttpServletjavax.servlet.ServletException
IOException
protected DownloadServlet.Context getDownloadContext(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
This method instantiates a DownloadServlet.Context and
initializes it with the Servlet, ServletConfig, ServletRequest,
and ServletResponse.
protected DownloadServlet.ContentSource getContentSource(javax.servlet.ServletRequest request)
This method locates the appropriate
DownloadServlet#ContentSource for this request. It uses
the given ServletRequest to look for a
ServletRequest Parameter named CONTENT_SOURCE_ID.
This value is used as the key when looking up registered
DownloadServlet#ContentSource implementations.
protected void writeHeader(DownloadServlet.ContentSource source,
DownloadServlet.Context context)
This method is responsible for setting the response header information.
protected void writeContent(DownloadServlet.ContentSource source,
DownloadServlet.Context context)
This method is responsible for copying the data from the given
InputStream to the ServletResponse's
OutputStream. The InputStream should be
the from the DownloadServlet#ContentSource.
protected long getLastModified(javax.servlet.http.HttpServletRequest request)
This method gets called before the doGet/doPost method. The
requires us to create the DownloadServlet#Context here.
However, we do not have the HttpServletResponse yet,
so it will be null.
getLastModified in class javax.servlet.http.HttpServlet
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||