org.mycore.frontend.fileupload
Class MCRUploadHandler

java.lang.Object
  extended by org.mycore.frontend.fileupload.MCRUploadHandler
Direct Known Subclasses:
MCRSWFUploadHandlerMyCoRe, MCRUploadHandlerIFS

public abstract class MCRUploadHandler
extends Object

This class does the server-side of uploading files from a client browser, which runs the upload applet. This is an abstract base class that must be subclassed to implement the storage of files at the server side for miless, MyCoRe or other usages of the upload framework. Every instance of MCRUploadHandler handles one singe upload session with the applet.

Version:
$Revision: 14552 $ $Date: 2008-12-10 13:50:10 +0100 (Mi, 10 Dez 2008) $
Author:
Harald Richter, Frank Lützenkirchen
See Also:
MCRUploadHandlerManager

Field Summary
protected  Logger logger
          The logger *
protected  String uploadID
          The unique ID of this upload session *
protected  String url
          The url where to go after upload is finished.
 
Constructor Summary
protected MCRUploadHandler()
          Creates a new upload handler and registers it at the handler manager *
 
Method Summary
 boolean acceptFile(String path, String checksum, long length)
          Before the applet sends each file, this method is called to ask if this file should be uploaded and will be accepted by the server.
 void cancelUpload()
          After the remote user canceled the upload process in the applet, this method is called so that the UploadHandler subclass can finish or cancel work.
abstract  void finishUpload()
          When the applet finished uploading all files, this method is called so that the UploadHandler subclass can finish work and commit all saved files.
 String getID()
          Returns the unique ID of this upload session *
 String getRedirectURL()
          Returns the url where to go after upload is finished *
abstract  long receiveFile(String path, InputStream in, long length, String md5)
          When the applet uploads a file, this method is called so that the UploadHandler subclass can store the file on the server side.
abstract  void startUpload(int numFiles)
          Starts the upload session.
 void unregister()
          When the applet is closed after uploading all files, the servlet calls this method automatically to unregister this upload handler from the UploadHandlerManager.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected Logger logger
The logger *


uploadID

protected String uploadID
The unique ID of this upload session *


url

protected String url
The url where to go after upload is finished. *

Constructor Detail

MCRUploadHandler

protected MCRUploadHandler()
Creates a new upload handler and registers it at the handler manager *

Method Detail

getID

public final String getID()
Returns the unique ID of this upload session *


getRedirectURL

public String getRedirectURL()
Returns the url where to go after upload is finished *


startUpload

public abstract void startUpload(int numFiles)
                          throws Exception
Starts the upload session.

Parameters:
numFiles - the number of files that the applet will upload
Throws:
Exception

acceptFile

public boolean acceptFile(String path,
                          String checksum,
                          long length)
                   throws Exception
Before the applet sends each file, this method is called to ask if this file should be uploaded and will be accepted by the server. The default implementation always returns true (always upload file), but subclasses should overwrite this method to decide whether the file's content must be uploaded. Decision can be based on the MD5 checksum that the applet calculated on the client side, so unchanged files do not have to be uploaded again.

Parameters:
path - the path and filename of the file
checksum - the MD5 checksum computed at the client applet side
length - the length of the file in bytes (file size)
Returns:
true, if the file should be uploaded, false if the file should be skipped
Throws:
Exception

receiveFile

public abstract long receiveFile(String path,
                                 InputStream in,
                                 long length,
                                 String md5)
                          throws Exception
When the applet uploads a file, this method is called so that the UploadHandler subclass can store the file on the server side. When the UploadHandler could read less than length bytes from the InputStream at the time the InputStream has no data any more, the user at the remote side canceled upload during file transfer. The UploadHandler then can decide to delete the file, but must return the number of bytes stored. The UploadHandler can also compare the MD5 checksum calculated at the client side with its own checksum, to detect magical transfer errors. This method is not covered by a database transaction. The implementation has to handle transactions by itself.

Parameters:
path - the path and filename of the file
in - the inputstream to read the content of the file from
length - the total file size as number of bytes. This may be 0, meaning that the file is empty or the file size is not known.
md5 - the md5 checksum calculated at the client applet side. This may be null, meaning that the md5 checksum is not known.
Returns:
the number of bytes that have been stored.
Throws:
Exception

finishUpload

public abstract void finishUpload()
                           throws Exception
When the applet finished uploading all files, this method is called so that the UploadHandler subclass can finish work and commit all saved files.

Throws:
Exception

cancelUpload

public void cancelUpload()
                  throws Exception
After the remote user canceled the upload process in the applet, this method is called so that the UploadHandler subclass can finish or cancel work. The implementation is optional, by default finishUpload() is called

Throws:
Exception

unregister

public void unregister()
When the applet is closed after uploading all files, the servlet calls this method automatically to unregister this upload handler from the UploadHandlerManager.