1 25 26 package org.snipsnap.render.macro; 27 28 import org.radeox.util.i18n.ResourceManager; 29 import org.snipsnap.container.Components; 30 import org.snipsnap.render.macro.parameter.SnipMacroParameter; 31 import org.snipsnap.snip.Snip; 32 import org.snipsnap.snip.SnipSpace; 33 import org.snipsnap.snip.label.Label; 34 import org.snipsnap.snip.label.Labels; 35 36 import java.io.IOException ; 37 import java.io.Writer ; 38 import java.text.MessageFormat ; 39 import java.util.ArrayList ; 40 import java.util.Collection ; 41 import java.util.Iterator ; 42 import java.util.List ; 43 44 50 51 public class LabelSearchMacro extends ListOutputMacro { 52 public String getName() { 53 return "label-search"; 54 } 55 56 public String getDescription() { 57 return ResourceManager.getString("i18n.messages", "macro.labelsearch.description"); 58 } 59 60 public String [] getParamDescription() { 61 return ResourceManager.getString("i18n.messages", "macro.labelsearch.params").split(";"); 62 } 63 64 public void execute(Writer writer, SnipMacroParameter params) 65 throws IllegalArgumentException , IOException { 66 67 String type = params.get("type"); 70 String name = params.get("name"); 71 String value = params.get("value"); 72 73 SnipSpace snipspace = (SnipSpace) Components.getComponent(SnipSpace.class); 74 List snipList = snipspace.getAll(); 75 76 List result = new ArrayList (); 77 78 Iterator iterator = snipList.iterator(); 79 while (iterator.hasNext()) { 80 Snip snip = (Snip) iterator.next(); 81 Labels labels = snip.getLabels(); 82 boolean noLabelsAll = labels.getAll().isEmpty(); 83 84 if (!noLabelsAll) { 85 Collection LabelsCat; 86 Label label = labels.getLabel(name, value); 88 if (label != null) { 89 result.add(snip); 90 } 91 } 92 } 93 94 if (params.getLength() > 1) { 101 MessageFormat mf = new MessageFormat (ResourceManager.getString("i18n.messages", "macro.labelsearch.title"), 102 ResourceManager.getLocale("i18n.messages")); 103 output(writer, params.getSnipRenderContext().getSnip(), 104 mf.format(new Object []{name, value}), result, 105 ResourceManager.getString("i18n.messages", "macro.labelsearch.notfound"), type, true); 106 } else { 107 throw new IllegalArgumentException ("Number of arguments does not match"); 108 } 109 } 110 } 111 | Popular Tags |