/* Mediaplay Plugin (ver.2.1) for JSPWiki (a JSP-based WikiWiki clone.) The parameter mispelled and depreciated method issues were reported and fixed by Ron Atkins, thanks a lot. Copyright (C) 2002 Janne Jalkanen (Janne.Jalkanen@iki.fi) Copyright (C) 2006 Geoffrey Wang (geoffrey.wang@gmail.com This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package tw.idv.ecoast.plugin; import com.ecyrd.jspwiki.plugin.*; import java.util.*; import com.ecyrd.jspwiki.*; import com.ecyrd.jspwiki.attachment.AttachmentManager; import com.ecyrd.jspwiki.attachment.Attachment; import com.ecyrd.jspwiki.providers.ProviderException; /** * Provides an media player plugin for display * Most source code adapted from com.ecyrd.jspwiki.plugin.Image (Janne Jalkanen) * * * @author Geoffrey * @since 2.4.6 */ public class Mediaplayer implements WikiPlugin { public static final String PARAM_SRC = "src"; public static final String PARAM_PTYPE = "playertype"; public static final String PARAM_ALIGN = "align"; public static final String PARAM_HEIGHT = "height"; public static final String PARAM_WIDTH = "width"; public static final String PARAM_ALT = "alt"; public static final String PARAM_CAPTION = "caption"; public static final String PARAM_LINK = "link"; public static final String PARAM_STYLE = "style"; public static final String PARAM_CLASS = "class"; public static final String PARAM_BORDER = "border"; public static final String PARAM_CONTROL = "control"; public static final String PARAM_AUTOSTART = "autostart"; public static final String PARAM_AUTOREWIND = "autorewind"; public static final String PARAM_COUNT = "playcount"; public static final String PARAM_MHEIGHT = "movieheight"; public static final String PARAM_MWIDTH = "moviewidth"; /** * This method is used to clean away things like quotation marks which * a malicious user could use to stop processing and insert javascript. */ private static final String getCleanParameter( Map params, String paramId ) { return TextUtil.replaceEntities( (String) params.get( paramId ) ); } public String execute( WikiContext context, Map params ) throws PluginException { WikiEngine engine = context.getEngine(); String src = getCleanParameter( params, PARAM_SRC ); String playertype = getCleanParameter( params, PARAM_PTYPE ); String align = getCleanParameter( params, PARAM_ALIGN ); String ht = getCleanParameter( params, PARAM_HEIGHT ); String wt = getCleanParameter( params, PARAM_WIDTH ); String alt = getCleanParameter( params, PARAM_ALT ); String caption = getCleanParameter( params, PARAM_CAPTION ); String link = getCleanParameter( params, PARAM_LINK ); String style = getCleanParameter( params, PARAM_STYLE ); String cssclass= getCleanParameter( params, PARAM_CLASS ); String border = getCleanParameter( params, PARAM_BORDER ); String control = getCleanParameter( params, PARAM_CONTROL ); String autostart = getCleanParameter( params, PARAM_AUTOSTART ); String autorewind = getCleanParameter( params, PARAM_AUTOREWIND ); String playcount = getCleanParameter( params, PARAM_COUNT ); String movieheight = getCleanParameter( params, PARAM_MHEIGHT ); String moviewidth = getCleanParameter( params, PARAM_MWIDTH ); if( src == null ) { throw new PluginException("Parameter 'src' is required for Mediaplayer plugin"); } // -- * section begin * default parameter, if no value input -- if( playertype == null ) { playertype = "mediaplayer"; } if( cssclass == null ) cssclass = "imageplugin"; // -- * section end * try { AttachmentManager mgr = engine.getAttachmentManager(); Attachment att = mgr.getAttachmentInfo( context, src ); if( att != null ) { src = context.getURL( WikiContext.ATTACH, att.getName() ); //src = engine.getAttachmentURL(att.getName()); } } catch( ProviderException e ) { throw new PluginException( "Attachment info failed: "+e.getMessage() ); } StringBuffer result = new StringBuffer(); result.append( "
| " ); if( link != null ) { result.append(""); } if(playertype.compareToIgnoreCase("quicktime")==0) { // html player code part1: ActiveX Object result.append( ""); } else { // html player code part1: ActiveX Object result.append( ""); } if( link != null ) result.append(""); result.append(" |