|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.ls.util.xml.XMLFragment
This class represents an XML structure that can deal with attributes, sub
elements and any String content.
The sub elements are handled in the order as they have been read from the
XML source (i.e. in the order as they have been created).
Hereby, every sub element itself is an instance of XMLFragment
.
Inner classes inherited from class java.util.Map |
Map.Entry |
Field Summary | |
protected Map |
documentAttributes
holds the root element's attributes |
protected Map |
documentChildren
holds the root element's sub elements (its 'children') |
static String |
EMTPY_ATTRIBUTE
constant for specifying that an element's attribute is empty |
static String |
EMTPY_CONTENT
constant for specifying that an element's content is empty |
Constructor Summary | |
XMLFragment(String element)
Creates an empty XMLFragment having the given root element. |
|
XMLFragment(String element,
Map attributes)
Creates an empty XMLFragment having the given root element and a list of attributes. |
Method Summary | |
void |
addAttribute(String attributeName,
String attributeValue)
Adds an attribute with the given name and value to the root element of this XMLFragment. |
XMLFragment |
addChild(String element,
String content)
Adds a new sub element to this XMLFragment. |
void |
addChild(XMLFragment element)
Adds a new sub element to this XMLFragment as given by element |
void |
addChildren(Map elementMapping)
Adds a new sub element to this XMLFragment. |
void |
addContent(String stringContent)
Adds the given stringContent to this XMLFragment's content. |
void |
clear()
Any call to this method throws always an UnsupportedOperationException! |
int |
compareTo(Object object)
Compares this object with the specified object for order. |
boolean |
containsKey(Object element)
Returns whether or not this XMLFragment contains a sub element element
. |
boolean |
containsValue(Object value)
Returns whether or not this XMLFragment contains a sub element element
. |
static Map |
convertToStandardMap(XMLFragment xmlFragment)
Converts the given XMLFragment object into a 'normal' the java.util.HashMap implementations of the Map interface and returns it. |
Set |
entrySet()
Returns a set view of the sub elements contained in this XMLFragment. |
boolean |
equals(Object object)
Returns whether or not the given Object is equal to this XMLFragment. |
Object |
get(Object object)
Returns the Object which is mapped to the given object .
|
String |
getAttribute(String attributeName)
Returns the value of the given attribute. |
Object |
getChild(String element)
Returns the sub element specified by the given name. |
List |
getChildren()
Returns a list of all sub elements. |
List |
getChildren(String element)
Returns a list of sub elements as specified by the given name. |
String |
getContent()
Returns the content of this XMLFragment. |
String |
getNamespaceURI()
Returns the namespace URI for this XMLFragment. |
String |
getQualifiedName()
Returns the qualified XML Name for this XMLFragment. |
String |
getRootName()
Returns the name of the root element of this XMLFragment. |
boolean |
hasAttributes()
Returns whether or not this XMLFragment's root has attributes. |
boolean |
hasChildren()
Returns whether or not this XMLFragment contains sub elements. |
boolean |
isEmpty()
Returns whether or not there are any sub elements of this XMLFragment. |
boolean |
isValidXMLName(String stringObject)
Validates the given String object against the rules of XML Names. |
Iterator |
iterateAttributes()
Returns an Iterator view on the attributes of this XMLFragment. |
Iterator |
iterateChildren()
Returns an Iterator view on the sub elements of this XMLFragment. |
Set |
keySet()
Returns a set view of the names of the sub element contained in this XMLFragment. |
List |
listChildrenNames()
Returns a List containing the names of the sub elements. |
int |
numberOfAttributes()
Returns the number of attributes of this XMLFragment. |
int |
numberOfChildren()
Returns the number of sub elements of this XMLFragment. |
static XMLFragment |
parseXML(Reader reader)
parses an xml structure from the given reader and creates an XMLFragment from it. |
static XMLFragment |
parseXML(String string)
parses an xml structure from the given reader and creates an XMLFragment from it. |
Object |
put(Object element,
Object content)
Creates a new XMLFragment with name element and a content of
content . |
void |
putAll(Map map)
Adds a number of sub elements to this XMLFragment, as specified in the given Map. |
Object |
remove(Object o)
Any call to this method throws always an UnsupportedOperationException! |
void |
setNamespaceURI(String namespaceURI)
Sets the namespace URI for this XMLFragment. |
void |
setQualifiedName(String qName)
Sets the qualified XML Name for this XMLFragment. |
int |
size()
Returns the number of sub elements of this XMLFragment. |
String |
toString()
Creates a string representation of this XMLFragment. |
Collection |
values()
Any call to this method throws always an UnsupportedOperationException! |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Map |
hashCode |
Field Detail |
public static final String EMTPY_ATTRIBUTE
public static final String EMTPY_CONTENT
protected Map documentAttributes
protected Map documentChildren
Constructor Detail |
public XMLFragment(String element) throws IllegalArgumentException, XMLException
element
- the root element (tag) of this XMLFragmentIllegalArgumentException
- if the given root element is null or emptyXMLException
- if the given root element is not a valid XML Namepublic XMLFragment(String element, Map attributes) throws IllegalArgumentException, XMLException, MissingDataException
element
- the root element (tag) of this XMLFragmentIllegalArgumentException
- if the given root element is null or emptyMissingDataException
- if the attributes contain objects other
than StringsXMLException
- if the given root element is not a valid XML Name,
or if the given attributes contain duplicate entriesMethod Detail |
public static XMLFragment parseXML(Reader reader) throws XMLException
reader
- the source from where to read the xml structureXMLException
- if the parsing failspublic static XMLFragment parseXML(String string) throws XMLException
string
- the source from where to read the xml structureXMLException
- if the parsing failspublic boolean isValidXMLName(String stringObject)
stringObject
- the String to be validatedtrue
if the given argument is a valid XML Namepublic String getRootName()
public void setNamespaceURI(String namespaceURI)
namespaceURI
- the namespace URI for this XMLFragmentpublic String getNamespaceURI()
public void setQualifiedName(String qName)
qName
- the qualified name for this XMLFragmentpublic String getQualifiedName()
public boolean hasAttributes()
true
if the root element has attributespublic int numberOfAttributes()
public Iterator iterateAttributes()
Iterator
public String getAttribute(String attributeName)
attributeName
- the name of the requested attributepublic void addAttribute(String attributeName, String attributeValue) throws IllegalArgumentException, XMLException
attributeName
- the name of the new attributeattributeValue
- the value of the new attributeIllegalArgumentException
- if the attribute's name is null or emptyXMLException
- if the attribute's name does already existpublic boolean hasChildren()
true
if this XMLFragment has 'children'public int numberOfChildren()
public List listChildrenNames()
public Iterator iterateChildren()
Iterator
public Object getChild(String element) throws IllegalArgumentException
element
- the name of the sub element to returnXMLFragment
objectIllegalArgumentException
- if the given argument is null or emptypublic List getChildren()
List
objectpublic List getChildren(String element) throws IllegalArgumentException
element
- the name of the sub element to returnXMLFragment
objectIllegalArgumentException
- if the given argument is null or emptypublic XMLFragment addChild(String element, String content) throws IllegalArgumentException, XMLException
element
, its content by
content
.
This method is good for adding simple sub elements. If you want to specify more
complex sub elements with attributes and nested childrens, please use the method
addChild(XMLFragment)
instead.element
- the name of the new sub elementcontent
- the content of the new sub elementIllegalArgumentException
- if the given argument is null or emptyXMLException
- if the given element is not a valid XML Namepublic void addChildren(Map elementMapping) throws IllegalArgumentException, XMLException
addChild(XMLFragment)
instead.elementMapping
- a Map
containing element/content mappingsIllegalArgumentException
- if element is null or emptyXMLException
- if the map contains objects other than Stringspublic void addChild(XMLFragment element) throws IllegalArgumentException
element
- the new element to be added to this XMLFragmentIllegalArgumentException
- if the given argument is nullpublic void addContent(String stringContent)
stringContent
- the content of this XMLFragmentpublic String getContent()
public static Map convertToStandardMap(XMLFragment xmlFragment) throws IllegalArgumentException, InvalidArgumentException
xmlFragment
- the XMLFragment to convertIllegalArgumentException
- if the xmlFragment is nullInvalidArgumentException
- if the given xmlFragment
cannot be convertedpublic int compareTo(Object object) throws ClassCastException
compareTo
in interface Comparable
object
- - the Object to be comparedClassCastException
- if the specified object's type prevents it
from being compared to this Objectpublic void clear() throws UnsupportedOperationException
clear
in interface Map
UnsupportedOperationException
- if this method gets invoked (always)public boolean containsKey(Object element)
element
. The passed argument should be a String object.containsKey
in interface Map
element
- the name of a sub elementtrue
if the element is availablepublic boolean containsValue(Object value)
element
. The passed argument should be a XMLFragment object.containsValue
in interface Map
value
- a concrete XMLFragment objecttrue
if the element is availablepublic Set entrySet()
entrySet
in interface Map
Set
public boolean equals(Object object)
equals
in interface Map
equals
in class Object
object
- the object to be compared to this XMLFragmenttrue
if both objects are equalpublic Object get(Object object) throws ProgrammingException
object
.
This method awaits object
to be of type String.
The returned object is either of type XMLFragment
or List
.get
in interface Map
object
- the object to be looked upProgrammingException
- if there is an error in the xml structurepublic boolean isEmpty()
isEmpty
in interface Map
true
if there exist no sub elementspublic Set keySet()
keySet
in interface Map
Set
public Object put(Object element, Object content)
element
and a content of
content
. The method awaits element
to be of type
String.put
in interface Map
element
- the name of the XMLFragment to be added as childcontent
- the content of the new XMLFragmentpublic void putAll(Map map) throws IllegalArgumentException
putAll
in interface Map
map
- a Map containing element/content pairsIllegalArgumentException
- if the given argument is nullput(Object, Object)
public Object remove(Object o) throws UnsupportedOperationException
remove
in interface Map
o
- the object to be removed from this XMLFragmentUnsupportedOperationException
- if this method gets invoked (always)public int size()
size
in interface Map
public Collection values() throws UnsupportedOperationException
values
in interface Map
UnsupportedOperationException
- if this method gets invoked (always)public String toString()
toString
in class Object
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |