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)
15: throws PluginException {
16: checkParameterKeysSupported(params.keySet().toArray());
17: }
18:
19: private void checkParameterKeysSupported(Object[] parameterKeys)
20: throws PluginException {
21: for (int i = 0; i < parameterKeys.length; i++) {
22: checkParameterKeySupported(parameterKeys[i]);
23: }
24: }
25:
26: private void checkParameterKeySupported(Object parameterKey)
27: throws PluginException {
28: if (!(parameterKey instanceof String)) {
29: return;
30: }
31: String parameterName = (String) parameterKey;
32: if (PluginParameter.isInternal(parameterName)) {
33: return;
34: }
35: if (!PluginParameter.getAllNames().contains(parameterName)) {
36: throw new PluginException("Unsupported parameter '"
37: + parameterName + "'."
38: + createValidParameterHtmlTable());
39: }
40: }
41:
42: public static String createValidParameterHtmlTable() {
43: StringBuffer html = new StringBuffer();
44: html
45: .append("<table border=\"1\"><tr>"
46: + "<th>Parameter</th>" + "<th>Description</th>"
47: + "<th>Example</th>" + "</tr>");
48: Set set = PluginParameter.getAll();
49: for (Iterator iter = set.iterator(); iter.hasNext();) {
50: PluginParameter parameter = (PluginParameter) iter.next();
51: if (!parameter.isInternal()) {
52: appendParameterTableRow(html, parameter);
53: }
54: }
55: html.append("</table>");
56: return html.toString();
57: }
58:
59: private static void appendParameterTableRow(StringBuffer html,
60: PluginParameter parameter) {
61: html.append("<tr>" + "<td><code>" + parameter.getName()
62: + "</code></td>" + "<td>" + parameter.getDescription()
63: + "</td>" + "<td><code>" + parameter.getName() + "="
64: + "'" + parameter.getExampleValue() + "'"
65: + "</code></td>" + "</tr>");
66: }
67: }
|