Expresso 5-6

com.jcorporate.expresso.ext.controller
Class Download

java.lang.Object
  extended byorg.apache.struts.action.Action
      extended bycom.jcorporate.expresso.core.controller.Controller
          extended bycom.jcorporate.expresso.core.controller.DBController
              extended bycom.jcorporate.expresso.ext.controller.Download
All Implemented Interfaces:
Serializable

public class Download
extends DBController

The download controller provides a ready-to-use component for people to download files through. See DBObject for the data definition objects that support this controller

Features supported include:

Author:
Michael Rimov
See Also:
DownloadFiles, MimeTypes, DownloadLog, Serialized Form

Field Summary
 
Fields inherited from class com.jcorporate.expresso.core.controller.Controller
CONTROLLER_PARAM_KEY, CTL_SUCC_CTL, CTL_SUCC_STATE, CTL_SUCC_TRAN, mLog, NEWSTATE_EXCEPTION_KEY, ORIGINAL_URL_KEY, REQUEST_KEY, RESPONSE_KEY, RETURN_TO_SENDER_TRAN, STATE_ERR_CTL, STATE_ERR_STATE, STATE_ERR_TRAN, STATE_PARAM_KEY, STATE_SUCC_CTL, STATE_SUCC_STATE, STATE_SUCC_TRAN
 
Fields inherited from class org.apache.struts.action.Action
ACTION_SERVLET_KEY, APPLICATION_KEY, DATA_SOURCE_KEY, defaultLocale, ERROR_KEY, EXCEPTION_KEY, FORM_BEANS_KEY, FORWARDS_KEY, LOCALE_KEY, MAPPING_KEY, MAPPINGS_KEY, MESSAGE_KEY, MESSAGES_KEY, MULTIPART_KEY, PLUG_INS_KEY, REQUEST_PROCESSOR_KEY, servlet, SERVLET_KEY, TRANSACTION_TOKEN_KEY
 
Constructor Summary
Download()
           
 
Method Summary
protected  void checkIsAllowed(ControllerRequest request, User u, DownloadFiles file)
          Checks file permissions and throws an Exception, and logs an event if the user does not have permission to run.
protected  String getDownloadTime(ControllerResponse response, long fileLength)
          Returns a string estimating download time at 28.8k This function assumes a download rate of 5 Mb / minute
protected  String getFriendlyName(DownloadFiles oneDownloadFile)
          Returns the friendly download name
protected  DownloadFiles getThisDownloadFile(ControllerRequest request, User u)
          Convenience method to retrieve the download file based upon the file parameter
 String getTitle()
          Returns title of this controller
protected  boolean isAllowed(ControllerRequest request, DownloadFiles oneFile, User myUser)
          Is it allowed for this user to download this particular file?
protected  void logInvalidFileRequest(ControllerRequest request, User myUser)
          Sets off the system event for an invalid file number requested.
protected  void returnFile(String filename, OutputStream out)
          Sends the contents of the specified file to the output stream
protected  ControllerResponse runBeginState(ControllerRequest request, ControllerResponse response)
          Starts a download for a file.
protected  ControllerResponse runDownloadState(ControllerRequest controllerRequest, ControllerResponse controllerResponse)
          Returns the file actually requested by the user.
protected  ControllerResponse runListState(ControllerRequest request, ControllerResponse response)
          Lists the files available for download.
protected  void runViewNotesState(ControllerRequest request, ControllerResponse response)
          View the notes associated with the download.
 
Methods inherited from class com.jcorporate.expresso.core.controller.DBController
getString, isAllowed, stateAllowed
 
Methods inherited from class com.jcorporate.expresso.core.controller.Controller
addFinalState, addPromptTransitions, addRegDomainParamtoSession, addRequestedURLtoSession, addState, addStatePairing, endTimer, execute, findControllerForm, generateToken, getActionForward, getControllerChainingTransition, getControllerSecurityTransition, getFinalState, getInitialState, getLogger, getParamValues, getRequestURL, getSchema, getSchemaHierarchy, getSchemaInstance, getSchemaStack, getState, getStates, getString, getString, handleException, instantiate, isFinalState, isHandleState, isPromptState, isTokenValid, loadStateForm, newState, nextHandleState, nextPromptState, populateStateForm, postPerform, prePerform, previousPromptState, processRequestTransitions, processTransitions, redirectRequest, redirectRequest, remapFromExtension, resetToken, saveToken, setControllerChainingTransition, setControllerSecurityTransition, setCurrentState, setInitialState, setSchema, setSchema, setupDefaultValues, setupReturnToSender, setupSubclassLog, transition, transition, transition, unloadStateForm
 
Methods inherited from class org.apache.struts.action.Action
execute, generateToken, getDataSource, getDataSource, getLocale, getResources, getResources, getResources, getServlet, isCancelled, isTokenValid, isTokenValid, perform, perform, resetToken, saveErrors, saveMessages, saveToken, setLocale, setServlet, toHex
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Download

public Download()
Method Detail

getThisDownloadFile

protected DownloadFiles getThisDownloadFile(ControllerRequest request,
                                            User u)
                                     throws ControllerException
Convenience method to retrieve the download file based upon the file parameter

Parameters:
request - The ControllerRequest object
u - the User requesting
Returns:
the DownloadFile DataObject representing the file parameter requested.
Throws:
ControllerException - upon illegal inputs

runBeginState

protected ControllerResponse runBeginState(ControllerRequest request,
                                           ControllerResponse response)
                                    throws ControllerException
Starts a download for a file. Will provide the capability for client side redirects to download the file from a public server

Parameters:
request - The controller request object handed to us by the framework
response - The controller Response that this class fills out.
Returns:
The generated ControllerResponse.
Throws:
ControllerException - if there's an error with the processing of the request.

runListState

protected ControllerResponse runListState(ControllerRequest request,
                                          ControllerResponse response)
                                   throws ControllerException
Lists the files available for download. Source code originally grabbed from the DownloadServlet and converted for controller use. Also

Parameters:
request - The controller request object handed to us by the framework
response - The controller Response that this class fills out.
Returns:
The generated ControllerResponse.
Throws:
ControllerException - if there's an error with the processing of the request.
See Also:
for more information

runDownloadState

protected ControllerResponse runDownloadState(ControllerRequest controllerRequest,
                                              ControllerResponse controllerResponse)
                                       throws ControllerException
Returns the file actually requested by the user. Records the download as well

Parameters:
controllerRequest - The controller request object handed to us by the framework
controllerResponse - The controller Response that this class fills out.
Returns:
The generated ControllerResponse.
Throws:
ControllerException - if there's an error with the processing of the request.

returnFile

protected void returnFile(String filename,
                          OutputStream out)
                   throws FileNotFoundException,
                          IOException
Sends the contents of the specified file to the output stream

Parameters:
filename - the file to send
out - the output stream to write the file
Throws:
FileNotFoundException - if the file does not exist
IOException - if an I/O error occurs

isAllowed

protected boolean isAllowed(ControllerRequest request,
                            DownloadFiles oneFile,
                            User myUser)
                     throws DBException
Is it allowed for this user to download this particular file?

Parameters:
request - The Controller Request object passed to the controller state handler
oneFile - The download file definition
myUser - The user making the controller request.
Returns:
true if the file is allowed
Throws:
DBException - upon database access error

logInvalidFileRequest

protected void logInvalidFileRequest(ControllerRequest request,
                                     User myUser)
                              throws ControllerException
Sets off the system event for an invalid file number requested.

Parameters:
request - The Controller Request object sent to this controller for the state handler.
myUser - The logged-in definition of the user currently logged in.
Throws:
ControllerException - if the download file number was invalid.

getFriendlyName

protected String getFriendlyName(DownloadFiles oneDownloadFile)
                          throws ControllerException,
                                 DBException
Returns the friendly download name

Parameters:
oneDownloadFile - The download file definition object
Returns:
java.lang.String A friendly name for display on the Download listing page.
Throws:
ControllerException - if the record is mal-formed
DBException - if there's an error accessing the database.
See Also:
DownloadFiles

getDownloadTime

protected String getDownloadTime(ControllerResponse response,
                                 long fileLength)
                          throws ControllerException
Returns a string estimating download time at 28.8k This function assumes a download rate of 5 Mb / minute

Parameters:
response - The controller response object to get the requesting user's Locale.
fileLength - The length of the file to calculate.
Returns:
java.lang.String estimating the download time at 28.8k
Throws:
ControllerException - if the download time is unable to get the internationalized strings for Minutes and Seconds.

checkIsAllowed

protected void checkIsAllowed(ControllerRequest request,
                              User u,
                              DownloadFiles file)
                       throws ControllerException
Checks file permissions and throws an Exception, and logs an event if the user does not have permission to run.

Parameters:
request - the ControllerRequest object
u - the user requesting the file
file - the file to download
Throws:
ControllerException - if the file is not allowed for the given user.

getTitle

public String getTitle()
Returns title of this controller

Overrides:
getTitle in class Controller
Returns:
java.lang.String The Title of the controller

runViewNotesState

protected void runViewNotesState(ControllerRequest request,
                                 ControllerResponse response)
                          throws ControllerException
View the notes associated with the download.

Parameters:
request - The controller request object handed to us by the framework
response - The controller Response that this class fills out.
Throws:
ControllerException - upon error [data access or otherwise]

Expresso 5-6

Please see www.jcorporate.com for information about new Expresso releases.