Package com.ribs

Class RXElement


public class RXElement extends RXAttribute
The RXElement 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 <info@reportmill.com>.

  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
     
    Creates a new element.
    protected
    RXElement(Object aSource)
    Private Constructor which uses XMLLoader inner class to load.
     
    Creates a new element with given name.
     
    RXElement(String aName, String aValue)
    Creates a new element with given name and value.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(RXAttribute anAttribute)
    Adds the given attribute to this element's list of attributes.
    void
    add(String aName, boolean aValue)
    Adds a new attribute with the given name and boolean value.
    void
    add(String aName, float aValue)
    Adds a new attribute with the given name and float value.
    void
    add(String aName, int aValue)
    Adds a new attribute with the given name and int value.
    void
    add(String aName, Boolean aValue)
    Adds a new attribute with the given name and Boolean value.
    void
    add(String aName, Object aValue)
    Adds a new attribute with the given name using the object's toString() method.
    void
    add(String aName, String aValue)
    Adds a new attribute with the given name and string value.
    get(int anIndex)
    Returns the specific child element at the given index.
    get(String aName)
    Returns the first child element with the given name.
    getAttribute(int anIndex)
    Returns the specific child attribute at the given index.
    Returns the specific child attribute with the given name.
    Returns the Boolean value for the given attribute name.
    getAttributeBooleanValue(String aName, Boolean defaultValue)
    Returns the Boolean value for the given attribute name (or the given default value, if name not found).
    boolean
    Returns the boolean value for the given attribute name.
    boolean
    getAttributeBoolValue(String aName, boolean defaultValue)
    Returns the boolean value for the given attribute name (or the given default value, if name not found).
    int
    Returns the number of child attributes for this element.
    float
    Returns the float value for the given attribute name.
    float
    getAttributeFloatValue(String aName, float defaultValue)
    Returns the float value for the given attribute name (or the given default value, if name not found).
    int
    Returns the int value for the given attribute name.
    int
    getAttributeIntValue(String aName, int defaultValue)
    Returns the int value for the given attribute name (or the given default value, if name not found).
    Returns the Number value for the given attribute name.
    getAttributeNumberValue(String aName, Number defaultValue)
    Returns the Number value for the given attribute name (or the given default value, if name not found).
    Returns the list of child attributes for this element.
    Returns the attribute string value for the given attribute name.
    getAttributeValue(String aName, String defaultValue)
    Returns the string value for the given attribute name (or the given default value, if name not found).
    byte[]
    Returns XML bytes for this element.
    static RXElement
    getElement(Object aSource)
    Returns a new element hierarchy loaded from aSource (File, String path, InputStream or whatever).
    static String
    Returns error message from Loading XML (Should really be a ThreadLocal).
    boolean
    Checks for presence of an attribute.
    int
    indexOf(String aName)
    Returns the index of the first child element with the given name.
    int
    indexOf(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(String aName)
    Removes the given attribute or element by name.
    int
    Returns child element list size.
    int
    size(String aName)
    Returns child element list size for child elements with given name.
    Returns a string representation of this element (XML).
    void
    write(Object aDest)
    Writes the element as an XML file to the given desination (presumably a String path or File).
    void
    write(Object aDest, boolean safely)
    Writes the element as an XML file to the given desination (presumably a String path or File).
    void
    write(StringBuffer aSB, int indent, 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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • RXElement

      public RXElement()
      Creates a new element.
    • RXElement

      public RXElement(String aName)
      Creates a new element with given name.
    • RXElement

      public RXElement(String aName, String aValue)
      Creates a new element with given name and value.
    • RXElement

      protected RXElement(Object aSource)
      Private Constructor which uses XMLLoader inner class to load.
  • Method Details

    • getElement

      public static RXElement getElement(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(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(String aName)
      Returns the first child element with the given name.
    • indexOf

      public int indexOf(String aName)
      Returns the index of the first child element with the given name.
    • indexOf

      public int indexOf(String aName, int startIndex)
      Returns the index of the first child element with the given name at or beyond the given index.
    • getAttributes

      public 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(String aName)
      Returns the specific child attribute with the given name.
    • hasAttribute

      public boolean hasAttribute(String aName)
      Checks for presence of an attribute.
    • getAttributeValue

      public String getAttributeValue(String aName)
      Returns the attribute string value for the given attribute name.
    • getAttributeValue

      public String getAttributeValue(String aName, String defaultValue)
      Returns the string value for the given attribute name (or the given default value, if name not found).
    • getAttributeBoolValue

      public boolean getAttributeBoolValue(String aName)
      Returns the boolean value for the given attribute name.
    • getAttributeBoolValue

      public boolean getAttributeBoolValue(String aName, boolean defaultValue)
      Returns the boolean value for the given attribute name (or the given default value, if name not found).
    • getAttributeBooleanValue

      public Boolean getAttributeBooleanValue(String aName)
      Returns the Boolean value for the given attribute name.
    • getAttributeBooleanValue

      public Boolean getAttributeBooleanValue(String aName, Boolean defaultValue)
      Returns the Boolean value for the given attribute name (or the given default value, if name not found).
    • getAttributeIntValue

      public int getAttributeIntValue(String aName)
      Returns the int value for the given attribute name.
    • getAttributeIntValue

      public int getAttributeIntValue(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(String aName)
      Returns the float value for the given attribute name.
    • getAttributeFloatValue

      public float getAttributeFloatValue(String aName, float defaultValue)
      Returns the float value for the given attribute name (or the given default value, if name not found).
    • getAttributeNumberValue

      public Number getAttributeNumberValue(String aName)
      Returns the Number value for the given attribute name.
    • getAttributeNumberValue

      public Number getAttributeNumberValue(String aName, 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(String aName)
      Removes the given attribute or element by name.
    • add

      public void add(String aName, String aValue)
      Adds a new attribute with the given name and string value.
    • add

      public void add(String aName, Object aValue)
      Adds a new attribute with the given name using the object's toString() method.
    • add

      public void add(String aName, boolean aValue)
      Adds a new attribute with the given name and boolean value.
    • add

      public void add(String aName, Boolean aValue)
      Adds a new attribute with the given name and Boolean value.
    • add

      public void add(String aName, int aValue)
      Adds a new attribute with the given name and int value.
    • add

      public void add(String aName, float aValue)
      Adds a new attribute with the given name and float value.
    • toString

      public String toString()
      Returns a string representation of this element (XML).
      Overrides:
      toString in class RXAttribute
    • getBytes

      public byte[] getBytes()
      Returns XML bytes for this element.
    • write

      public void write(Object aDest)
      Writes the element as an XML file to the given desination (presumably a String path or File).
    • write

      public void write(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(StringBuffer aSB, int indent, String indentStr)
      Writes the element to the given string buffer using the given indent level and indent string.
    • getError

      public static String getError()
      Returns error message from Loading XML (Should really be a ThreadLocal).