Java Code Examples for java.util.prefs.Preferences#removeNode()

The following examples show how to use java.util.prefs.Preferences#removeNode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractPreferencesDiscoverer.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void remove ( final ConnectionDescriptor connectionInformation ) throws CoreException
{
    try
    {
        if ( removeConnection ( connectionInformation ) )
        {
            final String uri = URLEncoder.encode ( connectionInformation.getConnectionInformation ().toString (), "UTF-8" ); //$NON-NLS-1$
            if ( getNode ().nodeExists ( uri ) )
            {
                final Preferences node = getNode ().node ( uri );
                node.removeNode ();
                getNode ().flush ();
                fireDiscoveryUpdate ( null, new ConnectionDescriptor[] { connectionInformation } );
            }
        }
    }
    catch ( final Exception e )
    {
        throw new CoreException ( StatusHelper.convertStatus ( Activator.PLUGIN_ID, e ) );
    }
}
 
Example 2
Source File: ProxyPreferencesTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testRemoveNode() throws BackingStoreException {
    Preferences orig = Preferences.userRoot().node(getName());
    Preferences origChild = orig.node("child");

    Preferences test = ProxyPreferences.getProxyPreferences(this, orig);
    assertTrue("Test child shoculd exist", test.nodeExists("child"));
    Preferences testChild = test.node("child");

    testChild.removeNode();
    assertFalse("Removed test child should not exist", testChild.nodeExists(""));
    assertFalse("Removed test child should not exist in parent", test.nodeExists("child"));

    test.flush();
    assertFalse("Test.flush did not remove orig child", origChild.nodeExists(""));
    assertFalse("Test.flush did not remove orig child from parent", orig.nodeExists("child"));
}
 
Example 3
Source File: ProxyPreferencesImplTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testRemoveNode() throws BackingStoreException {
    Preferences orig = Preferences.userRoot().node(getName());
    Preferences origChild = orig.node("child");

    Preferences test = ProxyPreferencesImpl.getProxyPreferences(this, orig);
    assertTrue("Test child shoculd exist", test.nodeExists("child"));
    Preferences testChild = test.node("child");

    testChild.removeNode();
    assertFalse("Removed test child should not exist", testChild.nodeExists(""));
    assertFalse("Removed test child should not exist in parent", test.nodeExists("child"));

    test.flush();
    assertFalse("Test.flush did not remove orig child", origChild.nodeExists(""));
    assertFalse("Test.flush did not remove orig child from parent", orig.nodeExists("child"));
}
 
Example 4
Source File: HistorySettings.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static void migrate() { 
    // migrate pre 7.2 settings 
    String prevPath = "org/netbeans/modules/localhistory"; // NOI18N
    try {
        if(!NbPreferences.root().nodeExists(prevPath)) {
            return;
        }
        Preferences prev = NbPreferences.root().node(prevPath);
        Preferences cur =  NbPreferences.forModule(HistorySettings.class);
        String[] keys = prev.keys();
        for (String key : keys) {
            String value = prev.get(key, null);
            if(value != null && cur.get(key, null) == null) {
                cur.put(key, value);
            }
        }
        prev.removeNode();
    } catch (BackingStoreException ex) {
        Exceptions.printStackTrace(ex);
    }
    
}
 
Example 5
Source File: ProxyPreferencesImplTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testRemoveNode() throws BackingStoreException {
    Preferences orig = Preferences.userRoot().node(getName());
    Preferences origChild = orig.node("child");

    Preferences test = ProxyPreferencesImpl.getProxyPreferences(this, orig);
    assertTrue("Test child shoculd exist", test.nodeExists("child"));
    Preferences testChild = test.node("child");

    testChild.removeNode();
    assertFalse("Removed test child should not exist", testChild.nodeExists(""));
    assertFalse("Removed test child should not exist in parent", test.nodeExists("child"));

    test.flush();
    assertFalse("Test.flush did not remove orig child", origChild.nodeExists(""));
    assertFalse("Test.flush did not remove orig child from parent", orig.nodeExists("child"));
}
 
Example 6
Source File: DefaultStageService.java    From pdfsam with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void clear() {
    Preferences prefs = Preferences.userRoot().node(STAGE_PATH);
    try {
        prefs.removeNode();
        prefs.flush();
    } catch (BackingStoreException e) {
        LOG.error("Unable to clear stage status", e);
    }
}
 
Example 7
Source File: Configuration.java    From wpcleaner with Apache License 2.0 5 votes vote down vote up
/**
 * Remove a node.
 * 
 * @param prefs Preferences.
 * @param property Node name.
 */
private void removeNode(Preferences prefs, String property) {
  if (prefs != null) {
    try {
      if (prefs.nodeExists(property)) {
        Preferences node = prefs.node(property);
        node.removeNode();
      }
    } catch (BackingStoreException e) {
      //
    }
  }
}
 
Example 8
Source File: PreferencesWiper.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
public static void main(final String[] args) {
	try {
		final Preferences store = Preferences.userRoot().node("gama");
		store.removeNode();
	} catch (final Exception e) {
		e.printStackTrace();
	}
}
 
Example 9
Source File: ProjectManager.java    From markdown-writer-fx with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private static void removeProjectState(File project) {
	Preferences projectState = getProjectState(project, false);
	if (projectState != null) {
		try {
			projectState.removeNode();
		} catch (BackingStoreException ex) {
			// ignore
			ex.printStackTrace();
		}
	}
}
 
Example 10
Source File: FactoryImpl.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
private void removeFile ( final File file ) throws Exception
{
    for ( final String childName : this.prefs.childrenNames () )
    {
        final Preferences child = this.prefs.node ( childName );
        final String fileName = new File ( child.get ( "file", null ) ).getAbsolutePath ();
        if ( file.getAbsolutePath ().equals ( fileName ) )
        {
            child.removeNode ();
        }
    }
    this.prefs.flush ();
}
 
Example 11
Source File: InstancePropertiesTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void tearDown() throws Exception {
    super.tearDown();

    Preferences prefs = NbPreferences.forModule(InstancePropertiesManager.class);
    prefs.removeNode();
}
 
Example 12
Source File: DefaultNewsService.java    From pdfsam with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void clear() {
    Preferences prefs = Preferences.userRoot().node(NEWS_PATH);
    try {
        prefs.removeNode();
        prefs.flush();
    } catch (BackingStoreException e) {
        LOG.error("Unable to clear latest news store", e);
    }
}
 
Example 13
Source File: ConfigurationsManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void remove(Configuration config) {
    configs.remove(config);
    Preferences prefs = NbPreferences.forModule(this.getClass()).node(config.id());
    try {
        prefs.removeNode();
    } catch (BackingStoreException ex) {
        Exceptions.printStackTrace(ex);
    }
    changeSupport.fireChange();
}
 
Example 14
Source File: GroupsManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
void removeGroup(DocumentGroupImpl group) {
    try {

        Preferences prefs = getPreferences();
        if( group.getName().equals(prefs.get(SEL_GROUP, "")) ) { //NOI18N
            prefs.put(SEL_GROUP, ""); //NOI18N
        }
        prefs = prefs.node(group.getName());
        prefs.removeNode();
        //delete all cached files

    } catch( Exception e ) {
        LOG.log(Level.INFO, "Failed to remove document group '" + group.toString() + "'", e); //NOI18N
    }
}
 
Example 15
Source File: TestPreferences.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testNodeExists() throws Exception {
    Preferences pref = getPreferencesNode();
    Preferences pref2 = pref.node("a/b/c");
    while(pref2 != Preferences.userRoot()) {
        assertTrue(pref2.nodeExists(""));
        Preferences parent = pref2.parent();
        pref2.removeNode();
        assertFalse(pref2.nodeExists(""));
        pref2 = parent;
    }
    
    assertNotNull(getPreferencesNode().node("a/b/c/d"));
    assertTrue(getPreferencesNode().node("a/b/c/d").nodeExists(""));
}
 
Example 16
Source File: PreferencesUsageDataStore.java    From pdfsam with GNU Affero General Public License v3.0 5 votes vote down vote up
public void clear() {
    Preferences prefs = Preferences.userRoot().node(USAGE_PATH);
    try {
        prefs.removeNode();
        prefs.flush();
    } catch (BackingStoreException e) {
        LOG.error("Unable to clear modules usage statistics", e);
    }
}
 
Example 17
Source File: ConfigurationsManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void remove(Configuration config) {
    configs.remove(config);
    Preferences prefs = NbPreferences.forModule(this.getClass()).node(config.id());
    try {
        prefs.removeNode();
    } catch (BackingStoreException ex) {
        Exceptions.printStackTrace(ex);
    }
    changeSupport.fireChange();
}
 
Example 18
Source File: Debug.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static void removeAll(Preferences prefs, boolean delete) throws BackingStoreException {

    String[] kidName = prefs.childrenNames();
    for (String aKidName : kidName) {
      Preferences pkid = prefs.node(aKidName);
      removeAll(pkid, true);
    }

    if (delete)
      prefs.removeNode();
    else
      prefs.clear();
  }
 
Example 19
Source File: AutoupdateSettings.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static void expirationCheck () {
    Preferences p = getPreferences ();
    String exp = p.get (EXPIRATION_RECORD, null);
    Collection<String> forImport = new HashSet<String> (Arrays.asList (VERSIONS_FOR_IMPORT));
    String currentVersion = new File (System.getProperty ("netbeans.user")).getName ();
    forImport.add (currentVersion);
    if (exp != null && ! forImport.contains (exp)) {
        try {
            final int period = getPeriod();
            boolean shared = Utilities.isGlobalInstallation() == null ? false : Utilities.isGlobalInstallation();
            p.removeNode ();
            getPreferences ().put (IMPORTED, Boolean.toString (true));
            getPreferences ().putInt(PROP_PERIOD, period);
            if (shared) {
                // Check that we can use 'shared' flag imported from previous installation with a new one.
                // Obtained from SettingsTab.cbGlobalInstallActionPerformed
                Collection<File> dirs = Utilities.sharedDirs();
                if (!dirs.isEmpty()) {
                    for (File f : dirs) {
                        if (f.exists() && f.isDirectory() && !Utilities.canWriteInCluster(f)) {
                            shared = false;
                            break;
                        }
                    }
                    if (shared) {
                        Utilities.setGlobalInstallation(shared);
                    }
                }
            }
            err.log (Level.FINE, "Don't read preferences from userdir " + exp);
        } catch (BackingStoreException ex) {
            err.log (Level.INFO, ex.getLocalizedMessage (), ex);
        }
    } else if (exp == null) {
        err.log (Level.FINEST, "No preferences imported from previous version.");
    } else {
        err.log (Level.FINEST, "Read preferences from userdir " + exp);
    }
    err.log (Level.FINEST, "Store current version " + currentVersion + " for future import.");
    getPreferences ().put (EXPIRATION_RECORD, currentVersion);
}
 
Example 20
Source File: Configuration.java    From wpcleaner with Apache License 2.0 4 votes vote down vote up
/**
 * Move a child.
 * 
 * @param oldParent Old parent node.
 * @param newParent New parent node.
 * @param childName Child name.
 * @return True if the child has been completely moved.
 * @throws BackingStoreException
 */
private boolean moveChild(
    Preferences oldParent, Preferences newParent, String childName)
    throws BackingStoreException {
  if ((oldParent == null) || (childName == null)) {
    return true;
  }
  if (!oldParent.nodeExists(childName)) {
    return true;
  }
  if (newParent == null) {
    return false;
  }
  Preferences oldChild = oldParent.node(childName);
  Preferences newChild = newParent.node(childName);

  // Move keys
  String[] keyNames = oldChild.keys();
  if (keyNames != null) {
    for (String keyName : keyNames) {
      String value = oldChild.get(keyName, null);
      if (value != null) {
        newChild.put(keyName, value);
      }
      oldChild.remove(keyName);
    }
  }

  // Move children
  String[] childNames2 = oldChild.childrenNames();
  if (childNames2 != null) {
    for (String childName2 : childNames2) {
      moveChild(oldChild, newChild, childName2);
    }
  }

  // Clean up
  boolean ok = false;
  newChild.flush();
  keyNames = oldChild.keys();
  childNames2 = oldChild.childrenNames();
  if (((keyNames == null) || (keyNames.length == 0)) ||
      ((childNames2 == null) || (childNames2.length == 0))) {
    oldChild.removeNode();
    ok = true;
  }
  oldChild.flush();
  return ok;
}