java.util.prefs.BackingStoreException Java Examples

The following examples show how to use java.util.prefs.BackingStoreException. 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: ExecutableInputMethodManager.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private String findPreferredInputMethodNode(Locale locale) {
    if (userRoot == null) {
        return null;
    }

    // create locale node relative path
    String nodePath = preferredIMNode + "/" + createLocalePath(locale);

    // look for the descriptor
    while (!nodePath.equals(preferredIMNode)) {
        try {
            if (userRoot.nodeExists(nodePath)) {
                if (readPreferredInputMethod(nodePath) != null) {
                    return nodePath;
                }
            }
        } catch (BackingStoreException bse) {
        }

        // search at parent's node
        nodePath = nodePath.substring(0, nodePath.lastIndexOf('/'));
    }

    return null;
}
 
Example #2
Source File: PreferencesEntityStoreMixin.java    From attic-polygene-java with Apache License 2.0 6 votes vote down vote up
@Override
public Stream<EntityState> entityStates( final ModuleDescriptor module )
{
    UsecaseBuilder builder = UsecaseBuilder.buildUsecase( "polygene.entitystore.preferences.visit" );
    Usecase visitUsecase = builder.withMetaInfo( CacheOptions.NEVER ).newUsecase();
    EntityStoreUnitOfWork uow = newUnitOfWork( module, visitUsecase, SystemTime.now() );

    try
    {
        return Stream.of( root.childrenNames() )
                     .map( EntityReference::parseEntityReference )
                     .map( ref -> uow.entityStateOf( module, ref ) )
                     .onClose( uow::discard );
    }
    catch( BackingStoreException e )
    {
        throw new EntityStoreException( e );
    }
}
 
Example #3
Source File: Debug.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private static void addToMenu(JMenu menu, Preferences prefs) throws BackingStoreException {
  if (debug)
    System.out.println(" addMenu " + prefs.name());

  String[] keys = prefs.keys();
  for (String key : keys) {
    boolean bval = prefs.getBoolean(key, false);
    String fullname = prefs.absolutePath() + "/" + key;
    menu.add(new DebugMenuItem(fullname, key, bval)); // menu leaf
    if (debug)
      System.out.println("   leaf= <" + key + "><" + fullname + ">");
  }

  String[] kidName = prefs.childrenNames();
  for (String aKidName : kidName) {
    Preferences pkid = prefs.node(aKidName);
    JMenu subMenu = new JMenu(pkid.name());
    menu.add(subMenu);
    addToMenu(subMenu, pkid);
  }
}
 
Example #4
Source File: ProxyPreferencesImplTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void checkNotContains(Preferences prefs, String[] tree, String prefsId) throws BackingStoreException {
    for(String s : tree) {
        int equalIdx = s.lastIndexOf('=');
        assertTrue(equalIdx != -1);
        String value = s.substring(equalIdx + 1);

        String key;
        String nodePath;
        int slashIdx = s.lastIndexOf('/', equalIdx);
        if (slashIdx != -1) {
            key = s.substring(slashIdx + 1, equalIdx);
            nodePath = s.substring(0, slashIdx);
        } else {
            key = s.substring(0, equalIdx);
            nodePath = "";
        }

        if (prefs.nodeExists(nodePath)) {
            Preferences node = prefs.node(nodePath);
            String realValue = node.get(key, null);
            if (realValue != null && realValue.equals(value)) {
                fail(prefsId + ", '" + nodePath + "' node contains key '" + key + "' = '" + realValue + "'");
            }
        }
    }
}
 
Example #5
Source File: ProxyPreferencesImplTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void checkEquals(String msg, Preferences expected, Preferences test) throws BackingStoreException {
    assertEquals("Won't compare two Preferences with different absolutePath", expected.absolutePath(), test.absolutePath());
    
    // check the keys and their values
    for(String key : expected.keys()) {
        String expectedValue = expected.get(key, null);
        assertNotNull(msg + "; Expected:" + expected.absolutePath() + " has no '" + key + "'", expectedValue);
        
        String value = test.get(key, null);
        assertNotNull(msg + "; Test:" + test.absolutePath() + " has no '" + key + "'", value);
        assertEquals(msg + "; Test:" + test.absolutePath() + "/" + key + " has wrong value", expectedValue, value);
    }

    // check the children
    for(String child : expected.childrenNames()) {
        assertTrue(msg + "; Expected:" + expected.absolutePath() + " has no '" + child + "' subnode", expected.nodeExists(child));
        Preferences expectedChild = expected.node(child);

        assertTrue(msg + "; Test:" + test.absolutePath() + " has no '" + child + "' subnode", test.nodeExists(child));
        Preferences testChild = test.node(child);

        checkEquals(msg, expectedChild, testChild);
    }
}
 
Example #6
Source File: GroovyConsoleState.java    From Lemur with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected void disable() {
    
    // See if we can grab the text
    String text = console.getInputArea().getText();
    if( text.trim().length() > 0 ) {
        log.info("Saving for next time:\n" + text);
        
        // Save it for next time 
        Preferences prefs = Preferences.userNodeForPackage(getClass());
        prefs.put(PREF_LAST_SCRIPT, text);
        try {
            prefs.flush();
        } catch( BackingStoreException e ) {
            log.warn( "Error saving last script to preferences", e );
        }
    }        

    if( frame != null && frame.isDisplayable() ) {
        console.exit(null);
    }
}
 
Example #7
Source File: RecentMenu.java    From ApkToolPlus with Apache License 2.0 6 votes vote down vote up
/**
    Read the list of recently used workspaces from the preferences store.
    @param preferences the preferences node
 */
public void read(Preferences preferences) {

    recentWorkspaces.clear();

    TreeMap<Integer, String> numberToFile = new TreeMap<Integer, String>();
    Preferences recentNode = preferences.node(SETTINGS_RECENT_WORKSPACES);
    try {
        String[] keys = recentNode.keys();
        for (int i = 0; i < keys.length; i++) {
            String key = keys[i];
            String fileName = recentNode.get(key, null);
            if (fileName != null) {
                numberToFile.put(new Integer(key), fileName);
            }
        }
        recentWorkspaces.addAll(numberToFile.values());
    } catch (BackingStoreException ex) {
    }
}
 
Example #8
Source File: Configuration.java    From wpcleaner with Apache License 2.0 6 votes vote down vote up
/**
 * @param wikipedia Wikipedia.
 * @param property Property name.
 * @param subProperty Sub property name.
 * @return Property value.
 */
public Properties getSubProperties(
    EnumWikipedia wikipedia, String property, String subProperty) {
  Properties values = new Properties();
  try {
    if ((getPreferences(wikipedia) != null) &&
        (getPreferences(wikipedia).nodeExists(property)) &&
        (getPreferences(wikipedia).nodeExists(property + "/" + subProperty))) {
      Preferences node = getPreferences(wikipedia).node(property + "/" + subProperty);
      String[] children = node.keys();
      for (String child : children) {
        values.setProperty(child, node.get(child, ""));
      }
    }
  } catch (BackingStoreException e) {
    //
  }
  return values;
}
 
Example #9
Source File: ProxyPreferencesImplTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void checkNotContains(Preferences prefs, String[] tree, String prefsId) throws BackingStoreException {
    for(String s : tree) {
        int equalIdx = s.lastIndexOf('=');
        assertTrue(equalIdx != -1);
        String value = s.substring(equalIdx + 1);

        String key;
        String nodePath;
        int slashIdx = s.lastIndexOf('/', equalIdx);
        if (slashIdx != -1) {
            key = s.substring(slashIdx + 1, equalIdx);
            nodePath = s.substring(0, slashIdx);
        } else {
            key = s.substring(0, equalIdx);
            nodePath = "";
        }

        if (prefs.nodeExists(nodePath)) {
            Preferences node = prefs.node(nodePath);
            String realValue = node.get(key, null);
            if (realValue != null && realValue.equals(value)) {
                fail(prefsId + ", '" + nodePath + "' node contains key '" + key + "' = '" + realValue + "'");
            }
        }
    }
}
 
