1 25 26 package examples; 27 28 import org.snipsnap.render.context.SnipRenderContext; 29 import org.snipsnap.render.macro.SnipMacro; 30 import org.snipsnap.render.macro.parameter.SnipMacroParameter; 31 import org.snipsnap.snip.Snip; 32 import org.snipsnap.snip.attachment.Attachment; 33 import org.snipsnap.snip.attachment.Attachments; 34 35 import java.io.IOException ; 36 import java.io.Writer ; 37 import java.util.Iterator ; 38 39 45 46 public class ShowAttachmentsMacro extends SnipMacro { 47 48 public void execute(Writer writer, SnipMacroParameter params) 49 throws IllegalArgumentException , IOException { 50 51 SnipRenderContext context = params.getSnipRenderContext(); 52 Snip snip = (Snip) context.getAttribute(SnipRenderContext.SNIP); 53 54 Attachments attachments = snip.getAttachments(); 56 Iterator iterator = attachments.iterator(); 57 while (iterator.hasNext()) { 58 Attachment attachment = (Attachment) iterator.next(); 59 writer.write(attachment.getName()); 60 if (iterator.hasNext()) { 61 writer.write(", "); 62 } 63 } 64 } 66 67 public String getName() { 68 return "show-attachments"; 69 } 70 } 71 72 73 | Popular Tags |