Commit cf0585dd authored by Valérie Maquil's avatar Valérie Maquil

fixed problem regarding loading of custom xml files

parent 712881a7
......@@ -23,7 +23,6 @@ package lu.list.itis.dkd.tui.utility;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
......@@ -83,6 +82,21 @@ public final class PropertiesFetcher {
}
}
/**
* Method used to load the properties file from a given external location such that it can be
* easily modified. The file needs to reside along the JAR launching this program.
*
* @param location
* The name of the properties file to load.
* @throws IOException
* Thrown when the file could not be located or loaded.
*/
private static void loadFromExternalFile(final String location) throws IOException {
try (FileInputStream inputStream = new FileInputStream(new File(location))) {
properties.load(inputStream);
}
}
/**
* Method loading a given property file. The properties must be on the class path accessible by
* the the class loader to find.
......@@ -92,24 +106,22 @@ public final class PropertiesFetcher {
* @return The property file.
*/
public static Properties fetchProperties(final String location) {
Properties userDefinedProperties = new Properties();
if (properties != null) {
return properties;
}
properties = new Properties();
try {
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
InputStream is = contextClassLoader.getResourceAsStream(location);
userDefinedProperties.load(is);
loadFromExternalFile(location);
} catch (final IOException e) {
Logger.getLogger(PropertiesFetcher.class.getSimpleName()).log(Level.SEVERE, "The porperties file could not be loaded!", e); //$NON-NLS-1$
} catch (final NullPointerException e) {
try (FileInputStream inputStream = new FileInputStream(new File(location))) {
properties = new Properties();
properties.load(inputStream);
return properties;
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
logger.log(Level.INFO, "Properties file " + location + " could not be loaded!"); //$NON-NLS-1$
try {
properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream(PropertiesFetcher.TANGIBLE_PROPERTIES));
} catch (final IOException ioe) {
logger.log(Level.SEVERE, "The porperties file could not be loaded!", ioe); //$NON-NLS-1$
}
}
return userDefinedProperties;
return properties;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment