Java Code Examples for java.util.prefs.Preferences#systemRoot()
The following examples show how to use
java.util.prefs.Preferences#systemRoot() .
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: AdminValidator.java From G-Earth with MIT License | 6 votes |
public static boolean isAdmin() { if (isAdmin == null) { Preferences prefs = Preferences.systemRoot(); PrintStream systemErr = System.err; synchronized(systemErr){ // better synchroize to avoid problems with other threads that access System.err System.setErr(null); try{ prefs.put("foo", "bar"); // SecurityException on Windows prefs.remove("foo"); prefs.flush(); // BackingStoreException on Linux isAdmin = true; }catch(Exception e){ isAdmin = false; }finally{ System.setErr(systemErr); } } } return isAdmin; }
Example 2
Source File: FilePreferencesXmlSupport.java From phoebus with Eclipse Public License 1.0 | 6 votes |
/** * Import preferences from the specified input stream, which is assumed to * contain an XML document in the format described in the Preferences spec. * * @throws IOException * if reading from the specified output stream results in an * <tt>IOException</tt>. * @throws InvalidPreferencesFormatException * Data on input stream does not constitute a valid XML document * with the mandated document type. */ static void importPreferences(InputStream is) throws IOException, InvalidPreferencesFormatException { try { Document doc = loadPrefsDoc(is); String xmlVersion = doc.getDocumentElement().getAttribute("EXTERNAL_XML_VERSION"); if (xmlVersion.compareTo(EXTERNAL_XML_VERSION) > 0) throw new InvalidPreferencesFormatException("Exported preferences file format version " + xmlVersion + " is not supported. This java installation can read" + " versions " + EXTERNAL_XML_VERSION + " or older. You may need" + " to install a newer version of JDK."); Element xmlRoot = (Element) doc.getDocumentElement().getChildNodes().item(0); Preferences prefsRoot = (xmlRoot.getAttribute("type").equals("user") ? Preferences.userRoot() : Preferences.systemRoot()); ImportSubtree(prefsRoot, xmlRoot); } catch (SAXException | BackingStoreException e) { throw new InvalidPreferencesFormatException(e); } }
Example 3
Source File: XmlSupport.java From java-scanner-access-twain with GNU Affero General Public License v3.0 | 6 votes |
static void importPreferences(InputStream is) throws IOException, InvalidPreferencesFormatException { try { Document doc = loadPrefsDoc(is); String xmlVersion = doc.getDocumentElement().getAttribute("EXTERNAL_XML_VERSION"); if (xmlVersion.compareTo(EXTERNAL_XML_VERSION) > 0) throw new InvalidPreferencesFormatException( "Exported preferences file format version " + xmlVersion + " is not supported. This java installation can read" + " versions " + EXTERNAL_XML_VERSION + " or older. You may need" + " to install a newer version of JDK."); Element xmlRoot = (Element) doc.getDocumentElement(). getChildNodes().item(0); Preferences prefsRoot = (xmlRoot.getAttribute("type").equals("user") ? Preferences.userRoot() : Preferences.systemRoot()); ImportSubtree(prefsRoot, xmlRoot); } catch(SAXException e) { throw new InvalidPreferencesFormatException(e); } }
Example 4
Source File: XmlSupport.java From java-ocr-api with GNU Affero General Public License v3.0 | 6 votes |
static void importPreferences(InputStream is) throws IOException, InvalidPreferencesFormatException { try { Document doc = loadPrefsDoc(is); String xmlVersion = doc.getDocumentElement().getAttribute("EXTERNAL_XML_VERSION"); if (xmlVersion.compareTo(EXTERNAL_XML_VERSION) > 0) throw new InvalidPreferencesFormatException( "Exported preferences file format version " + xmlVersion + " is not supported. This java installation can read" + " versions " + EXTERNAL_XML_VERSION + " or older. You may need" + " to install a newer version of JDK."); Element xmlRoot = (Element) doc.getDocumentElement(). getChildNodes().item(0); Preferences prefsRoot = (xmlRoot.getAttribute("type").equals("user") ? Preferences.userRoot() : Preferences.systemRoot()); ImportSubtree(prefsRoot, xmlRoot); } catch(SAXException e) { throw new InvalidPreferencesFormatException(e); } }
Example 5
Source File: PreferencesEntityStoreMixin.java From attic-polygene-java with Apache License 2.0 | 6 votes |
private Preferences getApplicationRoot() { PreferencesEntityStoreInfo storeInfo = descriptor.metaInfo( PreferencesEntityStoreInfo.class ); Preferences preferences; if( storeInfo == null ) { // Default to use system root + application name preferences = Preferences.systemRoot(); String name = application.name(); preferences = preferences.node( name ); } else { preferences = storeInfo.rootNode(); } return preferences; }
Example 6
Source File: PreferencesPlaceholderConfigurer.java From lams with GNU General Public License v2.0 | 5 votes |
/** * This implementation eagerly fetches the Preferences instances * for the required system and user tree nodes. */ @Override public void afterPropertiesSet() { this.systemPrefs = (this.systemTreePath != null) ? Preferences.systemRoot().node(this.systemTreePath) : Preferences.systemRoot(); this.userPrefs = (this.userTreePath != null) ? Preferences.userRoot().node(this.userTreePath) : Preferences.userRoot(); }
Example 7
Source File: PreferencesPlaceholderConfigurer.java From blog_demos with Apache License 2.0 | 5 votes |
/** * This implementation eagerly fetches the Preferences instances * for the required system and user tree nodes. */ @Override public void afterPropertiesSet() { this.systemPrefs = (this.systemTreePath != null) ? Preferences.systemRoot().node(this.systemTreePath) : Preferences.systemRoot(); this.userPrefs = (this.userTreePath != null) ? Preferences.userRoot().node(this.userTreePath) : Preferences.userRoot(); }
Example 8
Source File: PreferencesPlaceholderConfigurer.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * This implementation eagerly fetches the Preferences instances * for the required system and user tree nodes. */ @Override public void afterPropertiesSet() { this.systemPrefs = (this.systemTreePath != null) ? Preferences.systemRoot().node(this.systemTreePath) : Preferences.systemRoot(); this.userPrefs = (this.userTreePath != null) ? Preferences.userRoot().node(this.userTreePath) : Preferences.userRoot(); }
Example 9
Source File: PrefsDisplayer.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
void mountBundles(Bundle[] bl) { if(bundlesNode != null) { if(bl.length == 0) { return; } Bundle[] bl0 = bundlesNode.getBundles(); if(bl.length == bl0.length) { boolean bSame = true; for(int i = 0; i < bl.length; i++) { if(bl[i].getBundleId() != bl0[i].getBundleId()) { bSame = false; } } if(bSame) { return; } } } if(bundlesNode != null) { bundlesNode.close(); bundlesNode = null; } rootNode = new MountedPreferences(); Preferences sys = Preferences.systemRoot(); Preferences user = Preferences.userRoot(); jvmNode = new MountedPreferences(); jvmNode.mount((AbstractPreferences)user, "user"); jvmNode.mount((AbstractPreferences)sys, "sys"); rootNode.mount(jvmNode, JVM_NAME); boolean hasPS = psTracker.getService() != null; if(hasPS) { bundlesNode = new OSGiBundlesPreferences(bl != null ? bl : (new Bundle[0])); rootNode.mount(bundlesNode, BUNDLES_NAME); } editor.setPreferences(rootNode); if(hasPS) { editor.getJPrefsTree().searchAndExpand(BUNDLES_NAME, 3); } editor.getJPrefsTree().searchAndExpand(JVM_NAME, 3); editor.setPreferences(rootNode); }