-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathPropertyHelper.java
More file actions
97 lines (85 loc) · 2.66 KB
/
PropertyHelper.java
File metadata and controls
97 lines (85 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package com.edurekademo.utilities;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Properties;
@SuppressWarnings("unchecked")
/**
* Helper Class to load Properties from a property file to be passed to caller for execution.
* Multiple properties can be loaded.
* Note that if same property is specified multiple times in a single file, there is no guaranteed "Winner"
* Also note in the case of loading multiple files and duplicate definition of properties across files,
* the last loaded property file "wins".
* The getProperty()/get() methods also returns "" silently if no such query exists.
* @author Seshagiri Sriram
* @version 1.0
* @see PropertyLoader
*/
public final class PropertyHelper {
/**
* hMapProperties contains the hashmap of key/value pairs associated with each property
*/
protected final static HashMap<String, Object> HMAPPROPERTIES = new HashMap<String,Object>();
/**
* @param propertyFile
* @return
*/
public static HashMap<String, Object> loadProperties(String propertyFile) {
Properties properties = PropertyLoader.loadProperties(propertyFile);
Enumeration <String> keys = (Enumeration<String>) properties.propertyNames();
while (keys.hasMoreElements()) {
String tmpKey = (String) keys.nextElement();
HMAPPROPERTIES.put(tmpKey,properties.getProperty(tmpKey));
}
return HMAPPROPERTIES;
}
/**
* @param propertyName
* @return
*/
public static String getProperty(String propertyName){
String propertyValue = "";
try {
propertyValue = (String) HMAPPROPERTIES.get(propertyName);
}
catch (Exception e){
LoggerStackTraceUtil.printErrorMessage(e);
propertyValue = "";
}
finally {
}
return propertyValue;
}
/**
* Function used to get the default value if the property is null
* @param propertyName - Name of the property
* @param strDefault - Default value that needs to be returned if the value is null
* @return Property value/Default Value as String
*/
public static String getProperty(String propertyName,String strDefault){
String propertyValue = "";
try {
propertyValue = (String) HMAPPROPERTIES.get(propertyName);
// Check the property value is null/not
if(propertyValue == null){
// Assign the default value to the propertyValue
propertyValue=strDefault;
}
}
catch (Exception e){
LoggerStackTraceUtil.printErrorMessage(e);
propertyValue = "";
}
finally {
}
return propertyValue;
}
/**
* A convenience method (aliasing getProperty)
* @param propertyName property to be retrieved.
* @return
* @see getProperty
*/
public static String get(String propertyName){
return getProperty(propertyName);
}
}