summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/src/com/vaadin/server/ExternalResource.java1
-rw-r--r--server/src/com/vaadin/server/FileResource.java1
-rw-r--r--server/src/com/vaadin/ui/AbstractMedia.java52
-rw-r--r--server/src/com/vaadin/ui/Video.java39
-rw-r--r--server/src/com/vaadin/ui/declarative/converters/DesignResourceConverter.java3
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/audio/AudioDeclarativeTest.java63
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/audio/VideoDeclarativeTest.java59
7 files changed, 215 insertions, 3 deletions
diff --git a/server/src/com/vaadin/server/ExternalResource.java b/server/src/com/vaadin/server/ExternalResource.java
index 0c724ae19f..e3b026dde8 100644
--- a/server/src/com/vaadin/server/ExternalResource.java
+++ b/server/src/com/vaadin/server/ExternalResource.java
@@ -124,5 +124,4 @@ public class ExternalResource implements Resource, Serializable {
public void setMIMEType(String mimeType) {
this.mimeType = mimeType;
}
-
}
diff --git a/server/src/com/vaadin/server/FileResource.java b/server/src/com/vaadin/server/FileResource.java
index b32905f972..28de124fe9 100644
--- a/server/src/com/vaadin/server/FileResource.java
+++ b/server/src/com/vaadin/server/FileResource.java
@@ -156,5 +156,4 @@ public class FileResource implements ConnectorResource {
public void setBufferSize(int bufferSize) {
this.bufferSize = bufferSize;
}
-
}
diff --git a/server/src/com/vaadin/ui/AbstractMedia.java b/server/src/com/vaadin/ui/AbstractMedia.java
index 0bd8c3ea77..a0344624d7 100644
--- a/server/src/com/vaadin/ui/AbstractMedia.java
+++ b/server/src/com/vaadin/ui/AbstractMedia.java
@@ -18,12 +18,17 @@ package com.vaadin.ui;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.jsoup.nodes.Attributes;
+import org.jsoup.nodes.Element;
+import org.jsoup.nodes.Node;
+
import com.vaadin.server.ConnectorResource;
import com.vaadin.server.DownloadStream;
import com.vaadin.server.Resource;
@@ -34,6 +39,8 @@ import com.vaadin.server.VaadinSession;
import com.vaadin.shared.communication.URLReference;
import com.vaadin.shared.ui.AbstractMediaState;
import com.vaadin.shared.ui.MediaControl;
+import com.vaadin.ui.declarative.DesignAttributeHandler;
+import com.vaadin.ui.declarative.DesignContext;
/**
* Abstract base class for the HTML5 media components.
@@ -256,4 +263,49 @@ public abstract class AbstractMedia extends AbstractComponent {
getRpcProxy(MediaControl.class).play();
}
+ @Override
+ public void writeDesign(Element design, DesignContext designContext) {
+ super.writeDesign(design, designContext);
+
+ String altText = getAltText();
+ if (altText != null && !altText.isEmpty()) {
+ design.append(altText);
+ }
+
+ for (Resource r : getSources()) {
+ Attributes attr = design.appendElement("source").attributes();
+ DesignAttributeHandler.writeAttribute("href", attr, r, null,
+ Resource.class);
+ }
+ }
+
+ @Override
+ public void readDesign(Element design, DesignContext designContext) {
+ super.readDesign(design, designContext);
+
+ String altText = "";
+ for (Node child : design.childNodes()) {
+ if (child instanceof Element
+ && ((Element) child).tagName().equals("source")
+ && child.hasAttr("href")) {
+ addSource(DesignAttributeHandler.readAttribute("href",
+ child.attributes(), Resource.class));
+ } else {
+ altText += child.toString();
+ }
+ }
+
+ altText = altText.trim();
+ if (!altText.isEmpty()) {
+ setAltText(altText);
+ }
+ }
+
+ @Override
+ protected Collection<String> getCustomAttributes() {
+ Collection<String> result = super.getCustomAttributes();
+ result.add("alt-text");
+ return result;
+ }
+
}
diff --git a/server/src/com/vaadin/ui/Video.java b/server/src/com/vaadin/ui/Video.java
index e690218e6f..46a4293b36 100644
--- a/server/src/com/vaadin/ui/Video.java
+++ b/server/src/com/vaadin/ui/Video.java
@@ -16,9 +16,17 @@
package com.vaadin.ui;
+import java.util.Collection;
+
+import org.jsoup.nodes.Attributes;
+import org.jsoup.nodes.Element;
+import org.jsoup.select.Elements;
+
import com.vaadin.server.Resource;
import com.vaadin.shared.ui.video.VideoConstants;
import com.vaadin.shared.ui.video.VideoState;
+import com.vaadin.ui.declarative.DesignAttributeHandler;
+import com.vaadin.ui.declarative.DesignContext;
/**
* The Video component translates into an HTML5 &lt;video&gt; element and as
@@ -89,4 +97,35 @@ public class Video extends AbstractMedia {
return getResource(VideoConstants.POSTER_RESOURCE);
}
+ @Override
+ public void readDesign(Element design, DesignContext designContext) {
+ Elements elems = design.getElementsByTag("poster");
+ for (Element poster : elems) {
+ if (getPoster() == null && poster.hasAttr("href")) {
+ setPoster(DesignAttributeHandler.readAttribute("href",
+ poster.attributes(), Resource.class));
+ }
+ poster.remove();
+ }
+
+ // Poster is extracted so AbstractMedia does not include it in alt text
+ super.readDesign(design, designContext);
+ }
+
+ @Override
+ public void writeDesign(Element design, DesignContext designContext) {
+ super.writeDesign(design, designContext);
+ if (getPoster() != null) {
+ Attributes attr = design.appendElement("poster").attributes();
+ DesignAttributeHandler.writeAttribute("href", attr, getPoster(),
+ null, Resource.class);
+ }
+ }
+
+ @Override
+ protected Collection<String> getCustomAttributes() {
+ Collection<String> result = super.getCustomAttributes();
+ result.add("poster");
+ return result;
+ }
}
diff --git a/server/src/com/vaadin/ui/declarative/converters/DesignResourceConverter.java b/server/src/com/vaadin/ui/declarative/converters/DesignResourceConverter.java
index 70e46b8e7f..21f20e6403 100644
--- a/server/src/com/vaadin/ui/declarative/converters/DesignResourceConverter.java
+++ b/server/src/com/vaadin/ui/declarative/converters/DesignResourceConverter.java
@@ -39,7 +39,8 @@ public class DesignResourceConverter implements Converter<String, Resource> {
public Resource convertToModel(String value,
Class<? extends Resource> targetType, Locale locale)
throws Converter.ConversionException {
- if (value.startsWith("http://")) {
+ if (value.startsWith("http://") || value.startsWith("https://")
+ || value.startsWith("ftp://") || value.startsWith("ftps://")) {
return new ExternalResource(value);
} else if (value.startsWith("theme://")) {
return new ThemeResource(value.substring(8));
diff --git a/server/tests/src/com/vaadin/tests/server/component/audio/AudioDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/audio/AudioDeclarativeTest.java
new file mode 100644
index 0000000000..4390499c4e
--- /dev/null
+++ b/server/tests/src/com/vaadin/tests/server/component/audio/AudioDeclarativeTest.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.server.component.audio;
+
+import java.io.File;
+
+import org.junit.Test;
+
+import com.vaadin.server.ExternalResource;
+import com.vaadin.server.FileResource;
+import com.vaadin.tests.design.DeclarativeTestBase;
+import com.vaadin.ui.Audio;
+
+/**
+ * Tests specs of declarative support for abstract media and its
+ * implementations.
+ *
+ * @since 7.4
+ * @author Vaadin Ltd
+ */
+public class AudioDeclarativeTest extends DeclarativeTestBase<Audio> {
+
+ @Test
+ public void testEmptyAudio() {
+ String design = "<v-audio />";
+ Audio audio = new Audio();
+ testRead(design, audio);
+ testWrite(design, audio);
+ }
+
+ @Test
+ public void testAudioMultipleSources() {
+ String design = "<v-audio muted='true' show-controls='false'>"
+ + "some <b>text</b>" //
+ + "<source href='http://foo.pl' />"
+ + "<source href='https://bar.pl' />" //
+ + "<source href='ohai' />" //
+ + "</v-audio>";
+ Audio audio = new Audio();
+ audio.setAltText("some <b>text</b>");
+ audio.setAutoplay(false);
+ audio.setMuted(true);
+ audio.setShowControls(false);
+ audio.setSources(new ExternalResource("http://foo.pl"),
+ new ExternalResource("https://bar.pl"), new FileResource(
+ new File("ohai")));
+ testRead(design, audio);
+ testWrite(design, audio);
+ }
+}
diff --git a/server/tests/src/com/vaadin/tests/server/component/audio/VideoDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/audio/VideoDeclarativeTest.java
new file mode 100644
index 0000000000..fc0b3d9512
--- /dev/null
+++ b/server/tests/src/com/vaadin/tests/server/component/audio/VideoDeclarativeTest.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.server.component.audio;
+
+import java.io.File;
+
+import org.junit.Test;
+
+import com.vaadin.server.ExternalResource;
+import com.vaadin.server.FileResource;
+import com.vaadin.tests.design.DeclarativeTestBase;
+import com.vaadin.ui.Video;
+
+public class VideoDeclarativeTest extends DeclarativeTestBase<Video> {
+
+ @Test
+ public void testEmptyVideo() {
+ String design = "<v-video />";
+ Video audio = new Video();
+ testRead(design, audio);
+ testWrite(design, audio);
+ }
+
+ @Test
+ public void testVideoMultipleSources() {
+ String design = "<v-video muted='true' show-controls='false'>"
+ + "some <b>text</b>" //
+ + "<source href='http://foo.pl' />"
+ + "<source href='https://bar.pl' />" //
+ + "<source href='ohai' />" //
+ + "<poster href='http://foo.pl/poster' />" //
+ + "</v-video>";
+ Video video = new Video();
+ video.setAltText("some <b>text</b>");
+ video.setAutoplay(false);
+ video.setMuted(true);
+ video.setShowControls(false);
+ video.setSources(new ExternalResource("http://foo.pl"),
+ new ExternalResource("https://bar.pl"), new FileResource(
+ new File("ohai")));
+ video.setPoster(new ExternalResource("http://foo.pl/poster"));
+ testRead(design, video);
+ testWrite(design, video);
+ }
+
+}