|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.granite.util.XMap
public class XMap
Utility class that makes XML fragment tree manipulation easier.
This class relies on JDK DOM & XPath built-in implementations.
| Field Summary | |
|---|---|
protected static String |
DEFAULT_ROOT_NAME
|
static XMap |
EMPTY_XMAP
An empty and unmodifiable XMap instance. |
| Constructor Summary | |
|---|---|
|
XMap()
Constructs a new XMap instance. |
protected |
XMap(DOM dom,
Element root,
boolean clone)
Constructs a new XMap instance. |
|
XMap(Element root)
Constructs a new XMap instance. |
|
XMap(InputStream input)
Constructs a new XMap instance from an XML input stream. |
|
XMap(InputStream input,
EntityResolver resolver)
Constructs a new XMap instance from an XML input stream. |
|
XMap(String root)
Constructs a new XMap instance. |
|
XMap(XMap map)
Constructs a new XMap instance based on an existing XMap and clone its content. |
| Method Summary | ||
|---|---|---|
boolean |
containsKey(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. |
|
String |
get(String key)
Returns the text value of the element (or attribute or text) that matches the supplied XPath expression. |
|
|
get(String key,
Class<T> clazz,
T defaultValue)
|
|
|
get(String key,
Class<T> clazz,
T defaultValue,
boolean required,
boolean warn)
|
|
List<XMap> |
getAll(String key)
Returns a list of XMap instances with all elements that match the supplied XPath expression. |
|
protected DOM |
getDom()
Returns the DOM instance of this XMap (one is created if it is null). |
|
XMap |
getOne(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. |
|
Element |
getRoot()
Allows direct manipulation of the root element. |
|
String |
put(String key,
String value)
Creates or updates the text value of the element (or text or attribute) matched by the supplied XPath expression. |
|
String |
put(String key,
String value,
boolean append)
Creates or updates the text value of the element (or text or attribute) matched by the supplied XPath expression. |
|
String |
remove(String key)
Removes the element, text or attribute that matches the supplied XPath expression. |
|
String |
toString()
Returns a "pretty" XML representation of the root element of this XMap (may be null). |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected static final String DEFAULT_ROOT_NAME
public static final XMap EMPTY_XMAP
| Constructor Detail |
|---|
public XMap()
public XMap(String root)
root - the name of the root element (may be null).
public XMap(InputStream input)
throws IOException,
SAXException
input - an XML input stream.
IOException
SAXException
public XMap(InputStream input,
EntityResolver resolver)
throws IOException,
SAXException
input - an XML input stream.
IOException
SAXExceptionpublic XMap(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(DOM dom,
Element root,
boolean clone)
root - the root element (may be null).clone - should we clone the root element (prevent original node modification).| Method Detail |
|---|
public Element getRoot()
protected DOM getDom()
public boolean containsKey(String key)
key - an XPath expression.
RuntimeException - if the XPath expression isn't correct.public String get(String key)
key - an XPath expression.
RuntimeException - if the XPath expression isn't correct.
public <T> T get(String key,
Class<T> clazz,
T defaultValue)
public <T> T get(String key,
Class<T> clazz,
T defaultValue,
boolean required,
boolean warn)
public List<XMap> getAll(String key)
key - an XPath expression.
RuntimeException - if the XPath expression isn't correct.public XMap getOne(String key)
key - an XPath expression.
RuntimeException - if the XPath expression isn't correct.
public String put(String key,
String value)
key - an XPath expression.value - the value to set (may be null).
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 String put(String key,
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?
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 String remove(String key)
key - an XPath expression.
RuntimeException - if the XPath expression isn't valid.public String toString()
toString in class Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||