1 26 package org.snipsnap.net; 27 28 import org.radeox.util.Service; 29 import org.radeox.util.logging.Logger; 30 import org.snipsnap.container.Components; 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 import org.snipsnap.snip.label.TypeLabel; 36 37 import java.util.HashMap ; 38 import java.util.Iterator ; 39 import java.util.Map ; 40 41 public class ServletPluginLoader { 42 private static Map pluginServlets; 44 45 50 public static Map getPlugins() { 51 initServletPlugins(); 52 53 Map allPlugins = getSnipPlugins(); 54 allPlugins.putAll(pluginServlets); 55 return allPlugins; 56 } 57 58 63 private static Map getSnipPlugins() { 64 Map snipPlugins = new HashMap (); 65 SnipSpace snipspace = (SnipSpace) Components.getComponent(SnipSpace.class); 66 Iterator iterator = snipspace.getAll().iterator(); 67 while (iterator.hasNext()) { 68 Snip snip = (Snip) iterator.next(); 69 Labels labels = snip.getLabels(); 70 boolean noLabelsAll = labels.getAll().isEmpty(); 71 72 if (!noLabelsAll) { 73 Label label = labels.getLabel("Type"); 74 if (null != label && label instanceof TypeLabel) { 75 String type = ((TypeLabel) label).getTypeValue(); 77 if ("text/gsp".equalsIgnoreCase(type) || "text/groovy".equalsIgnoreCase(type)) { 78 String handler = snip.getName(); 79 snipPlugins.put(handler, type); 80 } 81 } 82 } 83 } 84 return snipPlugins; 85 } 86 87 90 private static void initServletPlugins() { 91 if (null == pluginServlets) { 92 pluginServlets = new HashMap (); 93 94 Iterator pluginServletNames = Service.providerNames(ServletPlugin.class); 96 while (pluginServletNames.hasNext()) { 97 String pluginLine = (String ) pluginServletNames.next(); 98 if (!pluginLine.startsWith("#")) { 99 String [] pluginInfo = pluginLine.split("\\p{Space}+"); 100 if (pluginInfo.length > 0) { 101 pluginServlets.put(pluginInfo[0], pluginInfo.length > 1 ? pluginInfo[1] : null); 102 Logger.log("found plugin: " + pluginInfo[0]); 103 } else { 104 Logger.warn("ignoring servlet plugin '" + pluginLine + "': missing type or servlet"); 105 } 106 } 107 } 108 } 109 } 110 } 111 | Popular Tags |