Example #10
Source File: Group.java    From netbeans with Apache License 2.0 6 votes vote down vote up
protected static String sanitizeNameAndUniquifyForId(String name) {
    String sanitizedId = name.replaceAll("[^a-zA-Z0-9_.-]+", "_");
    Set<String> existing;
    try {
        existing = new HashSet<String>(Arrays.asList(NODE.childrenNames()));
    } catch (BackingStoreException x) {
        Exceptions.printStackTrace(x);
        return sanitizedId;
    }
    if (existing.contains(sanitizedId)) {
        for (int i = 2; ; i++) {
            String candidate = sanitizedId + "_" + i;
            if (!existing.contains(candidate)) {
                return candidate;
            }
        }
    } else {
        return sanitizedId;
    }
}
 
Example #11
Source File: ExecutableInputMethodManager.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private String findPreferredInputMethodNode(Locale locale) {
    if (userRoot == null) {
        return null;
    }

    // create locale node relative path
    String nodePath = preferredIMNode + "/" + createLocalePath(locale);

    // look for the descriptor
    while (!nodePath.equals(preferredIMNode)) {
        try {
            if (userRoot.nodeExists(nodePath)) {
                if (readPreferredInputMethod(nodePath) != null) {
                    return nodePath;
                }
            }
        } catch (BackingStoreException bse) {
        }

        // search at parent's node
        nodePath = nodePath.substring(0, nodePath.lastIndexOf('/'));
    }

    return null;
}
 
Example #12
Source File: HintsPanelLogic.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public ModifiedPreferences( Preferences node ) {
    super(FAKE_ROOT, MODIFIED_HINT_SETTINGS_MARKER); // NOI18N
    try {                
        for (java.lang.String key : node.keys()) {
            put(key, node.get(key, null));
        }
    }
    catch (BackingStoreException ex) {
        Exceptions.printStackTrace(ex);
    }
}
 
Example #13
Source File: LogViewLogger.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@Override
public void setLogLevel(int level) {
    Preferences p = Preferences.userNodeForPackage(LogViewLogger.class);
    p.putInt("loglevel", level);
    try {
        p.flush();
    } catch (BackingStoreException e) {
    }
    this.level = level;
}
 
Example #14
Source File: InputContext.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private AWTKeyStroke getInputMethodSelectionKeyStroke(Preferences root) {
    try {
        if (root.nodeExists(inputMethodSelectionKeyPath)) {
            Preferences node = root.node(inputMethodSelectionKeyPath);
            int keyCode = node.getInt(inputMethodSelectionKeyCodeName, KeyEvent.VK_UNDEFINED);
            if (keyCode != KeyEvent.VK_UNDEFINED) {
                int modifiers = node.getInt(inputMethodSelectionKeyModifiersName, 0);
                return AWTKeyStroke.getAWTKeyStroke(keyCode, modifiers);
            }
        }
    } catch (BackingStoreException bse) {
    }

    return null;
}
 
Example #15
Source File: ProxyPreferences.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
    protected String[] childrenNamesSpi() throws BackingStoreException {
//        Set<String> names = new HashSet<String>();
//        for(Preferences d : delegates) {
//            names.addAll(Arrays.asList(d.childrenNames()));
//        }
//        return names.toArray(new String[ names.size() ]);
        return EMPTY;
    }
 
Example #16
Source File: ProxyPreferencesImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public String[] childrenNames() throws BackingStoreException {
    synchronized (tree.treeLock()) {
        checkRemoved();
        HashSet<String> names = new HashSet<String>();
        if (delegate != null) {
            names.addAll(Arrays.asList(delegate.childrenNames()));
        }
        names.addAll(children.keySet());
        names.removeAll(removedChildren);
        return names.toArray(new String [names.size()]);
    }
}
 
Example #17
Source File: InputContext.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private AWTKeyStroke getInputMethodSelectionKeyStroke(Preferences root) {
    try {
        if (root.nodeExists(inputMethodSelectionKeyPath)) {
            Preferences node = root.node(inputMethodSelectionKeyPath);
            int keyCode = node.getInt(inputMethodSelectionKeyCodeName, KeyEvent.VK_UNDEFINED);
            if (keyCode != KeyEvent.VK_UNDEFINED) {
                int modifiers = node.getInt(inputMethodSelectionKeyModifiersName, 0);
                return AWTKeyStroke.getAWTKeyStroke(keyCode, modifiers);
            }
        }
    } catch (BackingStoreException bse) {
    }

    return null;
}
 
Example #18
Source File: PreferencesDialog.java    From petscii-bbs with Mozilla Public License 2.0 5 votes vote down vote up
public void actionPerformed(ActionEvent e) {
 
  if (e.getActionCommand().equals("Ok")) {
    
    // Transfer the settings to the user settings only, they will
    // only take effect on the next restart
    int stdfontsize = Integer.valueOf(stdfontSpinner.getValue().toString());
    int fixedfontsize = Integer.valueOf(fixedfontSpinner.getValue().toString());
    int bgcolor = ((ColorItem) backgroundCB.getSelectedItem()).color;
    int fgcolor = ((ColorItem) foregroundCB.getSelectedItem()).color;
    boolean antialias = antialiasCB.isSelected();
    
    preferences.put("stdfontsize", String.valueOf(stdfontsize));
    preferences.put("fixedfontsize", String.valueOf(fixedfontsize));
    preferences.put("defaultbackground", String.valueOf(bgcolor));
    preferences.put("defaultforeground", String.valueOf(fgcolor));
    preferences.put("antialias", antialias ? "on" : "off");
    settings.setSettings(stdfontsize, fixedfontsize, bgcolor, fgcolor, antialias);
    try {
      preferences.flush();
    } catch (BackingStoreException ex) {
      
      ex.printStackTrace();
    }
  }
  dispose();
}
 
Example #19
Source File: InstancePropertiesManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void remove() {
    try {
        synchronized (this) {
            if (prefs != null) {
                manager.remove(prefs);
                prefs = null;
            }
        }
    } catch (BackingStoreException ex) {
        LOGGER.log(Level.INFO, null, ex);
    }
}
 
Example #20
Source File: MavenProjectSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static void setSettings(Project project, String key, String value, boolean shared) {
    Preferences preferences = getPreferences(project, shared);
    if (value != null) {
        preferences.put(key, value);
    } else {
        preferences.remove(key);
    }
    try {
        preferences.flush();
        preferences.sync();
    } catch (BackingStoreException ex) {
        Exceptions.printStackTrace(ex);
    }
}
 
Example #21
Source File: HeadedUiContext.java    From triplea with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setUnitScaleFactor(final double scaleFactor) {
  unitImageFactory = unitImageFactory.withScaleFactor(scaleFactor);
  final Preferences prefs = getPreferencesMapOrSkin(getMapDir());
  prefs.putDouble(UNIT_SCALE_PREF, scaleFactor);
  try {
    prefs.flush();
  } catch (final BackingStoreException e) {
    log.log(Level.SEVERE, "Failed to flush preferences: " + prefs.absolutePath(), e);
  }
}
 
Example #22
Source File: PreferencesImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void run() {
    synchronized(lock) {
        try {
            flushSpi();
        } catch (BackingStoreException ex) {
            LOG.log(Level.WARNING, null, ex);
        }
    }
}
 
Example #23
Source File: QueriesCache.java    From netbeans with Apache License 2.0 5 votes vote down vote up
void updateRoot(final URL binaryRoot, final URL... rootsToAttach) {
    T currentMapping = null;
    synchronized (lck) {
        final Map<URL,T> currentRoots = loadRoots();
        currentMapping = currentRoots.get(binaryRoot);
        final Preferences root = NbPreferences.forModule(QueriesCache.class);
        final Preferences node = root.node(clazz.getSimpleName());
        final String binaryRootStr = binaryRoot.toExternalForm();
        try {
            for (String key : filterKeys(node.keys(),binaryRootStr)) {
                node.remove(key);
            }
            for (int i=0; i < rootsToAttach.length; i++) {
                node.put(String.format("%s-%d",binaryRootStr,i), rootsToAttach[i].toExternalForm());
            }
            node.flush();
        } catch (BackingStoreException bse) {
            Exceptions.printStackTrace(bse);
        }
        if (currentMapping == null) {
            try {
                currentMapping = clazz.newInstance();
                currentRoots.put(binaryRoot, currentMapping);
            } catch (InstantiationException ie) {
                Exceptions.printStackTrace(ie);
            } catch (IllegalAccessException iae) {
                Exceptions.printStackTrace(iae);
            }
        }
    }
    if (currentMapping != null) {
        currentMapping.update(Arrays.asList(rootsToAttach));
    }
}
 
Example #24
Source File: NbPreferences.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected final void removeNodeSpi() throws BackingStoreException {
    try {
        fileStorage.removeNode();
    } catch (IOException ex) {
        throw new BackingStoreException(ex);
    }
}
 
Example #25
Source File: PreferencesBasedStorageHandler.java    From PreferencesFX with Apache License 2.0 5 votes vote down vote up
/**
 * Clears the preferences.
 *
 * @return true if successful, false if there was an exception.
 */
public boolean clearPreferences() {
  try {
    preferences.clear();
  } catch (BackingStoreException e) {
    return false;
  }
  return true;
}
 
Example #26
Source File: ProxyPreferencesImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void sync() throws BackingStoreException {
    ArrayList<EventBag<PreferenceChangeListener, PreferenceChangeEvent>> prefEvents = new ArrayList<EventBag<PreferenceChangeListener, PreferenceChangeEvent>>();
    ArrayList<EventBag<NodeChangeListener, NodeChangeEvent>> nodeEvents = new ArrayList<EventBag<NodeChangeListener, NodeChangeEvent>>();

    synchronized (tree.treeLock()) {
        _sync(prefEvents, nodeEvents);
    }

    fireNodeEvents(nodeEvents);
    firePrefEvents(prefEvents);
}
 
Example #27
Source File: DockerInstance.java    From netbeans with Apache License 2.0 5 votes vote down vote up
final void delete() {
    synchronized (this) {
        if (prefs == null) {
            throw new IllegalStateException();
        }
        try {
            prefs.removePreferenceChangeListener(listener);
            prefs.removeNode();
        } catch (BackingStoreException ex) {
            LOGGER.log(Level.WARNING, null, ex);
        }
        prefs = null;
    }
}
 
Example #28
Source File: InputContext.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private AWTKeyStroke getInputMethodSelectionKeyStroke(Preferences root) {
    try {
        if (root.nodeExists(inputMethodSelectionKeyPath)) {
            Preferences node = root.node(inputMethodSelectionKeyPath);
            int keyCode = node.getInt(inputMethodSelectionKeyCodeName, KeyEvent.VK_UNDEFINED);
            if (keyCode != KeyEvent.VK_UNDEFINED) {
                int modifiers = node.getInt(inputMethodSelectionKeyModifiersName, 0);
                return AWTKeyStroke.getAWTKeyStroke(keyCode, modifiers);
            }
        }
    } catch (BackingStoreException bse) {
    }

    return null;
}
 
Example #29
Source File: AuxiliaryConfigBasedPreferencesProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected AbstractPreferences getChild(final String nodeName) throws BackingStoreException {
    try {
        return ProjectManager.mutex(false, project).readAccess(new ExceptionAction<AbstractPreferences>() {
            public AbstractPreferences run() throws BackingStoreException {
                return AuxiliaryConfigBasedPreferences.super.getChild(nodeName);
            }
        });
    } catch (MutexException ex) {
        throw (BackingStoreException) ex.getException();
    }
}
 
Example #30
Source File: MarkOccurrencesTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void setAndFlush(String key,boolean value) {
    try {
        Preferences pref = MarkOccurencesSettings.getCurrentNode();
        pref.putBoolean(key, value);
        pref.flush();            
    } catch (BackingStoreException ex) {
        fail("Error while storing settings");
    }
}