Extend CMS view.
[lgpl/argeo-commons.git] / org.argeo.util / src / org / argeo / util / LangUtils.java
index 779adb01eb4a204dd2dc07d27bee06be386d6083..2f99bb3e0d735bb75a99704ce9ffbee2847b560c 100644 (file)
@@ -71,6 +71,29 @@ public class LangUtils {
                return res;
        }
 
+       /**
+        * Get a string property from this map, expecting to find it, or
+        * <code>null</code> if not found.
+        */
+       public static String get(Map<String, ?> map, String key) {
+               Object res = map.get(key);
+               if (res == null)
+                       return null;
+               return res.toString();
+       }
+
+       /**
+        * Get a string property from this map, expecting to find it.
+        * 
+        * @throws IllegalArgumentException if the key was not found
+        */
+       public static String getNotNull(Map<String, ?> map, String key) {
+               Object res = map.get(key);
+               if (res == null)
+                       throw new IllegalArgumentException("Map " + map + " should contain key " + key);
+               return res.toString();
+       }
+
        /**
         * Wraps the keys of the provided {@link Dictionary} as an {@link Iterable}.
         */