1 package org.hibernate.util; 3 4 import java.util.HashMap ; 5 import java.util.Map ; 6 import java.util.Properties ; 7 import java.util.StringTokenizer ; 8 9 10 public final class PropertiesHelper { 11 12 public static boolean getBoolean(String property, Properties properties) { 13 return Boolean.valueOf( properties.getProperty(property) ).booleanValue(); 14 } 15 16 public static boolean getBoolean(String property, Properties properties, boolean defaultValue) { 17 String setting = properties.getProperty(property); 18 return (setting==null) ? defaultValue : Boolean.valueOf(setting).booleanValue(); 19 } 20 21 public static int getInt(String property, Properties properties, int defaultValue) { 22 String propValue = properties.getProperty(property); 23 return (propValue==null) ? defaultValue : Integer.parseInt(propValue); 24 } 25 26 public static String getString(String property, Properties properties, String defaultValue) { 27 String propValue = properties.getProperty(property); 28 return (propValue==null) ? defaultValue : propValue; 29 } 30 31 public static Integer getInteger(String property, Properties properties) { 32 String propValue = properties.getProperty(property); 33 return (propValue==null) ? null : Integer.valueOf(propValue); 34 } 35 36 public static Map toMap(String property, String delim, Properties properties) { 37 Map map = new HashMap (); 38 String propValue = properties.getProperty(property); 39 if (propValue!=null) { 40 StringTokenizer tokens = new StringTokenizer (propValue, delim); 41 while ( tokens.hasMoreTokens() ) { 42 map.put( 43 tokens.nextToken(), 44 tokens.hasMoreElements() ? tokens.nextToken() : "" 45 ); 46 } 47 } 48 return map; 49 } 50 51 public static String [] toStringArray(String property, String delim, Properties properties) { 52 return toStringArray( properties.getProperty(property), delim ); 53 } 54 55 public static String [] toStringArray(String propValue, String delim) { 56 if (propValue!=null) { 57 return StringHelper.split(delim, propValue); 58 } 59 else { 60 return ArrayHelper.EMPTY_STRING_ARRAY; 61 } 62 } 63 64 71 public static Properties maskOut(Properties props, String key) { 72 Properties clone = (Properties ) props.clone(); 73 if (clone.get(key) != null) { 74 clone.setProperty(key, "****"); 75 } 76 return clone; 77 } 78 79 80 81 private PropertiesHelper() {} 82 } 83 84 85 86 87 88 89 | Popular Tags |