summaryrefslogtreecommitdiffstats
path: root/src/com/itmill/toolkit/ui/Upload.java
diff options
context:
space:
mode:
authorMarc Englund <marc.englund@itmill.com>2008-02-27 08:47:57 +0000
committerMarc Englund <marc.englund@itmill.com>2008-02-27 08:47:57 +0000
commit92a209c77bb7a528a2f41ac1bf056c8c38c8603f (patch)
tree685690f7fd04e654695d547056f2ecc384bcf2df /src/com/itmill/toolkit/ui/Upload.java
parent44bd75c1ff84f67816a5d8f7d637fc3b94fc8d5b (diff)
downloadvaadin-framework-92a209c77bb7a528a2f41ac1bf056c8c38c8603f.tar.gz
vaadin-framework-92a209c77bb7a528a2f41ac1bf056c8c38c8603f.zip
Quite a bit of changes: added possibility to better detect _why_ upload failed. Tested all events, should fix #174
Javadoc still contains mention of ProgressEvent, that does not exist. svn changeset:3934/svn branch:trunk
Diffstat (limited to 'src/com/itmill/toolkit/ui/Upload.java')
-rw-r--r--src/com/itmill/toolkit/ui/Upload.java110
1 files changed, 99 insertions, 11 deletions
diff --git a/src/com/itmill/toolkit/ui/Upload.java b/src/com/itmill/toolkit/ui/Upload.java
index af5344c3cd..efe1f697e4 100644
--- a/src/com/itmill/toolkit/ui/Upload.java
+++ b/src/com/itmill/toolkit/ui/Upload.java
@@ -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.
*