public class XMap
extends java.lang.Object
implements java.io.Serializable
| Modifier and Type | Field and Description |
|---|---|
protected static java.lang.String |
DEFAULT_ROOT_NAME |
static XMap |
EMPTY_XMAP
An empty and unmodifiable XMap instance.
|
| Modifier | Constructor and Description |
|---|---|
|
XMap()
Constructs a new XMap instance.
|
|
XMap(org.w3c.dom.Element root)
Constructs a new XMap instance.
|
|
XMap(java.io.InputStream input)
Constructs a new XMap instance from an XML input stream.
|
|
XMap(java.io.InputStream input,
org.xml.sax.EntityResolver resolver)
Constructs a new XMap instance from an XML input stream.
|
|
XMap(java.lang.String root)
Constructs a new XMap instance.
|
|
XMap(XMap map)
Constructs a new XMap instance based on an existing XMap and clone its content.
|
protected |
XMap(XMLUtil xmlUtil,
org.w3c.dom.Element root,
boolean clone)
Constructs a new XMap instance.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
containsKey(java.lang.String key)
Returns true if the supplied key XPath expression matches at least one element, attribute
or text in the root element of this XMap.
|
java.lang.String |
get(java.lang.String key)
Returns the text value of the element (or attribute or text) that matches the supplied
XPath expression.
|
<T> T |
get(java.lang.String key,
java.lang.Class<T> clazz,
T defaultValue) |
<T> T |
get(java.lang.String key,
java.lang.Class<T> clazz,
T defaultValue,
boolean required,
boolean warn) |
java.util.List<XMap> |
getAll(java.lang.String key)
Returns a list of XMap instances with all elements that match the
supplied XPath expression.
|
XMap |
getOne(java.lang.String key)
Returns a new XMap instance with the first element that matches the
supplied XPath expression or null if this XMap root element is null, or if XPath evaluation
result is null, or this result is not an Element.
|
org.w3c.dom.Element |
getRoot()
Allows direct manipulation of the root element.
|
java.lang.String |
put(java.lang.String key,
java.lang.String value)
Creates or updates the text value of the element (or text or attribute) matched by
the supplied XPath expression.
|
java.lang.String |
put(java.lang.String key,
java.lang.String value,
boolean append)
Creates or updates the text value of the element (or text or attribute) matched by
the supplied XPath expression.
|
java.lang.String |
remove(java.lang.String key)
Removes the element, text or attribute that matches the supplied XPath expression.
|
java.lang.String |
toString()
Returns a "pretty" XML representation of the root element of this XMap (may be null).
|
protected static final java.lang.String DEFAULT_ROOT_NAME
public static final XMap EMPTY_XMAP
public XMap()
public XMap(java.lang.String root)
root - the name of the root element (may be null).public XMap(java.io.InputStream input)
throws java.io.IOException,
org.xml.sax.SAXException
input - an XML input stream.java.io.IOExceptionorg.xml.sax.SAXExceptionpublic XMap(java.io.InputStream input,
org.xml.sax.EntityResolver resolver)
throws java.io.IOException,
org.xml.sax.SAXException
input - an XML input stream.java.io.IOExceptionorg.xml.sax.SAXExceptionpublic XMap(org.w3c.dom.Element root)
root - a DOM element (may be null).public XMap(XMap map)
map - the map to duplicate (root element is cloned so modification to this
new instance won't modify the original XMap).protected XMap(XMLUtil xmlUtil, org.w3c.dom.Element root, boolean clone)
root - the root element (may be null).clone - should we clone the root element (prevent original node modification).public org.w3c.dom.Element getRoot()
public boolean containsKey(java.lang.String key)
key - an XPath expression.java.lang.RuntimeException - if the XPath expression isn't correct.public java.lang.String get(java.lang.String key)
key - an XPath expression.java.lang.RuntimeException - if the XPath expression isn't correct.public <T> T get(java.lang.String key,
java.lang.Class<T> clazz,
T defaultValue)
public <T> T get(java.lang.String key,
java.lang.Class<T> clazz,
T defaultValue,
boolean required,
boolean warn)
public java.util.List<XMap> getAll(java.lang.String key)
key - an XPath expression.java.lang.RuntimeException - if the XPath expression isn't correct.public XMap getOne(java.lang.String key)
key - an XPath expression.java.lang.RuntimeException - if the XPath expression isn't correct.public java.lang.String put(java.lang.String key,
java.lang.String value)
key - an XPath expression.value - the value to set (may be null).java.lang.RuntimeException - if the root element of this XMap is null, if the XPath expression is not valid,
or (creation case) if the parent node does not exist or is not an element instance.public java.lang.String put(java.lang.String key,
java.lang.String value,
boolean append)
key - an XPath expression.value - the value to set (may be null).append - should the new element be appended (created) next to a possibly existing element(s) of
the same name?java.lang.RuntimeException - if the root element of this XMap is null, if the XPath expression is not valid,
or (creation case) if the parent node does not exist or is not an element instance.public java.lang.String remove(java.lang.String key)
key - an XPath expression.java.lang.RuntimeException - if the XPath expression isn't valid.public java.lang.String toString()
toString in class java.lang.Object