|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectwt.clients.content.UploadDownloadTaskLogic
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 |
public static final String DOWNLOAD
String
used with saveContentChanges
to denote that the action to save the ContentHolder
includes
a Download operation.
public static final String UPLOAD
String
used with saveContentChanges
to denote that the action to save the ContentHolder
includes
an Upload operation.
private static String SECONDARY_EXCLUDE
Constructor Detail |
public UploadDownloadTaskLogic()
Method Detail |
public static HttpContentOperation downloadContentHolder(ContentHolder content_holder, AppletContext context) throws PropertyVetoException, InterruptedException, WTException
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
.
content_holder
- The ContentHolder
which contains
ApplicationData
items to be downloadedcontext
- The AppletContext
which is used
as the context for initiating the download
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
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 downloadContentHolder
,
HttpContentOperation
,
AppletContext
public static HttpContentOperation downloadContents(ContentHolder content_holder, AppletContext context) throws PropertyVetoException, InterruptedException, WTException
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.
content_holder
- The ContentHolder
which contains
the ApplicationData
items to be downloadedcontext
- The AppletContext
which is used
as the context for initiating the download
HttpContentOperation
which was used to initiate the download. This operation was
built by this method, and not retrieved from the given
ContentHolder
itself
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 downloadContentHolder
,
HttpContentOperation
,
AppletContext
public static HttpContentOperation downloadContents(ContentHolder content_holder, Vector content_items, AppletContext applet_context) throws PropertyVetoException, InterruptedException, WTException
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.
content_holder
- The ContentHolder
which is
associated with the given ApplicationData
items
to be downloadedcontent_items
- The Vector
of
ApplicationData
items to be downloaded
HttpContentOperation
which was used to initiate the download. This operation was
built by this method, and not retrieved from the given
ContentHolder
itself
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 downloadContentHolder
,
HttpContentOperation
,
AppletContext
public static HttpContentOperation downloadContents(AppletContext applet_context, HttpContentOperation operation) throws PropertyVetoException, InterruptedException, ContentException, WTException
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
.
operation
- The HttpContentOperation
which
encapsulates the ApplicationData
items to be
downloaded.
HttpContentOperation
which was used to initiate the downloading.
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 downloadHttpContentOperation
,
AppletContext
public static HttpContentOperation waitForHttpStatus(HttpContentOperation operation) throws InterruptedException, PropertyVetoException, WTException
waitForHttpStatus
waits for status on the given
HttpContentOperation
.
operation
- the HttpContentOperation
on which to wait for status
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 statuspublic static ContentHolder getUploadedContent(ContentHolder content_holder) throws PropertyVetoException, WTException
getUploadedContent
returns the ContentHolder
which contains any new content uploaded
content_holder
- the ContentHolder
for which to get
the uploaded content
ContentHolder
object containing the uploaded
content
PropertyVetoException
- if an error occurs retrieving the
ContentHolder
WTException
- if an error occurs retrieving the
ContentHolder
ContentHolder
public static ContentHolder refreshContentHolder(ContentHolder content_holder) throws PropertyVetoException, WTException
refreshContentHolder
returns a refreshed copy of
the given ContentHolder
.
content_holder
- the ContentHolder
to be refreshed
ContentHolder
object
PropertyVetoException
- if an error occurs retrieving the
ContentHolder
WTException
- if an error occurs retrieving the
ContentHolder
ContentHolder
public static Vector getContentItems(ContentHolder content_holder) throws PropertyVetoException, WTException
getContentItems
retrieves the content items associated
with the given ContentHolder
.
content_holder
- The ContentHolder
containing the
ContentItems
to be retrieved
Vector
of ContentItems
associated with
the given ContentHolder
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
ContentHolder
,
ContentItem
,
Vector
public static Vector getFileContentItems(ContentHolder content_holder) throws PropertyVetoException, WTException
getFileContentItems
retrieves all of the files
(ApplicationData
items) contained in the given
ContentHolder
.
content_holder
- the ContentHolder
containing
the files to be retrieved
Vector
of file (ApplicationData
)
items contained in the given ContentHolder
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 itemsContentHolder
,
Vector
public static Vector getUrlContentItems(ContentHolder content_holder) throws PropertyVetoException, WTException
getUrlContentItems
retrieves all of the URLs
(URLData
items) contained in the given ContentHolder
.
content_holder
- the ContentHolder
containing
the URLs to be retrieved
Vector
of URLs (URLData
)
contained in the given ContentHolder
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 URLsContentHolder
,
Vector
public static int getNumberOfContents(ContentHolder content_holder) throws PropertyVetoException, WTException
getNumberOfContents
returns a count of the number
of ContentItems
contained in the given ContentHolder
.
content_holder
- The ContentHolder
for which the
contained ContentItems
are counted
int
count of the current number of
ContentItems
contained in the ContentHolder
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
ContentHolder
public static int getNumberOfFiles(ContentHolder content_holder) throws PropertyVetoException, WTException
getNumberOfFiles
returns a count of the number
of files (ApplicationData
items) contained in the given
ContentHolder
.
content_holder
- The ContentHolder
for which the
contained files are counted
int
count of the current number of files
(ApplicationData
) contained in the
ContentHolder
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 filesContentHolder
,
ApplicationData
public static int getNumberOfUrls(ContentHolder content_holder) throws PropertyVetoException, WTException
getNumberOfUrls
returns a count of the number
of URLs (URLData
items) contained in the given
ContentHolder
.
content_holder
- The ContentHolder
for which the
contained URLs are counted
int
count of the current number of URLs
(URLData
) contained in the ContentHolder
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
itemsContentHolder
,
URLData
public static Vector getMarkedFiles(ContentHolder content_holder) throws PropertyVetoException, WTException
getMarkedFiles
returns all files (ApplicationData
)
associated with the given ContentHolder
which have their
INTENT_TO_CHANGE flag set to true
.
content_holder
- The ContentHolder
for which the
marked files are retrieved
int
count of the current number of files
(ApplicationData
) contained in the
ContentHolder
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 filesContentHolder
,
ApplicationData
public static boolean hasMarkedFiles(ContentHolder content_holder) throws PropertyVetoException, WTException
hasMarkedFiles
checks the given ContentHolder
for any ApplicationData
items that have their INTENT_TO_CHANGE flag
set to true.
content_holder
- the ContentHolder
tested for having any
marked files
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
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 checkedprotected static HttpOperationItem downloadItem(HttpContentOperation operation, HttpOperationItem operation_item, AppletContext context) throws PropertyVetoException, InterruptedException, WTException
PropertyVetoException
InterruptedException
WTException
public static boolean hasContentChanges(TransactionContainer transaction_container)
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.
transaction_container
- the TransactionContainer
to be tested
true
if the given TransactionContainer
contains any assertions; false
otherwiseTransactionContainer
public static ContentHolder saveContentChanges(TransactionContainer transaction_container, ContentHolder content_holder, String http_operation) throws PropertyVetoException, WTException
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 ); ...
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 persistedhttp_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
ContentHolder
PropertyVetoException
- a given change to the ContentHolder
has
been vetoed, or is invalid
WTException
- an error occurred while trying to update the
given ContentHolder
TransactionContainer
,
ContentHolder
,
UPLOAD
,
DOWNLOAD
,
saveContentChanges(wt.container.batch.TransactionContainer, wt.content.ContentHolder, java.lang.String)
public static ContentHolder saveContentChanges(TransactionContainer transaction_container, ContentHolder content_holder) throws PropertyVetoException, WTException
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 ); ...
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
ContentHolder
PropertyVetoException
- a given change to the ContentHolder
has
been vetoed, or is invalid
WTException
- an error occurred while trying to update the
given ContentHolder
TransactionContainer
,
ContentHolder
,
saveContentChanges(wt.container.batch.TransactionContainer, wt.content.ContentHolder, java.lang.String)
public static HttpContentOperation uploadContents(ContentHolder content_holder, AppletContext applet_context) throws PropertyVetoException, InterruptedException, ContentException, WTException
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 ); ...
content_holder
- the ContentHolder
which contains
ContentItems
marked to be uploadedapplet_context
- the AppletContext
used for performing
the actual upload
HttpContentOperation
corresponding to the upload
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 uploadAppletContext
,
ContentHolder
,
HttpContentOperation
public static HttpContentOperation uploadContents(ContentHolder content_holder, Vector files, AppletContext applet_context) throws PropertyVetoException, InterruptedException, ContentException, WTException
ApplicationData
items in the given Vector
.
This method prepares the given ContentHolder
for upload and
then performs the upload. The upload operation is returned.
content_holder
- the ContentHolder
which contains the
ApplicationData
items to be uploadedfiles
- the Vector
of ApplicationData
items to be uploadedapplet_context
- the AppletContext
used in performing the
upload
HttpContentOperation
corresponding to the upload
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 uploadpublic static Vector setIntentForHttpOp(Vector items, boolean flag) throws WTPropertyVetoException
setIntentForHttpOp
updates the intent-to-upload flag for each
ApplicationData
item in the given Vector
.
items
- the Vector
of ApplicationData
items
for which the intent-to-upload flag is set to the given valueflag
- 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.
Vector
of updated ApplicationData
items
WTPropertyVetoException
public static Vector setIntentToChange(Vector items, boolean flag) throws WTPropertyVetoException
setIntentToChange
updates the intent-to-change flag for each
ContentItems
in the given Vector
.
items
- the Vector
of ApplicationData
items
for which the intent-to-change flag is set to the given valueflag
- 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
Vector
of updated ContentItems
WTPropertyVetoException
- if attempt to set the intent-to-change failspublic static boolean isEqual(ContentItem content_a, ContentItem content_b)
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
.
content_a
- one of the two ContentItems
to comparecontent_b
- one of the two ContentItems
to compare
true
if the two ContentItems
reference the
same item; false
otherwisepublic static float getSizeInKilobytes(ApplicationData file)
file
- the ApplicationData
item whose size
is to be converted
float
representation of the file size
in KB.private static float roundToTwoDecimals(float number)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |