Package tigase.xml

## Class Element

- java.lang.Object
- - tigase.xml.Element

- All Implemented Interfaces:
    `java.lang.Cloneable`, `java.lang.Comparable<Element>`, `XMLNodeIfc<Element>`
  Direct Known Subclasses:
    `DBElement`

      @TODO(note="Make it a bit lighter.")
      public class Element
      extends java.lang.Object
      implements XMLNodeIfc<Element>

  `Element` - basic document tree node implementation. Supports Java 5.0 generic feature to make it easier to extend this class and still preserve some useful functionality. Sufficient for simple cases but probably in the most more advanced cases should be extended with additional features. Look in API documentation for more details and information about existing extensions. The most important features apart from abvious tree implementation are:
  - `toString()` implementation so it can generate valid XML content from this element and all children.
  - `addChild(...)`, `getChild(childName)` supporting generic types.
  - `findChild(childPath)` finding child in subtree by given path to element.
  - `getChildCData(childPath)`, `getAttribute(childPath, attName)` returning element CData from child in subtree by given path to element.

  Created: Mon Oct 4 17:55:16 2004

  Version:
    $Rev$
  Author:
    Artur Hefczyc

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `static interface` | `Element.Matcher<T>` |
    `protected class` | `Element.XMLIdentityHashMap<K,​V>` |

  - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `protected Element.XMLIdentityHashMap<java.lang.String,​java.lang.String>` | `attributes` |
    `protected java.util.LinkedList<XMLNodeIfc>` | `children` |
    `protected java.lang.String` | `defxmlns` |
    `protected java.lang.String` | `name` |
    `protected java.lang.String` | `xmlns` |

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `Element​(java.lang.String argName)` |
    `Element​(java.lang.String argName, java.lang.String argCData)` |
    `Element​(java.lang.String argName, java.lang.String[] att_names, java.lang.String[] att_values)` |
    `Element​(java.lang.String argName, java.lang.String argCData, java.lang.String[] att_names, java.lang.String[] att_values)` |
    `Element​(java.lang.String argName, java.lang.String argCData, java.lang.StringBuilder[] att_names, java.lang.StringBuilder[] att_values)` |
    `Element​(java.lang.String argName, Element[] children, java.lang.String[] att_names, java.lang.String[] att_values)` |
    `Element​(Element element)` |

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `addAttribute​(java.lang.String attName, java.lang.String attValue)` |
    `void` | `addAttributes​(java.util.Map<java.lang.String,​java.lang.String> attrs)` |
    `void` | `addCData​(java.lang.String argCData)` |
    `void` | `addChild​(XMLNodeIfc child)` |
    `void` | `addChildren​(java.util.List<Element> children)` |
    `protected java.lang.String` | `cdataToString()` |
    `java.lang.String` | `childrenToString()` |
    `void` | `childrenToString​(java.lang.StringBuilder result)` |
    `java.lang.String` | `childrenToStringPretty()` |
    `java.lang.String` | `childrenToStringSecure()` |
    `void` | `childrenToStringSecure​(java.lang.StringBuilder result)` |
    `Element` | `clone()` |
    `int` | `compareTo​(Element elem)` |
    `boolean` | `equals​(java.lang.Object obj)` |
    `Element` | `findChild​(java.lang.String elementPath)` | Deprecated. use `findChild(java.lang.String[])` instead.
    `Element` | `findChild​(java.lang.String[] elemPath)` |
    `Element` | `findChild​(Element.Matcher<Element> matcher)` |
    `java.util.List<Element>` | `findChildren​(Element.Matcher<Element> matcher)` |
    `Element` | `findChildStaticStr​(java.lang.String[] elementPath)` |
    `<R> java.util.List<R>` | `flatMapChildren​(java.util.function.Function<Element,​java.util.Collection<? extends R>> mapper)` |
    `void` | `forEachChild​(java.util.function.Consumer<Element> consumer)` |
    `java.lang.String` | `getAttribute​(java.lang.String attName)` | Deprecated. use `getAttributeStaticStr(java.lang.String)` instead.
    `java.lang.String` | `getAttribute​(java.lang.String[] elementPath, java.lang.String att_name)` | Deprecated. `getAttributeStaticStr(java.lang.String[], java.lang.String)` instead.
    `java.lang.String` | `getAttribute​(java.lang.String elementPath, java.lang.String att_name)` | Deprecated. use `getAttributeStaticStr(java.lang.String[], java.lang.String)` instead.
    `java.util.Map<java.lang.String,​java.lang.String>` | `getAttributes()` |
    `java.lang.String` | `getAttributeStaticStr​(java.lang.String attName)` |
    `java.lang.String` | `getAttributeStaticStr​(java.lang.String[] elementPath, java.lang.String att_name)` |
    `java.lang.String` | `getCData()` |
    `java.lang.String` | `getCData​(java.lang.String elementPath)` | Deprecated. use `getCData(java.lang.String[])` instead.
    `java.lang.String` | `getCData​(java.lang.String[] elementPath)` |
    `java.lang.String` | `getCDataStaticStr​(java.lang.String[] elementPath)` |
    `Element` | `getChild​(java.lang.String name)` |
    `Element` | `getChild​(java.lang.String name, java.lang.String child_xmlns)` |
    `java.lang.String` | `getChildAttribute​(java.lang.String childName, java.lang.String attName)` | Deprecated. use `getChildAttributeStaticStr(java.lang.String, java.lang.String)` instead.
    `java.lang.String` | `getChildAttributeStaticStr​(java.lang.String childName, java.lang.String attName)` |
    `java.lang.String` | `getChildCData​(java.lang.String elementPath)` | Deprecated. use `getCData(java.lang.String[])` instead.
    `java.lang.String` | `getChildCData​(java.lang.String[] elementPath)` |
    `java.lang.String` | `getChildCData​(Element.Matcher<Element> matcher)` |
    `java.lang.String` | `getChildCDataStaticStr​(java.lang.String[] elementPath)` |
    `java.util.List<Element>` | `getChildren()` |
    `java.util.List<Element>` | `getChildren​(java.lang.String elementPath)` | Deprecated. use `getChildren(java.lang.String[])` instead.
    `java.util.List<Element>` | `getChildren​(java.lang.String[] elementPath)` |
    `java.util.List<Element>` | `getChildren​(Element.Matcher<Element> matcher)` |
    `java.util.List<Element>` | `getChildrenStaticStr​(java.lang.String[] elementPath)` |
    `Element` | `getChildStaticStr​(java.lang.String name)` |
    `Element` | `getChildStaticStr​(java.lang.String name, java.lang.String child_xmlns)` |
    `java.lang.String` | `getName()` |
    `java.lang.String` | `getXMLNS()` |
    `java.lang.String` | `getXMLNS​(java.lang.String elementPath)` | Deprecated. use `getXMLNS(java.lang.String[])` instead.
    `java.lang.String` | `getXMLNS​(java.lang.String[] elementPath)` |
    `java.lang.String` | `getXMLNSStaticStr​(java.lang.String[] elementPath)` |
    `int` | `hashCode()` |
    `static void` | `main​(java.lang.String[] args)` |
    `<R> R` | `map​(java.util.function.Function<Element,​? extends R> mapper)` |
    `<R> java.util.List<R>` | `mapChildren​(java.util.function.Function<Element,​? extends R> mapper)` |
    `<R> java.util.List<R>` | `mapChildren​(Element.Matcher<Element> matcher, java.util.function.Function<Element,​? extends R> mapper)` |
    `boolean` | `matches​(Element.Matcher<Element> matcher)` |
    `void` | `removeAttribute​(java.lang.String key)` |
    `boolean` | `removeChild​(Element child)` |
    `void` | `setAttribute​(java.lang.String key, java.lang.String value)` |
    `void` | `setAttributes​(java.lang.String[] names, java.lang.String[] values)` |
    `void` | `setAttributes​(java.lang.StringBuilder[] names, java.lang.StringBuilder[] values)` |
    `void` | `setAttributes​(java.util.Map<java.lang.String,​java.lang.String> newAttributes)` |
    `void` | `setAttributeStaticStr​(java.lang.String[] elementPath, java.lang.String att_name, java.lang.String att_value)` |
    `void` | `setCData​(java.lang.String argCData)` |
    `void` | `setChildren​(java.util.List<XMLNodeIfc> children)` |
    `void` | `setDefXMLNS​(java.lang.String ns)` |
    `void` | `setName​(java.lang.String argName)` |
    `void` | `setXMLNS​(java.lang.String ns)` |
    `java.lang.String` | `toString()` |
    `void` | `toString​(java.lang.StringBuilder result)` |
    `java.lang.String` | `toStringNoChildren()` |
    `java.lang.String` | `toStringPretty()` |
    `java.lang.String` | `toStringSecure()` |
    `void` | `toStringSecure​(java.lang.StringBuilder result)` |
    `Element` | `withAttribute​(java.lang.String attName, java.lang.String attValue)` |
    `Element` | `withElement​(java.lang.String name, java.lang.String xmlns, java.lang.String cdata)` |
    `Element` | `withElement​(java.lang.String name, java.lang.String xmlns, java.util.function.Consumer<Element> consumer)` |
    `Element` | `withElement​(java.lang.String name, java.util.function.Consumer<Element> consumer)` |

    - ### Methods inherited from class java.lang.Object

      `finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### attributes

          protected Element.XMLIdentityHashMap<java.lang.String,​java.lang.String> attributes

    - #### children

          protected java.util.LinkedList<XMLNodeIfc> children

    - #### defxmlns

          protected java.lang.String defxmlns

    - #### name

          protected java.lang.String name

    - #### xmlns

          protected java.lang.String xmlns

  - ### Constructor Detail

    - #### Element

          public Element​(Element element)

    - #### Element

          public Element​(java.lang.String argName)

    - #### Element

          public Element​(java.lang.String argName,
                         java.lang.String argCData)

    - #### Element

          public Element​(java.lang.String argName,
                         java.lang.String[] att_names,
                         java.lang.String[] att_values)

    - #### Element

          public Element​(java.lang.String argName,
                         Element[] children,
                         java.lang.String[] att_names,
                         java.lang.String[] att_values)

    - #### Element

          public Element​(java.lang.String argName,
                         java.lang.String argCData,
                         java.lang.String[] att_names,
                         java.lang.String[] att_values)

    - #### Element

          public Element​(java.lang.String argName,
                         java.lang.String argCData,
                         java.lang.StringBuilder[] att_names,
                         java.lang.StringBuilder[] att_values)

  - ### Method Detail

    - #### main

          public static void main​(java.lang.String[] args)
                           throws java.lang.Exception

      Throws:
        `java.lang.Exception`

    - #### addAttribute

          public void addAttribute​(java.lang.String attName,
                                   java.lang.String attValue)

    - #### addAttributes

          public void addAttributes​(java.util.Map<java.lang.String,​java.lang.String> attrs)

    - #### addCData

          public void addCData​(java.lang.String argCData)

    - #### addChild

          public void addChild​(XMLNodeIfc child)

    - #### addChildren

          public void addChildren​(java.util.List<Element> children)

    - #### childrenToString

          public java.lang.String childrenToString()

    - #### childrenToString

          public void childrenToString​(java.lang.StringBuilder result)

    - #### childrenToStringPretty

          public java.lang.String childrenToStringPretty()

    - #### childrenToStringSecure

          public java.lang.String childrenToStringSecure()

    - #### childrenToStringSecure

          public void childrenToStringSecure​(java.lang.StringBuilder result)

    - #### clone

          public Element clone()

      Specified by:
        `clone` in interface `XMLNodeIfc<Element>`
      Overrides:
        `clone` in class `java.lang.Object`

    - #### compareTo

          public int compareTo​(Element elem)

      Specified by:
        `compareTo` in interface `java.lang.Comparable<Element>`

    - #### equals

          public boolean equals​(java.lang.Object obj)

      Overrides:
        `equals` in class `java.lang.Object`

    - #### findChildStaticStr

          public Element findChildStaticStr​(java.lang.String[] elementPath)

    - #### findChild

          public Element findChild​(java.lang.String[] elemPath)

    - #### findChild

          @Deprecated
          public Element findChild​(java.lang.String elementPath)

      Deprecated.
      use `findChild(java.lang.String[])` instead.

    - #### findChild

          public Element findChild​(Element.Matcher<Element> matcher)

    - #### findChildren

          public java.util.List<Element> findChildren​(Element.Matcher<Element> matcher)

    - #### flatMapChildren

          public <R> java.util.List<R> flatMapChildren​(java.util.function.Function<Element,​java.util.Collection<? extends R>> mapper)

    - #### forEachChild

          public void forEachChild​(java.util.function.Consumer<Element> consumer)

    - #### getAttribute

          @Deprecated
          public java.lang.String getAttribute​(java.lang.String attName)

      Deprecated.
      use `getAttributeStaticStr(java.lang.String)` instead.

    - #### getChildAttribute

          @Deprecated
          public java.lang.String getChildAttribute​(java.lang.String childName,
                                                    java.lang.String attName)

      Deprecated.
      use `getChildAttributeStaticStr(java.lang.String, java.lang.String)` instead.

    - #### getChildAttributeStaticStr

          public java.lang.String getChildAttributeStaticStr​(java.lang.String childName,
                                                             java.lang.String attName)

    - #### getAttributeStaticStr

          public java.lang.String getAttributeStaticStr​(java.lang.String attName)

    - #### getAttribute

          @Deprecated
          public java.lang.String getAttribute​(java.lang.String elementPath,
                                               java.lang.String att_name)

      Deprecated.
      use `getAttributeStaticStr(java.lang.String[], java.lang.String)` instead.

    - #### getAttribute

          @Deprecated
          public java.lang.String getAttribute​(java.lang.String[] elementPath,
                                               java.lang.String att_name)

      Deprecated.
      `getAttributeStaticStr(java.lang.String[], java.lang.String)` instead.

    - #### getAttributeStaticStr

          public java.lang.String getAttributeStaticStr​(java.lang.String[] elementPath,
                                                        java.lang.String att_name)

    - #### getAttributes

          public java.util.Map<java.lang.String,​java.lang.String> getAttributes()

    - #### setAttributes

          public void setAttributes​(java.util.Map<java.lang.String,​java.lang.String> newAttributes)

    - #### getCData

          @Deprecated
          public java.lang.String getCData​(java.lang.String elementPath)

      Deprecated.
      use `getCData(java.lang.String[])` instead.

    - #### getCData

          public java.lang.String getCData​(java.lang.String[] elementPath)

    - #### getCDataStaticStr

          public java.lang.String getCDataStaticStr​(java.lang.String[] elementPath)

    - #### getCData

          public java.lang.String getCData()

    - #### setCData

          public void setCData​(java.lang.String argCData)

    - #### getChild

          public Element getChild​(java.lang.String name)

    - #### getChildStaticStr

          public Element getChildStaticStr​(java.lang.String name)

    - #### getChild

          public Element getChild​(java.lang.String name,
                                  java.lang.String child_xmlns)

    - #### getChildStaticStr

          public Element getChildStaticStr​(java.lang.String name,
                                           java.lang.String child_xmlns)

    - #### getChildCData

          @Deprecated
          public java.lang.String getChildCData​(java.lang.String elementPath)

      Deprecated.
      use `getCData(java.lang.String[])` instead.

    - #### getChildCData

          public java.lang.String getChildCData​(java.lang.String[] elementPath)

    - #### getChildCDataStaticStr

          public java.lang.String getChildCDataStaticStr​(java.lang.String[] elementPath)

    - #### getChildCData

          public java.lang.String getChildCData​(Element.Matcher<Element> matcher)

    - #### getChildren

          public java.util.List<Element> getChildren()

    - #### setChildren

          public void setChildren​(java.util.List<XMLNodeIfc> children)

    - #### getChildren

          @Deprecated
          public java.util.List<Element> getChildren​(java.lang.String elementPath)

      Deprecated.
      use `getChildren(java.lang.String[])` instead.

    - #### getChildren

          public java.util.List<Element> getChildren​(java.lang.String[] elementPath)

    - #### getChildrenStaticStr

          public java.util.List<Element> getChildrenStaticStr​(java.lang.String[] elementPath)

    - #### getChildren

          public java.util.List<Element> getChildren​(Element.Matcher<Element> matcher)

    - #### getName

          public java.lang.String getName()

    - #### setName

          public void setName​(java.lang.String argName)

    - #### getXMLNS

          public java.lang.String getXMLNS()

    - #### setXMLNS

          public void setXMLNS​(java.lang.String ns)

    - #### getXMLNS

          @Deprecated
          public java.lang.String getXMLNS​(java.lang.String elementPath)

      Deprecated.
      use `getXMLNS(java.lang.String[])` instead.

    - #### getXMLNS

          public java.lang.String getXMLNS​(java.lang.String[] elementPath)

    - #### getXMLNSStaticStr

          public java.lang.String getXMLNSStaticStr​(java.lang.String[] elementPath)

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `java.lang.Object`

    - #### map

          public <R> R map​(java.util.function.Function<Element,​? extends R> mapper)

    - #### mapChildren

          public <R> java.util.List<R> mapChildren​(java.util.function.Function<Element,​? extends R> mapper)

    - #### mapChildren

          public <R> java.util.List<R> mapChildren​(Element.Matcher<Element> matcher,
                                                   java.util.function.Function<Element,​? extends R> mapper)

    - #### matches

          public boolean matches​(Element.Matcher<Element> matcher)

    - #### removeAttribute

          public void removeAttribute​(java.lang.String key)

    - #### removeChild

          public boolean removeChild​(Element child)

    - #### setAttributeStaticStr

          public void setAttributeStaticStr​(java.lang.String[] elementPath,
                                            java.lang.String att_name,
                                            java.lang.String att_value)

    - #### setAttribute

          public void setAttribute​(java.lang.String key,
                                   java.lang.String value)

    - #### setAttributes

          public void setAttributes​(java.lang.StringBuilder[] names,
                                    java.lang.StringBuilder[] values)

    - #### setAttributes

          public void setAttributes​(java.lang.String[] names,
                                    java.lang.String[] values)

    - #### setDefXMLNS

          public void setDefXMLNS​(java.lang.String ns)

    - #### toString

          public java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.Object`

    - #### toString

          public void toString​(java.lang.StringBuilder result)

    - #### toStringPretty

          public java.lang.String toStringPretty()

      Specified by:
        `toStringPretty` in interface `XMLNodeIfc<Element>`

    - #### toStringNoChildren

          public java.lang.String toStringNoChildren()

    - #### toStringSecure

          public java.lang.String toStringSecure()

      Specified by:
        `toStringSecure` in interface `XMLNodeIfc<Element>`

    - #### toStringSecure

          public void toStringSecure​(java.lang.StringBuilder result)

    - #### withAttribute

          public Element withAttribute​(java.lang.String attName,
                                       java.lang.String attValue)

    - #### withElement

          public Element withElement​(java.lang.String name,
                                     java.util.function.Consumer<Element> consumer)

    - #### withElement

          public Element withElement​(java.lang.String name,
                                     java.lang.String xmlns,
                                     java.lang.String cdata)

    - #### withElement

          public Element withElement​(java.lang.String name,
                                     java.lang.String xmlns,
                                     java.util.function.Consumer<Element> consumer)

    - #### cdataToString

          protected java.lang.String cdataToString()