wt.clients.content
Class UploadDownloadTaskLogic

java.lang.Object
  extended bywt.clients.content.UploadDownloadTaskLogic

public class UploadDownloadTaskLogic
extends Object

Class UploadDownloadTaskLogic is a utility class which provides static methods for uploading and downloading files, and manipulating ContentHolder objects. The methods in this class encapsulate the calls to the server.

Supported API:true

Extendable:false


Field Summary
static String DOWNLOAD
          Defined constant String used with saveContentChanges to denote that the action to save the ContentHolder includes a Download operation.
private static String SECONDARY_EXCLUDE
           
static String UPLOAD
          Defined constant String used with saveContentChanges to denote that the action to save the ContentHolder includes an Upload operation.
 
Constructor Summary
UploadDownloadTaskLogic()
           
 
Method Summary
static HttpContentOperation downloadContentHolder(ContentHolder content_holder, AppletContext context)
          Method downloadContentHolder initiates a download of ApplicationData items contained in the given ContentHolder.
static HttpContentOperation downloadContents(AppletContext applet_context, HttpContentOperation operation)
          Method downloadContents downloads ApplicationData items which are associated with a ContentHolder object.
static HttpContentOperation downloadContents(ContentHolder content_holder, AppletContext context)
          Method downloadContents initiates a download of all of the files (ApplicationData items) contained in the given ContentHolder.
static HttpContentOperation downloadContents(ContentHolder content_holder, Vector content_items, AppletContext applet_context)
          Method downloadContents downloads the given Vector of ApplicationData items which are associated with the given ContentHolder.
protected static HttpOperationItem downloadItem(HttpContentOperation operation, HttpOperationItem operation_item, AppletContext context)
           
static Vector getContentItems(ContentHolder content_holder)
          Method getContentItems retrieves the content items associated with the given ContentHolder.
static Vector getFileContentItems(ContentHolder content_holder)
          Method getFileContentItems retrieves all of the files (ApplicationData items) contained in the given ContentHolder.
static Vector getMarkedFiles(ContentHolder content_holder)
          Method getMarkedFiles returns all files (ApplicationData) associated with the given ContentHolder which have their INTENT_TO_CHANGE flag set to true.
static int getNumberOfContents(ContentHolder content_holder)
          Method getNumberOfContents returns a count of the number of ContentItems contained in the given ContentHolder.
static int getNumberOfFiles(ContentHolder content_holder)
          Method getNumberOfFiles returns a count of the number of files (ApplicationData items) contained in the given ContentHolder.
static int getNumberOfUrls(ContentHolder content_holder)
          Method getNumberOfUrls returns a count of the number of URLs (URLData items) contained in the given ContentHolder.
static float getSizeInKilobytes(ApplicationData file)
          Convenience method to convert the file size into KiloBytes.
static ContentHolder getUploadedContent(ContentHolder content_holder)
          Method getUploadedContent returns the ContentHolder which contains any new content uploaded
static Vector getUrlContentItems(ContentHolder content_holder)
          Method getUrlContentItems retrieves all of the URLs (URLData items) contained in the given ContentHolder.
static boolean hasContentChanges(TransactionContainer transaction_container)
          Method hasContentChanges determines if the given TransactionContainer is non-empty.
static boolean hasMarkedFiles(ContentHolder content_holder)
          Method hasMarkedFiles checks the given ContentHolder for any ApplicationData items that have their INTENT_TO_CHANGE flag set to true.
static boolean isEqual(ContentItem content_a, ContentItem content_b)
          Method isEqual tests whether two given ContentItems are the same item.
static ContentHolder refreshContentHolder(ContentHolder content_holder)
          Method refreshContentHolder returns a refreshed copy of the given ContentHolder.
private static float roundToTwoDecimals(float number)
           
static ContentHolder saveContentChanges(TransactionContainer transaction_container, ContentHolder content_holder)
          Method saveContentChanges makes the given changes to the given ContentHolder persistent.
static ContentHolder saveContentChanges(TransactionContainer transaction_container, ContentHolder content_holder, String http_operation)
          Method saveContentChanges makes the given changes to the given ContentHolder persistent.
static Vector setIntentForHttpOp(Vector items, boolean flag)
          Method setIntentForHttpOp updates the intent-to-upload flag for each ApplicationData item in the given Vector.
static Vector setIntentToChange(Vector items, boolean flag)
          Method setIntentToChange updates the intent-to-change flag for each ContentItems in the given Vector.
static HttpContentOperation uploadContents(ContentHolder content_holder, AppletContext applet_context)
          Method uploadContents uploads ApplicationData as specified by the HttpContentOperation contained in the given ContentHolder.
static HttpContentOperation uploadContents(ContentHolder content_holder, Vector files, AppletContext applet_context)
          Uploads the ApplicationData items in the given Vector.
static HttpContentOperation waitForHttpStatus(HttpContentOperation operation)
          Method waitForHttpStatus waits for status on the given HttpContentOperation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DOWNLOAD

public static final String DOWNLOAD
Defined constant String used with saveContentChanges to denote that the action to save the ContentHolder includes a Download operation.

See Also:
Constant Field Values

UPLOAD

public static final String UPLOAD
Defined constant String used with saveContentChanges to denote that the action to save the ContentHolder includes an Upload operation.

See Also:
Constant Field Values

SECONDARY_EXCLUDE

private static String SECONDARY_EXCLUDE
Constructor Detail

UploadDownloadTaskLogic

public UploadDownloadTaskLogic()
Method Detail

downloadContentHolder

public static HttpContentOperation downloadContentHolder(ContentHolder content_holder,
                                                         AppletContext context)
                                                  throws PropertyVetoException,
                                                         InterruptedException,
                                                         WTException
Method downloadContentHolder initiates a download of ApplicationData items contained in the given ContentHolder. This method assumes that the files (ApplicationData items) to be downloaded are given in the HttpContentOperation which is contained within the given ContentHolder itself.

This method attempts to retrieve the HttpContentOperation from the given ContentHolder and initiates a download using the retrieved HttpContentOperation.

Parameters:
content_holder - The ContentHolder which contains ApplicationData items to be downloaded
context - The AppletContext which is used as the context for initiating the download
Returns:
HttpContentOperation The HttpContentOperation which was retrieved from the ContentHolder and used to initiate the download. The returned operation could be null if no operation was contained in the given ContentHolder
Throws:
PropertyVetoException - if waiting for the status of the upload fails
InterruptedException - if the download operation is interrupted
WTException - if an error occurs trying to get the URL for the download
See Also:
ContentHolder, HttpContentOperation, AppletContext

downloadContents

public static HttpContentOperation downloadContents(ContentHolder content_holder,
                                                    AppletContext context)
                                             throws PropertyVetoException,
                                                    InterruptedException,
                                                    WTException
Method downloadContents initiates a download of all of the files (ApplicationData items) contained in the given ContentHolder. The download is serialized in which each ApplicationData item is downloaded individually.

Parameters:
content_holder - The ContentHolder which contains the ApplicationData items to be downloaded
context - The AppletContext which is used as the context for initiating the download
Returns:
HttpContentOperation The HttpContentOperation which was used to initiate the download. This operation was built by this method, and not retrieved from the given ContentHolder itself
Throws:
PropertyVetoException - if waiting for the status of the upload fails
InterruptedException - if the download operation is interrupted
WTException - if an error occurs trying to get the URL for the download
See Also:
ContentHolder, HttpContentOperation, AppletContext

downloadContents

public static HttpContentOperation downloadContents(ContentHolder content_holder,
                                                    Vector content_items,
                                                    AppletContext applet_context)
                                             throws PropertyVetoException,
                                                    InterruptedException,
                                                    WTException
Method downloadContents downloads the given Vector of ApplicationData items which are associated with the given ContentHolder. The download is serialized in which each of the given ApplicationData items is downloaded individually.

Parameters:
content_holder - The ContentHolder which is associated with the given ApplicationData items to be downloaded
content_items - The Vector of ApplicationData items to be downloaded
Returns:
HttpContentOperation The HttpContentOperation which was used to initiate the download. This operation was built by this method, and not retrieved from the given ContentHolder itself
Throws:
PropertyVetoException - if waiting for the status of the upload fails
InterruptedException - if the download operation is interrupted
WTException - if an error occurs trying to get the URL for the download
See Also:
ContentHolder, HttpContentOperation, AppletContext

downloadContents

public static HttpContentOperation downloadContents(AppletContext applet_context,
                                                    HttpContentOperation operation)
                                             throws PropertyVetoException,
                                                    InterruptedException,
                                                    ContentException,
                                                    WTException
Method downloadContents downloads ApplicationData items which are associated with a ContentHolder object. The specific ApplicationData items to be downloaded are specified in the given HttpContentOperation. The download is serialized in which each of the ApplicationData items specified in the given HttpContentOperation are downloaded individually. This method provides support for downloading each ApplicationData item in a separate Thread.

Parameters:
operation - The HttpContentOperation which encapsulates the ApplicationData items to be downloaded.
Returns:
HttpContentOperation The updated HttpContentOperation which was used to initiate the downloading.
Throws:
PropertyVetoException - if waiting for the status of the upload fails
InterruptedException - if the download operation is interrupted
ContentException - if an error occurs getting the status of the downloads
WTException - if an error occurs trying to get the URL for the download
See Also:
HttpContentOperation, AppletContext

waitForHttpStatus

public static HttpContentOperation waitForHttpStatus(HttpContentOperation operation)
                                              throws InterruptedException,
                                                     PropertyVetoException,
                                                     WTException
Method waitForHttpStatus waits for status on the given HttpContentOperation.

Parameters:
operation - the HttpContentOperation on which to wait for status
Returns:
HttpContentOperation the updated operation which contains the status of the HTTP operation
Throws:
InterruptedException - if the HttpContentOperation is interrupted
PropertyVetoException - if waiting for the status of the operation fails
WTException - if an error occurs trying to get the status

getUploadedContent

public static ContentHolder getUploadedContent(ContentHolder content_holder)
                                        throws PropertyVetoException,
                                               WTException
Method getUploadedContent returns the ContentHolder which contains any new content uploaded

Parameters:
content_holder - the ContentHolder for which to get the uploaded content
Returns:
the ContentHolder object containing the uploaded content
Throws:
PropertyVetoException - if an error occurs retrieving the ContentHolder
WTException - if an error occurs retrieving the ContentHolder
See Also:
ContentHolder

refreshContentHolder

public static ContentHolder refreshContentHolder(ContentHolder content_holder)
                                          throws PropertyVetoException,
                                                 WTException
Method refreshContentHolder returns a refreshed copy of the given ContentHolder.

Parameters:
content_holder - the ContentHolder to be refreshed
Returns:
the refreshed ContentHolder object
Throws:
PropertyVetoException - if an error occurs retrieving the ContentHolder
WTException - if an error occurs retrieving the ContentHolder
See Also:
ContentHolder

getContentItems

public static Vector getContentItems(ContentHolder content_holder)
                              throws PropertyVetoException,
                                     WTException
Method getContentItems retrieves the content items associated with the given ContentHolder.

Parameters:
content_holder - The ContentHolder containing the ContentItems to be retrieved
Returns:
the Vector of ContentItems associated with the given ContentHolder
Throws:
PropertyVetoException - if an error is thrown by the server while retrieving the ContentItems
WTException - if an error is thrown by the server while retrieving the ContentItems
See Also:
ContentHolder, ContentItem, Vector

getFileContentItems

public static Vector getFileContentItems(ContentHolder content_holder)
                                  throws PropertyVetoException,
                                         WTException
Method getFileContentItems retrieves all of the files (ApplicationData items) contained in the given ContentHolder.

Parameters:
content_holder - the ContentHolder containing the files to be retrieved
Returns:
the Vector of file (ApplicationData) items contained in the given ContentHolder
Throws:
PropertyVetoException - if an error is thrown by the server while retrieving the file items
WTException - if an error is thrown by the server while retrieving the file items
See Also:
ContentHolder, Vector

getUrlContentItems

public static Vector getUrlContentItems(ContentHolder content_holder)
                                 throws PropertyVetoException,
                                        WTException
Method getUrlContentItems retrieves all of the URLs (URLData items) contained in the given ContentHolder.

Parameters:
content_holder - the ContentHolder containing the URLs to be retrieved
Returns:
the Vector of URLs (URLData) contained in the given ContentHolder
Throws:
PropertyVetoException - if an error is thrown by the server while retrieving the URLs
WTException - if an error is thrown by the server while retrieving the URLs
See Also:
ContentHolder, Vector

getNumberOfContents

public static int getNumberOfContents(ContentHolder content_holder)
                               throws PropertyVetoException,
                                      WTException
Method getNumberOfContents returns a count of the number of ContentItems contained in the given ContentHolder.

Parameters:
content_holder - The ContentHolder for which the contained ContentItems are counted
Returns:
an int count of the current number of ContentItems contained in the ContentHolder
Throws:
PropertyVetoException - if an error is thrown by the server while retrieving the ContentItems
WTException - if an error is thrown by the server while retrieving the ContentItems
See Also:
ContentHolder

getNumberOfFiles

public static int getNumberOfFiles(ContentHolder content_holder)
                            throws PropertyVetoException,
                                   WTException
Method getNumberOfFiles returns a count of the number of files (ApplicationData items) contained in the given ContentHolder.

Parameters:
content_holder - The ContentHolder for which the contained files are counted
Returns:
an int count of the current number of files (ApplicationData) contained in the ContentHolder
Throws:
PropertyVetoException - if an error is thrown by the server while retrieving the files
WTException - if an error is thrown by the server while retrieving the files
See Also:
ContentHolder, ApplicationData

getNumberOfUrls

public static int getNumberOfUrls(ContentHolder content_holder)
                           throws PropertyVetoException,
                                  WTException
Method getNumberOfUrls returns a count of the number of URLs (URLData items) contained in the given ContentHolder.

Parameters:
content_holder - The ContentHolder for which the contained URLs are counted
Returns:
an int count of the current number of URLs (URLData) contained in the ContentHolder
Throws:
PropertyVetoException - if an error is thrown by the server while retrieving the URLData items
WTException - if an error is thrown by the server while retrieving the URLData items
See Also:
ContentHolder, URLData

getMarkedFiles

public static Vector getMarkedFiles(ContentHolder content_holder)
                             throws PropertyVetoException,
                                    WTException
Method getMarkedFiles returns all files (ApplicationData) associated with the given ContentHolder which have their INTENT_TO_CHANGE flag set to true.

Parameters:
content_holder - The ContentHolder for which the marked files are retrieved
Returns:
an int count of the current number of files (ApplicationData) contained in the ContentHolder
Throws:
PropertyVetoException - if an error is thrown by the server while retrieving the files
WTException - if an error is thrown by the server while retrieving the files
See Also:
ContentHolder, ApplicationData

hasMarkedFiles

public static boolean hasMarkedFiles(ContentHolder content_holder)
                              throws PropertyVetoException,
                                     WTException
Method hasMarkedFiles checks the given ContentHolder for any ApplicationData items that have their INTENT_TO_CHANGE flag set to true.

Parameters:
content_holder - the ContentHolder tested for having any marked files
Returns:
true if the given ContentHolder contains files (ApplicationData items) that have their INTENT_TO_CHANGE flag set to true; false if the given ContentHolder does not contain any marked files
Throws:
PropertyVetoException - if an error is thrown by the server while retrieving the files to be checked
WTException - if an error is thrown by the server while retrieving the files to be checked

downloadItem

protected static HttpOperationItem downloadItem(HttpContentOperation operation,
                                                HttpOperationItem operation_item,
                                                AppletContext context)
                                         throws PropertyVetoException,
                                                InterruptedException,
                                                WTException
Throws:
PropertyVetoException
InterruptedException
WTException

hasContentChanges

public static boolean hasContentChanges(TransactionContainer transaction_container)
Method hasContentChanges determines if the given TransactionContainer is non-empty. For APIs that manipulate objects via TransactionContainers (i.e. saveContentChanges), this method is useful in testing if any changes have been made that should be saved.

Parameters:
transaction_container - the TransactionContainer to be tested
Returns:
true if the given TransactionContainer contains any assertions; false otherwise
See Also:
TransactionContainer

saveContentChanges

public static ContentHolder saveContentChanges(TransactionContainer transaction_container,
                                               ContentHolder content_holder,
                                               String http_operation)
                                        throws PropertyVetoException,
                                               WTException
