|
|
@@ -4,7 +4,6 @@ |
|
|
|
|
|
|
|
package com.itmill.toolkit.ui; |
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.io.OutputStream; |
|
|
|
import java.lang.reflect.Method; |
|
|
@@ -120,17 +119,16 @@ public class Upload extends AbstractComponent implements Component.Focusable { |
|
|
|
// Gets the output target stream |
|
|
|
final OutputStream out = receiver.receiveUpload(filename, type); |
|
|
|
if (out == null) { |
|
|
|
fireUploadInterrupted(filename, type, 0); |
|
|
|
fireNoOutputStream(filename, type, 0); |
|
|
|
endUpload(); |
|
|
|
throw new RuntimeException( |
|
|
|
"Error getting outputstream from upload receiver"); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
final InputStream in = upload.getStream(); |
|
|
|
|
|
|
|
if (null == in) { |
|
|
|
// No file, for instance non-existent filename in html upload |
|
|
|
fireUploadInterrupted(filename, type, 0); |
|
|
|
fireNoInputStream(filename, type, 0); |
|
|
|
endUpload(); |
|
|
|
return; |
|
|
|
} |
|
|
@@ -155,10 +153,10 @@ public class Upload extends AbstractComponent implements Component.Focusable { |
|
|
|
endUpload(); |
|
|
|
requestRepaint(); |
|
|
|
|
|
|
|
} catch (final IOException e) { |
|
|
|
} catch (final Exception e) { |
|
|
|
|
|
|
|
// Download interrupted |
|
|
|
fireUploadInterrupted(filename, type, totalBytes); |
|
|
|
fireUploadInterrupted(filename, type, totalBytes, e); |
|
|
|
endUpload(); |
|
|
|
} |
|
|
|
} |
|
|
@@ -359,18 +357,91 @@ public class Upload extends AbstractComponent implements Component.Focusable { |
|
|
|
*/ |
|
|
|
private static final long serialVersionUID = 3833746590157386293L; |
|
|
|
|
|
|
|
private Exception reason = null; |
|
|
|
|
|
|
|
/** |
|
|
|
* |
|
|
|
* @param source |
|
|
|
* @param filename |
|
|
|
* @param MIMEType |
|
|
|
* @param length |
|
|
|
* @param exception |
|
|
|
*/ |
|
|
|
public FailedEvent(Upload source, String filename, String MIMEType, |
|
|
|
long length, Exception reason) { |
|
|
|
this(source, filename, MIMEType, length); |
|
|
|
this.reason = reason; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* |
|
|
|
* @param source |
|
|
|
* @param filename |
|
|
|
* @param MIMEType |
|
|
|
* @param length |
|
|
|
* @param exception |
|
|
|
*/ |
|
|
|
public FailedEvent(Upload source, String filename, String MIMEType, |
|
|
|
long length) { |
|
|
|
super(source, filename, MIMEType, length); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Gets the exception that caused the failure. |
|
|
|
* |
|
|
|
* @return the exception that caused the failure, null if n/a |
|
|
|
*/ |
|
|
|
public Exception getReason() { |
|
|
|
return reason; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* FailedEvent that indicates that an output stream could not be obtained. |
|
|
|
*/ |
|
|
|
public class NoOutputStreamEvent extends FailedEvent { |
|
|
|
|
|
|
|
/** |
|
|
|
* Serial generated by eclipse. |
|
|
|
*/ |
|
|
|
private static final long serialVersionUID = 4745219890852396500L; |
|
|
|
|
|
|
|
/** |
|
|
|
* |
|
|
|
* @param source |
|
|
|
* @param filename |
|
|
|
* @param MIMEType |
|
|
|
* @param length |
|
|
|
*/ |
|
|
|
public NoOutputStreamEvent(Upload source, String filename, |
|
|
|
String MIMEType, long length) { |
|
|
|
super(source, filename, MIMEType, length); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* FailedEvent that indicates that an input stream could not be obtained. |
|
|
|
*/ |
|
|
|
public class NoInputStreamEvent extends FailedEvent { |
|
|
|
|
|
|
|
/** |
|
|
|
* Serial generated by eclipse. |
|
|
|
*/ |
|
|
|
private static final long serialVersionUID = -529960205445737170L; |
|
|
|
|
|
|
|
/** |
|
|
|
* |
|
|
|
* @param source |
|
|
|
* @param filename |
|
|
|
* @param MIMEType |
|
|
|
* @param length |
|
|
|
*/ |
|
|
|
public NoInputStreamEvent(Upload source, String filename, |
|
|
|
String MIMEType, long length) { |
|
|
|
super(source, filename, MIMEType, length); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@@ -554,7 +625,7 @@ public class Upload extends AbstractComponent implements Component.Focusable { |
|
|
|
* the Listener to be removed. |
|
|
|
*/ |
|
|
|
public void removeListener(StartedListener listener) { |
|
|
|
removeListener(FinishedEvent.class, listener, UPLOAD_STARTED_METHOD); |
|
|
|
removeListener(StartedEvent.class, listener, UPLOAD_STARTED_METHOD); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@@ -594,7 +665,7 @@ public class Upload extends AbstractComponent implements Component.Focusable { |
|
|
|
* the Listener to be removed. |
|
|
|
*/ |
|
|
|
public void removeListener(FailedListener listener) { |
|
|
|
removeListener(FinishedEvent.class, listener, UPLOAD_FAILED_METHOD); |
|
|
|
removeListener(FailedEvent.class, listener, UPLOAD_FAILED_METHOD); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@@ -629,7 +700,7 @@ public class Upload extends AbstractComponent implements Component.Focusable { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Emit upload received event. |
|
|
|
* Emit upload finished event. |
|
|
|
* |
|
|
|
* @param filename |
|
|
|
* @param MIMEType |
|
|
@@ -641,7 +712,7 @@ public class Upload extends AbstractComponent implements Component.Focusable { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Emits the upload interrupted event. |
|
|
|
* Emits the upload failed event. |
|
|
|
* |
|
|
|
* @param filename |
|
|
|
* @param MIMEType |
|
|
@@ -652,6 +723,23 @@ public class Upload extends AbstractComponent implements Component.Focusable { |
|
|
|
fireEvent(new Upload.FailedEvent(this, filename, MIMEType, length)); |
|
|
|
} |
|
|
|
|
|
|
|
protected void fireNoInputStream(String filename, String MIMEType, |
|
|
|
long length) { |
|
|
|
fireEvent(new Upload.NoInputStreamEvent(this, filename, MIMEType, |
|
|
|
length)); |
|
|
|
} |
|
|
|
|
|
|
|
protected void fireNoOutputStream(String filename, String MIMEType, |
|
|
|
long length) { |
|
|
|
fireEvent(new Upload.NoOutputStreamEvent(this, filename, MIMEType, |
|
|
|
length)); |
|
|
|
} |
|
|
|
|
|
|
|
protected void fireUploadInterrupted(String filename, String MIMEType, |
|
|
|
long length, Exception e) { |
|
|
|
fireEvent(new Upload.FailedEvent(this, filename, MIMEType, length, e)); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Emits the upload success event. |
|
|
|
* |