import java.util.*; import com.ecyrd.jspwiki.*; import com.ecyrd.jspwiki.attachment.AttachmentManager; import com.ecyrd.jspwiki.attachment.Attachment; import com.ecyrd.jspwiki.plugin.*; import com.ecyrd.jspwiki.providers.ProviderException; public class IFramePlugin implements WikiPlugin { public static final String PARAM_ATTACHMENT = "attachment"; public static final String PARAM_URL = "url"; public static final String PARAM_ALIGN = "align"; public static final String PARAM_BORDER = "border"; public static final String PARAM_WIDTH = "width"; public static final String PARAM_HEIGHT = "height"; public static final String PARAM_MARGINWIDTH = "marginwidth"; public static final String PARAM_MARGINHEIGHT = "marginheight"; public static final String PARAM_SCROLLING = "scrolling"; public String execute(WikiContext context, Map params) throws PluginException { WikiEngine engine = context.getEngine(); String attachment = getCleanParameter(params, PARAM_ATTACHMENT); String url = getCleanParameter(params, PARAM_URL); String align = getCleanParameter(params, PARAM_ALIGN, "center").toLowerCase(); String border = getCleanParameter(params, PARAM_BORDER, "0"); String width = getCleanParameter(params, PARAM_WIDTH, "100%"); String height = getCleanParameter(params, PARAM_HEIGHT, "100%"); String marginwidth = getCleanParameter(params, PARAM_MARGINWIDTH, "10"); String marginheight = getCleanParameter(params, PARAM_MARGINHEIGHT, "10"); String scrolling = getCleanParameter(params, PARAM_SCROLLING, "auto"); if (attachment == null && url == null) { throw new PluginException("Parameter 'attachment' or 'url' is required for the MediaPlugin to work"); } String src = null; if (attachment != null) { try { AttachmentManager mgr = engine.getAttachmentManager(); Attachment att = mgr.getAttachmentInfo(context, attachment); src = context.getURL(WikiContext.ATTACH, att.getName()); } catch (ProviderException ex) { throw new PluginException("Could not resolve the attachment: " + ex.getMessage()); } } else { if (url.startsWith("http")) { try { src = new java.net.URL(url).toExternalForm(); } catch (java.net.MalformedURLException ex) { throw new PluginException("Could not resolve the url: " + ex.getMessage()); } } else { src = url; } } StringBuffer result = new StringBuffer(); result.append("\n"); return result.toString(); } private static final String getCleanParameter(Map params, String paramId, String defaultValue) { String value = getCleanParameter(params, paramId); if (value == null) { value = defaultValue; } return value; } /** * 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)); } }