Method saveContentChanges makes the given changes to the given ContentHolder persistent. This method applies the modifications contained in the given TransactionContainer to the given ContentHolder and persists the resulting changes. If the modifications include any pending uploads or downloads, then the specific type of HTTP operation pending - either UPLOAD or DOWNLOAD - must be specified by the given String. If the given String does not specify the type of HTTP operation, the changes contained in the TransactionContainer will be applied to the ContentHolder and no preparations for pending HTTP operations will be made.

Eg.

       TransactionContainer trx =
                 BatchContainerFactory.instantiateTransactionContainer();
       BatchContainer contents  =
                 BatchContainerFactory.instantiateGeneralBatchContainer(trx, "Contents");
       Vector content_items     =
                 UploadDownloadTaskLogic.getContentItems( content_holder );
       contents.populate( content_items );
       ...
       my_file.setIntentToChange( true );
       my_file.setIntendedForHttpOp( true );
       ...
       if( content_items.contains( my_file ) ) {
          content_items.replace( my_file );
       } else {
          content_items.add( my_file );
       }
       content_holder =
                UploadDownloadTaskLogic.saveContentChanges( trx, content_holder,
                                                            UploadDownloadTaskLogic.UPLOAD );
       ...
  

Parameters:
transaction_container - the TransactionContainer containing the asserted modifications which are to be applied to the given ContentHolder.
content_holder - the ContentHolder to which the changes are applied and persisted
http_operation - UploadDownloadTaskLogic.UPLOAD -- the changes specified by the TransactionContainer include files (ApplicationData items) that have been set for an intended upload, UploadDownloadTaskLogic.DOWNLOAD -- the changes specified by the TransactionContainer include files (ApplicationData items) that have been set for an intended download, null -- there are no pending uploads or downloads specified by the given changes
Returns:
the updated ContentHolder
Throws:
PropertyVetoException - a given change to the ContentHolder has been vetoed, or is invalid
WTException - an error occurred while trying to update the given ContentHolder
See Also:
TransactionContainer, ContentHolder, UPLOAD, DOWNLOAD, saveContentChanges(wt.container.batch.TransactionContainer, wt.content.ContentHolder, java.lang.String)

saveContentChanges

public static ContentHolder saveContentChanges(TransactionContainer transaction_container,
                                               ContentHolder content_holder)
                                        throws PropertyVetoException,
                                               WTException
Method saveContentChanges makes the given changes to the given ContentHolder persistent. This method applies the modifications contained in the given TransactionContainer to the given ContentHolder and persists the resulting changes.

Eg.

       TransactionContainer trx =
                 BatchContainerFactory.instantiateTransactionContainer();
       BatchContainer contents  =
                 BatchContainerFactory.instantiateGeneralBatchContainer(trx, "Contents");
       Vector content_items     =
                 UploadDownloadTaskLogic.getContentItems( content_holder );
       contents.populate( content_items );
       ...
       my_file.setFileName( "new_file.doc" );
       ...
       if( content_items.contains( my_file ) ) {
          content_items.replace( my_file );
       } else {
          content_items.add( my_file );
       }
       content_holder =
                UploadDownloadTaskLogic.saveContentChanges( trx, content_holder );
       ...
  

Parameters:
transaction_container - the TransactionContainer containing the asserted modifications which are to be applied to the given ContentHolder.
content_holder - the ContentHolder to which the changes are applied and persisted
Returns:
the updated ContentHolder
Throws:
PropertyVetoException - a given change to the ContentHolder has been vetoed, or is invalid
WTException - an error occurred while trying to update the given ContentHolder
See Also:
TransactionContainer, ContentHolder, saveContentChanges(wt.container.batch.TransactionContainer, wt.content.ContentHolder, java.lang.String)

uploadContents

public static HttpContentOperation uploadContents(ContentHolder content_holder,
                                                  AppletContext applet_context)
                                           throws PropertyVetoException,
                                                  InterruptedException,
                                                  ContentException,
                                                  WTException
