public class [[#variable18c39800]]{
/** Logger for this class. */
private final static ILogger s_log = LoggerController.createLogger( [[#variable18c39800]].class );
/** Name of preferences file. */
private static final String USER_PREFS_FILE_NAME = "prefs.xml";
/** Folder to store user settings in. */
private static File _userSettingsFolder;
private static [[#variable18c39700]] _prefs = null;
private static IPlugin plugin = null;
public static void initialize(IPlugin thePlugin) throws PluginException {
plugin = thePlugin;
// Folder to store user settings.
try {
_userSettingsFolder = plugin.getPluginUserSettingsFolder();
}
catch (IOException
ex) {
throw new PluginException(ex);
}
loadPrefs();
}
public static [[#variable18c39700]] getPreferences() {
return _prefs;
}
public static void unload() {
savePrefs();
}
/**
* Save preferences to disk.
*/
public static void savePrefs() {
try {
XMLBeanWriter wtr = new XMLBeanWriter(_prefs);
wtr.save(new File(_userSettingsFolder, USER_PREFS_FILE_NAME));
}
catch (Exception
ex) {
s_log.error("Error occured writing to preferences file: " + USER_PREFS_FILE_NAME, ex);
}
}
/**
* Load from preferences file.
*/
private static void loadPrefs() {
try {
XMLBeanReader doc = new XMLBeanReader();
File prefFile = PreferenceUtil.getPreferenceFileToReadFrom(plugin);
doc.load(prefFile, [[#variable18c39700]].class .getClassLoader());
Iterator<? > it = doc.iterator();
if (it.hasNext()) {
_prefs = ( [[#variable18c39700]]) it.next();
}
}
catch (FileNotFoundException
ignore) {
s_log.info(USER_PREFS_FILE_NAME + " not found - will be created");
}
catch (Exception
ex) {
s_log.error("Error occured reading from preferences file: " + USER_PREFS_FILE_NAME, ex);
}
if (_prefs == null) {
_prefs = new [[#variable18c39700]]();
}
_prefs.setClientName(Version.getApplicationName() + "/" + plugin.getDescriptiveName());
_prefs.setClientVersion(Version.getShortVersion() + "/" + plugin.getVersion());
}
}
|