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 final 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 }
28 catch (final NumberFormatException e) {
29 throw new PluginException("Illegal value for integer '" + intString + "'");
30 }
31 }
32
33 public static boolean getBoolean(String booleanString) throws PluginException {
34 if ("true".equals(booleanString) || "on".equals(booleanString)) {
35 return true;
36 }
37 if ("false".equals(booleanString) || "off".equals(booleanString)) {
38 return false;
39 }
40 throw new PluginException("Illegal value for boolean '" + booleanString + "'");
41 }
42 }
|