package com.itmill.toolkit.ui;
-import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Method;
// 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;
}
endUpload();
requestRepaint();
- } catch (final IOException e) {
+ } catch (final Exception e) {
// Download interrupted
- fireUploadInterrupted(filename, type, totalBytes);
+ fireUploadInterrupted(filename, type, totalBytes, e);
endUpload();
}
}
*/
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);
+ }
+
}
/**
* the Listener to be removed.
*/
public void removeListener(StartedListener listener) {
- removeListener(FinishedEvent.class, listener, UPLOAD_STARTED_METHOD);
+ removeListener(StartedEvent.class, listener, UPLOAD_STARTED_METHOD);
}
/**
* the Listener to be removed.
*/
public void removeListener(FailedListener listener) {
- removeListener(FinishedEvent.class, listener, UPLOAD_FAILED_METHOD);
+ removeListener(FailedEvent.class, listener, UPLOAD_FAILED_METHOD);
}
/**
}
/**
- * Emit upload received event.
+ * Emit upload finished event.
*
* @param filename
* @param MIMEType
}
/**
- * Emits the upload interrupted event.
+ * Emits the upload failed event.
*
* @param filename
* @param MIMEType
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.
*