Example usage for java.util.prefs Preferences childrenNames

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

Introduction

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

Prototype

public abstract String[] childrenNames() throws BackingStoreException;

Source Link

Document

Returns the names of the children of this preference node, relative to this node.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {

    Preferences prefs = Preferences.userNodeForPackage(java.lang.String.class);

    Preferences node = prefs.parent(); // /java
    node = node.parent(); // null

    String[] names = null;/*from   www  .  j  av  a 2 s .  c  o  m*/
    names = prefs.childrenNames();

    for (int i = 0; i < names.length; i++) {
        node = prefs.node(names[i]);
    }
}

From source file:PreferenceExample.java

public static void main(String args[]) throws Exception {
    Preferences prefsRoot = Preferences.userRoot();
    Preferences myPrefs = prefsRoot.node("PreferenceExample");

    myPrefs.put("A", "a");
    myPrefs.put("B", "b");
    myPrefs.put("C", "c");

    System.out.print("Node's children: ");
    for (String s : myPrefs.childrenNames()) {
        System.out.print(s + "");
    }/*from  ww w  .j a v a  2s.c o m*/

}

From source file:de.tbuchloh.kiskis.gui.common.Application.java

/**
 * @param prefs/*w ww.j  av a 2s  .  com*/
 *            the preferences object to load the program from
 * @return a list with Program-objects
 */
public static List<Program> loadPrograms(final Preferences prefs) {
    final List<Program> allProgs = new ArrayList<Program>();
    final Preferences n = prefs.node(Settings.K_URL_ALLPROGS_NODE);
    String[] progs;
    try {
        progs = n.childrenNames();
    } catch (final BackingStoreException e) {
        throw new Error(e);
    }
    for (final String prog : progs) {
        final Preferences child = n.node(prog);
        final String prefix = child.get(Settings.K_URL_PROG_PREFIX, null);
        final String cmd = child.get(Settings.K_URL_PROG_CMD, null);
        if (prefix == null || cmd == null) {
            LOG.error("The application " //$NON-NLS-1$
                    + prog + " is not specified correctly!"); //$NON-NLS-1$
            continue;
        }
        LOG.debug("command: " + cmd + " for prefix " + prefix); //$NON-NLS-1$ //$NON-NLS-2$
        allProgs.add(new Program(prefix, cmd));
    }

    if (progs.length == 0) {
        allProgs.add(new Program("http", DEFAULT_BROWSER + " " + URL_KEY));
    }
    return allProgs;
}

From source file:PreferenceExample.java

public void printInformation(Preferences p) throws BackingStoreException {
    System.out.println("Node's absolute path: " + p.absolutePath());

    System.out.print("Node's children: ");
    for (String s : p.childrenNames()) {
        System.out.print(s + " ");
    }//from ww  w. ja  va  2s.c om
    System.out.println("");

    System.out.print("Node's keys: ");
    for (String s : p.keys()) {
        System.out.print(s + " ");
    }
    System.out.println("");

    System.out.println("Node's name: " + p.name());
    System.out.println("Node's parent: " + p.parent());
    System.out.println("NODE: " + p);
    System.out.println("userNodeForPackage: " + Preferences.userNodeForPackage(PreferenceExample.class));

    System.out.println("All information in node");
    for (String s : p.keys()) {
        System.out.println("  " + s + " = " + p.get(s, ""));
    }
}

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

public List<ModuleUsage> getUsages() {
    Preferences prefs = Preferences.userRoot().node(USAGE_PATH);
    List<ModuleUsage> retList = new ArrayList<>();
    try {/*from  ww  w.j a va 2s  . c  o m*/
        List<String> jsons = Arrays.stream(prefs.childrenNames()).parallel().map(name -> prefs.node(name))
                .map(node -> node.get(MODULE_USAGE_KEY, "")).filter(json -> isNotBlank(json)).collect(toList());
        for (String json : jsons) {
            retList.add(JSON.std.beanFrom(ModuleUsage.class, json));
        }
    } catch (BackingStoreException | IOException e) {
        LOG.error("Unable to get modules usage statistics", e);
    }
    return retList;
}

From source file:de.fhg.igd.mapviewer.server.wms.wizard.pages.BasicConfigurationWithWMSListPage.java

@Override
public void createComponent() {
    super.createComponent();

    Button storeWMS = new Button(getComposite(), SWT.PUSH);
    storeWMS.setText(Messages.WMSListConfigurationPage_2);

    // add new WMS to list and refresh
    storeWMS.addSelectionListener(new SelectionAdapter() {

        @Override//from  w w  w  .j  av a  2 s .  com
        public void widgetSelected(SelectionEvent e) {
            // store WMS i UI list
            map.put(getServiceName(), getServiceURL());
            getListForUI(listUI);
            comboViewer.refresh();
        }
    });

    // free line
    new Text(getComposite(), SWT.NONE).setEditable(false);
    new Text(getComposite(), SWT.NONE).setEditable(false);
    new Text(getComposite(), SWT.NONE).setEditable(false);
    new Text(getComposite(), SWT.NONE).setEditable(false);
    new Text(getComposite(), SWT.NONE).setEditable(false);

    // add text and combo viewer
    Text text = new Text(getComposite(), SWT.NONE);
    text.setEditable(false);
    text.setText(Messages.WMSListConfigurationPage_0);

    // get a list of all WMS

    // get all WMS, storing as WMS Map Server
    Preferences PREF_SERVERS = new WMSMapServer().getPreferences();

    String[] prefs = null;
    try {
        prefs = PREF_SERVERS.childrenNames();

        // put all in map
        for (String current : prefs) {

            Preferences child = PREF_SERVERS.node(current);
            map.put(current, child.get("baseUrl", "baseUrl"));
        }

    } catch (BackingStoreException e) {
        log.warn(Messages.WMSListConfigurationPage_1, e); // $NON-NLS-1$
    }

    // get all WMS, storing as extension points
    IConfigurationElement[] allER = Platform.getExtensionRegistry()
            .getConfigurationElementsFor("de.fhg.igd.mapviewer.server.MapServer");

    for (IConfigurationElement current : allER) {
        String name = "";
        String url = "";

        // name is stored directly as attribute
        name = current.getAttribute("name");

        // url is stored as child
        for (IConfigurationElement child : current.getChildren()) {
            if (child.getAttribute("name").equals("baseUrl")) {
                url = child.getAttribute("value");
            }
        }
        // store everything into map
        if (name != null && !name.isEmpty() && url != null && !url.isEmpty()) {
            map.put(name, url);
        }
    }

    // show stored WMS as DropDown
    comboViewer = new ComboViewer(getComposite(), SWT.DROP_DOWN | SWT.BORDER | SWT.READ_ONLY);
    comboViewer.setContentProvider(new ArrayContentProvider());
    getListForUI(listUI);
    comboViewer.setInput(listUI);
    comboViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            if (selection.size() > 0) {
                String currentSelection = (String) selection.getFirstElement();
                name.setStringValue(currentSelection);
                location.setStringValue(map.get(currentSelection));
            }
        }
    });
}

From source file:com.adito.server.DefaultAditoServerFactory.java

void copyNode(Preferences from, Preferences to) throws BackingStoreException {
    String[] keys = from.keys();//  w w w  . j  av  a2s  . c  om
    for (String key : keys) {
        to.put(key, from.get(key, ""));
    }
    String childNodes[] = from.childrenNames();
    for (String childNode : childNodes) {
        Preferences cn = from.node(childNode);
        Preferences tn = to.node(childNode);
        copyNode(cn, tn);
    }
}

From source file:com.adito.server.Main.java

void copyNode(Preferences from, Preferences to) throws BackingStoreException {
    String[] keys = from.keys();//from  w w  w .j  a  v a  2s .  c  o  m
    for (int i = 0; i < keys.length; i++) {
        to.put(keys[i], from.get(keys[i], ""));
    }
    String childNodes[] = from.childrenNames();
    for (int i = 0; i < childNodes.length; i++) {
        Preferences cn = from.node(childNodes[i]);
        Preferences tn = to.node(childNodes[i]);
        copyNode(cn, tn);
    }
}

From source file:org.apache.cayenne.modeler.CodeTemplateManager.java

/**
 * Updates custom templates from preferences.
 *//*from   ww  w  .j  a  va2s  . com*/
public void updateCustomTemplates(Preferences preference) {
    String[] keys = null;
    try {
        keys = preference.childrenNames();
    } catch (BackingStoreException e) {
        logger.warn("Error reading preferences");
    }
    this.customTemplates = new HashMap<>(keys.length, 1);

    for (int j = 0; j < keys.length; j++) {
        FSPath path = new FSPath(preference.node(keys[j]));
        customTemplates.put(keys[j], path.getPath());
    }
}

From source file:org.javaswift.cloudie.login.CredentialsStore.java

/**
 * lists the available credentials for this user.
 * @return the credentials.//from   www  .  ja v  a  2 s  .  co m
 */
public List<Credentials> getAvailableCredentials() {
    List<Credentials> results = new ArrayList<Credentials>();
    try {
        Preferences prefs = Preferences.userNodeForPackage(CredentialsStore.class);
        for (String node : prefs.childrenNames()) {
            Preferences cred = prefs.node(node);
            try {
                results.add(toCredentials(cred));
            } catch (IllegalArgumentException ex) {
                LoggerFactory.getLogger(getClass()).warn("Bad preferences node - skipping");
            }
        }
    } catch (BackingStoreException ex) {
        throw new RuntimeException(ex);
    }
    return results;
}