Package tigase.xml
Class Element
java.lang.Object
tigase.xml.Element
- All Implemented Interfaces:
Cloneable,XMLNodeIfc<Element>
- Direct Known Subclasses:
DBElement
@TODO(note="Make it a bit lighter.")
public class Element
extends 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
more advanced cases should be extended with additional features. Look in API documentation for more details and
information about existing extensions.
Created: Mon Oct 4 17:55:16 2004
- Author:
- Artur Hefczyc
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static BiFunction<String, String, String> protected static BiFunction<String, String, String> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription@NonNull ElementAdd CData node with passed value@NonNull ElementAdd element as a child.@NonNull ElementaddChildren(@NonNull List<Element> children) Add childrenMethod returns joined CData valuesclone()<R> @NotNull List<R> compactMapChildren(@NonNull Function<Element, ? extends R> mapper) Method applies function against each child of the element and returns list of non-null return values<R> @NotNull List<R> compactMapChildren(@Nullable Predicate<Element> predicate, @NonNull Function<Element, ? extends R> mapper) Method applies function against each child of the element and returns list of non-null return valuesbooleanMethods checks equality of instances of `Element` excluding list of children@Nullable ElementMethod returns first child which name matches@Nullable ElementMethod returns first child which matches name and xmlns@Nullable ElementMethod returns first child which matches predicate@Nullable ElementfindChildAt(@NonNull Predicate<Element> predicate, @NonNull Predicate<Element>... path) Method returns first element which matches path@Nullable ElementfindChildAt(@NonNull Path path) Method returns first element which matches pathfindChildren(@NonNull Predicate<Element> predicate) Method returns list of children matching predicatefindChildrenAt(@NonNull Path path) Method returns list of children matching pathvoidforEachChild(@NonNull Predicate<Element> predicate, Consumer<Element> consumer) voidforEachChild(Consumer<Element> consumer) @Nullable StringgetAttribute(String name) Method returns value of the attribute@Nullable StringgetAttributeAt(Path path, String name) Method returns value of the attribute of the first element matching pathMethod returns copy of all attributes@Nullable StringgetCData()Method returns CData value of the element@Nullable StringgetCDataAt(@NonNull Path path) Method returns CData value of the first element matching pathMethod returns list of all children@NonNull StringgetName()Method returns name of the element@Nullable StringgetXMLNS()Method returns XMLNS of the elementbooleanhasAttribute(@NonNull String name) Method check if attribute is setbooleanhasAttribute(@NonNull String name, @NonNull String value) Method check if attribute is set to the valueinthashCode()<R> @Nullable RMethod executes function passing self as a parameter and returns its result<R> RMethod transforms first child element matching predicate<R> @NonNull List<R> mapChildren(@NonNull Function<Element, ? extends R> mapper) Method applies function against each child of the element and returns list results<R> @NonNull List<R> mapChildren(@NonNull Predicate<Element> predicate, @NonNull Function<Element, ? extends R> mapper) Method applies function against each child of the element and returns list resultsbooleanMethod test if this element matches predicate@NonNull ElementMethod executes consumer passing self as a parameter Useful for conditional building of element in the single linevoidnodesToString(@NonNull StringBuilder result) Serialize subnodes to passed buildervoidnodesToStringPretty(@NonNull StringBuilder result) Serialize subnodes as a formatted stringvoidnodesToStringSecure(@NonNull StringBuilder result) Serialize subnodes to passed builder as a secure stringvoidremoveAttribute(@NonNull String name) Method removes attributebooleanremoveChild(@NonNull String name, @NonNull String xmlns) Method removes first child with matching name and xmlnsbooleanremoveChild(@NonNull Predicate<Element> predicate) Method removes first child matching predicatebooleanremoveChild(@NonNull Element child) Method removes child instance@NonNull ElementsetAttribute(@NonNull String name, @NonNull String value) Method sets attribute value@NonNull ElementsetAttributes(@NonNull Map<String, String> attributes) Method replaces all attributes with name-value pairs provided in the map@NonNull ElementMethod sets CData of the element.@NonNull ElementsetChildren(@NonNull List<XMLNodeIfc> nodes) Method replaces all nodes (children and cdata) with passed list of children@NonNull ElementMethod sets XMLNS of the elementtoString()voidtoString(StringBuilder result) Method serializes element to passed buildMethod serializes element without childrenMethod serializes element to formatted stringMethod serializes element to a secure stringvoidtoStringSecure(StringBuilder result) Method serializes element as a secure string to passed builder
-
Field Details
-
elementNameDeduplicationFn
-
attributesDeduplicationFn
-
-
Constructor Details
-
Element
Shallow cloning constructor. Will create a copy of the element (name, attributes and list of subnodes) but it will not create copy of children - the same instances will be added to the new copy). -
Element
Constructor creating element with a name
-
-
Method Details
-
addCData
Add CData node with passed value- Returns:
- this element
-
addChild
Add element as a child.- Returns:
- this element
-
addChildren
Add children- Returns:
- this element
-
nodesToString
Serialize subnodes to passed builder -
nodesToStringPretty
Serialize subnodes as a formatted string -
nodesToStringSecure
Serialize subnodes to passed builder as a secure string -
clone
- Specified by:
clonein interfaceXMLNodeIfc<Element>- Overrides:
clonein classObject
-
equals
Methods checks equality of instances of `Element` excluding list of children -
findChild
Method returns first child which matches predicate -
findChild
Method returns first child which name matches -
findChild
Method returns first child which matches name and xmlns -
findChildAt
Method returns first element which matches path -
findChildAt
public @Nullable Element findChildAt(@NonNull Predicate<Element> predicate, @NonNull Predicate<Element>... path) Method returns first element which matches path -
findChildren
Method returns list of children matching predicate -
findChildrenAt
Method returns list of children matching path -
getAttribute
Method returns value of the attribute -
getAttributeAt
Method returns value of the attribute of the first element matching path -
getAttributes
Method returns copy of all attributes -
setAttributes
Method replaces all attributes with name-value pairs provided in the map- Returns:
- this element
-
getCData
Method returns CData value of the element -
getCDataAt
Method returns CData value of the first element matching path -
setCData
Method sets CData of the element. WARNING: This method replaces existing CData and removes children of the element! -
getChildren
Method returns list of all children -
setChildren
Method replaces all nodes (children and cdata) with passed list of children- Returns:
- this element
-
getName
Method returns name of the element -
getXMLNS
Method returns XMLNS of the element -
setXMLNS
Method sets XMLNS of the element- Returns:
- this element
-
hashCode
public int hashCode() -
map
Method executes function passing self as a parameter and returns its result -
modify
Method executes consumer passing self as a parameter Useful for conditional building of element in the single line- Returns:
- this element
-
mapChild
Method transforms first child element matching predicate -
mapChildren
Method applies function against each child of the element and returns list results -
mapChildren
public <R> @NonNull List<R> mapChildren(@NonNull Predicate<Element> predicate, @NonNull Function<Element, ? extends R> mapper) Method applies function against each child of the element and returns list results -
compactMapChildren
@NotNull public <R> @NotNull List<R> compactMapChildren(@NonNull Function<Element, ? extends R> mapper) Method applies function against each child of the element and returns list of non-null return values -
compactMapChildren
@NotNull public <R> @NotNull List<R> compactMapChildren(@Nullable Predicate<Element> predicate, @NonNull Function<Element, ? extends R> mapper) Method applies function against each child of the element and returns list of non-null return values -
forEachChild
-
forEachChild
-
matches
Method test if this element matches predicate -
removeAttribute
Method removes attribute -
removeChild
Method removes child instance- Returns:
- true - if child was removed
-
removeChild
Method removes first child with matching name and xmlns- Returns:
- true - if child was removed
-
removeChild
Method removes first child matching predicate- Returns:
- true - if child was removed
-
hasAttribute
Method check if attribute is set -
hasAttribute
Method check if attribute is set to the value -
setAttribute
Method sets attribute value- Returns:
- this element
-
toString
-
toString
Method serializes element to passed build -
toStringPretty
Method serializes element to formatted string- Specified by:
toStringPrettyin interfaceXMLNodeIfc<Element>
-
toStringNoChildren
Method serializes element without children -
toStringSecure
Method serializes element to a secure string- Specified by:
toStringSecurein interfaceXMLNodeIfc<Element>
-
toStringSecure
Method serializes element as a secure string to passed builder -
cdataToString
Method returns joined CData values
-