org.figure8.join.control
Class DownloadServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by org.figure8.join.control.DownloadServlet
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class DownloadServlet
extends javax.servlet.http.HttpServlet

Servlet that allows to download a file which full UNC path is put into to the query parameters ("path" denotes the directory and "file" short name of file itself).

Version:
$Revision: 1.2 $
Author:
Laurent Broudoux
See Also:
Serialized Form

Field Summary
protected  java.lang.String notExistsURL
          URL to redirect to in case the specified file does not exists.
protected  java.lang.String notReadableURL
          URL to redirect to in case the specified file is not readable.
 
Constructor Summary
DownloadServlet()
           
 
Method Summary
 void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Override of default doGet() method: just call the protected downloadFile() method, passing around request and response.
protected  void downloadFile(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Retrieve the file to download path from query string.
protected  void dumpFile(java.io.File file, java.io.OutputStream os)
          Dump a file content into the given ouput stream.
 void init()
          Override of default init() method.
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPost, doPut, doTrace, getLastModified, 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

notExistsURL

protected java.lang.String notExistsURL
URL to redirect to in case the specified file does not exists.


notReadableURL

protected java.lang.String notReadableURL
URL to redirect to in case the specified file is not readable.

Constructor Detail

DownloadServlet

public DownloadServlet()
Method Detail

init

public void init()
          throws javax.servlet.ServletException
Override of default init() method. Call super.init() and then retrieve and store servlet parameters.

Overrides:
init in class javax.servlet.GenericServlet
Throws:
javax.servlet.ServletException - if one init parameter is missing

doGet

public void doGet(javax.servlet.http.HttpServletRequest request,
                  javax.servlet.http.HttpServletResponse response)
           throws javax.servlet.ServletException,
                  java.io.IOException
Override of default doGet() method: just call the protected downloadFile() method, passing around request and response.

Overrides:
doGet in class javax.servlet.http.HttpServlet
Parameters:
request - The http request (containing query string specifying file)
response - Thee http response (for writing ouput)
Throws:
java.io.IOException - if requested file cannot be opened or written to response
javax.servlet.ServletException - in any other exception case

downloadFile

protected void downloadFile(javax.servlet.http.HttpServletRequest request,
                            javax.servlet.http.HttpServletResponse response)
                     throws java.io.IOException
Retrieve the file to download path from query string. Make some check (non null, existence, readability) before dumping the file into ouputstream. If gzip encoding is supported, wrap the dump into a GZIPOutputStream to save bandwidth ...

Parameters:
request - The http request (containing parameters specifying file)
response - Thee http response (for writing ouput)
Throws:
java.io.IOException - if outputstream cannot be opened or written

dumpFile

protected void dumpFile(java.io.File file,
                        java.io.OutputStream os)
Dump a file content into the given ouput stream. Best efforts are made to cleanly flush & close input and ouput streams.

Parameters:
file - The file to dump
os - The ouput stream to dump in


Copyright © 2005-2008 Join. All Rights Reserved.