EchoPoint API - 3.0.0b5
App Webcontainer

echopoint.tucana.event
Class DefaultUploadCallback

java.lang.Object
  extended by echopoint.tucana.event.UploadCallbackAdapter
      extended by echopoint.tucana.event.DefaultUploadCallback
All Implemented Interfaces:
UploadCallback, Serializable, EventListener

public class DefaultUploadCallback
extends UploadCallbackAdapter

A default implementation of an UploadCallback that saves the uploaded file(s) to a specified directory.

Note: Development of this component was sponsored by TCN Broadcasting. We are grateful for their support and sponsorship.

Version:
$Id: DefaultUploadCallback.java 106 2009-02-03 16:00:33Z sptrakesh $
Author:
Rakesh 2008-11-9
See Also:
Serialized Form

Field Summary
protected static String FILE_SEPARATOR
          The file separator character to use.
protected static String TEMP_DIR
          The system default temporary directory.
 
Fields inherited from class echopoint.tucana.event.UploadCallbackAdapter
event, level, logger, uploadIndex
 
Constructor Summary
protected DefaultUploadCallback()
          Default constructor to allow sub-classing.
  DefaultUploadCallback(File directory)
          Create a new callback handler that saves files to the specified directory.
 
Method Summary
 File getDirectory()
          Accessor for property 'directory'.
protected  File getFileName(String name)
          Return a file object that represents the uploaded file that is to be saved.
protected  File getTempFile()
          Return a temporary file to which the contents of the uploaded file will be initially written.
 void setDirectory(File directory)
          Mutator for property 'directory'.
 void uploadSucceeded(UploadFinishEvent event)
          Over-ridden to save the contents of the uploaded file to directory.
 
Methods inherited from class echopoint.tucana.event.UploadCallbackAdapter
getEvent, getLevel, setLevel, uploadCancelled, uploadDisallowed, uploadFailed, uploadProgressed, uploadStarted
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FILE_SEPARATOR

protected static final String FILE_SEPARATOR
The file separator character to use.


TEMP_DIR

protected static final String TEMP_DIR
The system default temporary directory.

Constructor Detail

DefaultUploadCallback

protected DefaultUploadCallback()
Default constructor to allow sub-classing.


DefaultUploadCallback

public DefaultUploadCallback(File directory)
                      throws IllegalArgumentException
Create a new callback handler that saves files to the specified directory.

Parameters:
directory - The directory to which files are to be saved.
Throws:
IllegalArgumentException - If the file specified is not a directory.
Method Detail

uploadSucceeded

public void uploadSucceeded(UploadFinishEvent event)
Over-ridden to save the contents of the uploaded file to directory. Client-code should ideally wrap this method in a try-catch clause to handle file copying errors and update the UI as appropriate. Call back method invoked once an upload event completes.

Specified by:
uploadSucceeded in interface UploadCallback
Overrides:
uploadSucceeded in class UploadCallbackAdapter
Parameters:
event - The event that has completed.
Throws:
RuntimeException - If errors are encountered while copying the uploaded file to the specified directory.

getFileName

protected File getFileName(String name)
Return a file object that represents the uploaded file that is to be saved.

Parameters:
name - The file name of the uploaded file.
Returns:
The new file object that represents the file to be saved.

getTempFile

protected File getTempFile()
Return a temporary file to which the contents of the uploaded file will be initially written. This file will then be moved to the proper destination file. This ensures atomic creation of the new file.

Returns:
The temporary file to create.

getDirectory

public File getDirectory()
Accessor for property 'directory'.

Returns:
Value for property 'directory'.

setDirectory

public void setDirectory(File directory)
                  throws IllegalArgumentException
Mutator for property 'directory'.

Parameters:
directory - Value to set for property 'directory'.
Throws:
IllegalArgumentException - If the file specified is not a directory.

EchoPoint API - 3.0.0b5
App Webcontainer