| java.lang.Object org.jivesoftware.util.ElementUtil
ElementUtil | public class ElementUtil (Code) | | We use a simple
naming convention of meta-data key names: data is stored
heirarchically separated by dots. The last name may contain
a colon ':' character that is read as name:attribute.
For example setting X.Y.Z to someValue, would map to an XML snippet of:
<X>
<Y>
<Z>someValue</Z>
</Y>
</X>
And X.Y.Z:key to anotherValue as:
<X>
<Y>
<Z key="anotherValue" />
</Y>
</X>
Some XML cannot be built or accessed using this naming
convention (e.g. a typical Roster reset packet). More complex XML
packet should be represented using the XMPPDOMFragment. The
Element class is designed to provide 80% of XML
manipulation capabilities with the simplest 20% of code and API size
making it convenient for meta-data, simple IQ packets, etc.
|
Method Summary | |
public static void | deleteProperty(Element element, String name) Deletes the specified property.
You MAY NOT use the atttribute
markup (using a ':' in the last element name) with this call. | public static String[] | getChildrenProperties(Element element, 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. | public String[] | getProperties(Element element, 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. | public static String | getProperty(Element element, String name) Returns the value of the specified property. | public static String[] | getRecursiveChildrenProperties(Element element, String parent) Returns all recursive children of the given parent property or an empty string array
if no children exist. | public static boolean | includesProperty(Element element, String name) Returns true if the specified property is included in the XML hierarchy. | public static void | setProperties(Element element, String name, String[] values) Sets a property to an array of values. | public static void | setProperty(Element element, String name, String value) Sets the value of the specified property. |
deleteProperty | public static void deleteProperty(Element element, String name)(Code) | | Deletes the specified property.
You MAY NOT use the atttribute
markup (using a ':' in the last element name) with this call.
deleteProperty() removes both the containing text, and the element itself along with
any attributes associated with that element.
Parameters: name - the property to delete. |
getChildrenProperties | public static String[] getChildrenProperties(Element element, String parent)(Code) | | Return all children property names of a parent property as a String array,
or an empty array if the if there are no children. You MAY NOT use the atttribute
markup (using a ':' in the last element name) with this call.
For example, given the properties X.Y.A, X.Y.B, and X.Y.C, then
the child properties of X.Y are A, B, and
C.
Parameters: parent - the name of the parent property. all child property values for the given parent. |
getProperties | public String[] getProperties(Element element, String name)(Code) | | 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. You MAY NOT use the atttribute
markup (using a ':' in the last element name) with this call.
getProperties() allows you to retrieve several values with the same property name.
For example, consider the XML file entry:
<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"}.
Parameters: name - the name of the property to retrieve all child property values for the given node name. |
getProperty | public static String getProperty(Element element, String name)(Code) | | Returns the value of the specified property. A null answer does not necessarily mean
that the property does not exist.
Parameters: name - the name of the property to get. the value of the specified property. |
getRecursiveChildrenProperties | public static String[] getRecursiveChildrenProperties(Element element, String parent)(Code) | | Returns all recursive children of the given parent property or an empty string array
if no children exist. The list of children is depth-first so the array is optimized
for easy displaying.
Parameters: parent - the parent property. all recursive children of the given property in depth-first order or an emptystring array if no children exist. |
includesProperty | public static boolean includesProperty(Element element, String name)(Code) | | Returns true if the specified property is included in the XML hierarchy. A property could
have a value associated or not. If the property has an associated value then
Parameters: name - the name of the property to find out. true if the specified property is included in the XML hierarchy. |
setProperties | public static void setProperties(Element element, String name, String[] values)(Code) | | Sets a property to an array of values. You MAY NOT use the atttribute
markup (using a ':' in the last element name) with this call. Multiple values matching the
same property is mapped to an XML file as multiple elements containing each value.
For example, using the name "foo.bar.prop", and the value string array containing
{"some value", "other value", "last value"} would produce the following XML:
<foo>
<bar>
<prop>some value</prop>
<prop>other value</prop>
<prop>last value</prop>
</bar>
</foo>
Parameters: name - the name of the property. Parameters: values - The array of values for the property (can be empty but not null) |
setProperty | public static void setProperty(Element element, String name, String value)(Code) | | Sets the value of the specified property. If the property doesn't
currently exist, it will be automatically created.
Parameters: name - the name of the property to set. Parameters: value - the new value for the property. |
|
|