public class

UploadFileTask

extends AbstractBaseTask
java.lang.Object
   ↳ com.microstrategy.web.tasks.AbstractBaseTask
     ↳ com.microstrategy.web.tasks.UploadFileTask

Class Overview

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.

Summary

Nested Classes
class UploadFileTask.UploadFileParseOptions A class which holds all parsing options used by the parseUploadedFile(com.microstrategy.web.tasks.UploadFileTask.UploadFileParseOptions, PostedFile, StringBuffer) method. 
[Expand]
Inherited Constants
From class com.microstrategy.web.tasks.AbstractBaseTask
[Expand]
Inherited Fields
From class com.microstrategy.web.tasks.AbstractBaseTask
Public Constructors
UploadFileTask()
Creates a new UploadFileTask object.
Public Methods
void processRequest(TaskRequestContext context, TaskOutput taskOutput)
This method uploads the contents of a file and processes it for use in the MicroStrategy Prompts page.
Protected Methods
void constructTaskOutput(TaskOutput taskOutput, String uploadText, boolean isTruncated, TaskRequestContext ctx, UploadFileTask.UploadFileParseOptions options)
Construct the Task output given the upload file text.
UploadFileTask.UploadFileParseOptions generateParseOptions(RequestKeys requestKeys)
Generate a list of parse options based on the contents of the Task parameters.
boolean parseUploadedFile(UploadFileTask.UploadFileParseOptions options, PostedFile file, StringBuffer buffer)
Parses the contents of the uploaded file text.
PostedFile retrieveUploadedFile(TaskRequestContext context, RequestKeys requestKeys)
Retrieves the uploaded file as an instance of a PostedFile.
void validateExtension(RequestKeys requestKeys, PostedFile file)
Validates whether the extension of the file is acceptable or not.
void validateMaxSize(RequestKeys requestKeys, PostedFile file)
Validate that the maximum size of the uploaded file does not exceed the maximum specified.
void validateUploadedFile(RequestKeys requestKeys, PostedFile file)
Performs a validation of the uploaded file.
[Expand]
Inherited Methods
From class com.microstrategy.web.tasks.AbstractBaseTask
From class java.lang.Object
From interface com.microstrategy.web.tasks.Task

Public Constructors

public UploadFileTask ()

Creates a new UploadFileTask object.

Public Methods

public void processRequest (TaskRequestContext context, TaskOutput taskOutput)

This method uploads the contents of a file and processes it for use in the MicroStrategy Prompts page. It follows through these steps:

  1. Check for required parameters.
  2. Try to retrieve the uploaded file. See retrieveUploadedFile(TaskRequestContext, RequestKeys).
  3. Validate the basic characteristics of the file: max size, extension. See validateUploadedFile(RequestKeys, PostedFile).
  4. Generate a set of options that control the parsing of the uploaded file. See generateParseOptions(RequestKeys).
  5. Parse the text of the uploaded file contents. See parseUploadedFile(com.microstrategy.web.tasks.UploadFileTask.UploadFileParseOptions, PostedFile, StringBuffer).
  6. Generate the full Task response using the parsed uploaded file text. See constructTaskOutput(TaskOutput, String, boolean, TaskRequestContext, com.microstrategy.web.tasks.UploadFileTask.UploadFileParseOptions).

Parameters
context The TaskRequestContext that contains all information about this Task invocation.
taskOutput The TaskOutput that contains our response.
Throws
TaskException If anything fails along the way. See the individual methods invoked by this method.

Protected Methods

protected void constructTaskOutput (TaskOutput taskOutput, String uploadText, boolean isTruncated, TaskRequestContext ctx, UploadFileTask.UploadFileParseOptions options)

Construct the Task output given the upload file text.

Parameters
taskOutput The TaskOutput instance to populate into.
uploadText The uploaded, processed file text.
isTruncated Whether the uploaded text has been truncated because the size limitation
options A UploadFileTask.UploadFileParseOptions object that controls how the parsing is performed.
Throws
TaskException If there was any problem serializing the results to the TaskOutput.

protected UploadFileTask.UploadFileParseOptions generateParseOptions (RequestKeys requestKeys)

Generate a list of parse options based on the contents of the Task parameters.

Parameters
requestKeys The RequestKeys that contains the values of all Task parameters.
Returns

protected boolean parseUploadedFile (UploadFileTask.UploadFileParseOptions options, PostedFile file, StringBuffer buffer)

Parses the contents of the uploaded file text.

Parameters
options A UploadFileTask.UploadFileParseOptions object that controls how the parsing is performed.
file The PostedFile that represents the uploade file.
buffer The output buffer to append the content from file.
Returns
  • Whether the file text has been truncated. true means the file is longer than the limitation set in options, and truncated content has been put into the output buffer. false means full content of the file has been put into the output buffer.
Throws
TaskException If anything fails while parsing the contents of the file.

protected PostedFile retrieveUploadedFile (TaskRequestContext context, RequestKeys requestKeys)

Retrieves the uploaded file as an instance of a PostedFile.

Parameters
context The TaskRequestContext that contains all information about the incoming Task request.
requestKeys The RequestKeys that contains all Task parameter values.
Returns
  • A PostedFile that contains the contents of the uploaded file.
Throws
TaskException If there is no file uploaded.

protected void validateExtension (RequestKeys requestKeys, PostedFile file)

Validates whether the extension of the file is acceptable or not.

Parameters
requestKeys The RequestKeys instance that contains all values of Task parameters.
file The PostedFile that represents our uploaded file.
Throws
TaskException If validation fails.

protected void validateMaxSize (RequestKeys requestKeys, PostedFile file)

Validate that the maximum size of the uploaded file does not exceed the maximum specified.

Parameters
requestKeys The RequestKeys instance that contains all values of Task parameters.
file The PostedFile that represents our uploaded file.
Throws
TaskException If validation fails.

protected void validateUploadedFile (RequestKeys requestKeys, PostedFile file)

Performs a validation of the uploaded file. In this particular instance, it performs two checks:

  1. Checks the size of the uploaded file. See validateMaxSize(RequestKeys, PostedFile).
  2. Checks the extension of the uploaded file. See validateExtension(RequestKeys, PostedFile).

Parameters
requestKeys The RequestKeys instance that contains all values of Task parameters.
file The PostedFile that represents our uploaded file.
Throws
TaskException If any validation fails.