|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.dhmp.io.AbstractMapInput org.dhmp.io.XMLMapInputStream
This class reads XML input and generates HierarchicalMap. Each element of XML will become a key for HierarchicalMap's entry and the corresponding value will become a value for that key. So a XML like <Element>Value of Element</Element> will generate a entry in the HierarchicalMap with "Element" as a key and "Value of Element" as its value.
Due to the concept of map, HierarchicalMap can only hold a single value, some adjustments was made to represent the XML using HierarchicalMap. Basically, there are two modes to map XML into HierarchicalMap: simplified mode (default) and pure mode. The latter mode can be set initializing the XMLMapInputStream calling init method:
In pure mode, there are two auxiliary classes: org.dhmp.util.xml.Attribute and
org.dhmp.util.xml.ElementValue.
If an element has a set of attributes, a new HierarchicalMap will be created
holding each attribute/value pair. This HierarchicalMap will be added as a
value for that element. The value will be a String in simplified mode and Class
Attribute will be used to hold the attribute's value to distinguish from element's value in pure mode.
If the element has itself a value, this will be put in the same HierarchicalMap
as for attributes but the class ElementValue will be used to distinguish from
attribute's value and the key "_ElementValue" will be used.
Let's use the followin XML as example:
XMLMapInputStream xin = new XMLMapInputStream(new FileInputStream("somexmlfile.xml"));
xin.init("<Param pure='true'/>");
<Root_Element Root_attribute="roots attribute"> roots text <Element/> <ElementWithValue>elements value</ElementWithValue> <ElementWithChild> <Element Attrib1="a1" Attrib2="a2"/> <Element Attrib3="a3" Attrib4="a4">e0</Element> <Element Attrib5="a5" Attrib6="a6"> <Element1>e1</Element1> </Element> <Element Attrib7="a7" Attrib8="a8"> <Element2>e2</Element2> asd hjk <Element3 Attrib9="a9" Attrib10="a10">e3</Element3> def ghi jkl mno </Element> <Element Attrib11="a11" Attrib12="a12">e1</Element> </ElementWithChild> </Root_Element>
<Root_Element> <Root_attribute>roots attribute</Root_attribute> <_ElementValue>roots text</_ElementValue> <Element></Element> <ElementWithValue>elements value</ElementWithValue> <ElementWithChild> <Element> <Attrib1>a1</Attrib1> <Attrib2>a2</Attrib2> </Element> <Element> <Attrib3>a3</Attrib3> <Attrib4>a4</Attrib4> <_ElementValue>e0</_ElementValue> </Element> <Element> <Attrib5>a5</Attrib5> <Attrib6>a6</Attrib6> <Element1>e1</Element1> </Element> <Element> <Attrib7>a7</Attrib7> <Attrib8>a8</Attrib8> <Element2>e2</Element2> <_ElementValue>asd hjk</_ElementValue> <Element3> <Attrib9>a9</Attrib9> <Attrib10>a10</Attrib10> <_ElementValue>e3</_ElementValue> </Element3> <_ElementValue>def ghi jkl mno</_ElementValue> </Element> <Element> <Attrib11>a11</Attrib11> <Attrib12>a12</Attrib12> <_ElementValue>e1</_ElementValue> </Element> </ElementWithChild> </Root_Element>
Constructor Summary | |
XMLMapInputStream(java.io.InputStream in)
Creates a new instance of XMLMapInputStream. |
|
XMLMapInputStream(java.io.InputStream in,
java.nio.charset.Charset cs)
Creates a new instance of XMLMapInputStream. |
|
XMLMapInputStream(java.io.InputStream in,
java.lang.String charsetName)
Creates a new instance of XMLMapInputStream. |
Method Summary | |
protected java.lang.String |
getKey()
|
java.lang.String |
getPrefix(java.lang.String UI)
|
protected int |
getReference()
|
protected int |
getType()
Error handler to report errors and warnings |
protected java.lang.Object |
getValue()
|
protected void |
init()
|
void |
init(HierarchicalMap paramMap)
Initializes this class using the configuration passed. |
void |
init(java.lang.String config)
Initializes this class using the configuration passed. |
Methods inherited from class org.dhmp.io.AbstractMapInput |
close, getBaseMap, readMap, readMap, readMap, readMap, readMapUntil, readMapUntil, replace, setBaseMap |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public XMLMapInputStream(java.io.InputStream in)
in
- Input stream from where the maps are read.public XMLMapInputStream(java.io.InputStream in, java.lang.String charsetName)
in
- Input stream from where the maps are read.charsetName
- name of charset to be used.public XMLMapInputStream(java.io.InputStream in, java.nio.charset.Charset cs)
in
- Input stream from where the maps are read.cs
- charset to be used.Method Detail |
public void init(java.lang.String config)
Valid configurations are (bold for default value) :
init
in interface MapInput
init
in class AbstractMapInput
config
- configuration used by this class.public void init(HierarchicalMap paramMap)
MapInput
init(String)
.
init
in interface MapInput
init
in class AbstractMapInput
protected void init()
init
in class AbstractMapInput
public java.lang.String getPrefix(java.lang.String UI)
protected int getType() throws java.io.IOException
getType
in class AbstractMapInput
java.io.IOException
protected java.lang.String getKey() throws java.io.IOException
getKey
in class AbstractMapInput
java.io.IOException
protected int getReference() throws java.io.IOException
getReference
in class AbstractMapInput
java.io.IOException
protected java.lang.Object getValue() throws java.io.IOException
getValue
in class AbstractMapInput
java.io.IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |