Search in sources :

Example 6 with BackingStoreException

use of java.util.prefs.BackingStoreException in project JMRI by JMRI.

the class RosterConfigManager method savePreferences.

@Override
public void savePreferences(Profile profile) {
    Preferences preferences = ProfileUtils.getPreferences(profile, this.getClass(), true);
    preferences.put(DIRECTORY, FileUtil.getPortableFilename(this.getDirectory()));
    preferences.put(DEFAULT_OWNER, this.getDefaultOwner());
    try {
        preferences.sync();
    } catch (BackingStoreException ex) {
        log.error("Unable to save preferences", ex);
    }
}
Also used : BackingStoreException(java.util.prefs.BackingStoreException) FileLocationsPreferences(jmri.implementation.FileLocationsPreferences) Preferences(java.util.prefs.Preferences)

Example 7 with BackingStoreException

use of java.util.prefs.BackingStoreException in project JMRI by JMRI.

the class LnTcpPreferences method savePreferences.

public void savePreferences() {
    Preferences sharedPreferences = ProfileUtils.getPreferences(this.getProfile(), this.getClass(), true);
    sharedPreferences.putInt(PORT, this.getPort());
    try {
        sharedPreferences.sync();
        //  Resets only when stored
        setIsDirty(false);
    } catch (BackingStoreException ex) {
        log.error("Exception while saving web server preferences", ex);
    }
}
Also used : BackingStoreException(java.util.prefs.BackingStoreException) Preferences(java.util.prefs.Preferences)

Example 8 with BackingStoreException

use of java.util.prefs.BackingStoreException in project JMRI by JMRI.

the class LnTcpPreferences method readPreferences.

private void readPreferences(Preferences sharedPreferences) {
    boolean migrate = false;
    try {
        if (sharedPreferences.keys().length == 0) {
            log.debug("No LocoNetOverTCP preferences exist.");
            migrate = true;
        }
    } catch (BackingStoreException ex) {
        log.debug("No preferences file exists.");
        migrate = true;
    }
    if (!migrate) {
        this.port = sharedPreferences.getInt(PORT, this.getPort());
        this.setIsDirty(false);
    } else {
        Properties settings = new Properties();
        File file = new File(FileUtil.getUserFilesPath(), SETTINGS_FILE_NAME);
        log.debug("Opening settings file {}", file);
        try (FileInputStream stream = new FileInputStream(file)) {
            settings.load(stream);
            this.port = Integer.parseInt(settings.getProperty(PORT_NUMBER_KEY, Integer.toString(this.getPort())));
            this.setIsDirty(true);
        } catch (FileNotFoundException ex) {
            log.debug("old preferences file not found");
        } catch (IOException ex) {
            log.debug("exception reading old preferences file", ex);
        }
    }
}
Also used : BackingStoreException(java.util.prefs.BackingStoreException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Properties(java.util.Properties) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 9 with BackingStoreException

use of java.util.prefs.BackingStoreException in project JMRI by JMRI.

the class WebServerPreferences method save.

public void save() {
    Preferences sharedPreferences = ProfileUtils.getPreferences(this.getProfile(), this.getClass(), true);
    sharedPreferences.putInt(PORT, this.getPort());
    sharedPreferences.putInt(CLICK_DELAY, this.getClickDelay());
    sharedPreferences.putInt(REFRESH_DELAY, this.getRefreshDelay());
    sharedPreferences.putBoolean(USE_AJAX, this.isUseAjax());
    sharedPreferences.putBoolean(SIMPLE, this.isSimple());
    sharedPreferences.putBoolean(ALLOW_REMOTE_CONFIG, this.allowRemoteConfig());
    sharedPreferences.putBoolean(READONLY_POWER, this.isReadonlyPower());
    sharedPreferences.put(RAILROAD_NAME, getRailRoadName());
    sharedPreferences.putBoolean(DISABLE_FRAME_SERVER, this.isDisableFrames());
    sharedPreferences.putBoolean(REDIRECT_FRAMES, this.redirectFramesToPanels);
    try {
        Preferences node = sharedPreferences.node(DISALLOWED_FRAMES);
        this.disallowedFrames.stream().forEach((frame) -> {
            node.put(Integer.toString(this.disallowedFrames.indexOf(frame)), frame);
        });
        if (this.disallowedFrames.size() < node.keys().length) {
            for (int i = node.keys().length - 1; i >= this.disallowedFrames.size(); i--) {
                node.remove(Integer.toString(i));
            }
        }
        sharedPreferences.sync();
        //  Resets only when stored
        setIsDirty(false);
    } catch (BackingStoreException ex) {
        log.error("Exception while saving web server preferences", ex);
    }
}
Also used : BackingStoreException(java.util.prefs.BackingStoreException) Preferences(java.util.prefs.Preferences)

Example 10 with BackingStoreException

use of java.util.prefs.BackingStoreException in project JMRI by JMRI.

the class WebServerPreferences method readPreferences.

private void readPreferences(Preferences sharedPreferences) {
    this.allowRemoteConfig = sharedPreferences.getBoolean(ALLOW_REMOTE_CONFIG, this.allowRemoteConfig);
    this.clickDelay = sharedPreferences.getInt(CLICK_DELAY, this.clickDelay);
    this.simple = sharedPreferences.getBoolean(SIMPLE, this.simple);
    this.railRoadName = sharedPreferences.get(RAILROAD_NAME, this.railRoadName);
    this.readonlyPower = sharedPreferences.getBoolean(READONLY_POWER, this.readonlyPower);
    this.refreshDelay = sharedPreferences.getInt(REFRESH_DELAY, this.refreshDelay);
    this.useAjax = sharedPreferences.getBoolean(USE_AJAX, this.useAjax);
    this.disableFrames = sharedPreferences.getBoolean(DISABLE_FRAME_SERVER, this.disableFrames);
    this.redirectFramesToPanels = sharedPreferences.getBoolean(REDIRECT_FRAMES, this.redirectFramesToPanels);
    try {
        Preferences frames = sharedPreferences.node(DISALLOWED_FRAMES);
        if (frames.keys().length != 0) {
            this.disallowedFrames.clear();
            for (String key : frames.keys()) {
                // throws BackingStoreException
                String frame = frames.get(key, null);
                if (frame != null && !frame.trim().isEmpty()) {
                    this.disallowedFrames.add(frame);
                }
            }
        }
    } catch (BackingStoreException ex) {
    // this is expected if sharedPreferences have not been written previously,
    // so do nothing.
    }
    this.port = sharedPreferences.getInt(PORT, this.port);
    this.setIsDirty(false);
}
Also used : BackingStoreException(java.util.prefs.BackingStoreException) Preferences(java.util.prefs.Preferences)

Aggregations

BackingStoreException (java.util.prefs.BackingStoreException)112 Preferences (java.util.prefs.Preferences)95 NbPreferences (org.openide.util.NbPreferences)14 File (java.io.File)11 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)4 AutoCompletePreferences (org.jabref.logic.autocompleter.AutoCompletePreferences)4 FieldContentParserPreferences (org.jabref.logic.bibtex.FieldContentParserPreferences)4 LatexFieldFormatterPreferences (org.jabref.logic.bibtex.LatexFieldFormatterPreferences)4 BibtexKeyPatternPreferences (org.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences)4 CleanupPreferences (org.jabref.logic.cleanup.CleanupPreferences)4 ImportFormatPreferences (org.jabref.logic.importer.ImportFormatPreferences)4 JournalAbbreviationPreferences (org.jabref.logic.journals.JournalAbbreviationPreferences)4 LayoutFormatterPreferences (org.jabref.logic.layout.LayoutFormatterPreferences)4 FileLinkPreferences (org.jabref.logic.layout.format.FileLinkPreferences)4 NameFormatterPreferences (org.jabref.logic.layout.format.NameFormatterPreferences)4 ProxyPreferences (org.jabref.logic.net.ProxyPreferences)4 OpenOfficePreferences (org.jabref.logic.openoffice.OpenOfficePreferences)4 ProtectedTermsPreferences (org.jabref.logic.protectedterms.ProtectedTermsPreferences)4