| 1 |
|
package be.dvw.administration.util; |
| 2 |
|
|
| 3 |
|
import org.apache.commons.logging.Log; |
| 4 |
|
import org.apache.commons.logging.LogFactory; |
| 5 |
|
|
| 6 |
|
import java.util.Properties; |
| 7 |
|
import java.io.*; |
| 8 |
|
import java.net.URL; |
| 9 |
|
|
| 10 |
|
import be.dvw.administration.mvc.taglibs.LeftMenuTag; |
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
0 |
public class PropertyManager { |
| 20 |
|
|
| 21 |
|
private static Properties PROPERTIES; |
| 22 |
6 |
private static String PROPERTIES_FILE_PATH = "application.properties"; |
| 23 |
12 |
private static Log LOG = LogFactory.getLog(PropertyManager.class); |
| 24 |
|
|
| 25 |
|
private static void loadProperties() throws IOException { |
| 26 |
|
|
| 27 |
6 |
LOG.debug("Loading application properties"); |
| 28 |
|
|
| 29 |
6 |
InputStream is = FileUtils.getFileInputStream(PROPERTIES_FILE_PATH); |
| 30 |
6 |
PROPERTIES = new Properties(); |
| 31 |
6 |
PROPERTIES.load( is ); |
| 32 |
6 |
is.close(); |
| 33 |
|
|
| 34 |
6 |
LOG.debug("Properties loaded"); |
| 35 |
|
|
| 36 |
6 |
} |
| 37 |
|
|
| 38 |
|
public static String getProperty(String property) throws IOException |
| 39 |
|
{ |
| 40 |
48 |
LOG.debug("Get Property " + property); |
| 41 |
48 |
if ( PROPERTIES == null || PROPERTIES.isEmpty() || PROPERTIES.size() == 0) |
| 42 |
|
try { |
| 43 |
6 |
loadProperties(); |
| 44 |
0 |
} catch (IOException e) { |
| 45 |
0 |
LOG.fatal("Unable to read property file", e); |
| 46 |
6 |
} |
| 47 |
48 |
String propertyValue = PROPERTIES.getProperty(property); |
| 48 |
48 |
LOG.debug("Returning property " + propertyValue); |
| 49 |
48 |
return propertyValue; |
| 50 |
|
} |
| 51 |
|
|
| 52 |
|
|
| 53 |
|
|
| 54 |
|
} |