View Javadoc
1   /*******************************************************************************
2    *   Gisgraphy Project 
3    * 
4    *   This library is free software; you can redistribute it and/or
5    *   modify it under the terms of the GNU Lesser General Public
6    *   License as published by the Free Software Foundation; either
7    *   version 2.1 of the License, or (at your option) any later version.
8    * 
9    *   This library is distributed in the hope that it will be useful,
10   *   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   *   Lesser General Public License for more details.
13   * 
14   *   You should have received a copy of the GNU Lesser General Public
15   *   License along with this library; if not, write to the Free Software
16   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
17   * 
18   *  Copyright 2008  Gisgraphy project 
19   *  David Masclet <davidmasclet@gisgraphy.com>
20   *  
21   *  
22   *******************************************************************************/
23  package com.gisgraphy.helper;
24  
25  import java.util.Enumeration;
26  import java.util.HashMap;
27  import java.util.Map;
28  import java.util.ResourceBundle;
29  
30  import org.slf4j.Logger;
31  import org.slf4j.LoggerFactory;
32  
33  /**
34   * Some useful functions for properties files
35   * 
36   * @author <a href="mailto:david.masclet@gisgraphy.com">David Masclet</a>
37   */
38  public class PropertiesHelper {
39  
40      protected static final Logger logger = LoggerFactory
41  	    .getLogger(PropertiesHelper.class);
42  
43  	/**
44  	 * Method to convert a ResourceBundle to a Map object.
45  	 * 
46  	 * @param rb
47  	 *                a given resource bundle
48  	 * @return Map a populated map
49  	 */
50  	public static Map<String, String> convertBundleToMap(ResourceBundle rb) {
51  	Map<String, String> map = new HashMap<String, String>();
52  	
53  	Enumeration<String> keys = rb.getKeys();
54  	while (keys.hasMoreElements()) {
55  	    String key = keys.nextElement();
56  	    map.put(key, rb.getString(key));
57  	}
58  	
59  	return map;
60  	}
61  
62     
63  
64  }