1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-11-14 05:15:03 -05:00
filebot/source/net/sourceforge/tuned/prefs/FilePreferencesFactory.java
2011-12-28 13:51:36 +00:00

74 lines
2.2 KiB
Java

// https://github.com/sonatype/nexus/blob/2f0e154ec565969b4fd8698883ab76a461210f4f/nexus/nexus-test-harness/nexus-it-helper-plugin/src/main/java/org/sonatype/nexus/rt/prefs/FilePreferencesFactory.java
package net.sourceforge.tuned.prefs;
import java.io.File;
import java.util.prefs.Preferences;
import java.util.prefs.PreferencesFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* PreferencesFactory implementation that stores the preferences in a user-defined file. To use it, set the system
* property <tt>java.util.prefs.PreferencesFactory</tt> to <tt>net.sourceforge.tuned.pref.FilePreferencesFactory</tt>
* <p/>
* The file defaults to [user.home]/.fileprefs, but may be overridden with the system property
* <tt>net.sourceforge.tuned.pref.FilePreferencesFactory.file</tt>. Modified by cstamas, switched to SLF4J logging, and
* exposed preferences file property.
*
* @author David Croft (<a href="http://www.davidc.net">www.davidc.net</a>)
* @version $Id: FilePreferencesFactory.java 282 2009-06-18 17:05:18Z david $
*/
public class FilePreferencesFactory implements PreferencesFactory {
private static final Logger log = LoggerFactory.getLogger(FilePreferencesFactory.class.getName());
Preferences rootPreferences;
public static final String SYSTEM_PROPERTY_FILE = "net.sourceforge.tuned.prefs.file";
public Preferences systemRoot() {
return userRoot();
}
public Preferences userRoot() {
if (rootPreferences == null) {
log.debug("Instantiating root preferences");
rootPreferences = new FilePreferences(null, "");
}
return rootPreferences;
}
private static File preferencesFile;
public static File getPreferencesFile() {
if (preferencesFile == null) {
String prefsFile = System.getProperty(SYSTEM_PROPERTY_FILE);
if (prefsFile == null || prefsFile.length() == 0) {
prefsFile = System.getProperty("user.home") + File.separator + ".fileprefs";
}
preferencesFile = new File(prefsFile).getAbsoluteFile();
log.info("Preferences file is {}", preferencesFile);
}
return preferencesFile;
}
public static void setPreferencesFile(File file) {
preferencesFile = file;
}
}