18 package org.turro.file;
21 import java.io.FileNotFoundException;
22 import java.io.FileReader;
23 import java.io.IOException;
24 import java.util.Properties;
25 import java.util.logging.Level;
26 import java.util.logging.Logger;
27 import org.turro.elephant.context.ElephantContext;
38 private Properties props;
44 public Properties
getProperties() throws FileNotFoundException, IOException {
46 props =
new Properties();
47 if(file.isDirectory()) {
48 loadProperties(props, file.getAbsolutePath());
50 String parentPath = getParentPath(file.getAbsolutePath());
51 if(parentPath !=
null) {
52 loadProperties(props, parentPath);
59 private void loadProperties(Properties props, String path) {
60 String folders[] = path.split(
"\\/"),
63 for(String folder : folders) {
64 current = current +
"/" + folder;
69 private void loadFrom(Properties props, File file) {
70 if(!file.exists() || !file.isFile()) {
75 fr =
new FileReader(file);
78 }
catch (IOException ex) {
79 Logger.getLogger(
PropertiesFile.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(
null), ex);
83 }
catch (IOException ex) {
84 Logger.getLogger(
PropertiesFile.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(
null), ex);
89 private String getParentPath(String path) {
90 int p = path.lastIndexOf(
"/");
92 return path.substring(0, p);
static final String FILES_PROPERTIES_FILE
PropertiesFile(File file)
Properties getProperties()