summaryrefslogtreecommitdiffstats
path: root/server/src/com/vaadin/ui/AbstractMedia.java
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2012-08-30 11:30:39 +0300
committerLeif Åstrand <leif@vaadin.com>2012-08-30 12:47:35 +0300
commitfd3826abf42f69db546eff18d269e462843feb49 (patch)
tree2852b77e657e90061842bc2d99dad09b36cd4150 /server/src/com/vaadin/ui/AbstractMedia.java
parente71794ee177e309a4cba15ebd6b65d5950721dd7 (diff)
downloadvaadin-framework-fd3826abf42f69db546eff18d269e462843feb49.tar.gz
vaadin-framework-fd3826abf42f69db546eff18d269e462843feb49.zip
Replace ApplicationResource with ConnectorResource (#9419)
Diffstat (limited to 'server/src/com/vaadin/ui/AbstractMedia.java')
-rw-r--r--server/src/com/vaadin/ui/AbstractMedia.java41
1 files changed, 40 insertions, 1 deletions
diff --git a/server/src/com/vaadin/ui/AbstractMedia.java b/server/src/com/vaadin/ui/AbstractMedia.java
index f9eb67f666..940d85a8b9 100644
--- a/server/src/com/vaadin/ui/AbstractMedia.java
+++ b/server/src/com/vaadin/ui/AbstractMedia.java
@@ -16,11 +16,18 @@
package com.vaadin.ui;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import java.util.logging.Logger;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import com.vaadin.server.ConnectorResource;
import com.vaadin.server.Resource;
import com.vaadin.server.ResourceReference;
+import com.vaadin.server.WrappedRequest;
+import com.vaadin.server.WrappedResponse;
import com.vaadin.shared.communication.URLReference;
import com.vaadin.shared.ui.AbstractMediaState;
import com.vaadin.shared.ui.MediaControl;
@@ -64,11 +71,43 @@ public abstract class AbstractMedia extends AbstractComponent {
*/
public void addSource(Resource source) {
if (source != null) {
- getState().getSources().add(new ResourceReference(source));
+ List<URLReference> sources = getState().getSources();
+ sources.add(new ResourceReference(source, this, Integer
+ .toString(sources.size())));
getState().getSourceTypes().add(source.getMIMEType());
}
}
+ @Override
+ public boolean handleConnectorRequest(WrappedRequest request,
+ WrappedResponse response, String path) throws IOException {
+ Matcher matcher = Pattern.compile("(\\d+)(/.*)?").matcher(path);
+ if (matcher.matches()) {
+ List<URLReference> sources = getState().getSources();
+
+ int sourceIndex = Integer.parseInt(matcher.group(1));
+
+ if (sourceIndex < 0 || sourceIndex >= sources.size()) {
+ getLogger().warning(
+ "Requested source index " + sourceIndex
+ + " is out of bounds");
+ return false;
+ }
+
+ URLReference reference = sources.get(sourceIndex);
+ ConnectorResource resource = (ConnectorResource) ResourceReference
+ .getResource(reference);
+ resource.getStream().writeTo(response);
+ return true;
+ } else {
+ return super.handleConnectorRequest(request, response, path);
+ }
+ }
+
+ private Logger getLogger() {
+ return Logger.getLogger(AbstractMedia.class.getName());
+ }
+
/**
* Set multiple sources at once. Which of the sources is used is selected by
* the browser depending on which file formats it supports. See <a