1 package de.java2html.plugin.jspwiki; 2 3 import java.util.Iterator ; 4 import java.util.Map ; 5 import java.util.Set ; 6 7 import com.ecyrd.jspwiki.plugin.PluginException; 8 9 12 public class PluginParameterChecker { 13 14 public void checkParametersSupported(Map params) throws PluginException { 15 checkParameterKeysSupported(params.keySet().toArray()); 16 } 17 18 private void checkParameterKeysSupported(Object [] parameterKeys) throws PluginException { 19 for (int i = 0; i < parameterKeys.length; i++) { 20 checkParameterKeySupported(parameterKeys[i]); 21 } 22 } 23 24 private void checkParameterKeySupported(Object parameterKey) throws PluginException { 25 if (!(parameterKey instanceof String )) { 26 return; 27 } 28 String parameterName = (String ) parameterKey; 29 if (PluginParameter.isInternal(parameterName)) { 30 return; 31 } 32 if (!PluginParameter.getAllNames().contains(parameterName)) { 33 throw new PluginException( 34 "Unsupported parameter '" + parameterName + "'." + createValidParameterHtmlTable()); 35 } 36 } 37 38 public static String createValidParameterHtmlTable() { 39 StringBuffer html = new StringBuffer (); 40 html.append( 41 "<table border=\"1\"><tr>" + "<th>Parameter</th>" + "<th>Description</th>" + "<th>Example</th>" + "</tr>"); 42 Set set = PluginParameter.getAll(); 43 for (Iterator iter = set.iterator(); iter.hasNext();) { 44 PluginParameter parameter = (PluginParameter) iter.next(); 45 if (!parameter.isInternal()) { 46 appendParameterTableRow(html, parameter); 47 } 48 } 49 html.append("</table>"); 50 return html.toString(); 51 } 52 53 private static void appendParameterTableRow(StringBuffer html, PluginParameter parameter) { 54 html.append( 55 "<tr>" 56 + "<td><code>" 57 + parameter.getName() 58 + "</code></td>" 59 + "<td>" 60 + parameter.getDescription() 61 + "</td>" 62 + "<td><code>" 63 + parameter.getName() 64 + "=" 65 + "'" 66 + parameter.getExampleValue() 67 + "'" 68 + "</code></td>" 69 + "</tr>"); 70 } 71 } | Popular Tags |