Created
April 10, 2013 18:02
-
-
Save basgys/5356952 to your computer and use it in GitHub Desktop.
BundleReader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ch.hegarc.ig.clientscomptes.configuration; | |
import java.io.File; | |
import java.io.FileReader; | |
import java.io.IOException; | |
import java.util.Properties; | |
import java.util.logging.Level; | |
import java.util.logging.Logger; | |
import org.apache.commons.lang3.StringUtils; | |
/** | |
* | |
* @author basgys | |
*/ | |
public class BundleReader { | |
Properties properties; | |
public BundleReader(Properties properties) { | |
this.properties = properties; | |
} | |
public String get(String key) { | |
return properties.getProperty(key); | |
} | |
public static BundleReader createReaderForBundle(String bundleName) { | |
return new BundleReader(read(find(bundleName))); | |
} | |
private static Properties read(String filePath) { | |
FileReader fileReader = null; | |
try { | |
fileReader = new FileReader(filePath); | |
Properties props = new Properties(); | |
props.load(fileReader); | |
return props; | |
} catch (IOException ex) { | |
Logger.getLogger(BundleReader.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
return null; | |
} | |
private static String find(String fileName) { | |
StringBuilder sb = new StringBuilder(); | |
String packageName = BundleReader.class.getPackage().getName(); | |
String[] test = BundleReader.class.getPackage().getName().split("."); | |
String appPath = StringUtils.join(test, "/"); | |
sb.append(appPath).append("/").append(fileName); | |
File file = new File(sb.toString()); | |
return file.getAbsolutePath(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment