Package com.helger.xml.microdom
Class MicroElement
- java.lang.Object
-
- com.helger.xml.microdom.AbstractMicroNode
-
- com.helger.xml.microdom.AbstractMicroNodeWithChildren
-
- com.helger.xml.microdom.MicroElement
-
- All Implemented Interfaces:
com.helger.commons.hierarchy.IHasChildren<IMicroNode>,com.helger.commons.hierarchy.IHasChildrenRecursive<IMicroNode>,com.helger.commons.hierarchy.IHasChildrenSorted<IMicroNode>,com.helger.commons.hierarchy.IHasParent<IMicroNode>,com.helger.commons.lang.ICloneable<IMicroNode>,IMicroAttributeContainer<IMicroElement>,IMicroElement,IMicroNode,IMicroNodeWithChildren,Serializable
public final class MicroElement extends AbstractMicroNodeWithChildren implements IMicroElement
Default implementation of theIMicroElementinterface.- Author:
- Philip Helger
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description MicroElement(String sTagName)MicroElement(String sNamespaceURI, String sTagName)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontainsAnyChildElement(Predicate<? super IMicroElement> aFilter)Check if this element has at least one direct child element that matches the provided filter.voidforAllAttributes(com.helger.commons.functional.ITriConsumer<? super String,? super String,? super String> aConsumer)Iterate all attribute objects.voidforAllAttributes(BiConsumer<? super IMicroQName,? super String> aConsumer)Iterate all attribute objects.voidforAllAttributes(Consumer<? super IMicroAttribute> aConsumer)Iterate all attribute objects.voidforAllChildElements(Predicate<? super IMicroElement> aFilter, Consumer<? super IMicroElement> aConsumer)com.helger.commons.state.EContinueforAllChildElementsBreakable(Predicate<? super IMicroElement> aFilter, Function<? super IMicroElement,com.helger.commons.state.EContinue> aConsumer)com.helger.commons.collection.impl.ICommonsList<MicroAttribute>getAllAttributeObjs()Get a list of all attributes.com.helger.commons.collection.impl.ICommonsOrderedSet<IMicroQName>getAllAttributeQNames()Get a set of all attribute names.com.helger.commons.collection.impl.ICommonsList<IMicroElement>getAllChildElementsRecursive()Recursively get all child elements.com.helger.commons.collection.impl.ICommonsOrderedMap<IMicroQName,String>getAllQAttributes()Get a map of all fully qualified attribute names and values.intgetAttributeCount()MicroAttributegetAttributeObj(IMicroQName aQName)Get the attribute object with the specified qualified name.Iterable<MicroAttribute>getAttributeObjs()Get a iterable objects of all attributes.<DSTTYPE> DSTTYPEgetAttributeValueWithConversion(IMicroQName aAttrName, Class<DSTTYPE> aDstClass)Get the attribute value of the given attribute name.IMicroElementgetClone()IMicroElementgetFirstChildElement(Predicate<? super IMicroElement> aFilter)StringgetLocalName()Get the local name of the element.StringgetNamespaceURI()Get the namespace URI of this elementStringgetNodeName()StringgetTagName()Get the name of the tag.EMicroNodeTypegetType()booleanhasAttribute(IMicroQName aAttrName)Check if this element has an attribute with the specified name.booleanhasAttributes()booleanhasNoAttributes()booleanisEqualContent(IMicroNode o)As instances of this class may not implement equals/hashCode we need a way to determine, if 2 nodes are equal by content.com.helger.commons.state.EChangeremoveAllAttributes()Remove all attributes from this elementcom.helger.commons.state.EChangeremoveAttribute(IMicroQName aAttrName)Remove the attribute with the given name.MicroElementsetAttribute(IMicroQName aAttrName, String sAttrValue)Set an attribute value of this element.com.helger.commons.state.EChangesetNamespaceURI(String sNamespaceURI)Set a new namespace URI for this element.StringtoString()-
Methods inherited from class com.helger.xml.microdom.AbstractMicroNodeWithChildren
containsAnyChild, directGetAllChildren, findFirstChild, findFirstChildMapped, forAllChildren, forAllChildren, forAllChildrenBreakable, forAllChildrenMapped, getAllChildren, getChildAtIndex, getChildCount, getChildren, getFirstChild, getLastChild, getTextContent, getTextContentWithConversion, hasChildren, onAppendChild, onInsertAfter, onInsertAtIndex, onInsertBefore, onRemoveAllChildren, onRemoveChild, onRemoveChildAtIndex
-
Methods inherited from class com.helger.xml.microdom.AbstractMicroNode
appendChild, detachFromParent, findParentElement, getAllEventTargets, getAllEventTargets, getNextSibling, getParent, getPreviousSibling, hasParent, insertAfter, insertAtIndex, insertBefore, internalResetParentNode, internalSetParentNode, internalTriggerEvent, isCDATA, isComment, isContainer, isDocument, isDocumentType, isElement, isEntityReference, isProcessingInstruction, isText, onEvent, registerEventTarget, removeAllChildren, removeChild, removeChildAtIndex, unregisterEventTarget
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.helger.commons.hierarchy.IHasChildren
forAllChildren, forAllChildren, forAllChildrenBreakable, forAllChildrenMapped, getChildCount, getChildren, hasChildren, hasNoChildren
-
Methods inherited from interface com.helger.commons.hierarchy.IHasChildrenRecursive
forAllChildrenRecursive, forAllChildrenRecursive
-
Methods inherited from interface com.helger.commons.hierarchy.IHasChildrenSorted
findFirstChild, findFirstChildMapped, getChildAtIndex
-
Methods inherited from interface com.helger.xml.microdom.IMicroAttributeContainer
getAttributeObj, getAttributeObj, getAttributeValue, getAttributeValue, getAttributeValue, getAttributeValueAsBool, getAttributeValueAsBool, getAttributeValueAsBool, getAttributeValueAsDouble, getAttributeValueAsDouble, getAttributeValueAsDouble, getAttributeValueAsFloat, getAttributeValueAsFloat, getAttributeValueAsFloat, getAttributeValueAsInt, getAttributeValueAsInt, getAttributeValueAsInt, getAttributeValueAsLong, getAttributeValueAsLong, getAttributeValueAsLong, getAttributeValueWithConversion, getAttributeValueWithConversion, hasAttribute, hasAttribute, removeAttribute, removeAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttributeWithConversion, setAttributeWithConversion, setAttributeWithConversion, setAttributeWithConversion, setAttributeWithConversion, setAttributeWithConversion
-
Methods inherited from interface com.helger.xml.microdom.IMicroElement
forAllChildElements, forAllChildElementsBreakable, getAllChildElements, getAllChildElements, getAllChildElements, getAllChildElements, getChildElementCount, getChildElementCount, getFirstChildElement, getFirstChildElement, getFirstChildElement, hasChildElements, hasChildElements, hasChildElements, hasLocalName, hasNamespaceURI, hasNamespaceURI, hasNoNamespaceURI, hasTagName, hasTagNameIgnoreCase
-
Methods inherited from interface com.helger.xml.microdom.IMicroNode
appendCDATA, appendCDATA, appendCDATA, appendCDATAWithConversion, appendChild, appendChildren, appendChildren, appendComment, appendComment, appendComment, appendCommentWithConversion, appendContainer, appendElement, appendElement, appendEntityReference, appendIgnorableWhitespaceText, appendIgnorableWhitespaceText, appendIgnorableWhitespaceText, appendProcessingInstruction, appendText, appendText, appendText, appendTextWithConversion, containsAnyChild, detachFromParent, findParentElement, getAllChildren, getAllChildrenRecursive, getAllEventTargets, getAllEventTargets, getFirstChild, getLastChild, getNextSibling, getNodeValue, getParent, getParentElementWithName, getParentElementWithName, getPreviousSibling, hasParent, insertAfter, insertAtIndex, insertBefore, isCDATA, isComment, isContainer, isDocument, isDocumentType, isElement, isEntityReference, isProcessingInstruction, isText, registerEventTarget, removeAllChildren, removeChild, removeChildAtIndex, replaceChild, unregisterEventTarget
-
Methods inherited from interface com.helger.xml.microdom.IMicroNodeWithChildren
getTextContent, getTextContentTrimmed, getTextContentWithConversion
-
-
-
-
Method Detail
-
getType
@Nonnull public EMicroNodeType getType()
- Specified by:
getTypein interfaceIMicroNode- Returns:
- The node type. Never
null.
-
getNodeName
@Nonnull @Nonempty public String getNodeName()
- Specified by:
getNodeNamein interfaceIMicroNode- Returns:
- Just an abstract name that depends on the implementing class. For
IMicroElementnodes this is the same as the tag name.
-
hasAttributes
public boolean hasAttributes()
- Specified by:
hasAttributesin interfaceIMicroAttributeContainer<IMicroElement>- Returns:
trueif this element has at least one attribute,falseotherwise
-
hasNoAttributes
public boolean hasNoAttributes()
- Specified by:
hasNoAttributesin interfaceIMicroAttributeContainer<IMicroElement>- Returns:
trueif this element has no attribute,falseif at least one attribute is present.
-
getAttributeCount
@Nonnegative public int getAttributeCount()
- Specified by:
getAttributeCountin interfaceIMicroAttributeContainer<IMicroElement>- Returns:
- The number of assigned attributes. Always ≥ 0.
-
getAttributeObjs
@Nullable @ReturnsImmutableObject public Iterable<MicroAttribute> getAttributeObjs()
Description copied from interface:IMicroAttributeContainerGet a iterable objects of all attributes. Is ensured to be notnullifIMicroAttributeContainer.hasAttributes()returnstrue.- Specified by:
getAttributeObjsin interfaceIMicroAttributeContainer<IMicroElement>- Returns:
- May be
null.
-
getAllAttributeObjs
@Nullable @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<MicroAttribute> getAllAttributeObjs()
Description copied from interface:IMicroAttributeContainerGet a list of all attributes. Is ensured to be notnullifIMicroAttributeContainer.hasAttributes()returnstrue.- Specified by:
getAllAttributeObjsin interfaceIMicroAttributeContainer<IMicroElement>- Returns:
- May be
null.
-
getAllQAttributes
@Nullable @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsOrderedMap<IMicroQName,String> getAllQAttributes()
Description copied from interface:IMicroAttributeContainerGet a map of all fully qualified attribute names and values. Is ensured to be notnullifIMicroAttributeContainer.hasAttributes()returnstrue.- Specified by:
getAllQAttributesin interfaceIMicroAttributeContainer<IMicroElement>- Returns:
- May be
null.
-
getAllAttributeQNames
@Nullable @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsOrderedSet<IMicroQName> getAllAttributeQNames()
Description copied from interface:IMicroAttributeContainerGet a set of all attribute names. Is ensured to be notnullifIMicroAttributeContainer.hasAttributes()returnstrue.- Specified by:
getAllAttributeQNamesin interfaceIMicroAttributeContainer<IMicroElement>- Returns:
- May be
null.
-
forAllAttributes
public void forAllAttributes(@Nonnull Consumer<? super IMicroAttribute> aConsumer)
Description copied from interface:IMicroAttributeContainerIterate all attribute objects.- Specified by:
forAllAttributesin interfaceIMicroAttributeContainer<IMicroElement>- Parameters:
aConsumer- The consumer. May not benull. May only perform reading operations!
-
forAllAttributes
public void forAllAttributes(@Nonnull BiConsumer<? super IMicroQName,? super String> aConsumer)
Description copied from interface:IMicroAttributeContainerIterate all attribute objects.- Specified by:
forAllAttributesin interfaceIMicroAttributeContainer<IMicroElement>- Parameters:
aConsumer- The consumer that takes the QName and the value. May not benull. May only perform reading operations!
-
forAllAttributes
public void forAllAttributes(@Nonnull com.helger.commons.functional.ITriConsumer<? super String,? super String,? super String> aConsumer)
Description copied from interface:IMicroAttributeContainerIterate all attribute objects.- Specified by:
forAllAttributesin interfaceIMicroAttributeContainer<IMicroElement>- Parameters:
aConsumer- The consumer that takes the namespace URI, the attribute local name and the attribute value. May not benull. May only perform reading operations!
-
getAttributeObj
@Nullable public MicroAttribute getAttributeObj(@Nullable IMicroQName aQName)
Description copied from interface:IMicroAttributeContainerGet the attribute object with the specified qualified name.- Specified by:
getAttributeObjin interfaceIMicroAttributeContainer<IMicroElement>- Parameters:
aQName- The qualified attribute name to check. May benull.- Returns:
nullof no such attribute object exists.
-
getAttributeValueWithConversion
@Nullable public <DSTTYPE> DSTTYPE getAttributeValueWithConversion(@Nullable IMicroQName aAttrName, @Nonnull Class<DSTTYPE> aDstClass)
Description copied from interface:IMicroAttributeContainerGet the attribute value of the given attribute name. If this element has no such attribute,nullis returned. The attribute value is converted via theTypeConverterto the desired destination class. If no such attribute is present,nullis returned.- Specified by:
getAttributeValueWithConversionin interfaceIMicroAttributeContainer<IMicroElement>- Type Parameters:
DSTTYPE- Destination type- Parameters:
aAttrName- The attribute qualified name to retrieve the value of.aDstClass- The destination class.- Returns:
- The assigned attribute value or
null.
-
hasAttribute
public boolean hasAttribute(@Nullable IMicroQName aAttrName)
Description copied from interface:IMicroAttributeContainerCheck if this element has an attribute with the specified name.- Specified by:
hasAttributein interfaceIMicroAttributeContainer<IMicroElement>- Parameters:
aAttrName- The qualified attribute name to check. May benull.- Returns:
trueif such an attribute is present,falseotherwise
-
removeAttribute
@Nonnull public com.helger.commons.state.EChange removeAttribute(@Nullable IMicroQName aAttrName)
Description copied from interface:IMicroAttributeContainerRemove the attribute with the given name.- Specified by:
removeAttributein interfaceIMicroAttributeContainer<IMicroElement>- Parameters:
aAttrName- The qualified name of the attribute to be removed. May benull.- Returns:
EChange.CHANGEDif the attribute was removed,EChange.UNCHANGEDif no such attribute exists at this element.
-
setAttribute
@Nonnull public MicroElement setAttribute(@Nonnull IMicroQName aAttrName, @Nullable String sAttrValue)
Description copied from interface:IMicroAttributeContainerSet an attribute value of this element.- Specified by:
setAttributein interfaceIMicroAttributeContainer<IMicroElement>- Parameters:
aAttrName- Qualified name of the attribute. May neither benullnor empty.sAttrValue- If the value isnullthe attribute is removed (if present)- Returns:
- this
-
removeAllAttributes
@Nonnull public com.helger.commons.state.EChange removeAllAttributes()
Description copied from interface:IMicroAttributeContainerRemove all attributes from this element- Specified by:
removeAllAttributesin interfaceIMicroAttributeContainer<IMicroElement>- Returns:
EChange.
-
getNamespaceURI
@Nullable public String getNamespaceURI()
Description copied from interface:IMicroElementGet the namespace URI of this element- Specified by:
getNamespaceURIin interfaceIMicroElement- Returns:
- May be
nullif this element has no namespace URI.
-
setNamespaceURI
@Nonnull public com.helger.commons.state.EChange setNamespaceURI(@Nullable String sNamespaceURI)
Description copied from interface:IMicroElementSet a new namespace URI for this element.- Specified by:
setNamespaceURIin interfaceIMicroElement- Parameters:
sNamespaceURI- The namespace URI to be set. May benullor empty to indicate that the namespace should be removed.- Returns:
EChange
-
getLocalName
@Nullable public String getLocalName()
Description copied from interface:IMicroElementGet the local name of the element. Is the same name as returned byIMicroElement.getTagName()but it is only present, if a namespace URI is present.- Specified by:
getLocalNamein interfaceIMicroElement- Returns:
- May be
nullif no namespace is present.
-
getTagName
@Nonnull public String getTagName()
Description copied from interface:IMicroElementGet the name of the tag. It never contains XML schema prefixes or the like. Is the same asIMicroElement.getLocalName()if a namespace URI is present.- Specified by:
getTagNamein interfaceIMicroElement- Returns:
- May not be
null.
-
getAllChildElementsRecursive
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<IMicroElement> getAllChildElementsRecursive()
Description copied from interface:IMicroElementRecursively get all child elements. Micro container children are inlined.- Specified by:
getAllChildElementsRecursivein interfaceIMicroElement- Returns:
- A list containing all recursively contained elements. May not be
nullbut empty.
-
containsAnyChildElement
public boolean containsAnyChildElement(@Nullable Predicate<? super IMicroElement> aFilter)
Description copied from interface:IMicroElementCheck if this element has at least one direct child element that matches the provided filter. Micro container children are also checked.- Specified by:
containsAnyChildElementin interfaceIMicroElement- Parameters:
aFilter- The filter to be applied. May benull.- Returns:
trueif this element has at least one direct child element that matches the passed filter,falseotherwise.
-
getFirstChildElement
@Nullable public IMicroElement getFirstChildElement(@Nullable Predicate<? super IMicroElement> aFilter)
- Specified by:
getFirstChildElementin interfaceIMicroElement
-
forAllChildElements
public void forAllChildElements(@Nullable Predicate<? super IMicroElement> aFilter, @Nonnull Consumer<? super IMicroElement> aConsumer)
- Specified by:
forAllChildElementsin interfaceIMicroElement
-
forAllChildElementsBreakable
@Nonnull public com.helger.commons.state.EContinue forAllChildElementsBreakable(@Nullable Predicate<? super IMicroElement> aFilter, @Nonnull Function<? super IMicroElement,com.helger.commons.state.EContinue> aConsumer)
- Specified by:
forAllChildElementsBreakablein interfaceIMicroElement
-
getClone
@Nonnull public IMicroElement getClone()
Description copied from interface:IMicroElement- Specified by:
getClonein interfacecom.helger.commons.lang.ICloneable<IMicroNode>- Specified by:
getClonein interfaceIMicroElement- Specified by:
getClonein interfaceIMicroNodeWithChildren
-
isEqualContent
public boolean isEqualContent(@Nullable IMicroNode o)
Description copied from interface:IMicroNodeAs instances of this class may not implement equals/hashCode we need a way to determine, if 2 nodes are equal by content.- Specified by:
isEqualContentin interfaceIMicroNode- Overrides:
isEqualContentin classAbstractMicroNodeWithChildren- Parameters:
o- The node to compare to this.- Returns:
trueif the nodes are of the same type and the same content,falseotherwise.
-
toString
public String toString()
- Overrides:
toStringin classAbstractMicroNodeWithChildren
-
-