From: Artur Signell Date: Mon, 14 Dec 2009 15:49:09 +0000 (+0000) Subject: Fix for #3367 - It should be possible to specify parameters for embedded flash X-Git-Tag: 6.7.0.beta1~2156 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=853f99b3307424f21607366017588fc008192362;p=vaadin-framework.git Fix for #3367 - It should be possible to specify parameters for embedded flash svn changeset:10291/svn branch:6.2 --- diff --git a/src/com/vaadin/terminal/gwt/client/ui/VEmbedded.java b/src/com/vaadin/terminal/gwt/client/ui/VEmbedded.java index 871e2ae35f..7d69e5682a 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VEmbedded.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VEmbedded.java @@ -4,7 +4,9 @@ package com.vaadin.terminal.gwt.client.ui; +import java.util.HashMap; import java.util.Iterator; +import java.util.Map; import com.google.gwt.dom.client.Document; import com.google.gwt.dom.client.Node; @@ -66,7 +68,7 @@ public class VEmbedded extends HTML implements Paintable { if (type.equals("image")) { Element el = null; boolean created = false; - NodeList nodes = getElement().getChildNodes(); + NodeList nodes = getElement().getChildNodes(); if (nodes != null && nodes.getLength() == 1) { Node n = nodes.getItem(0); if (n.getNodeType() == Node.ELEMENT_NODE) { @@ -130,17 +132,32 @@ public class VEmbedded extends HTML implements Paintable { } else if (uidl.hasAttribute("mimetype")) { final String mime = uidl.getStringAttribute("mimetype"); if (mime.equals("application/x-shockwave-flash")) { - setHTML(""); + String html = ""; + + Map parameters = getParameters(uidl); + if (parameters.get("movie") == null) { + parameters.put("movie", getSrc(uidl, client)); + } + + for (String name : parameters.keySet()) { + html += ""; + } + + html += ""; + + html += ""; + setHTML(html); } else if (mime.equals("image/svg+xml")) { String data; - if (getParameter("data", uidl) == null) { + Map parameters = getParameters(uidl); + if (parameters.get("data") == null) { data = getSrc(uidl, client); } else { - data = "data:image/svg+xml," + getParameter("data", uidl); + data = "data:image/svg+xml," + parameters.get("data"); } setHTML(""); ObjectElement obj = Document.get().createObjectElement(); @@ -169,21 +186,48 @@ public class VEmbedded extends HTML implements Paintable { } - private static String getParameter(String paramName, UIDL uidl) { - Iterator childIterator = uidl.getChildIterator(); + /** + * Escapes the string so it is safe to write inside an HTML attribute. + * + * @param attribute + * The string to escape + * @return An escaped version of attribute. + */ + private String escapeAttribute(String attribute) { + attribute = attribute.replace("\"", """); + attribute = attribute.replace("'", "'"); + attribute = attribute.replace(">", ">"); + attribute = attribute.replace("<", "<"); + attribute = attribute.replace("&", "&"); + return attribute; + } + + /** + * Returns a map (name -> value) of all parameters in the UIDL. + * + * @param uidl + * @return + */ + private static Map getParameters(UIDL uidl) { + Map parameters = new HashMap(); + + Iterator childIterator = uidl.getChildIterator(); while (childIterator.hasNext()) { + Object child = childIterator.next(); if (child instanceof UIDL) { + UIDL childUIDL = (UIDL) child; - if (childUIDL.getTag().equals("embeddedparam") - && childUIDL.getStringAttribute("name").equals( - paramName)) { - return childUIDL.getStringAttribute("value"); + if (childUIDL.getTag().equals("embeddedparam")) { + String name = childUIDL.getStringAttribute("name"); + String value = childUIDL.getStringAttribute("value"); + parameters.put(name, value); } - } + } - return null; + + return parameters; } /**