01: package de.java2html.plugin;
02:
03: import java.util.Map;
04:
05: import com.ecyrd.jspwiki.plugin.PluginException;
06:
07: /**
08: * @author Markus Gebhard
09: */
10: public class ParameterUtilities {
11: private ParameterUtilities() {
12: //nothing to do
13: }
14:
15: public static String getParameter(Map params, IParameter parameter) {
16: String stringValue = null;
17: Object value = params.get(parameter.getName());
18: if (value != null && value instanceof String) {
19: stringValue = (String) value;
20: }
21: return stringValue;
22: }
23:
24: public static int getInt(String intString) throws PluginException {
25: try {
26: return Integer.parseInt(intString);
27: } catch (NumberFormatException e) {
28: throw new PluginException("Illegal value for integer '"
29: + intString + "'");
30: }
31: }
32:
33: public static boolean getBoolean(String booleanString)
34: throws PluginException {
35: if ("true".equals(booleanString) || "on".equals(booleanString)) {
36: return true;
37: }
38: if ("false".equals(booleanString)
39: || "off".equals(booleanString)) {
40: return false;
41: }
42: throw new PluginException("Illegal value for boolean '"
43: + booleanString + "'");
44: }
45: }
|