public class XMLStore
extends java.lang.Object
A chain of stored defaults might look like:
try { XMLStore store3 = XMLStore.createFromResource("/auxdata/system.xml", null); XMLStore store2 = XMLStore.createFromFile("/usr/local/metapps/GDV/site.xml", store3); XMLStore store1 = XMLStore.createFromFile("/home/username/.GDV/user.xml", store2); PreferencesExt prefs = store1.getPreferences(); } catch (IOException e) { System.out.println("XMLStore Creation failed "+e); }If you plan to call Preferences.userRoot(), you must explicilty set it, eg:
PreferencesExt.setUserRoot( prefs);
Before exiting the application, in order to save changes, you must call:
try { store1.save(); } catch (IOException e) { System.out.println("XMLStore Save failed "+e); }
PreferencesExt
,
Preferences
Constructor and Description |
---|
XMLStore() |
Modifier and Type | Method and Description |
---|---|
static XMLStore |
createFromFile(java.lang.String fileName,
XMLStore storedDefaults)
Create an XMLStore reading from the specified filename.
|
static XMLStore |
createFromInputStream(java.io.InputStream is1,
java.io.InputStream is2,
XMLStore storedDefaults)
Create an XMLStore reading from an input stream.
|
static XMLStore |
createFromResource(java.lang.String resourceName,
XMLStore storedDefaults)
Create a read-only XMLStore reading from the specified resource, opened as a Resource stream using the
XMLStore ClassLoader.
|
PreferencesExt |
getPreferences()
Get the root Preferences node.
|
static java.lang.String |
makeStandardFilename(java.lang.String appName,
java.lang.String storeName)
Convenience routine for creating an XMLStore file in a standard place.
|
void |
save()
Save the current state of the Preferences tree to disk, using the
original filename.
|
void |
save(java.io.OutputStream out)
Save the current state of the Preferences tree to the given OutputStream.
|
public static XMLStore createFromFile(java.lang.String fileName, XMLStore storedDefaults) throws java.io.IOException
fileName
- The XMLStore is stored in this files.storedDefaults
- This contains the "stored defaults", or null if none.java.io.IOException
- on errorpublic static XMLStore createFromInputStream(java.io.InputStream is1, java.io.InputStream is2, XMLStore storedDefaults) throws java.io.IOException
is1
- the first copy of the input stream.is2
- the second copy of the input stream.storedDefaults
- This contains the "stored defaults", or null if none.java.io.IOException
- on errorpublic static XMLStore createFromResource(java.lang.String resourceName, XMLStore storedDefaults) throws java.io.IOException
resourceName
- The XMLStore is stored in this resource. By convention it has .xml suffix.storedDefaults
- This contains the "stored defaults", or null if none.java.io.IOException
- if Resource not found or error reading itpublic static java.lang.String makeStandardFilename(java.lang.String appName, java.lang.String storeName)
Initialize:
appName
- application namestoreName
- store namepublic PreferencesExt getPreferences()
public void save() throws java.io.IOException
UnsupportedOperationException:
- if XMLStore was created from createFromResource.java.io.IOException
- on read errorpublic void save(java.io.OutputStream out) throws java.io.IOException
java.io.IOException