Open Source Repository

Home /web/java2html | Repository Home



de/java2html/plugin/jspwiki/PluginParameterChecker.java
package de.java2html.plugin.jspwiki;

import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import com.ecyrd.jspwiki.plugin.PluginException;

/**
 @author Markus Gebhard
 */
public class PluginParameterChecker {

  public void checkParametersSupported(Map paramsthrows PluginException {
    checkParameterKeysSupported(params.keySet().toArray());
  }

  private void checkParameterKeysSupported(Object[] parameterKeysthrows PluginException {
    for (int i = 0; i < parameterKeys.length; i++) {
      checkParameterKeySupported(parameterKeys[i]);
    }
  }

  private void checkParameterKeySupported(Object parameterKeythrows PluginException {
    if (!(parameterKey instanceof String)) {
      return;
    }
    String parameterName = (StringparameterKey;
    if (PluginParameter.isInternal(parameterName)) {
      return;
    }
    if (!PluginParameter.getAllNames().contains(parameterName)) {
      throw new PluginException(
        "Unsupported parameter '" + parameterName + "'." + createValidParameterHtmlTable());
    }
  }

  public static String createValidParameterHtmlTable() {
    StringBuffer html = new StringBuffer();
    html.append(
      "<table border=\"1\"><tr>" "<th>Parameter</th>" "<th>Description</th>" "<th>Example</th>" "</tr>");
    Set set = PluginParameter.getAll();
    for (Iterator iter = set.iterator(); iter.hasNext();) {
      PluginParameter parameter = (PluginParameteriter.next();
      if (!parameter.isInternal()) {
        appendParameterTableRow(html, parameter);
      }
    }
    html.append("</table>");
    return html.toString();
  }

  private static void appendParameterTableRow(StringBuffer html, PluginParameter parameter) {
    html.append(
      "<tr>"
        "<td><code>"
        + parameter.getName()
        "</code></td>"
        "<td>"
        + parameter.getDescription()
        "</td>"
        "<td><code>"
        + parameter.getName()
        "="
        "'"
        + parameter.getExampleValue()
        "'"
        "</code></td>"
        "</tr>");
  }
}