package com.ecyrd.jspwiki.plugin.i3g; import java.util.Collection; import java.util.Iterator; import java.util.Map; import com.ecyrd.jspwiki.WikiContext; import com.ecyrd.jspwiki.WikiEngine; import com.ecyrd.jspwiki.attachment.Attachment; import com.ecyrd.jspwiki.attachment.AttachmentManager; import com.ecyrd.jspwiki.plugin.PluginException; import com.ecyrd.jspwiki.providers.ProviderException; /** * Displays a list of all attachments of a page * usefull if you removed the attachments display * in your template. So you still are able to * display attachments on some pages, where it * seems to be important. * * @param title - set the title of the attachments * @param info - sets the alt attribute of the paperclip icon * * @author Christoph Sauer */ public class AttachmentList extends I3gWikiPlugin { public String execute(WikiContext context, Map params) throws PluginException { String title = getParameter(params, "title", "Attachments", false); String info = getParameter(params, "info", "Info on", false); String result = ""; try { WikiEngine engine = context.getEngine(); AttachmentManager mgr = engine.getAttachmentManager(); Collection atts = mgr.listAttachments( context.getPage() ); result = "

"+ title +":" + "

" + ""; if( atts == null ) { return ""; } Iterator iter = atts.iterator(); while(iter.hasNext()) { Attachment att = (Attachment) iter.next(); String src = context.getURL(WikiContext.ATTACH, att.getName()); String inf = context.getURL(WikiContext.INFO, att.getName()); String base = context.getEngine().getBaseURL(); String link1 = "" + att.getFileName() + ""; String link2 = "" + "\"""; result += "" + "" + "" + "" + "\n"; } result += "
No attachments to display.
" + link1 + "" + link2 + "" + att.getSize()+ " bytes
" + "

"; //Attachment att = mgr.getAttachmentInfo(context, src); } catch (ProviderException e) { throw new PluginException("Attachment info failed: " + e.getMessage()); } return result; } }