You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Piller Sébastien <pi...@hmcrecord.ch> on 2008/09/11 13:59:59 UTC
Wicket 1.3.4 + SWFObject
Hello,
this time I haven't any dummy question :)
I've developped a wicket panel to display a *.swf file with a
autoinstall feature of the flash player, using SWFObject, and I'm ready
to share it with the community.
Are you interested?
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Wicket 1.3.4 + SWFObject
Posted by Piller Sébastien <pi...@hmcrecord.ch>.
Sure!
AutoInstallShockwaveComponent.java
import java.util.Hashtable;
import java.util.Map;
import java.util.Set;
import org.apache.wicket.ResourceReference;
import org.apache.wicket.behavior.HeaderContributor;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.protocol.http.RequestUtils;
/**
* Classe permettant d'afficher un fichier *.swf tout en ayant une
fonction
* d'auto-installation du FlashPlayer si la version courante n'est pas
* suffisante. Ne fonctionne pas du tout si javascript est désactivé
(affiche le
* contenu alternatif).
*
* @see <a href="http://code.google.com/p/swfobject/">SWFObject</a>
* @version 11/09/2008
*/
public final class AutoInstallShockWaveComponent extends Panel {
/** Modèle contenu alternatif par défaut (si non précisé). */
private static final IModel DEFAULT_ALTERNATIVE_CONTENT = new Model(
"<h1>Unable to display flash content!</h1><p>You either
have JavaScript disabled or your browser doesn't support
SWFObject.</p><p><a
href=\"http://www.adobe.com/go/getflashplayer\"><img
src=\"http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif\"
alt=\"Get Adobe Flash player\" /></a></p>");
private final Map<String, String> flashvars = new
Hashtable<String, String>();
private final Map<String, String> params = new Hashtable<String,
String>();
private final Map<String, String> attributes = new
Hashtable<String, String>();
/**
* Constructeur minimal. Spécifie l'url du fichier swf + ses
dimensions.
*
* @param id
* {@link Panel#getId()}
* @param swfFullURL
* Adresse URL relative ou absolue du fichier *.swf à
utiliser.
* @param width
* Largeur du fichier swf.
* @param height
* Hauteur du fichier swf.
*/
public AutoInstallShockWaveComponent(String id, final String
swfFullURL, final String width, final String height) {
this(id, swfFullURL, width, height, "9", null);
}
/**
* Constructeur complet. Spécifie la version minimale de flash,
ainsi que le
* contenu alternatif à afficher.
*
* @param id
* {@link Panel#getId()}
* @param swfFullURL
* Adresse URL relative ou absolue du fichier *.swf à
utiliser.
* @param width
* Largeur du fichier swf.
* @param height
* Hauteur du fichier swf.
* @param flashMinimumVersion
* Version minimale de Flash (p.ex, "9.0.0")
* @param alternative
* Contenu alternatif, typiquement une {@link String}
ou un
* {@link IModel}. Passez <code>null</code> pour
utiliser le
* contenu alternatif par défaut (infos + lien vers flash
* player).
*/
public AutoInstallShockWaveComponent(String id, final String
swfFullURL, final String width, final String height, final String
flashMinimumVersion,
Object alternative) {
super(id);
add(HeaderContributor.forJavaScript(new
ResourceReference(AutoInstallShockWaveComponent.class,
"swfobject.js")));
final WebMarkupContainer swf = new WebMarkupContainer("swf");
swf.setOutputMarkupId(true);
add(swf);
add(new Label("js", new Model() {
public Object getObject() {
StringBuilder b = new StringBuilder(512);
b.append("<script type=\"text/javascript\">");
b.append(NL);
b.append("<!--/*--><![CDATA[/*><!--*/").append(NL);
b.append("swfobject.embedSWF(\"").append(swfFullURL).append("\",
\"").append(swf.getMarkupId()).append("\", \"");
b.append(width).append("\",
\"").append(height).append("\",
\"").append(flashMinimumVersion).append("\", \"");
b.append(RequestUtils.toAbsolutePath(urlFor(new
ResourceReference(AutoInstallShockWaveComponent.class,
"expressInstall.swf")).toString()))
.append("\"");
if (!flashvars.isEmpty()) {
b.append(", ").append(formatMapForJS(flashvars));
}
if (!params.isEmpty()) {
b.append(", ").append(formatMapForJS(params));
}
if (!attributes.isEmpty()) {
b.append(", ").append(formatMapForJS(attributes));
}
b.append(");");
b.append(NL);
b.append("/*-->]]>*/").append(NL);
b.append("</script>");
return b.toString();
}
}).setRenderBodyOnly(true).setEscapeModelStrings(false));
/* Ajout contenu alternatif */
Label alternativecontent;
if (alternative == null) {
alternativecontent = new Label("alternativecontent",
DEFAULT_ALTERNATIVE_CONTENT);
} else if (alternative instanceof String) {
alternativecontent = new Label("alternativecontent",
(String) alternative);
} else if (alternative instanceof IModel) {
alternativecontent = new Label("alternativecontent",
(IModel) alternative);
} else {
alternativecontent = new Label("alternativecontent", ""
+ alternative);
}
alternativecontent.setRenderBodyOnly(true);
alternativecontent.setEscapeModelStrings(false);
swf.add(alternativecontent);
}
private static final String NL = "\r\n";
private static String formatMapForJS(Map<String, String> map) {
if (map.isEmpty()) {
return "{}";
}
StringBuilder b = new StringBuilder(64);
b.append("{ ").append(NL);
Set<String> keySet = map.keySet();
int i = 0;
for (String key : keySet) {
b.append(key).append(" :
\"").append(map.get(key)).append("\" ");
if (++i >= keySet.size()) {
b.append(NL);
} else {
b.append(", ");
}
}
b.append(" }");
return b.toString();
}
public void setFlashvar(String name, String value) {
flashvars.put(name, value);
}
public void unsetFlashvar(String name) {
flashvars.remove(name);
}
public void setParam(String name, String value) {
params.put(name, value);
}
public void unsetParam(String name) {
params.remove(name);
}
public void setAttribute(String name, String value) {
attributes.put(name, value);
}
public void unsetAttribute(String name) {
attributes.remove(name);
}
}
AutoInstallShockwaveComponent.html
<html xmlns:wicket="http://wicket.apache.org">
<head>
</head>
<body>
<wicket:panel>
<span wicket:id="js">[here comes some js code]</span>
<div wicket:id="swf">
<div wicket:id="alternativecontent">
[here comes the alternative content]
</div>
</div>
</wicket:panel>
</body>
</html>
You have to download SWFObject from http://code.google.com/p/swfobject/
too, and add the files swfobject.js, expressInstall.swf next to the
AutoInstallShockwaveComponent.java to have it work
any feedback will be appreciated. I didn't try to add several
autoinstall to a page, so if you try, let me know if it works
;)
Kaspar Fischer a écrit :
>
> Hi Sébastien!
>
> I am interested! Could you post the code/markup?
>
> Thanks a lot for sharing,
> Kaspar
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Wicket 1.3.4 + SWFObject
Posted by Kaspar Fischer <fi...@inf.ethz.ch>.
On 11.09.2008, at 13:59, Piller Sébastien wrote:
> Hello,
>
> this time I haven't any dummy question :)
>
> I've developped a wicket panel to display a *.swf file with a
> autoinstall feature of the flash player, using SWFObject, and I'm
> ready to share it with the community.
>
> Are you interested?
Hi Sébastien!
I am interested! Could you post the code/markup?
Thanks a lot for sharing,
Kaspar
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org