public void addAttribute(String name, Resource value) throws PaintException;
/**
- * Adds details about {@link Receiver} to the UIDL stream. Eg. in web
+ * Adds details about {@link StreamVariable} to the UIDL stream. Eg. in web
* terminals Receivers are typically rendered for the client side as URLs,
* where the client side implementation can do an http post request.
* <p>
- * Note that a Receiver can only be used once per "paint". The same Receiver
+ * Note that a StreamVariable can only be used once per "paint". The same StreamVariable
* can be used several times, but it must be repainted before the next
* stream can be received.
*
* @param owner
* the ReceiverOwner that can track the progress of streaming to
- * the given Receiver
+ * the given StreamVariable
* @param name
- * an identifying name for the Receiver
+ * an identifying name for the StreamVariable
* @param value
- * the Receiver to paint
+ * the StreamVariable to paint
*
* @throws PaintException
* if the paint operation failed.
*/
- public void addVariable(ReceiverOwner owner, String name, Receiver value)
+ public void addVariable(VariableOwner owner, String name, StreamVariable value)
throws PaintException;
/**
+++ /dev/null
-package com.vaadin.terminal;
-
-import java.io.OutputStream;
-import java.io.Serializable;
-
-/**
- * Receiver is a special kind of variable whose value is streamed to a given
- * {@link OutputStream}. E.g. in web terminals Receivers can be used to send
- * large files from browsers to the server.
- * <p>
- * Note, writing to the {@link OutputStream} is not synchronized by the terminal
- * (to avoid stalls in other operations when eg. streaming to a slow network
- * service). If UI is changed as a side effect of writing to the output stream,
- * developer must handle synchronization manually.
- * <p>
- *
- * @author IT Mill Ltd.
- * @version
- * @VERSION@
- * @since 6.5
- * @see PaintTarget#addVariable(ReceiverOwner, String, Receiver)
- * @see ReceiverOwner
- */
-public interface Receiver extends Serializable {
-
- /**
- * Invoked by the terminal when a new upload arrives.
- *
- * @param filename
- * the filename of the upload if known by the terminal, usually
- * as specified by the client.
- * @param MIMEType
- * the MIME type of the uploaded file.
- * @return Stream to which the uploaded file should be written.
- */
- public OutputStream receiveUpload(String filename, String MIMEType);
-}
+++ /dev/null
-package com.vaadin.terminal;
-
-import java.io.Serializable;
-
-import com.vaadin.Application;
-import com.vaadin.terminal.ReceiverOwner.ReceivingController;
-
-/**
- * Special kind of {@link VariableOwner} that can send and receive information
- * with the terminal implementation about the progress of receiving data to its
- * Receiver. The actual communication happens via {@link ReceivingController}
- * which is fetched by the terminal when the Receiving is about to start.
- */
-public interface ReceiverOwner extends VariableOwner {
-
- /*
- * The monitor/control is passed to separate ReceivingController because:
- *
- * - possibly some component in the future may need support for streaming to
- * multiple Receivers at the same time.
- *
- * - we don't want to bloat implementing ReceiverOwner's API. Now only one
- * method is published and they can decide what event/methods to publish as
- * their public API.
- */
-
- /**
- * Returns a handle for the terminal via the ReceiverOwner can monitor and
- * control the steaming of data to {@link Receiver}.
- * <p>
- * Most commonly ReceiverOwner implementation wants to implement this method
- * as final and reveal its own API for the end users.
- *
- * @param receiver
- * the Receiver whose streaming is to be controlled
- * @return a {@link ReceivingController} that will be used to control and
- * monitor the progress of streaming
- */
- ReceivingController getReceivingController(Receiver receiver);
-
- interface ReceivingEvent extends Serializable {
-
- /**
- * @return the file name of the streamed file if known
- */
- String getFileName();
-
- /**
- * @return the mime type of the streamed file if known
- */
- String getMimeType();
-
- /**
- * @return the Receiver into which the content is being streamed
- */
- Receiver getReceiver();
-
- /**
- * @return the length of the stream (in bytes) if known, else -1
- */
- long getContentLength();
-
- /**
- * @return then number of bytes streamed to Receiver
- */
- long getBytesReceived();
- }
-
- /**
- * Event passed to
- * {@link ReceivingController#uploadStarted(ReceivingStartedEvent)} method
- * before the streaming of the content to {@link Receiver} starts.
- */
- public interface ReceivingStartedEvent extends ReceivingEvent {
- }
-
- /**
- * Event passed to
- * {@link ReceivingController#onProgress(ReceivingProgressedEvent)} method
- * during the streaming progresses.
- */
- public interface ReceivingProgressedEvent extends ReceivingEvent {
- }
-
- /**
- * Event passed to
- * {@link ReceivingController#uploadFinished(ReceivingEndedEvent)} method
- * the contents have been streamed to Receiver successfully.
- */
- public interface ReceivingEndedEvent extends ReceivingEvent {
- }
-
- /**
- * Event passed to
- * {@link ReceivingController#uploadFailed(ReceivingFailedEvent)} method
- * when the streaming ended before the end of the input. The streaming may
- * fail due an interruption by {@link ReceivingController} or due an other
- * unknown exception in communication. In the latter case the exception is
- * also passed to
- * {@link Application#terminalError(com.vaadin.terminal.Terminal.ErrorEvent)}
- * .
- */
- public interface ReceivingFailedEvent extends ReceivingEvent {
-
- /**
- * @return the exception that caused the receiving not to finish cleanly
- */
- Exception getException();
-
- }
-
- public interface ReceivingController extends Serializable {
- /**
- * Whether the {@link #onProgress(long, long)} method should be called
- * during the upload.
- * <p>
- * {@link #onProgress(long, long)} is called in a synchronized block
- * when the content is being received. This is potentially bit slow, so
- * we are calling that method only if requested. The value is requested
- * after the {@link #uploadStarted(ReceivingStartedEvent)} event, but
- * not after reading each buffer.
- *
- * @return true if this ReceiverOwner wants to by notified during the
- * upload of the progress of streaming.
- * @see ReceiverOwner#onProgress(int, int)
- */
- boolean listenProgress();
-
- /**
- * This method is called by the terminal if {@link #listenProgress()}
- * returns true when the streaming starts.
- */
- void onProgress(ReceivingProgressedEvent event);
-
- void uploadStarted(ReceivingStartedEvent event);
-
- void uploadFinished(ReceivingEndedEvent event);
-
- void uploadFailed(ReceivingFailedEvent event);
-
- /*
- * Not synchronized to avoid stalls (caused by UIDL requests) while
- * streaming the content. Implementations also most commonly atomic even
- * without the restriction.
- */
- /**
- * ReceiverOwner can set this flag to true if it wants the Terminal to
- * stop receiving current upload.
- * <p>
- * Note, the usage of this method is not synchronized over the
- * Application instance by the terminal like other methods. The
- * implementation should only return a boolean field and especially not
- * modify UI or implement a synchronization by itself.
- *
- * @return true if the streaming should be interrupted as soon as
- * possible.
- */
- boolean isInterrupted();
- }
-
-}
--- /dev/null
+package com.vaadin.terminal;
+
+import java.io.OutputStream;
+import java.io.Serializable;
+
+import com.vaadin.Application;
+
+/**
+ * StreamVariable is a special kind of variable whose value is streamed to an
+ * {@link OutputStream} provided by the {@link #getOutputStream()} method. E.g.
+ * in web terminals {@link StreamVariable} can be used to send large files from
+ * browsers to the server without consuming large amounts of memory.
+ * <p>
+ * Note, writing to the {@link OutputStream} is not synchronized by the terminal
+ * (to avoid stalls in other operations when eg. streaming to a slow network
+ * service or file system). If UI is changed as a side effect of writing to the
+ * output stream, developer must handle synchronization manually.
+ * <p>
+ *
+ * @author IT Mill Ltd.
+ * @version
+ * @VERSION@
+ * @since 6.5
+ * @see PaintTarget#addVariable(VariableOwner, String, StreamVariable)
+ */
+public interface StreamVariable extends Serializable {
+
+ /**
+ * Invoked by the terminal when a new upload arrives, after
+ * {@link #streamingStarted(StreamingStartedEvent)} method has been called.
+ * The terminal implementation will write the streamed variable to the
+ * returned output stream.
+ *
+ * @return Stream to which the uploaded file should be written.
+ */
+ public OutputStream getOutputStream();
+
+ /**
+ * Whether the {@link #onProgress(long, long)} method should be called
+ * during the upload.
+ * <p>
+ * {@link #onProgress(long, long)} is called in a synchronized block when
+ * the content is being received. This is potentially bit slow, so we are
+ * calling that method only if requested. The value is requested after the
+ * {@link #uploadStarted(StreamingStartedEvent)} event, but not after
+ * reading each buffer.
+ *
+ * @return true if this ReceiverOwner wants to by notified during the upload
+ * of the progress of streaming.
+ * @see ReceiverOwner#onProgress(int, int)
+ */
+ boolean listenProgress();
+
+ /**
+ * This method is called by the terminal if {@link #listenProgress()}
+ * returns true when the streaming starts.
+ */
+ void onProgress(StreamingProgressedEvent event);
+
+ void streamingStarted(StreamingStartedEvent event);
+
+ void streamingFinished(StreamingEndedEvent event);
+
+ void streamingFailed(StreamingFailedEvent event);
+
+ /*
+ * Not synchronized to avoid stalls (caused by UIDL requests) while
+ * streaming the content. Implementations also most commonly atomic even
+ * without the restriction.
+ */
+ /**
+ * ReceiverOwner can set this flag to true if it wants the Terminal to stop
+ * receiving current upload.
+ * <p>
+ * Note, the usage of this method is not synchronized over the Application
+ * instance by the terminal like other methods. The implementation should
+ * only return a boolean field and especially not modify UI or implement a
+ * synchronization by itself.
+ *
+ * @return true if the streaming should be interrupted as soon as possible.
+ */
+ boolean isInterrupted();
+
+ interface StreamingEvent extends Serializable {
+
+ /**
+ * @return the file name of the streamed file if known
+ */
+ String getFileName();
+
+ /**
+ * @return the mime type of the streamed file if known
+ */
+ String getMimeType();
+
+ /**
+ * @return the length of the stream (in bytes) if known, else -1
+ */
+ long getContentLength();
+
+ /**
+ * @return then number of bytes streamed to StreamVariable
+ */
+ long getBytesReceived();
+ }
+
+ /**
+ * Event passed to {@link #uploadStarted(StreamingStartedEvent)} method
+ * before the streaming of the content to {@link StreamVariable} starts.
+ */
+ public interface StreamingStartedEvent extends StreamingEvent {
+ }
+
+ /**
+ * Event passed to {@link #onProgress(StreamingProgressedEvent)} method
+ * during the streaming progresses.
+ */
+ public interface StreamingProgressedEvent extends StreamingEvent {
+ }
+
+ /**
+ * Event passed to {@link #uploadFinished(StreamingEndedEvent)} method the
+ * contents have been streamed to StreamVariable successfully.
+ */
+ public interface StreamingEndedEvent extends StreamingEvent {
+ }
+
+ /**
+ * Event passed to {@link #uploadFailed(StreamingFailedEvent)} method when
+ * the streaming ended before the end of the input. The streaming may fail
+ * due an interruption by {@link } or due an other unknown exception in
+ * communication. In the latter case the exception is also passed to
+ * {@link Application#terminalError(com.vaadin.terminal.Terminal.ErrorEvent)}
+ * .
+ */
+ public interface StreamingFailedEvent extends StreamingEvent {
+
+ /**
+ * @return the exception that caused the receiving not to finish cleanly
+ */
+ Exception getException();
+
+ }
+
+}
+++ /dev/null
-/*
-@ITMillApache2LicenseForJavaFiles@
- */
-
-package com.vaadin.terminal;
-
-import java.io.InputStream;
-import java.io.Serializable;
-
-/**
- * Defines a variable type, that is used for passing uploaded files from
- * terminal. Most often, file upload is implented using the
- * {@link com.vaadin.ui.Upload Upload} component.
- *
- * @author IT Mill Ltd.
- * @version
- * @VERSION@
- * @since 3.0
- */
-public interface UploadStream extends Serializable {
-
- /**
- * Gets the name of the stream.
- *
- * @return the name of the stream.
- */
- public String getStreamName();
-
- /**
- * Gets the input stream.
- *
- * @return the Input stream.
- */
- public InputStream getStream();
-
- /**
- * Gets the input stream content type.
- *
- * @return the content type of the input stream.
- */
- public String getContentType();
-
- /**
- * Gets stream content name. Stream content name usually differs from the
- * actual stream name. It is used to identify the content of the stream.
- *
- * @return the Name of the stream content.
- */
- public String getContentName();
-}
import com.vaadin.terminal.PaintTarget;
import com.vaadin.terminal.Paintable;
import com.vaadin.terminal.Paintable.RepaintRequestEvent;
-import com.vaadin.terminal.Receiver;
-import com.vaadin.terminal.ReceiverOwner;
-import com.vaadin.terminal.ReceiverOwner.ReceivingController;
-import com.vaadin.terminal.ReceiverOwner.ReceivingEndedEvent;
-import com.vaadin.terminal.ReceiverOwner.ReceivingFailedEvent;
-import com.vaadin.terminal.ReceiverOwner.ReceivingStartedEvent;
+import com.vaadin.terminal.StreamVariable;
+import com.vaadin.terminal.StreamVariable.StreamingEndedEvent;
+import com.vaadin.terminal.StreamVariable.StreamingFailedEvent;
+import com.vaadin.terminal.StreamVariable.StreamingStartedEvent;
import com.vaadin.terminal.Terminal.ErrorEvent;
import com.vaadin.terminal.Terminal.ErrorListener;
import com.vaadin.terminal.URIHandler;
/**
* Method used to stream content from a multipart request (either from
- * servlet or portlet request) to given Receiver
+ * servlet or portlet request) to given StreamVariable
*
*
* @param request
* @param response
- * @param receiver
+ * @param streamVariable
* @param owner
* @param boundary
* @throws IOException
*/
protected void doHandleSimpleMultipartFileUpload(Request request,
- Response response, Receiver receiver, ReceiverOwner owner,
+ Response response, StreamVariable streamVariable, VariableOwner owner,
String boundary) throws IOException {
boundary = CRLF + "--" + boundary + "--";
throw new UploadException(
"Warning: file upload ignored because the componente was read-only");
}
- streamToReceiver(simpleMultiPartReader, receiver, owner, filename,
+ streamToReceiver(simpleMultiPartReader, streamVariable, filename,
mimeType, contentLength);
} catch (Exception e) {
synchronized (application) {
*
* @param request
* @param response
- * @param receiver
+ * @param streamVariable
* @param owner
* @param contentLength
* @throws IOException
*/
protected void doHandleXhrFilePost(Request request, Response response,
- Receiver receiver, ReceiverOwner owner, int contentLength)
+ StreamVariable streamVariable, VariableOwner owner, int contentLength)
throws IOException {
// These are unknown in filexhr ATM, maybe add to Accept header that
Component component = (Component) owner;
if (component.isReadOnly()) {
throw new UploadException(
- "Warning: file upload ignored because the componente was read-only");
+ "Warning: file upload ignored because the component was read-only");
}
- streamToReceiver(stream, receiver, owner, filename, mimeType,
+ streamToReceiver(stream, streamVariable, filename, mimeType,
contentLength);
} catch (Exception e) {
synchronized (application) {
}
protected final void streamToReceiver(final InputStream in,
- Receiver receiver, ReceiverOwner source, String filename,
+ StreamVariable streamVariable, String filename,
String type, int contentLength) throws UploadException {
- if (receiver == null) {
- throw new IllegalStateException("Receiver for the post not found");
+ if (streamVariable == null) {
+ throw new IllegalStateException("StreamVariable for the post not found");
}
- ReceivingController controller = source
- .getReceivingController(receiver);
-
final Application application = getApplication();
OutputStream out = null;
try {
boolean listenProgress;
synchronized (application) {
- ReceivingStartedEvent startedEvent = new ReceivingStartedEventImpl(
- receiver, filename, type, contentLength);
- controller.uploadStarted(startedEvent);
- out = receiver.receiveUpload(filename, type);
- listenProgress = controller.listenProgress();
+ StreamingStartedEvent startedEvent = new StreamingStartedEventImpl(
+ streamVariable, filename, type, contentLength);
+ streamVariable.streamingStarted(startedEvent);
+ out = streamVariable.getOutputStream();
+ listenProgress = streamVariable.listenProgress();
}
// Gets the output target stream
// update progress if listener set and contentLength
// received
synchronized (application) {
- ReceivingProgressedEventImpl progressEvent = new ReceivingProgressedEventImpl(
- receiver, filename, type, contentLength,
+ StreamingProgressedEventImpl progressEvent = new StreamingProgressedEventImpl(
+ streamVariable, filename, type, contentLength,
totalBytes);
- controller.onProgress(progressEvent);
+ streamVariable.onProgress(progressEvent);
}
}
- if (controller.isInterrupted()) {
+ if (streamVariable.isInterrupted()) {
throw new UploadInterruptedException();
}
}
// upload successful
out.close();
- ReceivingEndedEvent event = new ReceivingEndedEventImpl(receiver,
+ StreamingEndedEvent event = new StremingEndedEventImpl(streamVariable,
filename, type, totalBytes);
synchronized (application) {
- controller.uploadFinished(event);
+ streamVariable.streamingFinished(event);
}
} catch (UploadInterruptedException e) {
// Download interrupted by application code
tryToCloseStream(out);
- ReceivingFailedEvent event = new ReceivingFailedEventImpl(receiver,
+ StreamingFailedEvent event = new StreamingFailedEventImpl(streamVariable,
filename, type, contentLength, totalBytes, e);
synchronized (application) {
- controller.uploadFailed(event);
+ streamVariable.streamingFailed(event);
}
// Note, we are not throwing interrupted exception forward as it is
// not a terminal level error like all other exception.
} catch (final Exception e) {
tryToCloseStream(out);
synchronized (application) {
- ReceivingFailedEvent event = new ReceivingFailedEventImpl(
- receiver, filename, type, contentLength, totalBytes, e);
+ StreamingFailedEvent event = new StreamingFailedEventImpl(
+ streamVariable, filename, type, contentLength, totalBytes, e);
synchronized (application) {
- controller.uploadFailed(event);
+ streamVariable.streamingFailed(event);
}
// throw exception for terminal to be handled (to be passed to
// terminalErrorHandler)
}
- abstract String createReceiverUrl(ReceiverOwner owner, String name,
- Receiver value);
+ abstract String createReceiverUrl(VariableOwner owner, String name,
+ StreamVariable value);
}
+++ /dev/null
-package com.vaadin.terminal.gwt.server;
-
-import com.vaadin.terminal.Receiver;
-import com.vaadin.terminal.ReceiverOwner.ReceivingEvent;
-
-/**
- * Abstract base class for ReceivingEvent implementations.
- */
-@SuppressWarnings("serial")
-abstract class AbstractReceivingEvent implements ReceivingEvent {
- private final String type;
- private final String filename;
- private final Receiver receiver;
- private final long contentLength;
- private final long bytesReceived;
-
- public final String getFileName() {
- return filename;
- }
-
- public final String getMimeType() {
- return type;
- }
-
- protected AbstractReceivingEvent(Receiver receiver, String filename,
- String type, long length, long bytesReceived) {
- this.receiver = receiver;
- this.filename = filename;
- this.type = type;
- contentLength = length;
- this.bytesReceived = bytesReceived;
- }
-
- public final Receiver getReceiver() {
- return receiver;
- }
-
- public final long getContentLength() {
- return contentLength;
- }
-
- public final long getBytesReceived() {
- return bytesReceived;
- }
-
-}
--- /dev/null
+package com.vaadin.terminal.gwt.server;
+
+import com.vaadin.terminal.StreamVariable;
+import com.vaadin.terminal.StreamVariable.StreamingEvent;
+
+/**
+ * Abstract base class for StreamingEvent implementations.
+ */
+@SuppressWarnings("serial")
+abstract class AbstractStreamingEvent implements StreamingEvent {
+ private final String type;
+ private final String filename;
+ private final StreamVariable streamVariable;
+ private final long contentLength;
+ private final long bytesReceived;
+
+ public final String getFileName() {
+ return filename;
+ }
+
+ public final String getMimeType() {
+ return type;
+ }
+
+ protected AbstractStreamingEvent(StreamVariable streamVariable, String filename,
+ String type, long length, long bytesReceived) {
+ this.streamVariable = streamVariable;
+ this.filename = filename;
+ this.type = type;
+ contentLength = length;
+ this.bytesReceived = bytesReceived;
+ }
+
+ public final StreamVariable getReceiver() {
+ return streamVariable;
+ }
+
+ public final long getContentLength() {
+ return contentLength;
+ }
+
+ public final long getBytesReceived() {
+ return bytesReceived;
+ }
+
+}
import com.vaadin.terminal.ApplicationResource;
import com.vaadin.terminal.DownloadStream;
import com.vaadin.terminal.Paintable;
-import com.vaadin.terminal.Receiver;
-import com.vaadin.terminal.ReceiverOwner;
+import com.vaadin.terminal.StreamVariable;
+import com.vaadin.terminal.VariableOwner;
import com.vaadin.ui.Component;
import com.vaadin.ui.Window;
/**
* Handles file upload request submitted via Upload component.
*
- * @see #createReceiverUrl(ReceiverOwner, String, Receiver)
+ * @see #createReceiverUrl(ReceiverOwner, String, StreamVariable)
*
* @param request
* @param response
String uppUri = pathInfo.substring(startOfData);
String[] parts = uppUri.split("/", 3); // 0 = pid, 1= name, 2 = sec key
- Receiver receiver = pidToNameToReceiver.get(parts[0]).remove(parts[1]);
- String secKey = receiverToSeckey.remove(receiver);
+ StreamVariable streamVariable = pidToNameToReceiver.get(parts[0]).remove(parts[1]);
+ String secKey = receiverToSeckey.remove(streamVariable);
if (secKey.equals(parts[2])) {
- ReceiverOwner source = (ReceiverOwner) getVariableOwner(parts[0]);
+ VariableOwner source = (VariableOwner) getVariableOwner(parts[0]);
String contentType = request.getContentType();
if (request.getContentType().contains("boundary")) {
// Multipart requests contain boundary string
doHandleSimpleMultipartFileUpload(
new HttpServletRequestWrapper(request),
- new HttpServletResponseWrapper(response), receiver,
+ new HttpServletResponseWrapper(response), streamVariable,
source, contentType.split("boundary=")[1]);
} else {
// if boundary string does not exist, the posted file is from
// XHR2.post(File)
doHandleXhrFilePost(new HttpServletRequestWrapper(request),
- new HttpServletResponseWrapper(response), receiver,
+ new HttpServletResponseWrapper(response), streamVariable,
source, request.getContentLength());
}
} else {
@Override
protected void unregisterPaintable(Component p) {
/* Cleanup possible receivers */
- if (pidToNameToReceiver != null && p instanceof ReceiverOwner) {
- Map<String, Receiver> removed = pidToNameToReceiver
+ if (pidToNameToReceiver != null) {
+ Map<String, StreamVariable> removed = pidToNameToReceiver
.remove(getPaintableId(p));
if (removed != null) {
for (String key : removed.keySet()) {
}
- private Map<String, Map<String, Receiver>> pidToNameToReceiver;
+ private Map<String, Map<String, StreamVariable>> pidToNameToReceiver;
- private Map<Receiver, String> receiverToSeckey;
+ private Map<StreamVariable, String> receiverToSeckey;
@Override
- String createReceiverUrl(ReceiverOwner owner, String name, Receiver value) {
+ String createReceiverUrl(VariableOwner owner, String name, StreamVariable value) {
+
+ /*
+ * TODO figure out how this can be simplified now that ReceiverOwner is removed.
+ */
/*
* We will use the same APP/* URI space as ApplicationResources but
* SECKEY is created on each paint to make URL's unpredictable (to
* prevent CSRF attacks).
*
- * NAME and PID from URI forms a key to fetch Receiver when handling
+ * NAME and PID from URI forms a key to fetch StreamVariable when handling
* post
*/
String paintableId = getPaintableId((Paintable) owner);
String key = paintableId + "/" + name;
if (pidToNameToReceiver == null) {
- pidToNameToReceiver = new HashMap<String, Map<String, Receiver>>();
+ pidToNameToReceiver = new HashMap<String, Map<String, StreamVariable>>();
}
- Map<String, Receiver> nameToReceiver = pidToNameToReceiver
+ Map<String, StreamVariable> nameToReceiver = pidToNameToReceiver
.get(paintableId);
if (nameToReceiver == null) {
- nameToReceiver = new HashMap<String, Receiver>();
+ nameToReceiver = new HashMap<String, StreamVariable>();
pidToNameToReceiver.put(paintableId, nameToReceiver);
}
nameToReceiver.put(name, value);
if (receiverToSeckey == null) {
- receiverToSeckey = new HashMap<Receiver, String>();
+ receiverToSeckey = new HashMap<StreamVariable, String>();
}
String seckey = UUID.randomUUID().toString();
receiverToSeckey.put(value, seckey);
+++ /dev/null
-/*
-@ITMillApache2LicenseForJavaFiles@
- */
-
-package com.vaadin.terminal.gwt.server;
-
-import java.io.InputStream;
-
-/**
- * AjaxAdapter implementation of the UploadStream interface.
- *
- * @author IT Mill Ltd.
- * @version
- * @VERSION@
- * @since 5.0
- */
-@SuppressWarnings("serial")
-public class HttpUploadStream implements com.vaadin.terminal.UploadStream {
-
- /**
- * Holds value of property variableName.
- */
- private final String streamName;
-
- private final String contentName;
-
- private final String contentType;
-
- /**
- * Holds value of property variableValue.
- */
- private final InputStream stream;
-
- /**
- * Creates a new instance of UploadStreamImpl.
- *
- * @param name
- * the name of the stream.
- * @param stream
- * the input stream.
- * @param contentName
- * the name of the content.
- * @param contentType
- * the type of the content.
- */
- public HttpUploadStream(String name, InputStream stream,
- String contentName, String contentType) {
- streamName = name;
- this.stream = stream;
- this.contentName = contentName;
- this.contentType = contentType;
- }
-
- /**
- * Gets the name of the stream.
- *
- * @return the name of the stream.
- */
- public String getStreamName() {
- return streamName;
- }
-
- /**
- * Gets the input stream.
- *
- * @return the Input stream.
- */
- public InputStream getStream() {
- return stream;
- }
-
- /**
- * Gets the input stream content type.
- *
- * @return the content type of the input stream.
- */
- public String getContentType() {
- return contentType;
- }
-
- /**
- * Gets the stream content name. Stream content name usually differs from
- * the actual stream name. It is used to identify the content of the stream.
- *
- * @return the Name of the stream content.
- */
- public String getContentName() {
- return contentName;
- }
-}
import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
import com.vaadin.terminal.Paintable;
-import com.vaadin.terminal.Receiver;
-import com.vaadin.terminal.ReceiverOwner;
+import com.vaadin.terminal.StreamVariable;
import com.vaadin.terminal.Resource;
import com.vaadin.terminal.ThemeResource;
import com.vaadin.terminal.VariableOwner;
return usedPaintableTypes;
}
- public void addVariable(ReceiverOwner owner, String name, Receiver value)
+ public void addVariable(VariableOwner owner, String name, StreamVariable value)
throws PaintException {
String url = manager.createReceiverUrl(owner, name, value);
addVariable(owner, name, url);
import com.vaadin.Application;
import com.vaadin.terminal.DownloadStream;
import com.vaadin.terminal.Paintable;
-import com.vaadin.terminal.Receiver;
-import com.vaadin.terminal.ReceiverOwner;
+import com.vaadin.terminal.StreamVariable;
+import com.vaadin.terminal.VariableOwner;
import com.vaadin.ui.Component;
import com.vaadin.ui.Window;
String contentType = request.getContentType();
String name = request.getParameter("name");
String ownerId = request.getParameter("rec-owner");
- ReceiverOwner variableOwner = (ReceiverOwner) getVariableOwner(ownerId);
- Receiver receiver = ownerToNameToReceiver.get(variableOwner).remove(
+ VariableOwner variableOwner = (VariableOwner) getVariableOwner(ownerId);
+ StreamVariable streamVariable = ownerToNameToReceiver.get(variableOwner).remove(
name);
// clean up, may be re added on next paint
if (contentType.contains("boundary")) {
doHandleSimpleMultipartFileUpload(
new PortletRequestWrapper(request),
- new PortletResponseWrapper(response), receiver,
+ new PortletResponseWrapper(response), streamVariable,
variableOwner, contentType.split("boundary=")[1]);
} else {
doHandleXhrFilePost(new PortletRequestWrapper(request),
- new PortletResponseWrapper(response), receiver,
+ new PortletResponseWrapper(response), streamVariable,
variableOwner, request.getContentLength());
}
application, assumedWindow);
}
- private Map<ReceiverOwner, Map<String, Receiver>> ownerToNameToReceiver;
+ private Map<VariableOwner, Map<String, StreamVariable>> ownerToNameToReceiver;
@Override
- String createReceiverUrl(ReceiverOwner owner, String name, Receiver value) {
+ String createReceiverUrl(VariableOwner owner, String name, StreamVariable value) {
if (ownerToNameToReceiver == null) {
- ownerToNameToReceiver = new HashMap<ReceiverOwner, Map<String, Receiver>>();
+ ownerToNameToReceiver = new HashMap<VariableOwner, Map<String, StreamVariable>>();
}
- Map<String, Receiver> nameToReceiver = ownerToNameToReceiver.get(owner);
+ Map<String, StreamVariable> nameToReceiver = ownerToNameToReceiver.get(owner);
if (nameToReceiver == null) {
- nameToReceiver = new HashMap<String, Receiver>();
+ nameToReceiver = new HashMap<String, StreamVariable>();
ownerToNameToReceiver.put(owner, nameToReceiver);
}
nameToReceiver.put(name, value);
+++ /dev/null
-package com.vaadin.terminal.gwt.server;
-
-import com.vaadin.terminal.Receiver;
-import com.vaadin.terminal.ReceiverOwner.ReceivingEndedEvent;
-
-@SuppressWarnings("serial")
-final class ReceivingEndedEventImpl extends AbstractReceivingEvent implements
- ReceivingEndedEvent {
-
- public ReceivingEndedEventImpl(Receiver receiver, String filename,
- String type, long totalBytes) {
- super(receiver, filename, type, totalBytes, totalBytes);
- }
-
-}
+++ /dev/null
-package com.vaadin.terminal.gwt.server;
-
-import com.vaadin.terminal.Receiver;
-import com.vaadin.terminal.ReceiverOwner.ReceivingFailedEvent;
-
-@SuppressWarnings("serial")
-final class ReceivingFailedEventImpl extends AbstractReceivingEvent implements
- ReceivingFailedEvent {
-
- private final Exception exception;
-
- public ReceivingFailedEventImpl(Receiver receiver, final String filename,
- final String type, long contentLength, long bytesReceived,
- final Exception exception) {
- super(receiver, filename, type, contentLength, bytesReceived);
- this.exception = exception;
- }
-
- public final Exception getException() {
- return exception;
- }
-
-}
+++ /dev/null
-package com.vaadin.terminal.gwt.server;
-
-import com.vaadin.terminal.Receiver;
-import com.vaadin.terminal.ReceiverOwner.ReceivingProgressedEvent;
-
-@SuppressWarnings("serial")
-final class ReceivingProgressedEventImpl extends AbstractReceivingEvent
- implements ReceivingProgressedEvent {
-
- public ReceivingProgressedEventImpl(Receiver receiver,
- final String filename, final String type, long contentLength,
- long bytesReceived) {
- super(receiver, filename, type, contentLength, bytesReceived);
- }
-
-}
+++ /dev/null
-package com.vaadin.terminal.gwt.server;
-
-import com.vaadin.terminal.Receiver;
-import com.vaadin.terminal.ReceiverOwner.ReceivingStartedEvent;
-
-@SuppressWarnings("serial")
-final class ReceivingStartedEventImpl extends AbstractReceivingEvent implements
- ReceivingStartedEvent {
-
- public ReceivingStartedEventImpl(Receiver receiver, final String filename,
- final String type, long contentLength) {
- super(receiver, filename, type, contentLength, 0);
- }
-
-}
--- /dev/null
+package com.vaadin.terminal.gwt.server;
+
+import com.vaadin.terminal.StreamVariable;
+import com.vaadin.terminal.StreamVariable.StreamingFailedEvent;
+
+@SuppressWarnings("serial")
+final class StreamingFailedEventImpl extends AbstractStreamingEvent implements
+ StreamingFailedEvent {
+
+ private final Exception exception;
+
+ public StreamingFailedEventImpl(StreamVariable streamVariable, final String filename,
+ final String type, long contentLength, long bytesReceived,
+ final Exception exception) {
+ super(streamVariable, filename, type, contentLength, bytesReceived);
+ this.exception = exception;
+ }
+
+ public final Exception getException() {
+ return exception;
+ }
+
+}
--- /dev/null
+package com.vaadin.terminal.gwt.server;
+
+import com.vaadin.terminal.StreamVariable;
+import com.vaadin.terminal.StreamVariable.StreamingProgressedEvent;
+
+@SuppressWarnings("serial")
+final class StreamingProgressedEventImpl extends AbstractStreamingEvent
+ implements StreamingProgressedEvent {
+
+ public StreamingProgressedEventImpl(StreamVariable streamVariable,
+ final String filename, final String type, long contentLength,
+ long bytesReceived) {
+ super(streamVariable, filename, type, contentLength, bytesReceived);
+ }
+
+}
--- /dev/null
+package com.vaadin.terminal.gwt.server;
+
+import com.vaadin.terminal.StreamVariable;
+import com.vaadin.terminal.StreamVariable.StreamingStartedEvent;
+
+@SuppressWarnings("serial")
+final class StreamingStartedEventImpl extends AbstractStreamingEvent implements
+ StreamingStartedEvent {
+
+ public StreamingStartedEventImpl(StreamVariable streamVariable, final String filename,
+ final String type, long contentLength) {
+ super(streamVariable, filename, type, contentLength, 0);
+ }
+
+}
--- /dev/null
+package com.vaadin.terminal.gwt.server;
+
+import com.vaadin.terminal.StreamVariable;
+import com.vaadin.terminal.StreamVariable.StreamingEndedEvent;
+
+@SuppressWarnings("serial")
+final class StremingEndedEventImpl extends AbstractStreamingEvent implements
+ StreamingEndedEvent {
+
+ public StremingEndedEventImpl(StreamVariable streamVariable, String filename,
+ String type, long totalBytes) {
+ super(streamVariable, filename, type, totalBytes, totalBytes);
+ }
+
+}
*/
package com.vaadin.ui;
+import java.io.OutputStream;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
+import java.util.Map.Entry;
import com.vaadin.event.Transferable;
import com.vaadin.event.TransferableImpl;
import com.vaadin.event.dd.TargetDetailsImpl;
import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
-import com.vaadin.terminal.Receiver;
-import com.vaadin.terminal.ReceiverOwner;
+import com.vaadin.terminal.StreamVariable;
import com.vaadin.terminal.gwt.client.MouseEventDetails;
import com.vaadin.terminal.gwt.client.ui.VDragAndDropWrapper;
import com.vaadin.terminal.gwt.client.ui.dd.HorizontalDropLocation;
import com.vaadin.terminal.gwt.client.ui.dd.VerticalDropLocation;
-import com.vaadin.ui.Html5File.ProxyReceiver;
@SuppressWarnings("serial")
@ClientWidget(VDragAndDropWrapper.class)
public class DragAndDropWrapper extends CustomComponent implements DropTarget,
- DragSource, ReceiverOwner {
+ DragSource {
public class WrapperTransferable extends TransferableImpl {
getDropHandler().getAcceptCriterion().paint(target);
}
if (receivers != null && receivers.size() > 0) {
- for (String id : receivers.keySet()) {
+ for (Iterator<Entry<String, Html5File>> it = receivers.entrySet()
+ .iterator(); it.hasNext();) {
+ String id = it.next().getKey();
Html5File html5File = receivers.get(id);
if (html5File.getReceiver() != null) {
- target.addVariable(this, "rec-" + id,
- html5File.getProxyReceiver());
+ target.addVariable(this, "rec-" + id, new ProxyReceiver(
+ html5File));
+ // these are cleaned from receivers once the upload has
+ // started
} else {
// instructs the client side not to send the file
target.addVariable(this, "rec-" + id, (String) null);
+ // forget the file from subsequent paints
+ it.remove();
}
}
}
}
private DropHandler dropHandler;
- private Html5File currentlyUploadedFile;
- private boolean listenProgressOfUploadedFile;
public DropHandler getDropHandler() {
return dropHandler;
return dragStartMode;
}
- /*
- * Single controller is enough for atm as files are transferred in serial.
- * If parallel transfer is needed, this logic needs to go to Html5File
- */
- private ReceivingController controller = new ReceivingController() {
- /*
- * With XHR2 file posts we can't provide as much information from the
- * terminal as with multipart request. This helper class wraps the
- * terminal event and provides the lacking information from the
- * Html5File.
- */
- class ReceivingEventWrapper implements ReceivingFailedEvent,
- ReceivingEndedEvent, ReceivingStartedEvent,
- ReceivingProgressedEvent {
- private ReceivingEvent wrappedEvent;
+ final class ProxyReceiver implements StreamVariable {
- ReceivingEventWrapper(ReceivingEvent e) {
- wrappedEvent = e;
- }
-
- public String getMimeType() {
- return currentlyUploadedFile.getType();
- }
-
- public String getFileName() {
- return currentlyUploadedFile.getFileName();
- }
+ private Html5File file;
- public long getContentLength() {
- return currentlyUploadedFile.getFileSize();
- }
+ public ProxyReceiver(Html5File file) {
+ this.file = file;
+ }
- public Receiver getReceiver() {
- return currentlyUploadedFile.getReceiver();
- }
+ private boolean listenProgressOfUploadedFile;
- public Exception getException() {
- if (wrappedEvent instanceof ReceivingFailedEvent) {
- return ((ReceivingFailedEvent) wrappedEvent).getException();
- }
+ public OutputStream getOutputStream() {
+ if (file.getReceiver() == null) {
return null;
}
-
- public long getBytesReceived() {
- return wrappedEvent.getBytesReceived();
- }
+ return file.getReceiver().getOutputStream();
}
public boolean listenProgress() {
- return listenProgressOfUploadedFile;
+ return file.getReceiver().listenProgress();
}
- public void onProgress(ReceivingProgressedEvent event) {
- currentlyUploadedFile.getUploadListener().onProgress(
- new ReceivingEventWrapper(event));
+ public void onProgress(StreamingProgressedEvent event) {
+ file.getReceiver().onProgress(new ReceivingEventWrapper(event));
}
- public void uploadStarted(ReceivingStartedEvent event) {
- currentlyUploadedFile = ((ProxyReceiver) event.getReceiver())
- .getFile();
- listenProgressOfUploadedFile = currentlyUploadedFile
- .getUploadListener() != null;
+ public void streamingStarted(StreamingStartedEvent event) {
+ listenProgressOfUploadedFile = file.getReceiver() != null;
if (listenProgressOfUploadedFile) {
- currentlyUploadedFile.getUploadListener().uploadStarted(
+ file.getReceiver().streamingStarted(
new ReceivingEventWrapper(event));
}
+ // no need tell to the client about this receiver on next paint
+ receivers.remove(file);
}
- public void uploadFinished(ReceivingEndedEvent event) {
+ public void streamingFinished(StreamingEndedEvent event) {
if (listenProgressOfUploadedFile) {
- currentlyUploadedFile.getUploadListener().uploadFinished(
+ file.getReceiver().streamingFinished(
new ReceivingEventWrapper(event));
}
- receivers.remove(event.getReceiver());
}
- public void uploadFailed(final ReceivingFailedEvent event) {
+ public void streamingFailed(final StreamingFailedEvent event) {
if (listenProgressOfUploadedFile) {
- currentlyUploadedFile.getUploadListener().uploadFailed(
+ file.getReceiver().streamingFailed(
new ReceivingEventWrapper(event));
}
- receivers.remove(event.getReceiver());
}
public boolean isInterrupted() {
- return currentlyUploadedFile.isInterrupted();
+ return file.getReceiver().isInterrupted();
}
- };
+ /*
+ * With XHR2 file posts we can't provide as much information from the
+ * terminal as with multipart request. This helper class wraps the
+ * terminal event and provides the lacking information from the
+ * Html5File.
+ */
+ class ReceivingEventWrapper implements StreamingFailedEvent,
+ StreamingEndedEvent, StreamingStartedEvent,
+ StreamingProgressedEvent {
+
+ private StreamingEvent wrappedEvent;
+
+ ReceivingEventWrapper(StreamingEvent e) {
+ wrappedEvent = e;
+ }
+
+ public String getMimeType() {
+ return file.getType();
+ }
+
+ public String getFileName() {
+ return file.getFileName();
+ }
+
+ public long getContentLength() {
+ return file.getFileSize();
+ }
+
+ public StreamVariable getReceiver() {
+ return ProxyReceiver.this;
+ }
+
+ public Exception getException() {
+ if (wrappedEvent instanceof StreamingFailedEvent) {
+ return ((StreamingFailedEvent) wrappedEvent).getException();
+ }
+ return null;
+ }
+
+ public long getBytesReceived() {
+ return wrappedEvent.getBytesReceived();
+ }
+ }
- public ReceivingController getReceivingController(Receiver receiver) {
- return controller;
}
}
package com.vaadin.ui;
-import java.io.OutputStream;
import java.io.Serializable;
import com.vaadin.event.dd.DropHandler;
-import com.vaadin.terminal.Receiver;
-import com.vaadin.terminal.ReceiverOwner.ReceivingEndedEvent;
-import com.vaadin.terminal.ReceiverOwner.ReceivingFailedEvent;
-import com.vaadin.terminal.ReceiverOwner.ReceivingProgressedEvent;
-import com.vaadin.terminal.ReceiverOwner.ReceivingStartedEvent;
+import com.vaadin.terminal.StreamVariable;
/**
* {@link DragAndDropWrapper} can receive also files from client computer if
* information about dragged file on server side.
*/
public class Html5File implements Serializable {
-
- final class ProxyReceiver implements Receiver {
- public OutputStream receiveUpload(String filename, String MIMEType) {
- if (receiver == null) {
- return null;
- }
- return receiver.receiveUpload(filename, MIMEType);
- }
-
- Html5File getFile() {
- return Html5File.this;
- }
- }
-
+
private String name;
private long size;
- private Receiver receiver;
+ private StreamVariable streamVariable;
private String type;
Html5File(String name, long size, String mimeType) {
type = mimeType;
}
- /**
- * The receiver that is registered to the terminal. Wraps the actual
- * Receiver set later by Html5File user.
- */
- private ProxyReceiver proxyReceiver = new ProxyReceiver();
- private boolean interrupted = false;
- private Html5FileUploadListener listener;
-
public String getFileName() {
return name;
}
}
/**
- * Sets the {@link Receiver} that into which the file contents will be
- * written. Usage of Receiver is similar to {@link Upload} component.
+ * Sets the {@link StreamVariable} that into which the file contents will be
+ * written. Usage of StreamVariable is similar to {@link Upload} component.
* <p>
- * If the {@link Receiver} is not set in the {@link DropHandler} the file
+ * If the {@link StreamVariable} is not set in the {@link DropHandler} the file
* contents will not be sent to server.
* <p>
* <em>Note!</em> receiving file contents is experimental feature depending
* 3.6 and above and recent webkit based browsers (Safari 5, Chrome 6) at
* this time.
*
- * @param receiver
+ * @param streamVariable
* the callback that returns stream where the implementation
* writes the file contents as it arrives.
*/
- public void setReceiver(Receiver receiver) {
- this.receiver = receiver;
- }
-
- public Receiver getReceiver() {
- return receiver;
- }
-
- ProxyReceiver getProxyReceiver() {
- return proxyReceiver;
- }
-
- /**
- * Gets the {@link Html5FileUploadListener} that is used to track the
- * progress of streaming the file contents to given {@link Receiver}.
- *
- * @return
- */
- public Html5FileUploadListener getUploadListener() {
- return listener;
+ public void setReceiver(StreamVariable streamVariable) {
+ this.streamVariable = streamVariable;
}
- /**
- * Sets the {@link Html5FileUploadListener} that can be used to track the
- * progress of streaming the file contents to given {@link Receiver}.
- *
- * @param listener
- * @see #setReceiver(Receiver)
- */
- public void setUploadListener(Html5FileUploadListener listener) {
- this.listener = listener;
- }
-
- public boolean isInterrupted() {
- return interrupted;
- }
-
- /**
- * Interrupts uploading this file.
- *
- * @param interrupted
- */
- public void setInterrupted(boolean interrupted) {
- this.interrupted = interrupted;
- }
-
- public interface Html5FileUploadListener extends Serializable {
-
- void onProgress(ReceivingProgressedEvent event);
-
- void uploadStarted(ReceivingStartedEvent event);
-
- void uploadFinished(ReceivingEndedEvent event);
-
- void uploadFailed(ReceivingFailedEvent event);
+ public StreamVariable getReceiver() {
+ return streamVariable;
}
+
}
\ No newline at end of file
package com.vaadin.ui;
+import java.io.OutputStream;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.Iterator;
import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
-import com.vaadin.terminal.ReceiverOwner;
+import com.vaadin.terminal.StreamVariable.StreamingStartedEvent;
import com.vaadin.terminal.gwt.client.ui.VUpload;
import com.vaadin.terminal.gwt.server.NoInputStreamException;
import com.vaadin.terminal.gwt.server.NoOutputStreamException;
*/
@SuppressWarnings("serial")
@ClientWidget(value = VUpload.class, loadStyle = LoadStyle.LAZY)
-public class Upload extends AbstractComponent implements Component.Focusable,
- ReceiverOwner {
+public class Upload extends AbstractComponent implements Component.Focusable {
/**
* Should the field be focused on next repaint?
/**
* The output of the upload is redirected to this receiver.
*/
- private com.vaadin.terminal.Receiver receiver;
+ private Receiver receiver;
private boolean isUploading;
public Upload() {
}
- /**
- * @deprecated use
- * {@link Upload#Upload(String, com.vaadin.terminal.Receiver)}
- * instead
- */
- @Deprecated
public Upload(String caption, Receiver uploadReceiver) {
setCaption(caption);
receiver = uploadReceiver;
}
- /**
- * Creates a new instance of Upload that redirects the uploaded data to
- * stream given by the Receiver.
- *
- * @param caption
- * Normal component caption. You can set the caption of the
- * upload submit button with setButtonCaption().
- * @param uploadReceiver
- * Receiver to call to retrieve output stream when upload starts.
- */
- public Upload(String caption, com.vaadin.terminal.Receiver uploadReceiver) {
- setCaption(caption);
- receiver = uploadReceiver;
- }
-
/**
* Invoked when the value of a variable has changed.
*
target.addAttribute("nextid", nextid);
- // Post file to this receiver
- target.addVariable(this, "action", getReceiver());
+ // Post file to this strean variable
+ target.addVariable(this, "action", getStreamVariable());
}
* @version
* @VERSION@
* @since 3.0
- * @deprecated use {@link com.vaadin.terminal.Receiver} instead. A "copy"
- * here is kept for backwards compatibility.
*/
- @Deprecated
- public interface Receiver extends com.vaadin.terminal.Receiver {
+ public interface Receiver extends Serializable {
+ public OutputStream receiveUpload(String filename, String mimetype);
}
/* Upload events */
/**
* Returns the current receiver.
*
- * @return the Receiver.
+ * @return the StreamVariable.
*/
- public com.vaadin.terminal.Receiver getReceiver() {
+ public Receiver getReceiver() {
return receiver;
}
/**
* Sets the receiver.
*
- * @deprecated use {@link #setReceiver(com.vaadin.terminal.Receiver)}
- * instead
* @param receiver
* the receiver to set.
*/
- @Deprecated
public void setReceiver(Receiver receiver) {
this.receiver = receiver;
}
- /**
- * Sets the receiver.
- *
- * @param receiver
- * the receiver to set.
- */
- public void setReceiver(com.vaadin.terminal.Receiver receiver) {
- this.receiver = receiver;
- }
-
/**
* {@inheritDoc}
*/
* Handle to terminal via Upload monitors and controls the upload during it
* is being streamed.
*/
- private final ReceivingController controller = new ReceivingController() {
- public boolean listenProgress() {
- return (progressListeners != null && !progressListeners.isEmpty());
- }
-
- public void onProgress(ReceivingProgressedEvent event) {
- fireUpdateProgress(event.getBytesReceived(),
- event.getContentLength());
- }
-
- public void uploadStarted(ReceivingStartedEvent event) {
- startUpload();
- contentLength = event.getContentLength();
- fireStarted(event.getFileName(), event.getMimeType());
- }
-
- public void uploadFinished(ReceivingEndedEvent event) {
- fireUploadSuccess(event.getFileName(), event.getMimeType(),
- event.getContentLength());
- endUpload();
- requestRepaint();
- }
-
- public void uploadFailed(ReceivingFailedEvent event) {
- Exception exception = event.getException();
- if (exception instanceof NoInputStreamException) {
- fireNoInputStream(event.getFileName(), event.getMimeType(), 0);
- } else if (exception instanceof NoOutputStreamException) {
- fireNoOutputStream(event.getFileName(), event.getMimeType(), 0);
- } else {
- fireUploadInterrupted(event.getFileName(), event.getMimeType(),
- 0, exception);
- }
- endUpload();
- }
-
- public boolean isInterrupted() {
- return interrupted;
- }
- };
-
- public ReceivingController getReceivingController(
- com.vaadin.terminal.Receiver receiver) {
- return controller;
+ private com.vaadin.terminal.StreamVariable streamVariable;
+
+ protected com.vaadin.terminal.StreamVariable getStreamVariable() {
+ if (streamVariable == null) {
+ streamVariable = new com.vaadin.terminal.StreamVariable() {
+ private StreamingStartedEvent lastStartedEvent;
+
+ public boolean listenProgress() {
+ return (progressListeners != null && !progressListeners
+ .isEmpty());
+ }
+
+ public void onProgress(StreamingProgressedEvent event) {
+ fireUpdateProgress(event.getBytesReceived(),
+ event.getContentLength());
+ }
+
+ public boolean isInterrupted() {
+ return interrupted;
+ }
+
+ public OutputStream getOutputStream() {
+ OutputStream receiveUpload = receiver.receiveUpload(
+ lastStartedEvent.getFileName(),
+ lastStartedEvent.getMimeType());
+ lastStartedEvent = null;
+ return receiveUpload;
+ }
+
+ public void streamingStarted(StreamingStartedEvent event) {
+ startUpload();
+ contentLength = event.getContentLength();
+ fireStarted(event.getFileName(), event.getMimeType());
+ lastStartedEvent = event;
+ }
+
+ public void streamingFinished(StreamingEndedEvent event) {
+ fireUploadSuccess(event.getFileName(), event.getMimeType(),
+ event.getContentLength());
+ endUpload();
+ requestRepaint();
+ }
+
+ public void streamingFailed(StreamingFailedEvent event) {
+ Exception exception = event.getException();
+ if (exception instanceof NoInputStreamException) {
+ fireNoInputStream(event.getFileName(),
+ event.getMimeType(), 0);
+ } else if (exception instanceof NoOutputStreamException) {
+ fireNoOutputStream(event.getFileName(),
+ event.getMimeType(), 0);
+ } else {
+ fireUploadInterrupted(event.getFileName(),
+ event.getMimeType(), 0, exception);
+ }
+ endUpload();
+ }
+ };
+ }
+ return streamVariable;
}
}
import com.vaadin.event.dd.acceptcriteria.AcceptCriterion;
import com.vaadin.event.dd.acceptcriteria.Not;
import com.vaadin.event.dd.acceptcriteria.SourceIsTarget;
+import com.vaadin.terminal.StreamVariable;
import com.vaadin.terminal.Resource;
import com.vaadin.terminal.StreamResource;
import com.vaadin.terminal.StreamResource.StreamSource;
import com.vaadin.ui.Tree;
import com.vaadin.ui.Tree.TreeDragMode;
import com.vaadin.ui.Tree.TreeTargetDetails;
-import com.vaadin.ui.Upload.Receiver;
import com.vaadin.ui.Window;
public class DDTest6 extends TestBase {
for (Html5File html5File : files2) {
String fileName = html5File.getFileName();
// int bytes = html5File.getFileSize();
- final ByteArrayOutputStream bas = new ByteArrayOutputStream() {
- @Override
- public void close() throws IOException {
- super.close();
- }
- };
+ final ByteArrayOutputStream bas = new ByteArrayOutputStream();
- Receiver receiver = new Receiver() {
- public OutputStream receiveUpload(String filename,
- String MIMEType) {
+ StreamVariable streamVariable = new StreamVariable() {
+
+ public OutputStream getOutputStream() {
return bas;
}
+
+ public boolean listenProgress() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public void onProgress(
+ StreamingProgressedEvent event) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void streamingStarted(
+ StreamingStartedEvent event) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void streamingFinished(
+ StreamingEndedEvent event) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void streamingFailed(
+ StreamingFailedEvent event) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public boolean isInterrupted() {
+ // TODO Auto-generated method stub
+ return false;
+ }
};
- html5File.setReceiver(receiver);
+ html5File.setReceiver(streamVariable);
File file = new File(fileName, bas);
file.setType(html5File.getType());
import com.vaadin.event.dd.DropHandler;
import com.vaadin.event.dd.acceptcriteria.AcceptAll;
import com.vaadin.event.dd.acceptcriteria.AcceptCriterion;
-import com.vaadin.terminal.Receiver;
-import com.vaadin.terminal.ReceiverOwner.ReceivingEndedEvent;
-import com.vaadin.terminal.ReceiverOwner.ReceivingFailedEvent;
-import com.vaadin.terminal.ReceiverOwner.ReceivingProgressedEvent;
-import com.vaadin.terminal.ReceiverOwner.ReceivingStartedEvent;
+import com.vaadin.terminal.StreamVariable;
+import com.vaadin.terminal.StreamVariable.StreamingEndedEvent;
+import com.vaadin.terminal.StreamVariable.StreamingFailedEvent;
+import com.vaadin.terminal.StreamVariable.StreamingProgressedEvent;
+import com.vaadin.terminal.StreamVariable.StreamingStartedEvent;
import com.vaadin.tests.components.TestBase;
import com.vaadin.ui.Component;
import com.vaadin.ui.CssLayout;
import com.vaadin.ui.DragAndDropWrapper;
import com.vaadin.ui.DragAndDropWrapper.WrapperTransferable;
import com.vaadin.ui.Html5File;
-import com.vaadin.ui.Html5File.Html5FileUploadListener;
import com.vaadin.ui.Label;
public class DragAndDropFiles extends TestBase {
continue;
}
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
-
- Receiver receiver = new Receiver() {
- public OutputStream receiveUpload(String filename,
- String MIMEType) {
- System.err.println("receiveUpload " + filename);
+ StreamVariable streamVariable = new StreamVariable() {
+ public OutputStream getOutputStream() {
return new NullOutputStream();
}
- };
- file.setReceiver(receiver);
- Html5FileUploadListener listener = new Html5FileUploadListener() {
- public void uploadStarted(
- ReceivingStartedEvent event) {
+ public boolean listenProgress() {
+ return true;
+ }
+
+ public void onProgress(
+ StreamingProgressedEvent event) {
+ System.err.println("Progress"
+ + event.getBytesReceived());
+ }
+
+ public void streamingStarted(
+ StreamingStartedEvent event) {
getMainWindow().showNotification(
"Started uploading "
+ event.getFileName());
-
}
- public void uploadFinished(ReceivingEndedEvent event) {
+ public void streamingFinished(
+ StreamingEndedEvent event) {
getMainWindow().showNotification(
"Finished uploading "
+ event.getFileName());
}
- public void uploadFailed(ReceivingFailedEvent event) {
+ public void streamingFailed(
+ StreamingFailedEvent event) {
getMainWindow().showNotification(
"Failed uploading "
+ event.getFileName());
-
}
- public void onProgress(
- ReceivingProgressedEvent event) {
- System.err.println("Progress"
- + event.getBytesReceived());
+ public boolean isInterrupted() {
+ return false;
}
};
- file.setUploadListener(listener);
+ file.setReceiver(streamVariable);
}
}
package com.vaadin.tests.dd;
import java.io.ByteArrayOutputStream;
-import java.io.IOException;
import java.io.OutputStream;
import com.vaadin.event.DataBoundTransferable;
import com.vaadin.event.dd.DropHandler;
import com.vaadin.event.dd.acceptcriteria.AcceptAll;
import com.vaadin.event.dd.acceptcriteria.AcceptCriterion;
+import com.vaadin.terminal.StreamVariable;
import com.vaadin.terminal.gwt.client.MouseEventDetails;
import com.vaadin.ui.AbsoluteLayout;
import com.vaadin.ui.AbsoluteLayout.ComponentPosition;
import com.vaadin.ui.DragAndDropWrapper;
import com.vaadin.ui.Html5File;
import com.vaadin.ui.Label;
-import com.vaadin.ui.Upload.Receiver;
/**
* replacement for a proto class to keep tests working
if (files != null) {
for (Html5File html5File : files) {
l.setCaption(html5File.getFileName());
- html5File.setReceiver(new Receiver() {
- public OutputStream receiveUpload(String filename,
- String MIMEType) {
-
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream() {
- @Override
- public void close() throws IOException {
- super.close();
- l.setValue((new String(toByteArray())
- .substring(0, 80) + "..."));
- }
- };
+ html5File.setReceiver(new StreamVariable() {
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+
+ public OutputStream getOutputStream() {
return byteArrayOutputStream;
}
+
+ public boolean listenProgress() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public void onProgress(StreamingProgressedEvent event) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void streamingStarted(StreamingStartedEvent event) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void streamingFinished(StreamingEndedEvent event) {
+ l.setValue((new String(byteArrayOutputStream
+ .toByteArray()).substring(0, 80) + "..."));
+ }
+
+ public void streamingFailed(StreamingFailedEvent event) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public boolean isInterrupted() {
+ // TODO Auto-generated method stub
+ return false;
+ }
});
}
}