1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.archive.util;
24
25 /***
26 * @author stack
27 * @version $Date: 2005-08-15 23:35:10 +0000 (Mon, 15 Aug 2005) $ $Revision: 3760 $
28 */
29 public class PropertyUtils {
30 /****
31 * @param key Property key.
32 * @return Named property or null if the property is null or empty.
33 */
34 public static String getPropertyOrNull(final String key) {
35 String value = System.getProperty(key);
36 return (value == null || value.length() <= 0)? null: value;
37 }
38
39 /****
40 * @param key Property key.
41 * @return Boolean value or false if null or unreadable.
42 */
43 public static boolean getBooleanProperty(final String key) {
44 return (getPropertyOrNull(key) == null)?
45 false: Boolean.valueOf(getPropertyOrNull(key)).booleanValue();
46 }
47
48 /***
49 * @param key Key to use looking up system property.
50 * @param fallback If no value found for passed <code>key</code>, return
51 * <code>fallback</code>.
52 * @return Value of property or <code>fallback</code>.
53 */
54 public static int getIntProperty(final String key, final int fallback) {
55 return getPropertyOrNull(key) == null?
56 fallback: Integer.parseInt(getPropertyOrNull(key));
57 }
58 }