Package org.mycore.frontend.fileupload
Class MCRUploadHandler
java.lang.Object
org.mycore.common.processing.MCRAbstractProgressable
org.mycore.common.processing.MCRAbstractProcessable
org.mycore.frontend.fileupload.MCRUploadHandler
- All Implemented Interfaces:
MCRListenableProgressable
,MCRProcessable
,MCRProgressable
- Direct Known Subclasses:
MCRUploadHandlerIFS
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$ $Date$
- Author:
- Harald Richter, Frank Lützenkirchen
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprotected String
The unique ID of this upload session *protected String
The url where to go after upload is finishedFields inherited from class org.mycore.common.processing.MCRAbstractProcessable
createTime, endTime, error, name, properties, startTime, status, statusListener, userId
Fields inherited from class org.mycore.common.processing.MCRAbstractProgressable
progress, progressListener, progressText
-
Constructor Summary
ModifierConstructorDescriptionprotected
Creates a new upload handler and registers it at the handler manager * -
Method Summary
Modifier and TypeMethodDescriptionboolean
acceptFile
(String path, String checksum, long length) This method is called to ask if this file should be uploaded and will be accepted by the server.void
This method is called so that the UploadHandler subclass can finish or cancel work.int
Decrements the uploaded number of files.abstract void
After finishing uploading all files, this method is called so that the UploadHandler subclass can finish work and commit all saved files.final String
getID()
Returns the unique ID of this upload session *int
Returns the number of files which will be uploadedReturns the url where to go after upload is finished *int
Increments the uploaded number of files.abstract long
receiveFile
(String path, InputStream in, long length, String md5) This method is called so that the UploadHandler subclass can store the file on the server side.void
startUpload
(int numberOfFiles) Starts the upload session.void
Automatically unregister this upload handler from the UploadHandlerManager.Methods inherited from class org.mycore.common.processing.MCRAbstractProcessable
addStatusListener, fireStatusChanged, getCreateTime, getEndTime, getError, getName, getProperties, getStartTime, getStatus, getUserId, removeStatusListener, setError, setName, setStatus, setUserId
Methods inherited from class org.mycore.common.processing.MCRAbstractProgressable
addProgressListener, fireProgressChanged, fireProgressTextChanged, getProgress, getProgressText, removeProgressListener, setProgress, setProgressText
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.mycore.common.processing.MCRListenableProgressable
addProgressListener, removeProgressListener
Methods inherited from interface org.mycore.common.processing.MCRProcessable
getProperty, getPropertyAs, isCanceled, isCreated, isDone, isFailed, isProcessing, isSuccessful, took
Methods inherited from interface org.mycore.common.processing.MCRProgressable
getProgress, getProgressText
-
Field Details
-
uploadID
The unique ID of this upload session * -
url
The url where to go after upload is finished. *
-
-
Constructor Details
-
MCRUploadHandler
protected MCRUploadHandler()Creates a new upload handler and registers it at the handler manager *
-
-
Method Details
-
getID
Returns the unique ID of this upload session * -
getRedirectURL
Returns the url where to go after upload is finished * -
startUpload
public void startUpload(int numberOfFiles) Starts the upload session.- Parameters:
numberOfFiles
- the number of files that will be uploaded
-
incrementNumFiles
public int incrementNumFiles()Increments the uploaded number of files. Use this method with care! In general a fixed number of files to upload should be set withstartUpload(int)
.- Returns:
- the new number of files to upload
-
decrementNumFiles
public int decrementNumFiles()Decrements the uploaded number of files. Use this method with care! In general a fixed number of files to upload should be set withstartUpload(int)
.- Returns:
- the new number of files to upload
-
getNumFiles
public int getNumFiles()Returns the number of files which will be uploaded- Returns:
- number of files to upload
-
acceptFile
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, so unchanged files do not have to be uploaded again.- Parameters:
path
- the path and filename of the filechecksum
- the MD5 checksum computed at the client sidelength
- 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 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 requires a database transaction.- Parameters:
path
- the path and filename of the filein
- the inputstream to read the content of the file fromlength
- 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 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
After finishing uploading all files, this method is called so that the UploadHandler subclass can finish work and commit all saved files.- Throws:
Exception
-
cancelUpload
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()Automatically unregister this upload handler from the UploadHandlerManager.
-