List of usage examples for java.util.prefs Preferences keys
public abstract String[] keys() throws BackingStoreException;
From source file:de.nrw.hbz.regal.sync.MyPreferences.java
MyPreferences(Class<?> cl) { try {// w ww. j av a 2 s.c om Preferences p = Preferences.userNodeForPackage(cl); for (String preference : p.keys()) { this.addProperty(preference, p.get(preference, null)); } } catch (BackingStoreException e) { // empty preferences are ok } }
From source file:net.bican.wordpress.configuration.PreferencesConfiguration.java
/** * @param cl Calling class/*from w w w . ja v a2 s . c om*/ */ public PreferencesConfiguration(Class<?> cl) { try { Preferences p = Preferences.userNodeForPackage(cl); for (String preference : p.keys()) { this.addProperty(preference, p.get(preference, null)); } } catch (BackingStoreException e) { // then we end up with an empty set of preferences, no big deal } }
From source file:net.sourceforge.metware.binche.loader.OfficialChEBIOboLoader.java
/** * The constructor loads the OBO file from the ChEBI ftp and executes the reasoning steps. * * @throws IOException// w w w . j av a 2 s . c o m * @throws BackingStoreException */ public OfficialChEBIOboLoader() throws IOException, BackingStoreException { Preferences binchePrefs = Preferences.userNodeForPackage(BiNChe.class); if (binchePrefs.keys().length == 0) { binchePrefs = (new DefaultPreferenceSetter()).getDefaultSetPrefs(); } PreProcessOboFile ppof = new PreProcessOboFile(); File tmpFileObo = File.createTempFile("BiNChE", ".obo"); FileUtils.copyURLToFile(new URL(oboURL), tmpFileObo); ppof.getTransitiveClosure(tmpFileObo.getAbsolutePath(), binchePrefs.get(BiNChEOntologyPrefs.RoleOntology.name(), null), false, true, BiNChEOntologyPrefs.RoleOntology.getRootChEBIEntries(), Arrays.asList("rdfs:label"), new ArrayList<String>()); File tmpRoleOnt = new File(binchePrefs.get(BiNChEOntologyPrefs.RoleOntology.name(), null) + ".temp"); tmpRoleOnt.delete(); ppof.getTransitiveClosure(tmpFileObo.getAbsolutePath(), binchePrefs.get(BiNChEOntologyPrefs.StructureOntology.name(), null), false, false, BiNChEOntologyPrefs.StructureOntology.getRootChEBIEntries(), Arrays.asList("rdfs:label", "InChI"), new ArrayList<String>()); File tmpStructOnt = new File(binchePrefs.get(BiNChEOntologyPrefs.StructureOntology.name(), null) + ".temp"); tmpStructOnt.delete(); ppof.getTransitiveClosure(tmpFileObo.getAbsolutePath(), binchePrefs.get(BiNChEOntologyPrefs.RoleAndStructOntology.name(), null), true, true, BiNChEOntologyPrefs.RoleAndStructOntology.getRootChEBIEntries(), Arrays.asList("rdfs:label", "InChI"), Arrays.asList("http://purl.obolibrary.org/obo/RO_0000087")); File tmpStructRoleOnt = new File( binchePrefs.get(BiNChEOntologyPrefs.RoleAndStructOntology.name(), null) + ".temp"); tmpStructRoleOnt.delete(); File structRoleAnnot = new File( binchePrefs.get(BiNChEOntologyPrefs.RoleAndStructOntology.name(), null).replace(".obo", ".txt")); String fullPath = binchePrefs.get(BiNChEOntologyPrefs.RoleAndStructOntology.name(), null); structRoleAnnot.renameTo(new File( fullPath.substring(0, fullPath.lastIndexOf(File.separator)) + File.separator + "chebi_roles.anno")); tmpFileObo.delete(); }
From source file:org.pdfsam.ui.PreferencesRecentWorkspacesService.java
private void populateCache() { Preferences prefs = Preferences.userRoot().node(WORKSPACES_PATH); try {/*from w w w . j a v a2 s.co m*/ Arrays.stream(prefs.keys()).sorted().forEach(k -> { String currentValue = prefs.get(k, EMPTY); if (isNotBlank(currentValue)) { cache.put(currentValue, k); } }); } catch (BackingStoreException e) { LOG.error("Error retrieving recently used workspaces", e); } }
From source file:net.sourceforge.metware.binche.execs.BiNCheExec.java
private void runDefault(String inputPath, String outputPath) { LOGGER.log(Level.INFO, "############ Start ############"); Preferences binchePrefs = Preferences.userNodeForPackage(BiNChe.class); try {// ww w .j a v a2 s . com if (binchePrefs.keys().length == 0) { new OfficialChEBIOboLoader(); } } catch (BackingStoreException e) { LOGGER.error("Problems loading preferences", e); return; } catch (IOException e) { LOGGER.error("Problems loading preferences", e); return; } //String ontologyFile = getClass().getResource("/BiNGO/data/chebi_clean.obo").getFile(); String ontologyFile = binchePrefs.get(BiNChEOntologyPrefs.RoleAndStructOntology.name(), null); String elementsForEnrichFile = inputPath; LOGGER.log(Level.INFO, "Setting default parameters ..."); BingoParameters parametersSaddle = getDefaultParameters(ontologyFile); BiNChe binche = new BiNChe(); binche.setParameters(parametersSaddle); LOGGER.log(Level.INFO, "Reading input file ..."); try { binche.loadDesiredElementsForEnrichmentFromFile(elementsForEnrichFile); } catch (IOException exception) { LOGGER.log(Level.ERROR, "Error reading file: " + exception.getMessage()); System.exit(1); } binche.execute(); ChebiGraph chebiGraph = new ChebiGraph(binche.getEnrichedNodes(), binche.getOntology(), binche.getInputNodes()); //new ChebiGraph(binche.getPValueMap(), binche.getOntology(), binche.getInputNodes()); LOGGER.log(Level.INFO, "Writing out graph ..."); SvgWriter writer = new SvgWriter(); writer.writeSvg(chebiGraph.getVisualisationServer(), outputPath); LOGGER.log(Level.INFO, "############ Stop ############"); }
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 . jav a 2 s .co m*/ 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:com.tag.FramePreferences.java
public boolean isFirst() { Preferences prefs = getPreferences(); try {/*from www . jav a 2 s.c o m*/ List<String> pref = Arrays.asList(prefs.keys()); for (String key : keys()) { if (pref.contains(key)) { return false; } } } catch (BackingStoreException ex) { ex.printStackTrace(); } return true; }
From source file:org.pentaho.reporting.ui.datasources.jdbc.connection.JdbcConnectionDefinitionManager.java
/** * package-local visibility for testing purposes *///from ww w . ja va 2 s .co m JdbcConnectionDefinitionManager(final Preferences externalPreferences, final String node) { userPreferences = externalPreferences; // Load the list of JNDI Sources try { final String[] childNodeNames = userPreferences.childrenNames(); for (int i = 0; i < childNodeNames.length; i++) { final String name = childNodeNames[i]; final Preferences p = userPreferences.node(name); final String type = p.get("type", null); if (type == null) { p.removeNode(); } else if (type.equals("local")) { final Properties props = new Properties(); if (p.nodeExists("properties")) { final Preferences preferences = p.node("properties"); final String[] strings = preferences.keys(); for (int j = 0; j < strings.length; j++) { final String string = strings[j]; final String value = preferences.get(string, null); if (value != null) { props.setProperty(string, value); } else { props.remove(string); } } } final DriverConnectionDefinition driverConnection = new DriverConnectionDefinition(name, p.get(DRIVER_KEY, null), p.get(URL_KEY, null), p.get(USERNAME_KEY, null), p.get(PASSWORD_KEY, null), p.get(HOSTNAME_KEY, null), p.get(DATABASE_NAME_KEY, null), p.get(DATABASE_TYPE_KEY, null), p.get(PORT_KEY, null), props); connectionDefinitions.put(name, driverConnection); } else if (type.equals("jndi")) { final JndiConnectionDefinition connectionDefinition = new JndiConnectionDefinition(name, p.get(JNDI_LOCATION, null), p.get(DATABASE_TYPE_KEY, null), p.get(USERNAME_KEY, null), p.get(PASSWORD_KEY, null)); connectionDefinitions.put(name, connectionDefinition); } else { p.removeNode(); } } } catch (BackingStoreException e) { // The system preferences system is not working - log this as a message and use defaults log.warn("Could not access the user prefererences while loading the " + "JNDI connection information - using default JNDI connection entries", e); } catch (final Exception e) { log.warn("Configuration information was invalid.", e); } // If the connectionDefinitions is empty, add any default entries if (connectionDefinitions.isEmpty() && DATASOURCE_PREFERENCES_NODE.equals(node)) { if (userPreferences.getBoolean("sample-data-created", false) == true) { // only create the sample connections once, if we work on a totally fresh config. return; } updateSourceList(SAMPLE_DATA_JNDI_SOURCE); updateSourceList(SAMPLE_DATA_DRIVER_SOURCE); updateSourceList(SAMPLE_DATA_MEMORY_SOURCE); updateSourceList(LOCAL_SAMPLE_DATA_DRIVER_SOURCE); updateSourceList(MYSQL_SAMPLE_DATA_DRIVER_SOURCE); userPreferences.putBoolean("sample-data-created", true); try { userPreferences.flush(); } catch (BackingStoreException e) { // ignored .. } } }
From source file:ome.formats.importer.util.IniFileLoader.java
/** * Parse Flex reader server maps// w w w . j a v a 2 s . c om * * @param maps * @return */ public Map<String, List<String>> parseFlexMaps(Preferences maps) { Map<String, List<String>> rv = new HashMap<String, List<String>>(); try { for (String key : maps.keys()) { String mapValues = maps.get(key, null); log.info("Raw Flex reader map values: " + mapValues); if (mapValues == null) { continue; } List<String> list = new ArrayList<String>(); rv.put(key, list); for (String value : mapValues.split(";")) { value = value.trim(); list.add(value); } } } catch (BackingStoreException e) { log.warn("Error updating Flex reader server maps.", e); } return rv; }
From source file:org.apache.cayenne.modeler.Application.java
/** * Reinitializes ModelerClassLoader from preferences. *//*from w w w.j a v a 2 s . co m*/ @SuppressWarnings("unchecked") public void initClassLoader() { final FileClassLoadingService classLoader = new FileClassLoadingService(); // init from preferences... Preferences classLoaderPreference = Application.getInstance().getPreferencesNode(ClasspathPreferences.class, ""); Collection details = new ArrayList<>(); String[] keys = null; ArrayList<String> values = new ArrayList<>(); try { keys = classLoaderPreference.keys(); for (String cpKey : keys) { values.add(classLoaderPreference.get(cpKey, "")); } } catch (BackingStoreException e) { // do nothing } for (int i = 0; i < values.size(); i++) { details.add(values.get(i)); } if (details.size() > 0) { // transform preference to file... Transformer transformer = new Transformer() { public Object transform(Object object) { String pref = (String) object; return new File(pref); } }; classLoader.setPathFiles(CollectionUtils.collect(details, transformer)); } this.modelerClassLoader = classLoader; // set as EventDispatch thread default class loader if (SwingUtilities.isEventDispatchThread()) { Thread.currentThread().setContextClassLoader(classLoader.getClassLoader()); } else { SwingUtilities.invokeLater(new Runnable() { public void run() { Thread.currentThread().setContextClassLoader(classLoader.getClassLoader()); } }); } }