Method uploadContents uploads ApplicationData as specified by the HttpContentOperation contained in the given ContentHolder. This method retrieves the HttpContentOperation corresponding to the upload from the given ContentHolder and initiates the upload using that retrieved HTTP operation object. This method should be called after invoking saveContentChanges in which the content changes included marking files as intended to be uploaded. E.g.
       TransactionContainer trx =
                 BatchContainerFactory.instantiateTransactionContainer();
       BatchContainer contents  =
                 BatchContainerFactory.instantiateGeneralBatchContainer(trx, "Contents");
       Vector content_items     =
                 UploadDownloadTaskLogic.getContentItems( content_holder );
       contents.populate( content_items );
       ...
       my_file.setIntentToChange( true );
       my_file.setIntendedForHttpOp( true );
       ...
       if( content_items.contains( my_file ) ) {
          content_items.replace( my_file );
       } else {
          content_items.add( my_file );
       }
       // Save changes and prepare for Upload
       content_holder =
                UploadDownloadTaskLogic.saveContentChanges( trx, content_holder,
                                                            UploadDownloadTaskLogic.UPLOAD );
       // Now perform upload
       HttpContentOperation upload =
                UploadDownloadTaskLogic.uploadContents( content_holder, my_applet_context );
       ...
 

Parameters:
content_holder - the ContentHolder which contains ContentItems marked to be uploaded
applet_context - the AppletContext used for performing the actual upload
Returns:
the HttpContentOperation corresponding to the upload
Throws:
PropertyVetoException - if an error is thrown by the server while trying to retrieve the upload status
InterruptedException - if the upload is interrupted
ContentException - if an error is thrown by the server while performing the upload
WTException - if an error is thrown by the server while performing the upload
See Also:
AppletContext, ContentHolder, HttpContentOperation

uploadContents

public static HttpContentOperation uploadContents(ContentHolder content_holder,
                                                  Vector files,
                                                  AppletContext applet_context)
                                           throws PropertyVetoException,
                                                  InterruptedException,
                                                  ContentException,
                                                  WTException
Uploads the ApplicationData items in the given Vector. This method prepares the given ContentHolder for upload and then performs the upload. The upload operation is returned.

Parameters:
content_holder - the ContentHolder which contains the ApplicationData items to be uploaded
files - the Vector of ApplicationData items to be uploaded
applet_context - the AppletContext used in performing the upload
Returns:
the HttpContentOperation corresponding to the upload
Throws:
PropertyVetoException - if an error is thrown by the server while trying to retrieve the upload status
InterruptedException - if the upload is interrupted
ContentException - if an error is thrown by the server while performing the upload
WTException - if an error is thrown by the server while performing the upload

setIntentForHttpOp

public static Vector setIntentForHttpOp(Vector items,
                                        boolean flag)
                                 throws WTPropertyVetoException
Method setIntentForHttpOp updates the intent-to-upload flag for each ApplicationData item in the given Vector.

Parameters:
items - the Vector of ApplicationData items for which the intent-to-upload flag is set to the given value
flag - the value to which the intent-to-upload flag on each of the given ApplicationData items is set; true indicates the ApplicationData item is intended to be either uploaded or downloaded, false indicates there is no intention of either uploading or downloading the ApplicationData item.
Returns:
the Vector of updated ApplicationData items
Throws:
WTPropertyVetoException

setIntentToChange

public static Vector setIntentToChange(Vector items,
                                       boolean flag)
                                throws WTPropertyVetoException
Method setIntentToChange updates the intent-to-change flag for each ContentItems in the given Vector.

Parameters:
items - the Vector of ApplicationData items for which the intent-to-change flag is set to the given value
flag - the value to which the intent-to-change flag is set; true indicates the ContentItem is intended to be modified, false indicates there is no intention of modifying the ContentItem
Returns:
the Vector of updated ContentItems
Throws:
WTPropertyVetoException - if attempt to set the intent-to-change fails

isEqual

public static boolean isEqual(ContentItem content_a,
                              ContentItem content_b)
Method isEqual tests whether two given ContentItems are the same item. This method does not test to see whether or not two ContentItems have the same value, but tests to see if the two ContentItems are referencing the same ContentItem.

Parameters:
content_a - one of the two ContentItems to compare
content_b - one of the two ContentItems to compare
Returns:
true if the two ContentItems reference the same item; false otherwise

getSizeInKilobytes

public static float getSizeInKilobytes(ApplicationData file)
Convenience method to convert the file size into KiloBytes.

Parameters:
file - the ApplicationData item whose size is to be converted
Returns:
a float representation of the file size in KB.

roundToTwoDecimals

private static float roundToTwoDecimals(float number)