Search in sources :

Example 81 with BackingStoreException

use of java.util.prefs.BackingStoreException in project certmgr by hdecarne.

the class CertOptionsTemplates method load.

public static List<Template> load() {
    List<Template> templates = new ArrayList<>();
    try {
        Preferences templateStore;
        if (TEMPLATE_STORE_INITIALIZED.getBoolean(false)) {
            templateStore = TEMPLATE_STORE;
        } else {
            try (InputStream standardTemplatesStream = getStandardTemplatesUrl().openStream()) {
                Properties standardTemplates = new Properties();
                standardTemplates.load(standardTemplatesStream);
                templateStore = FilePreferencesFactory.customRoot(standardTemplates);
            }
        }
        String[] templateNodeNames = templateStore.childrenNames();
        Arrays.sort(templateNodeNames);
        for (String templateNodeName : templateNodeNames) {
            Preferences templateNode = templateStore.node(templateNodeName);
            @Nullable Template template = loadTemplate(templateNode);
            if (template != null) {
                templates.add(template);
            }
        }
    } catch (IOException | BackingStoreException e) {
        Exceptions.warn(e);
    }
    return templates;
}
Also used : InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) BackingStoreException(java.util.prefs.BackingStoreException) IOException(java.io.IOException) Preferences(java.util.prefs.Preferences) Properties(java.util.Properties) Nullable(de.carne.check.Nullable)

Example 82 with BackingStoreException

use of java.util.prefs.BackingStoreException in project certmgr by hdecarne.

the class CertOptionsTemplates method loadTemplate.

@Nullable
private static Template loadTemplate(Preferences templateNode) {
    @Nullable Template template = null;
    @Nullable String name = templateNode.get(Template.KEY_NAME, null);
    @Nullable String aliasInput = templateNode.get(Template.KEY_ALIAS, null);
    @Nullable String dnInput = templateNode.get(Template.KEY_DN, null);
    if (Strings.notEmpty(name) && Strings.notEmpty(aliasInput) && Strings.notEmpty(dnInput)) {
        assert name != null;
        assert aliasInput != null;
        assert dnInput != null;
        template = new Template(name, new CertOptionsPreset(aliasInput, dnInput));
        @Nullable String keyAlg = templateNode.get(Template.KEY_KEYALG, null);
        if (keyAlg != null) {
            template.setKeyAlg(KeyHelper.getKeyAlg(keyAlg));
        }
        int keySize = templateNode.getInt(Template.KEY_KEYSIZE, 0);
        if (keySize != 0) {
            template.setKeySize(keySize);
        }
        try {
            String[] extensionNodeNames = templateNode.childrenNames();
            for (String extensionNodeName : extensionNodeNames) {
                Preferences extensionNode = templateNode.node(extensionNodeName);
                @Nullable String oid = extensionNode.get(Template.KEY_EXTENSION_OID, null);
                boolean criticial = extensionNode.getBoolean(Template.KEY_EXTENSION_CRITICAL, false);
                @Nullable byte[] data = extensionNode.getByteArray(Template.KEY_EXTENSION_DATA, null);
                if (Strings.notEmpty(oid) && data != null) {
                    assert oid != null;
                    template.addExtension(X509ExtensionData.decode(oid, criticial, data));
                } else {
                    LOG.warning("Ignoring incomplete extension node ''{0}''", extensionNode.absolutePath());
                }
            }
        } catch (BackingStoreException | IOException e) {
            LOG.warning(e, "Ignoring inaccessible extension data for template node ''{0}''", templateNode.absolutePath());
        }
    } else {
        LOG.warning("Ignoring incomplete template node ''{0}''", templateNode.absolutePath());
    }
    return template;
}
Also used : BackingStoreException(java.util.prefs.BackingStoreException) IOException(java.io.IOException) Preferences(java.util.prefs.Preferences) Nullable(de.carne.check.Nullable) DistributionPoint(de.carne.certmgr.certs.x509.DistributionPoint) Nullable(de.carne.check.Nullable)

Example 83 with BackingStoreException

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

the class RecentPalettes method store.

private void store() {
    Preferences prefs = getPreferences();
    // clear the backing store
    try {
        prefs.clear();
    } catch (BackingStoreException ex) {
    }
    int i = 0;
    for (LinearGradient gradient : gradients) {
        try {
            prefs.putByteArray(COLORS + i, serializeColors(gradient.getColors()));
            prefs.putByteArray(POSITIONS + i, serializePositions(gradient.getPositions()));
        } catch (Exception e) {
            Exceptions.printStackTrace(e);
        }
        i++;
    }
}
Also used : LinearGradient(org.gephi.appearance.plugin.RankingElementColorTransformer.LinearGradient) BackingStoreException(java.util.prefs.BackingStoreException) NbPreferences(org.openide.util.NbPreferences) Preferences(java.util.prefs.Preferences) BackingStoreException(java.util.prefs.BackingStoreException)

Example 84 with BackingStoreException

use of java.util.prefs.BackingStoreException in project pivot by apache.

the class DesktopApplicationContext method exit.

/**
 * Terminates the application context.
 *
 * @param optional If <tt>true</tt>, shutdown is optional and may be
 * cancelled. If <tt>false</tt>, shutdown cannot be cancelled.
 * @return Whether shutdown was canceled by the application.
 */
public static boolean exit(boolean optional) {
    boolean cancelShutdown = false;
    if (application != null) {
        try {
            cancelShutdown = application.shutdown(optional);
        } catch (Throwable exception) {
            handleUncaughtException(exception);
        } finally {
            if (!cancelShutdown) {
                // Remove the application from the application list
                applications.remove(application);
            }
        }
    }
    if (!cancelShutdown) {
        try {
            Preferences preferences = Preferences.userNodeForPackage(DesktopApplicationContext.class);
            preferences = preferences.node(applicationClassName);
            boolean maximized = (windowedHostFrame.getExtendedState() & MAXIMIZED_BOTH) == MAXIMIZED_BOTH;
            if (!maximized) {
                preferences.putInt(X_ARGUMENT, windowedHostFrame.getX());
                preferences.putInt(Y_ARGUMENT, windowedHostFrame.getY());
                preferences.putInt(WIDTH_ARGUMENT, windowedHostFrame.getWidth());
                preferences.putInt(HEIGHT_ARGUMENT, windowedHostFrame.getHeight());
            }
            preferences.putBoolean(MAXIMIZED_ARGUMENT, maximized);
            preferences.flush();
        } catch (SecurityException exception) {
        // No-op
        } catch (BackingStoreException exception) {
        // No-op
        }
        windowedHostFrame.dispose();
        fullScreenHostFrame.dispose();
    }
    return cancelShutdown;
}
Also used : BackingStoreException(java.util.prefs.BackingStoreException) Preferences(java.util.prefs.Preferences)

Example 85 with BackingStoreException

use of java.util.prefs.BackingStoreException in project blue by kunstmusik.

the class FileManagerRoots method saveCustomRoots.

private void saveCustomRoots() {
    Preferences p = NbPreferences.forModule(FileManagerRoots.class);
    try {
        p.clear();
    } catch (BackingStoreException ex) {
        Exceptions.printStackTrace(ex);
    }
    int i = 0;
    for (File f : customRoots) {
        p.put("customRoot" + i, f.getAbsolutePath());
        i++;
    }
    try {
        p.flush();
    } catch (BackingStoreException ex) {
        Exceptions.printStackTrace(ex);
    }
}
Also used : BackingStoreException(java.util.prefs.BackingStoreException) NbPreferences(org.openide.util.NbPreferences) Preferences(java.util.prefs.Preferences) File(java.io.File)

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