diff options
Diffstat (limited to 'src/com/vaadin/terminal')
19 files changed, 297 insertions, 492 deletions
diff --git a/src/com/vaadin/terminal/PaintTarget.java b/src/com/vaadin/terminal/PaintTarget.java index 2ee69247e7..76ebd19a7d 100644 --- a/src/com/vaadin/terminal/PaintTarget.java +++ b/src/com/vaadin/terminal/PaintTarget.java @@ -152,26 +152,26 @@ public interface PaintTarget extends Serializable { 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; /** diff --git a/src/com/vaadin/terminal/Receiver.java b/src/com/vaadin/terminal/Receiver.java deleted file mode 100644 index 0841ad01e0..0000000000 --- a/src/com/vaadin/terminal/Receiver.java +++ /dev/null @@ -1,37 +0,0 @@ -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); -} diff --git a/src/com/vaadin/terminal/ReceiverOwner.java b/src/com/vaadin/terminal/ReceiverOwner.java deleted file mode 100644 index 6f19192081..0000000000 --- a/src/com/vaadin/terminal/ReceiverOwner.java +++ /dev/null @@ -1,161 +0,0 @@ -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(); - } - -} diff --git a/src/com/vaadin/terminal/StreamVariable.java b/src/com/vaadin/terminal/StreamVariable.java new file mode 100644 index 0000000000..aeadaad611 --- /dev/null +++ b/src/com/vaadin/terminal/StreamVariable.java @@ -0,0 +1,145 @@ +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(); + + } + +} diff --git a/src/com/vaadin/terminal/UploadStream.java b/src/com/vaadin/terminal/UploadStream.java deleted file mode 100644 index 95351e071d..0000000000 --- a/src/com/vaadin/terminal/UploadStream.java +++ /dev/null @@ -1,50 +0,0 @@ -/* -@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(); -} diff --git a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java index 6102505883..73b83957c2 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java @@ -51,12 +51,10 @@ import com.vaadin.terminal.PaintException; 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; @@ -369,18 +367,18 @@ public abstract class AbstractCommunicationManager implements /** * 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 + "--"; @@ -530,7 +528,7 @@ public abstract class AbstractCommunicationManager implements 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) { @@ -547,13 +545,13 @@ public abstract class AbstractCommunicationManager implements * * @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 @@ -569,9 +567,9 @@ public abstract class AbstractCommunicationManager implements 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) { @@ -583,15 +581,12 @@ public abstract class AbstractCommunicationManager implements } 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; @@ -599,11 +594,11 @@ public abstract class AbstractCommunicationManager implements 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 @@ -625,42 +620,42 @@ public abstract class AbstractCommunicationManager implements // 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) @@ -2186,6 +2181,6 @@ public abstract class AbstractCommunicationManager implements } - abstract String createReceiverUrl(ReceiverOwner owner, String name, - Receiver value); + abstract String createReceiverUrl(VariableOwner owner, String name, + StreamVariable value); } diff --git a/src/com/vaadin/terminal/gwt/server/AbstractReceivingEvent.java b/src/com/vaadin/terminal/gwt/server/AbstractStreamingEvent.java index a3ada4ea53..91039d05e5 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractReceivingEvent.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractStreamingEvent.java @@ -1,16 +1,16 @@ package com.vaadin.terminal.gwt.server; -import com.vaadin.terminal.Receiver; -import com.vaadin.terminal.ReceiverOwner.ReceivingEvent; +import com.vaadin.terminal.StreamVariable; +import com.vaadin.terminal.StreamVariable.StreamingEvent; /** - * Abstract base class for ReceivingEvent implementations. + * Abstract base class for StreamingEvent implementations. */ @SuppressWarnings("serial") -abstract class AbstractReceivingEvent implements ReceivingEvent { +abstract class AbstractStreamingEvent implements StreamingEvent { private final String type; private final String filename; - private final Receiver receiver; + private final StreamVariable streamVariable; private final long contentLength; private final long bytesReceived; @@ -22,17 +22,17 @@ abstract class AbstractReceivingEvent implements ReceivingEvent { return type; } - protected AbstractReceivingEvent(Receiver receiver, String filename, + protected AbstractStreamingEvent(StreamVariable streamVariable, String filename, String type, long length, long bytesReceived) { - this.receiver = receiver; + this.streamVariable = streamVariable; this.filename = filename; this.type = type; contentLength = length; this.bytesReceived = bytesReceived; } - public final Receiver getReceiver() { - return receiver; + public final StreamVariable getReceiver() { + return streamVariable; } public final long getContentLength() { diff --git a/src/com/vaadin/terminal/gwt/server/CommunicationManager.java b/src/com/vaadin/terminal/gwt/server/CommunicationManager.java index df937688cb..73f6732cf0 100644 --- a/src/com/vaadin/terminal/gwt/server/CommunicationManager.java +++ b/src/com/vaadin/terminal/gwt/server/CommunicationManager.java @@ -20,8 +20,8 @@ import com.vaadin.Application; 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; @@ -208,7 +208,7 @@ public class CommunicationManager extends AbstractCommunicationManager { /** * Handles file upload request submitted via Upload component. * - * @see #createReceiverUrl(ReceiverOwner, String, Receiver) + * @see #createReceiverUrl(ReceiverOwner, String, StreamVariable) * * @param request * @param response @@ -231,23 +231,23 @@ public class CommunicationManager extends AbstractCommunicationManager { 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 { @@ -336,8 +336,8 @@ public class CommunicationManager extends AbstractCommunicationManager { @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()) { @@ -349,12 +349,16 @@ public class CommunicationManager extends AbstractCommunicationManager { } - 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 @@ -365,25 +369,25 @@ public class CommunicationManager extends AbstractCommunicationManager { * 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); diff --git a/src/com/vaadin/terminal/gwt/server/HttpUploadStream.java b/src/com/vaadin/terminal/gwt/server/HttpUploadStream.java deleted file mode 100644 index 40b5d41004..0000000000 --- a/src/com/vaadin/terminal/gwt/server/HttpUploadStream.java +++ /dev/null @@ -1,90 +0,0 @@ -/* -@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; - } -} diff --git a/src/com/vaadin/terminal/gwt/server/JsonPaintTarget.java b/src/com/vaadin/terminal/gwt/server/JsonPaintTarget.java index 27b9ea4ae9..2ea372264d 100644 --- a/src/com/vaadin/terminal/gwt/server/JsonPaintTarget.java +++ b/src/com/vaadin/terminal/gwt/server/JsonPaintTarget.java @@ -29,8 +29,7 @@ import com.vaadin.terminal.ExternalResource; 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; @@ -1112,7 +1111,7 @@ public class JsonPaintTarget implements PaintTarget { 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); diff --git a/src/com/vaadin/terminal/gwt/server/PortletCommunicationManager.java b/src/com/vaadin/terminal/gwt/server/PortletCommunicationManager.java index 37beafa172..cf2cab0edf 100644 --- a/src/com/vaadin/terminal/gwt/server/PortletCommunicationManager.java +++ b/src/com/vaadin/terminal/gwt/server/PortletCommunicationManager.java @@ -24,8 +24,8 @@ import javax.servlet.http.HttpServletRequestWrapper; 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; @@ -197,8 +197,8 @@ public class PortletCommunicationManager extends AbstractCommunicationManager { 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 @@ -207,11 +207,11 @@ public class PortletCommunicationManager extends AbstractCommunicationManager { 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()); } @@ -271,16 +271,16 @@ public class PortletCommunicationManager extends AbstractCommunicationManager { 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); diff --git a/src/com/vaadin/terminal/gwt/server/ReceivingEndedEventImpl.java b/src/com/vaadin/terminal/gwt/server/ReceivingEndedEventImpl.java deleted file mode 100644 index 06609f058e..0000000000 --- a/src/com/vaadin/terminal/gwt/server/ReceivingEndedEventImpl.java +++ /dev/null @@ -1,15 +0,0 @@ -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); - } - -} diff --git a/src/com/vaadin/terminal/gwt/server/ReceivingFailedEventImpl.java b/src/com/vaadin/terminal/gwt/server/ReceivingFailedEventImpl.java deleted file mode 100644 index c732e69cc9..0000000000 --- a/src/com/vaadin/terminal/gwt/server/ReceivingFailedEventImpl.java +++ /dev/null @@ -1,23 +0,0 @@ -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; - } - -} diff --git a/src/com/vaadin/terminal/gwt/server/ReceivingProgressedEventImpl.java b/src/com/vaadin/terminal/gwt/server/ReceivingProgressedEventImpl.java deleted file mode 100644 index f28f0ad453..0000000000 --- a/src/com/vaadin/terminal/gwt/server/ReceivingProgressedEventImpl.java +++ /dev/null @@ -1,16 +0,0 @@ -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); - } - -} diff --git a/src/com/vaadin/terminal/gwt/server/ReceivingStartedEventImpl.java b/src/com/vaadin/terminal/gwt/server/ReceivingStartedEventImpl.java deleted file mode 100644 index beb2ac8e25..0000000000 --- a/src/com/vaadin/terminal/gwt/server/ReceivingStartedEventImpl.java +++ /dev/null @@ -1,15 +0,0 @@ -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); - } - -} diff --git a/src/com/vaadin/terminal/gwt/server/StreamingFailedEventImpl.java b/src/com/vaadin/terminal/gwt/server/StreamingFailedEventImpl.java new file mode 100644 index 0000000000..23fb3b0e86 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/server/StreamingFailedEventImpl.java @@ -0,0 +1,23 @@ +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; + } + +} diff --git a/src/com/vaadin/terminal/gwt/server/StreamingProgressedEventImpl.java b/src/com/vaadin/terminal/gwt/server/StreamingProgressedEventImpl.java new file mode 100644 index 0000000000..6ca751d60c --- /dev/null +++ b/src/com/vaadin/terminal/gwt/server/StreamingProgressedEventImpl.java @@ -0,0 +1,16 @@ +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); + } + +} diff --git a/src/com/vaadin/terminal/gwt/server/StreamingStartedEventImpl.java b/src/com/vaadin/terminal/gwt/server/StreamingStartedEventImpl.java new file mode 100644 index 0000000000..f0b37479a5 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/server/StreamingStartedEventImpl.java @@ -0,0 +1,15 @@ +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); + } + +} diff --git a/src/com/vaadin/terminal/gwt/server/StremingEndedEventImpl.java b/src/com/vaadin/terminal/gwt/server/StremingEndedEventImpl.java new file mode 100644 index 0000000000..9117ce95a1 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/server/StremingEndedEventImpl.java @@ -0,0 +1,15 @@ +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); + } + +} |