Package com.microstrategy.web.tasks
Class UploadFileTask
- java.lang.Object
 - 
- com.microstrategy.web.tasks.AbstractBaseTask
 - 
- com.microstrategy.web.tasks.UploadFileTask
 
 
 
- 
- All Implemented Interfaces:
 Task
public class UploadFileTask extends AbstractBaseTask
This Task processes the file uploaded from an HTML form and returns the content of the file to client. Client side JavaScript can not read the contents of local files for security reasons.- Since:
 - MicroStrategy Web 9.0.0
 
 
- 
- 
Nested Class Summary
Nested Classes Modifier and Type Class Description static classUploadFileTask.UploadFileParseOptionsA class which holds all parsing options used by theparseUploadedFile(com.microstrategy.web.tasks.UploadFileTask.UploadFileParseOptions, PostedFile, StringBuffer)method. 
- 
Field Summary
- 
Fields inherited from class com.microstrategy.web.tasks.AbstractBaseTask
compressOutput, CONTENT_TYPE_BINARY, CONTENT_TYPE_HTML, CONTENT_TYPE_JSON, CONTENT_TYPE_JSON_ALL, CONTENT_TYPE_JSON_D, CONTENT_TYPE_JSON_P, CONTENT_TYPE_XML, CONTENT_TYPE_XML_ANF, DEFAULT_MAX_WAIT, DEFAULT_POLLING_FREQ, execFlagsParam, INDEFINITE_MAX_WAIT, maxWaitParam, metadata, mPrivileges, msgIDParam, objectIDParam, OTHER_CONTENT_KEY_LAYOUTS, PARAM_NAME_EXEC_FLAGS, PARAM_NAME_MAX_WAIT, PARAM_NAME_MESSAGE_ID, PARAM_NAME_OBJECT_ID, PARAM_NAME_POLLING_FREQ, PARAM_NAME_RESULT_FLAGS, PARAM_NAME_SESSION_ID, PARAM_NAME_SESSION_STATE, PARAM_NAME_STATE_ID, pollingFreqParam, PREFERENCE_DEFAULT_MAX_WAIT_IN_TASK, resultFlagsParam, sessionIDParam, sessionStateParam, stateIDParam 
 - 
 
- 
Constructor Summary
Constructors Constructor Description UploadFileTask()Creates a new UploadFileTask object. 
- 
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidconstructTaskOutput(TaskOutput taskOutput, java.lang.String uploadText, boolean isTruncated, TaskRequestContext ctx, UploadFileTask.UploadFileParseOptions options)Construct the Task output given the upload file text.protected UploadFileTask.UploadFileParseOptionsgenerateParseOptions(RequestKeys requestKeys)Generate a list of parse options based on the contents of the Task parameters.protected booleanparseUploadedFile(UploadFileTask.UploadFileParseOptions options, PostedFile file, java.lang.StringBuffer buffer)Parses the contents of the uploaded file text.voidprocessRequest(TaskRequestContext context, TaskOutput taskOutput)This method uploads the contents of a file and processes it for use in the MicroStrategy Prompts page.protected PostedFileretrieveUploadedFile(TaskRequestContext context, RequestKeys requestKeys)Retrieves the uploaded file as an instance of a PostedFile.protected voidvalidateExtension(RequestKeys requestKeys, PostedFile file)Validates whether the extension of the file is acceptable or not.protected voidvalidateMaxSize(RequestKeys requestKeys, PostedFile file)Validate that the maximum size of the uploaded file does not exceed the maximum specified.protected voidvalidateUploadedFile(RequestKeys requestKeys, PostedFile file)Performs a validation of the uploaded file.- 
Methods inherited from class com.microstrategy.web.tasks.AbstractBaseTask
addExecFlagsParam, addJuilLayouts, addMaxWaitParam, addMaxWaitParam, addMessageIDParam, addObjectIDParam, addParameterMetadata, addParameterMetadata, addParameterMetadata, addPollingFrequencyParam, addPollingFrequencyParam, addResultFlagsParam, addSessionIDParam, addSessionStateParam, addStateIDParam, checkForRequiredParameters, destroy, getCompressOutput, getID, getMetadata, getPrivileges, getSysDefaultPreferenceValue, init, newRequestContext, processRequest, retrieveUploadedFile, setCompressOutput, setDescription, setID, setMetadata, setPrivileges, validateContentType 
 - 
 
 - 
 
- 
- 
Method Detail
- 
processRequest
public void processRequest(TaskRequestContext context, TaskOutput taskOutput) throws TaskException
This method uploads the contents of a file and processes it for use in the MicroStrategy Prompts page. It follows through these steps:- Check for required parameters.
 - Try to retrieve the uploaded file. See 
retrieveUploadedFile(TaskRequestContext, RequestKeys). - Validate the basic characteristics of the file: max
      size, extension. See 
validateUploadedFile(RequestKeys, PostedFile). - Generate a set of options that control the parsing
      of the uploaded file. See 
generateParseOptions(RequestKeys). - Parse the text of the uploaded file contents. See
      
parseUploadedFile(com.microstrategy.web.tasks.UploadFileTask.UploadFileParseOptions, PostedFile, StringBuffer). - Generate the full Task response using the parsed
      uploaded file text. See 
constructTaskOutput(TaskOutput, String, boolean, TaskRequestContext, com.microstrategy.web.tasks.UploadFileTask.UploadFileParseOptions). 
- Specified by:
 processRequestin interfaceTask- Overrides:
 processRequestin classAbstractBaseTask- Parameters:
 context- TheTaskRequestContextthat contains all information about this Task invocation.taskOutput- TheTaskOutputthat contains our response.- Throws:
 TaskException- If anything fails along the way. See the individual methods invoked by this method.- See Also:
 Task.processRequest(TaskRequestContext, TaskOutput)
 
- 
retrieveUploadedFile
protected PostedFile retrieveUploadedFile(TaskRequestContext context, RequestKeys requestKeys) throws TaskException
Retrieves the uploaded file as an instance of a PostedFile.- Parameters:
 context- TheTaskRequestContextthat contains all information about the incoming Task request.requestKeys- TheRequestKeysthat contains all Task parameter values.- Returns:
 - A 
PostedFilethat contains the contents of the uploaded file. - Throws:
 TaskException- If there is no file uploaded.
 
- 
validateUploadedFile
protected void validateUploadedFile(RequestKeys requestKeys, PostedFile file) throws TaskException
Performs a validation of the uploaded file. In this particular instance, it performs two checks:- Checks the size of the uploaded file. See 
validateMaxSize(RequestKeys, PostedFile). - Checks the extension of the uploaded file. See
      
validateExtension(RequestKeys, PostedFile). 
- Parameters:
 requestKeys- TheRequestKeysinstance that contains all values of Task parameters.file- ThePostedFilethat represents our uploaded file.- Throws:
 TaskException- If any validation fails.
 - Checks the size of the uploaded file. See 
 
- 
validateExtension
protected void validateExtension(RequestKeys requestKeys, PostedFile file) throws TaskException
Validates whether the extension of the file is acceptable or not.- Parameters:
 requestKeys- TheRequestKeysinstance that contains all values of Task parameters.file- ThePostedFilethat represents our uploaded file.- Throws:
 TaskException- If validation fails.
 
- 
validateMaxSize
protected void validateMaxSize(RequestKeys requestKeys, PostedFile file) throws TaskException
Validate that the maximum size of the uploaded file does not exceed the maximum specified.- Parameters:
 requestKeys- TheRequestKeysinstance that contains all values of Task parameters.file- ThePostedFilethat represents our uploaded file.- Throws:
 TaskException- If validation fails.
 
- 
generateParseOptions
protected UploadFileTask.UploadFileParseOptions generateParseOptions(RequestKeys requestKeys)
Generate a list of parse options based on the contents of the Task parameters.- Parameters:
 requestKeys- TheRequestKeysthat contains the values of all Task parameters.- Returns:
 - An instance of the 
UploadFileTask.UploadFileParseOptionsclass that contains values for all parse options. 
 
- 
parseUploadedFile
protected boolean parseUploadedFile(UploadFileTask.UploadFileParseOptions options, PostedFile file, java.lang.StringBuffer buffer) throws TaskException
Parses the contents of the uploaded file text.- Parameters:
 options- AUploadFileTask.UploadFileParseOptionsobject that controls how the parsing is performed.file- ThePostedFilethat represents the uploade file.buffer- The output buffer to append the content from file.- Returns:
 - Whether the file text has been truncated. 
truemeans the file is longer than the limitation set in options, and truncated content has been put into the output buffer.falsemeans full content of the file has been put into the output buffer. - Throws:
 TaskException- If anything fails while parsing the contents of the file.
 
- 
constructTaskOutput
protected void constructTaskOutput(TaskOutput taskOutput, java.lang.String uploadText, boolean isTruncated, TaskRequestContext ctx, UploadFileTask.UploadFileParseOptions options) throws TaskException
Construct the Task output given the upload file text.- Parameters:
 taskOutput- TheTaskOutputinstance to populate into.uploadText- The uploaded, processed file text.isTruncated- Whether the uploaded text has been truncated because the size limitationoptions- AUploadFileTask.UploadFileParseOptionsobject that controls how the parsing is performed.- Throws:
 TaskException- If there was any problem serializing the results to the TaskOutput.
 
 - 
 
 -