01 package de.java2html.plugin.jspwiki;
02
03 import java.util.Iterator;
04 import java.util.Map;
05 import java.util.Set;
06
07 import com.ecyrd.jspwiki.plugin.PluginException;
08
09 /**
10 * @author Markus Gebhard
11 */
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 final 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 final StringBuffer html = new StringBuffer();
40 html.append(
41 "<table border=\"1\"><tr>" + "<th>Parameter</th>" + "<th>Description</th>" + "<th>Example</th>" + "</tr>");
42 final Set set = PluginParameter.getAll();
43 for (final Iterator iter = set.iterator(); iter.hasNext();) {
44 final 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 }
|