123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- /*
- @VaadinApache2LicenseForJavaFiles@
- */
-
- package com.vaadin.terminal.gwt.client.ui;
-
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.Map;
-
- import com.google.gwt.user.client.DOM;
- import com.google.gwt.user.client.Element;
- import com.google.gwt.user.client.Event;
- import com.google.gwt.user.client.ui.HTML;
- import com.vaadin.terminal.gwt.client.ApplicationConnection;
- import com.vaadin.terminal.gwt.client.BrowserInfo;
- import com.vaadin.terminal.gwt.client.ComponentConnector;
- import com.vaadin.terminal.gwt.client.ConnectorMap;
- import com.vaadin.terminal.gwt.client.UIDL;
- import com.vaadin.terminal.gwt.client.Util;
- import com.vaadin.terminal.gwt.client.VConsole;
-
- public class VEmbedded extends HTML {
- public static String CLASSNAME = "v-embedded";
-
- protected Element browserElement;
-
- protected String type;
-
- protected ApplicationConnection client;
-
- public VEmbedded() {
- setStyleName(CLASSNAME);
- }
-
- /**
- * Creates the Object and Embed tags for the Flash plugin so it works
- * cross-browser
- *
- * @param uidl
- * The UIDL
- * @return Tags concatenated into a string
- */
- protected String createFlashEmbed(UIDL uidl) {
- /*
- * To ensure cross-browser compatibility we are using the twice-cooked
- * method to embed flash i.e. we add a OBJECT tag for IE ActiveX and
- * inside it a EMBED for all other browsers.
- */
-
- StringBuilder html = new StringBuilder();
-
- // Start the object tag
- html.append("<object ");
-
- /*
- * Add classid required for ActiveX to recognize the flash. This is a
- * predefined value which ActiveX recognizes and must be the given
- * value. More info can be found on
- * http://kb2.adobe.com/cps/415/tn_4150.html. Allow user to override
- * this by setting his own classid.
- */
- if (uidl.hasAttribute("classid")) {
- html.append("classid=\""
- + Util.escapeAttribute(uidl.getStringAttribute("classid"))
- + "\" ");
- } else {
- html.append("classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" ");
- }
-
- /*
- * Add codebase required for ActiveX and must be exactly this according
- * to http://kb2.adobe.com/cps/415/tn_4150.html to work with the above
- * given classid. Again, see more info on
- * http://kb2.adobe.com/cps/415/tn_4150.html. Limiting Flash version to
- * 6.0.0.0 and above. Allow user to override this by setting his own
- * codebase
- */
- if (uidl.hasAttribute("codebase")) {
- html.append("codebase=\""
- + Util.escapeAttribute(uidl.getStringAttribute("codebase"))
- + "\" ");
- } else {
- html.append("codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" ");
- }
-
- ComponentConnector paintable = ConnectorMap.get(client).getConnector(
- this);
- String height = paintable.getDeclaredHeight();
- String width = paintable.getDeclaredWidth();
-
- // Add width and height
- html.append("width=\"" + Util.escapeAttribute(width) + "\" ");
- html.append("height=\"" + Util.escapeAttribute(height) + "\" ");
- html.append("type=\"application/x-shockwave-flash\" ");
-
- // Codetype
- if (uidl.hasAttribute("codetype")) {
- html.append("codetype=\""
- + Util.escapeAttribute(uidl.getStringAttribute("codetype"))
- + "\" ");
- }
-
- // Standby
- if (uidl.hasAttribute("standby")) {
- html.append("standby=\""
- + Util.escapeAttribute(uidl.getStringAttribute("standby"))
- + "\" ");
- }
-
- // Archive
- if (uidl.hasAttribute("archive")) {
- html.append("archive=\""
- + Util.escapeAttribute(uidl.getStringAttribute("archive"))
- + "\" ");
- }
-
- // End object tag
- html.append(">");
-
- // Ensure we have an movie parameter
- Map<String, String> parameters = getParameters(uidl);
- if (parameters.get("movie") == null) {
- parameters.put("movie", getSrc(uidl, client));
- }
-
- // Add parameters to OBJECT
- for (String name : parameters.keySet()) {
- html.append("<param ");
- html.append("name=\"" + Util.escapeAttribute(name) + "\" ");
- html.append("value=\"" + Util.escapeAttribute(parameters.get(name))
- + "\" ");
- html.append("/>");
- }
-
- // Build inner EMBED tag
- html.append("<embed ");
- html.append("src=\"" + Util.escapeAttribute(getSrc(uidl, client))
- + "\" ");
- html.append("width=\"" + Util.escapeAttribute(width) + "\" ");
- html.append("height=\"" + Util.escapeAttribute(height) + "\" ");
- html.append("type=\"application/x-shockwave-flash\" ");
-
- // Add the parameters to the Embed
- for (String name : parameters.keySet()) {
- html.append(Util.escapeAttribute(name));
- html.append("=");
- html.append("\"" + Util.escapeAttribute(parameters.get(name))
- + "\"");
- }
-
- // End embed tag
- html.append("></embed>");
-
- // End object tag
- html.append("</object>");
-
- return html.toString();
- }
-
- /**
- * Returns a map (name -> value) of all parameters in the UIDL.
- *
- * @param uidl
- * @return
- */
- protected static Map<String, String> getParameters(UIDL uidl) {
- Map<String, String> parameters = new HashMap<String, String>();
-
- Iterator<Object> childIterator = uidl.getChildIterator();
- while (childIterator.hasNext()) {
-
- Object child = childIterator.next();
- if (child instanceof UIDL) {
-
- UIDL childUIDL = (UIDL) child;
- if (childUIDL.getTag().equals("embeddedparam")) {
- String name = childUIDL.getStringAttribute("name");
- String value = childUIDL.getStringAttribute("value");
- parameters.put(name, value);
- }
- }
-
- }
-
- return parameters;
- }
-
- /**
- * Helper to return translated src-attribute from embedded's UIDL
- *
- * @param uidl
- * @param client
- * @return
- */
- protected String getSrc(UIDL uidl, ApplicationConnection client) {
- String url = client.translateVaadinUri(uidl.getStringAttribute("src"));
- if (url == null) {
- return "";
- }
- return url;
- }
-
- @Override
- protected void onDetach() {
- if (BrowserInfo.get().isIE()) {
- // Force browser to fire unload event when component is detached
- // from the view (IE doesn't do this automatically)
- if (browserElement != null) {
- DOM.setElementAttribute(browserElement, "src",
- "javascript:false");
- }
- }
- super.onDetach();
- }
-
- @Override
- public void onBrowserEvent(Event event) {
- super.onBrowserEvent(event);
- if (DOM.eventGetType(event) == Event.ONLOAD) {
- VConsole.log("Embeddable onload");
- Util.notifyParentOfSizeChange(this, true);
- }
-
- client.handleTooltipEvent(event, this);
- }
-
- }
|