Example usage for java.util.prefs Preferences userRoot

List of usage examples for java.util.prefs Preferences userRoot

Introduction

In this page you can find the example usage for java.util.prefs Preferences userRoot.

Prototype

public static Preferences userRoot() 

Source Link

Document

Returns the root preference node for the calling user.

Usage

From source file:org.settings4j.helper.spring.Settings4jPlaceholderConfigurerTest.java

@Before
public void setUp() throws Exception {
    removeUnitTestNode(Preferences.userRoot());
    removeUnitTestNode(Preferences.systemRoot());
    Properties props = System.getProperties();
    props.remove(SYSTEM_PROPERTY_TEST_1);
    props.remove(SYSTEM_PROPERTY_TEST_2);
    props.remove(SYSTEM_PROPERTY_TEST_3);
    System.setProperties(props);/*from w  w  w .  j a  va2 s .c  om*/
}

From source file:org.pdfsam.ui.DefaultStageService.java

public StageStatus getLatestStatus() {
    Preferences node = Preferences.userRoot().node(STAGE_PATH);
    try {/*from  w w w .  ja v  a2  s .  c o m*/
        String statusString = node.get(STAGE_STATUS_KEY, "");
        if (isNotBlank(statusString)) {
            return JSON.std.beanFrom(StageStatus.class, statusString);
        }
    } catch (IOException e) {
        LOG.error("Unable to get latest stage status", e);
    }
    return StageStatus.NULL;
}

From source file:org.pentaho.reporting.designer.extensions.pentaho.repository.util.PublishSettings.java

private PublishSettings() {
    properties = Preferences.userRoot().node("org/pentaho/reporting/designer/pentaho-publish-settings");
    settingsListeners = new WeakEventListenerList();
}

From source file:org.pdfsam.context.PreferencesUserWorkspacesContext.java

public PreferencesUserWorkspacesContext() {
    this.prefs = Preferences.userRoot().node("/pdfsam/user/workspaces");
    populateCache();
}

From source file:org.pdfsam.ui.DefaultStageServiceTest.java

@Test
public void testClear() {
    StageStatus status = new StageStatus(10, 20, 100, 200);
    victim.save(status);//from ww  w .  ja va  2  s .  c  o  m
    victim.clear();
    assertTrue(isBlank(Preferences.userRoot().node(DefaultStageService.STAGE_PATH)
            .get(DefaultStageService.STAGE_STATUS_KEY, "")));
}

From source file:backend.SoftwareSecurity.java

public void initialize() {

    System.out.println(this.getClass().getName());
    loadingGIF.passUI("Checking activation key");
    prefs = Preferences.userRoot().node(this.getClass().getName());
    activationKeyValue = prefs.get(activatedKeyToken, "failed"); //sets activationKeyValue, itll be failed if failed
    System.out.println("activationKeyValue: " + activationKeyValue);

    loadingGIF.passUI("Checking license activity");
    bannedKeyValue = prefs.getBoolean(bannedKeyToken, false); //sets banned value, banned is false upon failure
    System.out.println("bannedKeyValue from storage: " + bannedKeyValue);

    if (checkBanned()) { //it was banned
        prefs.putBoolean(bannedKeyToken, true);
        System.out.println("License was banned");
        bannedKeyValue = true;//  w  w  w . java 2  s  . c o  m
    }
    System.out.println("bannedKeyValue following server check: " + bannedKeyValue);

    loadingGIF.passUI("Checking if activated");
    enabledKeyValue = prefs.getBoolean(enabledKeyToken, false); //if enabled couldnt be recovered enabled was false
    System.out.println("enabledKeyValue: " + enabledKeyValue);

    loadingGIF.passUI("Checking license status");
    licenseStatusValue = licenseStatusEnum.valueOf(prefs.get(licenseStatusToken, "ERROR")); //version set to error if version couldn't be recovered
    System.out.println("licenseStatusValue from storage: " + licenseStatusValue);

    checkLicenseStatus(); //checks license status from server
    System.out.println("licenseStatusValue following server check: " + licenseStatusValue);

    Object[] res = checkOutdated(); //array of boolean of if its outdated and JSON of version info
    if ((Boolean) res[0])
        updateSoftware((JSONObject) res[1]);

}

From source file:PreferencesTest.java

public PreferencesFrame() {
    // get position, size, title from preferences

    Preferences root = Preferences.userRoot();
    final Preferences node = root.node("/com/horstmann/corejava");
    int left = node.getInt("left", 0);
    int top = node.getInt("top", 0);
    int width = node.getInt("width", DEFAULT_WIDTH);
    int height = node.getInt("height", DEFAULT_HEIGHT);
    setBounds(left, top, width, height);

    // if no title given, ask user

    String title = node.get("title", "");
    if (title.equals(""))
        title = JOptionPane.showInputDialog("Please supply a frame title:");
    if (title == null)
        title = "";
    setTitle(title);//  w w w.j  ava2 s .c  om

    // set up file chooser that shows XML files

    final JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(new File("."));

    // accept all files ending with .xml
    chooser.setFileFilter(new javax.swing.filechooser.FileFilter() {
        public boolean accept(File f) {
            return f.getName().toLowerCase().endsWith(".xml") || f.isDirectory();
        }

        public String getDescription() {
            return "XML files";
        }
    });

    // set up menus
    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);
    JMenu menu = new JMenu("File");
    menuBar.add(menu);

    JMenuItem exportItem = new JMenuItem("Export preferences");
    menu.add(exportItem);
    exportItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            if (chooser.showSaveDialog(PreferencesFrame.this) == JFileChooser.APPROVE_OPTION) {
                try {
                    OutputStream out = new FileOutputStream(chooser.getSelectedFile());
                    node.exportSubtree(out);
                    out.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    });

    JMenuItem importItem = new JMenuItem("Import preferences");
    menu.add(importItem);
    importItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            if (chooser.showOpenDialog(PreferencesFrame.this) == JFileChooser.APPROVE_OPTION) {
                try {
                    InputStream in = new FileInputStream(chooser.getSelectedFile());
                    Preferences.importPreferences(in);
                    in.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    });

    JMenuItem exitItem = new JMenuItem("Exit");
    menu.add(exitItem);
    exitItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            node.putInt("left", getX());
            node.putInt("top", getY());
            node.putInt("width", getWidth());
            node.putInt("height", getHeight());
            node.put("title", getTitle());
            System.exit(0);
        }
    });
}

From source file:org.pdfsam.module.PreferencesUsageDataStore.java

public void incrementUsageFor(String moduleId) {
    Preferences node = Preferences.userRoot().node(USAGE_PATH).node(moduleId);
    String json = node.get(MODULE_USAGE_KEY, "");
    try {//from  w  w w  . ja  va 2s.  c  o  m
        if (isNotBlank(json)) {
            node.put(MODULE_USAGE_KEY, JSON.std.asString(JSON.std.beanFrom(ModuleUsage.class, json).inc()));
        } else {
            node.put(MODULE_USAGE_KEY, JSON.std.asString(ModuleUsage.fistUsage(moduleId)));
        }
        LOG.trace("Usage incremented for module {}", moduleId);
    } catch (IOException e) {
        LOG.error("Unable to increment modules usage statistics", e);
    } finally {
        incrementTotalUsage();
    }
}

From source file:org.apache.cayenne.pref.UpgradeCayennePreference.java

public void upgrade() {
    try {/*  w w w .  j av a 2  s. c o m*/

        if (!Preferences.userRoot().nodeExists(CAYENNE_PREFERENCES_PATH)) {

            File prefsFile = new File(preferencesDirectory(), PREFERENCES_NAME_OLD);
            if (prefsFile.exists()) {
                ExtendedProperties ep = new ExtendedProperties();
                try {
                    ep.load(new FileInputStream(prefsFile));

                    Preferences prefEditor = Preferences.userRoot().node(CAYENNE_PREFERENCES_PATH).node(EDITOR);

                    prefEditor.putBoolean(ModelerPreferences.EDITOR_LOGFILE_ENABLED,
                            ep.getBoolean(EDITOR_LOGFILE_ENABLED_OLD));
                    prefEditor.put(ModelerPreferences.EDITOR_LOGFILE, ep.getString(EDITOR_LOGFILE_OLD));

                    Preferences frefLastProjFiles = prefEditor.node(LAST_PROJ_FILES);

                    Vector arr = ep.getVector(LAST_PROJ_FILES_OLD);

                    while (arr.size() > ModelerPreferences.LAST_PROJ_FILES_SIZE) {
                        arr.remove(arr.size() - 1);
                    }

                    frefLastProjFiles.clear();
                    int size = arr.size();

                    for (int i = 0; i < size; i++) {
                        frefLastProjFiles.put(String.valueOf(i), arr.get(i).toString());
                    }
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    } catch (BackingStoreException e) {
        // do nothing
    }
}

From source file:org.pdfsam.module.PreferencesUsageDataStoreTest.java

@Test
public void multipleIncrementUsageFor() throws JSONObjectException, IOException {
    victim.incrementUsageFor("moduleId");
    ModuleUsage usage = JSON.std.beanFrom(ModuleUsage.class,
            Preferences.userRoot().node(PreferencesUsageDataStore.USAGE_PATH).node("moduleId")
                    .get(PreferencesUsageDataStore.MODULE_USAGE_KEY, ""));
    victim.flush();/* w ww.  j a  v a 2 s.c  o m*/
    victim.incrementUsageFor("moduleId");
    ModuleUsage usage2 = JSON.std.beanFrom(ModuleUsage.class,
            Preferences.userRoot().node(PreferencesUsageDataStore.USAGE_PATH).node("moduleId")
                    .get(PreferencesUsageDataStore.MODULE_USAGE_KEY, ""));
    assertEquals(2, usage2.getTotalUsed());
    assertTrue(usage.getLastSeen() != usage2.getLastSeen());
}