diff options
Diffstat (limited to 'src/com/vaadin/terminal/gwt')
13 files changed, 127 insertions, 141 deletions
diff --git a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java index 73b83957c2..5b691438f3 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java @@ -52,9 +52,9 @@ import com.vaadin.terminal.PaintTarget; import com.vaadin.terminal.Paintable; import com.vaadin.terminal.Paintable.RepaintRequestEvent; 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.StreamVariable.StreamingEndEvent; +import com.vaadin.terminal.StreamVariable.StreamingErrorEvent; +import com.vaadin.terminal.StreamVariable.StreamingStartEvent; import com.vaadin.terminal.Terminal.ErrorEvent; import com.vaadin.terminal.Terminal.ErrorListener; import com.vaadin.terminal.URIHandler; @@ -378,8 +378,8 @@ public abstract class AbstractCommunicationManager implements * @throws IOException */ protected void doHandleSimpleMultipartFileUpload(Request request, - Response response, StreamVariable streamVariable, VariableOwner owner, - String boundary) throws IOException { + Response response, StreamVariable streamVariable, + VariableOwner owner, String boundary) throws IOException { boundary = CRLF + "--" + boundary + "--"; // multipart parsing, supports only one file for request, but that is @@ -551,8 +551,8 @@ public abstract class AbstractCommunicationManager implements * @throws IOException */ protected void doHandleXhrFilePost(Request request, Response response, - StreamVariable streamVariable, VariableOwner owner, int contentLength) - throws IOException { + StreamVariable streamVariable, VariableOwner owner, + int contentLength) throws IOException { // These are unknown in filexhr ATM, maybe add to Accept header that // is accessible in portlets @@ -581,10 +581,11 @@ public abstract class AbstractCommunicationManager implements } protected final void streamToReceiver(final InputStream in, - StreamVariable streamVariable, String filename, - String type, int contentLength) throws UploadException { + StreamVariable streamVariable, String filename, String type, + int contentLength) throws UploadException { if (streamVariable == null) { - throw new IllegalStateException("StreamVariable for the post not found"); + throw new IllegalStateException( + "StreamVariable for the post not found"); } final Application application = getApplication(); @@ -594,8 +595,8 @@ public abstract class AbstractCommunicationManager implements try { boolean listenProgress; synchronized (application) { - StreamingStartedEvent startedEvent = new StreamingStartedEventImpl( - streamVariable, filename, type, contentLength); + StreamingStartEvent startedEvent = new StreamingStartEventImpl( + filename, type, contentLength); streamVariable.streamingStarted(startedEvent); out = streamVariable.getOutputStream(); listenProgress = streamVariable.listenProgress(); @@ -620,9 +621,8 @@ public abstract class AbstractCommunicationManager implements // update progress if listener set and contentLength // received synchronized (application) { - StreamingProgressedEventImpl progressEvent = new StreamingProgressedEventImpl( - streamVariable, filename, type, contentLength, - totalBytes); + StreamingProgressEventImpl progressEvent = new StreamingProgressEventImpl( + filename, type, contentLength, totalBytes); streamVariable.onProgress(progressEvent); } } @@ -633,8 +633,8 @@ public abstract class AbstractCommunicationManager implements // upload successful out.close(); - StreamingEndedEvent event = new StremingEndedEventImpl(streamVariable, - filename, type, totalBytes); + StreamingEndEvent event = new StreamingEndEventImpl(filename, type, + totalBytes); synchronized (application) { streamVariable.streamingFinished(event); } @@ -642,8 +642,8 @@ public abstract class AbstractCommunicationManager implements } catch (UploadInterruptedException e) { // Download interrupted by application code tryToCloseStream(out); - StreamingFailedEvent event = new StreamingFailedEventImpl(streamVariable, - filename, type, contentLength, totalBytes, e); + StreamingErrorEvent event = new StreamingErrorEventImpl(filename, + type, contentLength, totalBytes, e); synchronized (application) { streamVariable.streamingFailed(event); } @@ -652,8 +652,8 @@ public abstract class AbstractCommunicationManager implements } catch (final Exception e) { tryToCloseStream(out); synchronized (application) { - StreamingFailedEvent event = new StreamingFailedEventImpl( - streamVariable, filename, type, contentLength, totalBytes, e); + StreamingErrorEvent event = new StreamingErrorEventImpl( + filename, type, contentLength, totalBytes, e); synchronized (application) { streamVariable.streamingFailed(event); } @@ -2181,6 +2181,6 @@ public abstract class AbstractCommunicationManager implements } - abstract String createReceiverUrl(VariableOwner owner, String name, + abstract String createStreamVariableTargetUrl(VariableOwner owner, String name, StreamVariable value); } diff --git a/src/com/vaadin/terminal/gwt/server/AbstractStreamingEvent.java b/src/com/vaadin/terminal/gwt/server/AbstractStreamingEvent.java index 91039d05e5..83ba45789d 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractStreamingEvent.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractStreamingEvent.java @@ -1,6 +1,5 @@ package com.vaadin.terminal.gwt.server; -import com.vaadin.terminal.StreamVariable; import com.vaadin.terminal.StreamVariable.StreamingEvent; /** @@ -10,7 +9,6 @@ import com.vaadin.terminal.StreamVariable.StreamingEvent; 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; @@ -22,19 +20,14 @@ abstract class AbstractStreamingEvent implements StreamingEvent { return type; } - protected AbstractStreamingEvent(StreamVariable streamVariable, String filename, - String type, long length, long bytesReceived) { - this.streamVariable = streamVariable; + protected AbstractStreamingEvent(String filename, String type, long length, + long bytesReceived) { this.filename = filename; this.type = type; contentLength = length; this.bytesReceived = bytesReceived; } - public final StreamVariable getReceiver() { - return streamVariable; - } - public final long getContentLength() { return contentLength; } diff --git a/src/com/vaadin/terminal/gwt/server/CommunicationManager.java b/src/com/vaadin/terminal/gwt/server/CommunicationManager.java index 73f6732cf0..ae4ec16c2a 100644 --- a/src/com/vaadin/terminal/gwt/server/CommunicationManager.java +++ b/src/com/vaadin/terminal/gwt/server/CommunicationManager.java @@ -208,7 +208,8 @@ public class CommunicationManager extends AbstractCommunicationManager { /** * Handles file upload request submitted via Upload component. * - * @see #createReceiverUrl(ReceiverOwner, String, StreamVariable) + * @see #createStreamVariableTargetUrl(ReceiverOwner, String, + * StreamVariable) * * @param request * @param response @@ -231,24 +232,26 @@ public class CommunicationManager extends AbstractCommunicationManager { String uppUri = pathInfo.substring(startOfData); String[] parts = uppUri.split("/", 3); // 0 = pid, 1= name, 2 = sec key - StreamVariable streamVariable = pidToNameToReceiver.get(parts[0]).remove(parts[1]); - String secKey = receiverToSeckey.remove(streamVariable); + StreamVariable streamVariable = pidToNameToStreamVariable.get(parts[0]) + .remove(parts[1]); + String secKey = streamVariableToSeckey.remove(streamVariable); if (secKey.equals(parts[2])) { - VariableOwner source = (VariableOwner) getVariableOwner(parts[0]); + VariableOwner source = getVariableOwner(parts[0]); String contentType = request.getContentType(); if (request.getContentType().contains("boundary")) { // Multipart requests contain boundary string doHandleSimpleMultipartFileUpload( new HttpServletRequestWrapper(request), - new HttpServletResponseWrapper(response), streamVariable, - source, contentType.split("boundary=")[1]); + 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), streamVariable, - source, request.getContentLength()); + new HttpServletResponseWrapper(response), + streamVariable, source, request.getContentLength()); } } else { throw new InvalidUIDLSecurityKeyException( @@ -336,12 +339,12 @@ public class CommunicationManager extends AbstractCommunicationManager { @Override protected void unregisterPaintable(Component p) { /* Cleanup possible receivers */ - if (pidToNameToReceiver != null) { - Map<String, StreamVariable> removed = pidToNameToReceiver + if (pidToNameToStreamVariable != null) { + Map<String, StreamVariable> removed = pidToNameToStreamVariable .remove(getPaintableId(p)); if (removed != null) { for (String key : removed.keySet()) { - receiverToSeckey.remove(removed.get(key)); + streamVariableToSeckey.remove(removed.get(key)); } } } @@ -349,16 +352,13 @@ public class CommunicationManager extends AbstractCommunicationManager { } - private Map<String, Map<String, StreamVariable>> pidToNameToReceiver; + private Map<String, Map<String, StreamVariable>> pidToNameToStreamVariable; - private Map<StreamVariable, String> receiverToSeckey; + private Map<StreamVariable, String> streamVariableToSeckey; @Override - String createReceiverUrl(VariableOwner owner, String name, StreamVariable value) { - - /* - * TODO figure out how this can be simplified now that ReceiverOwner is removed. - */ + String createStreamVariableTargetUrl(VariableOwner owner, String name, + StreamVariable value) { /* * We will use the same APP/* URI space as ApplicationResources but @@ -369,28 +369,28 @@ 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 StreamVariable when handling - * post + * 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, StreamVariable>>(); + if (pidToNameToStreamVariable == null) { + pidToNameToStreamVariable = new HashMap<String, Map<String, StreamVariable>>(); } - Map<String, StreamVariable> nameToReceiver = pidToNameToReceiver + Map<String, StreamVariable> nameToStreamVariable = pidToNameToStreamVariable .get(paintableId); - if (nameToReceiver == null) { - nameToReceiver = new HashMap<String, StreamVariable>(); - pidToNameToReceiver.put(paintableId, nameToReceiver); + if (nameToStreamVariable == null) { + nameToStreamVariable = new HashMap<String, StreamVariable>(); + pidToNameToStreamVariable.put(paintableId, nameToStreamVariable); } - nameToReceiver.put(name, value); + nameToStreamVariable.put(name, value); - if (receiverToSeckey == null) { - receiverToSeckey = new HashMap<StreamVariable, String>(); + if (streamVariableToSeckey == null) { + streamVariableToSeckey = new HashMap<StreamVariable, String>(); } String seckey = UUID.randomUUID().toString(); - receiverToSeckey.put(value, seckey); + streamVariableToSeckey.put(value, seckey); return getApplication().getURL() + AbstractApplicationServlet.UPLOAD_URL_PREFIX + key + "/" diff --git a/src/com/vaadin/terminal/gwt/server/JsonPaintTarget.java b/src/com/vaadin/terminal/gwt/server/JsonPaintTarget.java index 2ea372264d..d25619282c 100644 --- a/src/com/vaadin/terminal/gwt/server/JsonPaintTarget.java +++ b/src/com/vaadin/terminal/gwt/server/JsonPaintTarget.java @@ -1113,7 +1113,7 @@ public class JsonPaintTarget implements PaintTarget { public void addVariable(VariableOwner owner, String name, StreamVariable value) throws PaintException { - String url = manager.createReceiverUrl(owner, name, value); + String url = manager.createStreamVariableTargetUrl(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 cf2cab0edf..69e7b0ef27 100644 --- a/src/com/vaadin/terminal/gwt/server/PortletCommunicationManager.java +++ b/src/com/vaadin/terminal/gwt/server/PortletCommunicationManager.java @@ -198,11 +198,11 @@ public class PortletCommunicationManager extends AbstractCommunicationManager { String name = request.getParameter("name"); String ownerId = request.getParameter("rec-owner"); VariableOwner variableOwner = (VariableOwner) getVariableOwner(ownerId); - StreamVariable streamVariable = ownerToNameToReceiver.get(variableOwner).remove( + StreamVariable streamVariable = ownerToNameToStreamVariable.get(variableOwner).remove( name); // clean up, may be re added on next paint - ownerToNameToReceiver.get(variableOwner).remove(name); + ownerToNameToStreamVariable.get(variableOwner).remove(name); if (contentType.contains("boundary")) { doHandleSimpleMultipartFileUpload( @@ -220,8 +220,8 @@ public class PortletCommunicationManager extends AbstractCommunicationManager { @Override protected void unregisterPaintable(Component p) { super.unregisterPaintable(p); - if (ownerToNameToReceiver != null) { - ownerToNameToReceiver.remove(p); + if (ownerToNameToStreamVariable != null) { + ownerToNameToStreamVariable.remove(p); } } @@ -271,17 +271,17 @@ public class PortletCommunicationManager extends AbstractCommunicationManager { application, assumedWindow); } - private Map<VariableOwner, Map<String, StreamVariable>> ownerToNameToReceiver; + private Map<VariableOwner, Map<String, StreamVariable>> ownerToNameToStreamVariable; @Override - String createReceiverUrl(VariableOwner owner, String name, StreamVariable value) { - if (ownerToNameToReceiver == null) { - ownerToNameToReceiver = new HashMap<VariableOwner, Map<String, StreamVariable>>(); + String createStreamVariableTargetUrl(VariableOwner owner, String name, StreamVariable value) { + if (ownerToNameToStreamVariable == null) { + ownerToNameToStreamVariable = new HashMap<VariableOwner, Map<String, StreamVariable>>(); } - Map<String, StreamVariable> nameToReceiver = ownerToNameToReceiver.get(owner); + Map<String, StreamVariable> nameToReceiver = ownerToNameToStreamVariable.get(owner); if (nameToReceiver == null) { nameToReceiver = new HashMap<String, StreamVariable>(); - ownerToNameToReceiver.put(owner, nameToReceiver); + ownerToNameToStreamVariable.put(owner, nameToReceiver); } nameToReceiver.put(name, value); ResourceURL resurl = currentUidlResponse.createResourceURL(); diff --git a/src/com/vaadin/terminal/gwt/server/StreamingEndEventImpl.java b/src/com/vaadin/terminal/gwt/server/StreamingEndEventImpl.java new file mode 100644 index 0000000000..e6290cbf9a --- /dev/null +++ b/src/com/vaadin/terminal/gwt/server/StreamingEndEventImpl.java @@ -0,0 +1,13 @@ +package com.vaadin.terminal.gwt.server; + +import com.vaadin.terminal.StreamVariable.StreamingEndEvent; + +@SuppressWarnings("serial") +final class StreamingEndEventImpl extends AbstractStreamingEvent implements + StreamingEndEvent { + + public StreamingEndEventImpl(String filename, String type, long totalBytes) { + super(filename, type, totalBytes, totalBytes); + } + +} diff --git a/src/com/vaadin/terminal/gwt/server/StreamingErrorEventImpl.java b/src/com/vaadin/terminal/gwt/server/StreamingErrorEventImpl.java new file mode 100644 index 0000000000..367b4be277 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/server/StreamingErrorEventImpl.java @@ -0,0 +1,21 @@ +package com.vaadin.terminal.gwt.server; + +import com.vaadin.terminal.StreamVariable.StreamingErrorEvent; + +@SuppressWarnings("serial") +final class StreamingErrorEventImpl extends AbstractStreamingEvent implements + StreamingErrorEvent { + + private final Exception exception; + + public StreamingErrorEventImpl(final String filename, final String type, + long contentLength, long bytesReceived, final Exception exception) { + super(filename, type, contentLength, bytesReceived); + this.exception = exception; + } + + public final Exception getException() { + return exception; + } + +} diff --git a/src/com/vaadin/terminal/gwt/server/StreamingFailedEventImpl.java b/src/com/vaadin/terminal/gwt/server/StreamingFailedEventImpl.java deleted file mode 100644 index 23fb3b0e86..0000000000 --- a/src/com/vaadin/terminal/gwt/server/StreamingFailedEventImpl.java +++ /dev/null @@ -1,23 +0,0 @@ -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/StreamingProgressEventImpl.java b/src/com/vaadin/terminal/gwt/server/StreamingProgressEventImpl.java new file mode 100644 index 0000000000..a6308f67a1 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/server/StreamingProgressEventImpl.java @@ -0,0 +1,14 @@ +package com.vaadin.terminal.gwt.server; + +import com.vaadin.terminal.StreamVariable.StreamingProgressEvent; + +@SuppressWarnings("serial") +final class StreamingProgressEventImpl extends AbstractStreamingEvent implements + StreamingProgressEvent { + + public StreamingProgressEventImpl(final String filename, final String type, + long contentLength, long bytesReceived) { + super(filename, type, contentLength, bytesReceived); + } + +} diff --git a/src/com/vaadin/terminal/gwt/server/StreamingProgressedEventImpl.java b/src/com/vaadin/terminal/gwt/server/StreamingProgressedEventImpl.java deleted file mode 100644 index 6ca751d60c..0000000000 --- a/src/com/vaadin/terminal/gwt/server/StreamingProgressedEventImpl.java +++ /dev/null @@ -1,16 +0,0 @@ -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/StreamingStartEventImpl.java b/src/com/vaadin/terminal/gwt/server/StreamingStartEventImpl.java new file mode 100644 index 0000000000..fedd2bd110 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/server/StreamingStartEventImpl.java @@ -0,0 +1,14 @@ +package com.vaadin.terminal.gwt.server; + +import com.vaadin.terminal.StreamVariable.StreamingStartEvent; + +@SuppressWarnings("serial") +final class StreamingStartEventImpl extends AbstractStreamingEvent implements + StreamingStartEvent { + + public StreamingStartEventImpl(final String filename, final String type, + long contentLength) { + super(filename, type, contentLength, 0); + } + +} diff --git a/src/com/vaadin/terminal/gwt/server/StreamingStartedEventImpl.java b/src/com/vaadin/terminal/gwt/server/StreamingStartedEventImpl.java deleted file mode 100644 index f0b37479a5..0000000000 --- a/src/com/vaadin/terminal/gwt/server/StreamingStartedEventImpl.java +++ /dev/null @@ -1,15 +0,0 @@ -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 deleted file mode 100644 index 9117ce95a1..0000000000 --- a/src/com/vaadin/terminal/gwt/server/StremingEndedEventImpl.java +++ /dev/null @@ -1,15 +0,0 @@ -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); - } - -} |