/** * This class provides exactly the same functions are the getOdinPrefs method but doesn't record * anything in the Log * * <p>It should <b>only</b> be used by the LoggerFactory class to prevent a loop. All other * classes should use the getOdinPrefs method to utilise the logger. * * <p>It also retrieves much of the information from the Server's Root XML document and reads it * into the preferences for later reads. * * @return A new instance of Preferences to be used locally */ public static Preferences getInitialPreferences() { /* As mentioned in the JavaDoc comments, this is the same code but omitting the use of the log. It doesn't harm if * a class other than LoggerFactory uses it, we just lose the logs if something goes wrong. */ if (prefsOdin == null) { try { String prefsFilePath = getPrefsPath() + prefsFileName; File f = new File(prefsFilePath); if (f.exists()) { sPrefsPath = prefsFilePath; BufferedInputStream bisXMLPrefs = new BufferedInputStream(new FileInputStream(prefsFilePath)); if (bisXMLPrefs != null) { prefsOdin.importPreferences(bisXMLPrefs); } } else { File fBackup = new File(prefsFileName); if (fBackup.exists()) { // Using the backup preferences in the application directory. sPrefsPath = prefsFileName; } BufferedInputStream bisXMLPrefs = new BufferedInputStream(new FileInputStream(prefsFileName)); prefsOdin.importPreferences(bisXMLPrefs); } } catch (FileNotFoundException fnfX) { System.err.println("Couldn't retrieve either preferences."); } catch (Exception x) { // If any errors are thrown then put them in System.err rather than the Logger System.err.println( "An error was caught while trying to obtain preferences for the logger."); x.printStackTrace(); } } prefsOdin = Preferences.userNodeForPackage(OdinPreferences.class); // Get hold of the JAXB data contained within the Server Root document to find out where we // should store everything. getRootDocument(); prefsOdin.put("odin.jaxb.dir.Archive", rDocument.getLocations().getArchive()); prefsOdin.put("odin.jaxb.dir.Convert", rDocument.getLocations().getConversion()); prefsOdin.put("odin.jaxb.dir.Mime", rDocument.getLocations().getFormat()); prefsOdin.put("odin.jaxb.dir.Log", rDocument.getLocations().getLogging()); prefsOdin.put("odin.jaxb.dir.Prefs", rDocument.getLocations().getPreference()); prefsOdin.put("odin.jaxb.dir.Hazard", rDocument.getLocations().getQuarantine()); prefsOdin.put("odin.jaxb.dir.Store", rDocument.getLocations().getRepository()); silentUpdate(); return prefsOdin; }
public static void main(String[] args) throws Exception { String osName = System.getProperty("os.name"); if (osName.startsWith("Windows")) return; Preferences root = Preferences.userRoot(); Preferences node1 = root.node("node1"); Preferences node1A = node1.node("node1A"); Preferences node1B = node1.node("node1B"); node1B.put("mykey", "myvalue"); node1.flush(); String node1BDirName = System.getProperty("user.home") + "/.java/.userPrefs" + "/node1/node1B"; File node1BDir = new File(node1BDirName); node1BDir.setReadOnly(); try { node1.removeNode(); } catch (BackingStoreException ex) { // expected exception } finally { Runtime.getRuntime().exec("chmod 755 " + node1BDirName).waitFor(); try { node1.removeNode(); } catch (Exception e) { } } }