/** * Load preferences from the new file format. * * @param newPerfsFile FileWrapper containing the preferences information. * @throws XMLException Thrown if error reading preferences file. */ private void loadNewPrefs(FileWrapper newPrefsFile) throws XMLException { try { try { _settingsCache.load(newPrefsFile.getPath(), getClass().getClassLoader()); } catch (DuplicateObjectException ex) { s_log.error("Cache should have been empty", ex); } Iterator<LAFPreferences> it = _settingsCache.getAllForClass(LAFPreferences.class); if (it.hasNext()) { _lafPrefs = it.next(); } else { s_log.error("LAFPreferences object not loaded"); } } catch (FileNotFoundException ignore) { // property file not found for user - first time user ran pgm. } }
void load() { try { if (new File(_queriesFileName).exists()) { XMLObjectCache cache = new XMLObjectCache(); cache.load(_queriesFileName, getClass().getClassLoader()); Iterator it = cache.getAllForClass(Folder.class); if (it.hasNext()) { _rootFolder = (Folder) it.next(); } } } catch (FileNotFoundException ignore) { // first time user has run pgm. } catch (XMLException ex) { final Logger log = _app.getLogger(); log.showMessage(Logger.ILogTypes.ERROR, "Error loading queries file: " + _queriesFileName); log.showMessage(Logger.ILogTypes.ERROR, ex); } catch (DuplicateObjectException ex) { final Logger log = _app.getLogger(); log.showMessage(Logger.ILogTypes.ERROR, "Error loading queries file: " + _queriesFileName); log.showMessage(Logger.ILogTypes.ERROR, ex); } }
/** Load from preferences file. */ private void loadPrefs() { final FileWrapper oldPrefsFile = fileWrapperFactory.create(_userSettingsFolder, OLD_USER_PREFS_FILE_NAME); final FileWrapper newPrefsFile = fileWrapperFactory.create(_userSettingsFolder, USER_PREFS_FILE_NAME); final boolean oldExists = oldPrefsFile.exists(); final boolean newExists = newPrefsFile.exists(); try { if (oldExists) { loadOldPrefs(oldPrefsFile); try { _settingsCache.add(_lafPrefs); } catch (DuplicateObjectException ex) { s_log.error("LAFPreferences object already in cache", ex); } savePrefs(newPrefsFile); if (!oldPrefsFile.delete()) { s_log.error("Unable to delete old LAF preferences file"); } } else if (newExists) { loadNewPrefs(newPrefsFile); } } catch (IOException ex) { s_log.error("Error occured in preferences file", ex); } catch (XMLException ex) { s_log.error("Error occured in preferences file", ex); } if (_lafPrefs == null) { _lafPrefs = new LAFPreferences(IdentifierFactory.getInstance().createIdentifier()); _lafPrefs.setLookAndFeelClassName(MetalLookAndFeelController.METAL_LAF_CLASS_NAME); try { _settingsCache.add(_lafPrefs); } catch (DuplicateObjectException ex) { s_log.error("LAFPreferences object already in cache", ex); } } }
/** Save cached objects. */ void save() { try { XMLObjectCache cache = new XMLObjectCache(); try { if (_rootFolder != null) { cache.add(_rootFolder); } } catch (DuplicateObjectException ignore) { } cache.save(_queriesFileName); } catch (IOException ex) { final Logger logger = _app.getLogger(); logger.showMessage( Logger.ILogTypes.ERROR, "Error occured saving queries to " + _queriesFileName); logger.showMessage(Logger.ILogTypes.ERROR, ex); } catch (XMLException ex) { final Logger logger = _app.getLogger(); logger.showMessage( Logger.ILogTypes.ERROR, "Error occured saving queries to " + _queriesFileName); logger.showMessage(Logger.ILogTypes.ERROR, ex); } }
/** * Save preferences to disk. * * @param prefsFile File to save preferences to. */ private void savePrefs(FileWrapper prefsFile) throws IOException, XMLException { _settingsCache.save(prefsFile.getPath()); }