Package com.ribs
Class RXElement
- java.lang.Object
-
- com.ribs.RXAttribute
-
- com.ribs.RXElement
-
public class RXElement extends RXAttribute
TheRXElement
class represents an XML element and simply manages a list of XML elements (recursively) and a list of attributes. It also inherrits from RXAttribute to get name and value.For the sake of efficiency, when you need to iterate over a list of elements for a given name, you should do this:
for(int i=anElement.indexOf(elementName); i>=0; i=anElement.indexOf(elementName, i+1)) anElement.get(i).doThis();
Copyright (c) 2004 ReportMill Software, Inc. All Rights Reserved. Contact ReportMill
.
-
-
Constructor Summary
Constructors Modifier Constructor Description RXElement()
Creates a new element.protected
RXElement(java.lang.Object aSource)
Private Constructor which uses XMLLoader inner class to load.RXElement(java.lang.String aName)
Creates a new element with given name.RXElement(java.lang.String aName, java.lang.String aValue)
Creates a new element with given name and value.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(RXAttribute anAttribute)
Adds the given attribute to this element's list of attributes.void
add(java.lang.String aName, boolean aValue)
Adds a new attribute with the given name and boolean value.void
add(java.lang.String aName, float aValue)
Adds a new attribute with the given name and float value.void
add(java.lang.String aName, int aValue)
Adds a new attribute with the given name and int value.void
add(java.lang.String aName, java.lang.Boolean aValue)
Adds a new attribute with the given name and Boolean value.void
add(java.lang.String aName, java.lang.Object aValue)
Adds a new attribute with the given name using the object's toString() method.void
add(java.lang.String aName, java.lang.String aValue)
Adds a new attribute with the given name and string value.RXElement
get(int anIndex)
Returns the specific child element at the given index.RXElement
get(java.lang.String aName)
Returns the first child element with the given name.RXAttribute
getAttribute(int anIndex)
Returns the specific child attribute at the given index.RXAttribute
getAttribute(java.lang.String aName)
Returns the specific child attribute with the given name.java.lang.Boolean
getAttributeBooleanValue(java.lang.String aName)
Returns the Boolean value for the given attribute name.java.lang.Boolean
getAttributeBooleanValue(java.lang.String aName, java.lang.Boolean defaultValue)
Returns the Boolean value for the given attribute name (or the given default value, if name not found).boolean
getAttributeBoolValue(java.lang.String aName)
Returns the boolean value for the given attribute name.boolean
getAttributeBoolValue(java.lang.String aName, boolean defaultValue)
Returns the boolean value for the given attribute name (or the given default value, if name not found).int
getAttributeCount()
Returns the number of child attributes for this element.float
getAttributeFloatValue(java.lang.String aName)
Returns the float value for the given attribute name.float
getAttributeFloatValue(java.lang.String aName, float defaultValue)
Returns the float value for the given attribute name (or the given default value, if name not found).int
getAttributeIntValue(java.lang.String aName)
Returns the int value for the given attribute name.int
getAttributeIntValue(java.lang.String aName, int defaultValue)
Returns the int value for the given attribute name (or the given default value, if name not found).java.lang.Number
getAttributeNumberValue(java.lang.String aName)
Returns the Number value for the given attribute name.java.lang.Number
getAttributeNumberValue(java.lang.String aName, java.lang.Number defaultValue)
Returns the Number value for the given attribute name (or the given default value, if name not found).java.util.List
getAttributes()
Returns the list of child attributes for this element.java.lang.String
getAttributeValue(java.lang.String aName)
Returns the attribute string value for the given attribute name.java.lang.String
getAttributeValue(java.lang.String aName, java.lang.String defaultValue)
Returns the string value for the given attribute name (or the given default value, if name not found).byte[]
getBytes()
Returns XML bytes for this element.static RXElement
getElement(java.lang.Object aSource)
Returns a new element hierarchy loaded from aSource (File, String path, InputStream or whatever).static java.lang.String
getError()
Returns error message from Loading XML (Should really be a ThreadLocal).boolean
hasAttribute(java.lang.String aName)
Checks for presence of an attribute.int
indexOf(java.lang.String aName)
Returns the index of the first child element with the given name.int
indexOf(java.lang.String aName, int startIndex)
Returns the index of the first child element with the given name at or beyond the given index.void
remove(int anIndex)
Removes the child element at the given index.void
remove(RXAttribute attribute)
Removes the given attribute from this elements attributes list.void
remove(java.lang.String aName)
Removes the given attribute or element by name.int
size()
Returns child element list size.int
size(java.lang.String aName)
Returns child element list size for child elements with given name.java.lang.String
toString()
Returns a string representation of this element (XML).void
write(java.lang.Object aDest)
Writes the element as an XML file to the given desination (presumably a String path or File).void
write(java.lang.Object aDest, boolean safely)
Writes the element as an XML file to the given desination (presumably a String path or File).void
write(java.lang.StringBuffer aSB, int indent, java.lang.String indentStr)
Writes the element to the given string buffer using the given indent level and indent string.-
Methods inherited from class com.ribs.RXAttribute
getFloatValue, getIntValue, getName, getNumberValue, getValue, setName, setValue
-
-
-
-
Constructor Detail
-
RXElement
public RXElement()
Creates a new element.
-
RXElement
public RXElement(java.lang.String aName)
Creates a new element with given name.
-
RXElement
public RXElement(java.lang.String aName, java.lang.String aValue)
Creates a new element with given name and value.
-
RXElement
protected RXElement(java.lang.Object aSource)
Private Constructor which uses XMLLoader inner class to load.
-
-
Method Detail
-
getElement
public static RXElement getElement(java.lang.Object aSource)
Returns a new element hierarchy loaded from aSource (File, String path, InputStream or whatever).
-
size
public int size()
Returns child element list size.
-
size
public int size(java.lang.String aName)
Returns child element list size for child elements with given name.
-
get
public RXElement get(int anIndex)
Returns the specific child element at the given index.
-
get
public RXElement get(java.lang.String aName)
Returns the first child element with the given name.
-
indexOf
public int indexOf(java.lang.String aName)
Returns the index of the first child element with the given name.
-
indexOf
public int indexOf(java.lang.String aName, int startIndex)
Returns the index of the first child element with the given name at or beyond the given index.
-
getAttributes
public java.util.List getAttributes()
Returns the list of child attributes for this element.
-
getAttributeCount
public int getAttributeCount()
Returns the number of child attributes for this element.
-
getAttribute
public RXAttribute getAttribute(int anIndex)
Returns the specific child attribute at the given index.
-
getAttribute
public RXAttribute getAttribute(java.lang.String aName)
Returns the specific child attribute with the given name.
-
hasAttribute
public boolean hasAttribute(java.lang.String aName)
Checks for presence of an attribute.
-
getAttributeValue
public java.lang.String getAttributeValue(java.lang.String aName)
Returns the attribute string value for the given attribute name.
-
getAttributeValue
public java.lang.String getAttributeValue(java.lang.String aName, java.lang.String defaultValue)
Returns the string value for the given attribute name (or the given default value, if name not found).
-
getAttributeBoolValue
public boolean getAttributeBoolValue(java.lang.String aName)
Returns the boolean value for the given attribute name.
-
getAttributeBoolValue
public boolean getAttributeBoolValue(java.lang.String aName, boolean defaultValue)
Returns the boolean value for the given attribute name (or the given default value, if name not found).
-
getAttributeBooleanValue
public java.lang.Boolean getAttributeBooleanValue(java.lang.String aName)
Returns the Boolean value for the given attribute name.
-
getAttributeBooleanValue
public java.lang.Boolean getAttributeBooleanValue(java.lang.String aName, java.lang.Boolean defaultValue)
Returns the Boolean value for the given attribute name (or the given default value, if name not found).
-
getAttributeIntValue
public int getAttributeIntValue(java.lang.String aName)
Returns the int value for the given attribute name.
-
getAttributeIntValue
public int getAttributeIntValue(java.lang.String aName, int defaultValue)
Returns the int value for the given attribute name (or the given default value, if name not found).
-
getAttributeFloatValue
public float getAttributeFloatValue(java.lang.String aName)
Returns the float value for the given attribute name.
-
getAttributeFloatValue
public float getAttributeFloatValue(java.lang.String aName, float defaultValue)
Returns the float value for the given attribute name (or the given default value, if name not found).
-
getAttributeNumberValue
public java.lang.Number getAttributeNumberValue(java.lang.String aName)
Returns the Number value for the given attribute name.
-
getAttributeNumberValue
public java.lang.Number getAttributeNumberValue(java.lang.String aName, java.lang.Number defaultValue)
Returns the Number value for the given attribute name (or the given default value, if name not found).
-
add
public void add(RXAttribute anAttribute)
Adds the given attribute to this element's list of attributes.
-
remove
public void remove(int anIndex)
Removes the child element at the given index.
-
remove
public void remove(RXAttribute attribute)
Removes the given attribute from this elements attributes list.
-
remove
public void remove(java.lang.String aName)
Removes the given attribute or element by name.
-
add
public void add(java.lang.String aName, java.lang.String aValue)
Adds a new attribute with the given name and string value.
-
add
public void add(java.lang.String aName, java.lang.Object aValue)
Adds a new attribute with the given name using the object's toString() method.
-
add
public void add(java.lang.String aName, boolean aValue)
Adds a new attribute with the given name and boolean value.
-
add
public void add(java.lang.String aName, java.lang.Boolean aValue)
Adds a new attribute with the given name and Boolean value.
-
add
public void add(java.lang.String aName, int aValue)
Adds a new attribute with the given name and int value.
-
add
public void add(java.lang.String aName, float aValue)
Adds a new attribute with the given name and float value.
-
toString
public java.lang.String toString()
Returns a string representation of this element (XML).- Overrides:
toString
in classRXAttribute
-
getBytes
public byte[] getBytes()
Returns XML bytes for this element.
-
write
public void write(java.lang.Object aDest)
Writes the element as an XML file to the given desination (presumably a String path or File).
-
write
public void write(java.lang.Object aDest, boolean safely)
Writes the element as an XML file to the given desination (presumably a String path or File). If safely is true, it will write to a backup file then move it over.
-
write
public void write(java.lang.StringBuffer aSB, int indent, java.lang.String indentStr)
Writes the element to the given string buffer using the given indent level and indent string.
-
getError
public static java.lang.String getError()
Returns error message from Loading XML (Should really be a ThreadLocal).
-
-