68 lines
1.8 KiB
Java
68 lines
1.8 KiB
Java
|
package org.gcube.portlets.user.uriresolvermanager.type;
|
||
|
|
||
|
import java.io.IOException;
|
||
|
import java.io.InputStream;
|
||
|
import java.util.HashMap;
|
||
|
import java.util.Map;
|
||
|
import java.util.Properties;
|
||
|
|
||
|
import org.apache.log4j.Logger;
|
||
|
|
||
|
public class ApplicationTypePropertyReader {
|
||
|
|
||
|
protected static final String RESOURCE_FILE_PROPERTIES = "applicationtyperesources.properties";
|
||
|
|
||
|
private Map<String, String> applicationTypes; //A map ApplicationType - Resource Name
|
||
|
|
||
|
private Logger logger = Logger.getLogger(ApplicationTypePropertyReader.class);
|
||
|
|
||
|
public ApplicationTypePropertyReader() throws PropertyFileNotFoundException {
|
||
|
|
||
|
Properties prop = new Properties();
|
||
|
|
||
|
try {
|
||
|
|
||
|
InputStream in = (InputStream) ApplicationTypePropertyReader.class.getResourceAsStream(RESOURCE_FILE_PROPERTIES);
|
||
|
|
||
|
// load a properties file
|
||
|
prop.load(in);
|
||
|
|
||
|
applicationTypes = new HashMap<String, String>(prop.keySet().size());
|
||
|
|
||
|
for (Object key : prop.keySet()) {
|
||
|
String resource = (String) prop.get(key);
|
||
|
applicationTypes.put((String)key, resource);
|
||
|
}
|
||
|
|
||
|
} catch (IOException e) {
|
||
|
logger.error("An error occurred on read property file "+e, e);
|
||
|
throw new PropertyFileNotFoundException("An error occurred on read property file "+e);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public String toString() {
|
||
|
StringBuilder builder = new StringBuilder();
|
||
|
builder.append("ApplicationTypePropertyReader [applicationTypes=");
|
||
|
builder.append(applicationTypes);
|
||
|
builder.append("]");
|
||
|
return builder.toString();
|
||
|
}
|
||
|
|
||
|
public Map<String, String> getApplicationTypes() {
|
||
|
return applicationTypes;
|
||
|
}
|
||
|
|
||
|
public static void main(String[] args) {
|
||
|
try {
|
||
|
ApplicationTypePropertyReader reader = new ApplicationTypePropertyReader();
|
||
|
System.out.println(reader);
|
||
|
} catch (PropertyFileNotFoundException e) {
|
||
|
// TODO Auto-generated catch block
|
||
|
e.printStackTrace();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|