public class XMLProperties extends Object
<X> <Y> <Z>someValue</Z> </Y> </X>The XML file is passed in to the constructor and must be readable and writable. Setting property values will automatically persist those value to disk. The file encoding used is UTF-8.
Constructor and Description |
---|
XMLProperties()
Creates a new empty XMLPropertiesTest object.
|
XMLProperties(File file)
Deprecated.
|
XMLProperties(InputStream in)
Loads XML properties from a stream.
|
XMLProperties(Path file)
Creates a new XMLPropertiesTest object.
|
XMLProperties(String fileName)
Creates a new XMLPropertiesTest object.
|
Modifier and Type | Method and Description |
---|---|
boolean |
addToList(String propertyName,
String value)
Adds the given value to the list of values represented by the property name.
|
void |
deleteProperty(String name)
Deletes the specified property.
|
List<String> |
getAllPropertyNames()
Returns a list of names for all properties found in the XML file.
|
String |
getAttribute(String name,
String attribute)
Returns the value of the attribute of the given property name or
null
if it doesn't exist. |
Iterator |
getChildProperties(String name)
Return all values who's path matches the given property
name as a String array, or an empty array if the if there
are no children.
|
String[] |
getChildrenProperties(String parent)
Return all children property names of a parent property as a String array,
or an empty array if the if there are no children.
|
String[] |
getProperties(String name)
Deprecated.
Retained for backward compatibility. Prefer getProperties(String, boolean)
|
List<String> |
getProperties(String name,
boolean ignored)
Return all values who's path matches the given property
name as a String array, or an empty array if the if there
are no children.
|
String |
getProperty(String name)
Returns the value of the specified property.
|
String |
getProperty(String name,
boolean ignoreEmpty)
Returns the value of the specified property.
|
void |
migrateProperty(String name)
Convenience routine to migrate an XML property into the database
storage method.
|
String |
removeAttribute(String name,
String attribute)
Removes the given attribute from the XML document.
|
boolean |
removeFromList(String propertyName,
String value)
Removes the given value from the list of values represented by the property name.
|
void |
setProperties(Map<String,String> propertyMap) |
void |
setProperties(String name,
List<String> values)
Sets a property to an array of values.
|
boolean |
setProperty(String name,
String value)
Sets the value of the specified property.
|
public XMLProperties() throws IOException
IOException
- if an error occurs loading the properties.public XMLProperties(String fileName) throws IOException
fileName
- the full path the file that properties should be read from
and written to.IOException
- if an error occurs loading the properties.public XMLProperties(InputStream in) throws IOException
in
- the input stream of XML.IOException
- if an exception occurs when reading the stream.@Deprecated public XMLProperties(File file) throws IOException
file
- the file that properties should be read from and written to.IOException
- if an error occurs loading the properties.public XMLProperties(Path file) throws IOException
file
- the file that properties should be read from and written to.IOException
- if an error occurs loading the properties.public String getProperty(String name)
name
- the name of the property to get.public String getProperty(String name, boolean ignoreEmpty)
name
- the name of the property to get.ignoreEmpty
- Ignore empty property values (return null)public List<String> getProperties(String name, boolean ignored)
<foo> <bar> <prop>some value</prop> <prop>other value</prop> <prop>last value</prop> </bar> </foo>If you call getProperties("foo.bar.prop") will return a string array containing {"some value", "other value", "last value"}.
name
- the name of the property to retrieveignored
- unused parameterpublic String[] getProperties(String name)
<foo> <bar> <prop>some value</prop> <prop>other value</prop> <prop>last value</prop> </bar> </foo>If you call getProperties("foo.bar.prop") will return a string array containing {"some value", "other value", "last value"}.
name
- the name of the property to retrievepublic Iterator getChildProperties(String name)
<foo> <bar> <prop>some value</prop> <prop>other value</prop> <prop>last value</prop> </bar> </foo>If you call getProperties("foo.bar.prop") will return a string array containing {"some value", "other value", "last value"}.
name
- the name of the property to retrievepublic String getAttribute(String name, String attribute)
null
if it doesn't exist.name
- the property name to lookup - ie, "foo.bar"attribute
- the name of the attribute, ie "id"null
if
it doesn't exist.public String removeAttribute(String name, String attribute)
name
- the property name to lookup - ie, "foo.bar"attribute
- the name of the attribute, ie "id"null
if
it did not exist.public void setProperties(String name, List<String> values)
<foo> <bar> <prop>some value</prop> <prop>other value</prop> <prop>last value</prop> </bar> </foo>
name
- the name of the property.values
- the values for the property (can be empty but not null).public boolean addToList(String propertyName, String value)
propertyName
- The name of the property list to changevalue
- The value to be added to the listpublic boolean removeFromList(String propertyName, String value)
propertyName
- The name of the property list to changevalue
- The value to be removed from the listpublic List<String> getAllPropertyNames()
public String[] getChildrenProperties(String parent)
X.Y.A
, X.Y.B
, and X.Y.C
, then
the child properties of X.Y
are A
, B
, and
C
.parent
- the name of the parent property.public boolean setProperty(String name, String value)
name
- the name of the property to set.value
- the new value for the property.true
if the property was correctly saved to file, otherwise false
public void deleteProperty(String name)
name
- the property to delete.public void migrateProperty(String name)
name
- the name of the property to migrate.Copyright © 2003–2019 Ignite Realtime. All rights reserved.