diff options
author | Miki <miki@vaadin.com> | 2015-02-06 14:49:03 +0200 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2015-03-26 13:53:58 +0000 |
commit | b96861c1809d12f2d1339fd64f825a3c513977d2 (patch) | |
tree | 3adc4a233dee7b53347148640500acada4ea268d /server/src | |
parent | ebcf64b94911597a123a599cd758e36b4abfe8bf (diff) | |
download | vaadin-framework-b96861c1809d12f2d1339fd64f825a3c513977d2.tar.gz vaadin-framework-b96861c1809d12f2d1339fd64f825a3c513977d2.zip |
Fix declarative support for AbstractMedia (#16330 #16331 #16332)
Also fixes HTTPS resource handling (#17267)
Contains tests for both Audio and Video.
Change-Id: Id4a7325f0d29f6857ff2236757b28b9eb911e39a
Diffstat (limited to 'server/src')
5 files changed, 93 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 <video> 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)); |