Package com.helger.xml.microdom
Class MicroText
- java.lang.Object
-
- com.helger.xml.microdom.AbstractMicroNode
-
- com.helger.xml.microdom.MicroText
-
- 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>,IMicroDataAware,IMicroNode,IMicroText,Serializable
public final class MicroText extends AbstractMicroNode implements IMicroText
Default implementation of theIMicroTextinterface.- Author:
- Philip Helger
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static booleanDEFAULT_ESCAPEBy default the text should be XML escaped when emitting to a file etc.static booleanDEFAULT_IGNORABLE_WHITESPACEBy default the text is not ignorable whitespaces
-
Constructor Summary
Constructors Constructor Description MicroText(char[] aChars, int nOfs, int nLen, boolean bIgnorableWhitespace)MicroText(CharSequence sText)MicroText(CharSequence sText, boolean bIgnorableWhitespace)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidappendData(char cChar)Append a character to the string.voidappendData(char[] aChars, int nOfs, int nLen)Append characters to the string.voidappendData(CharSequence sData)Append characters to the string.IMicroTextgetClone()CharSequencegetData()StringgetNodeName()StringgetNodeValue()EMicroNodeTypegetType()booleanisElementContentWhitespace()Check whether the text node consists solely of whitespaces.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.booleanisEscape()voidprependData(char cChar)Add a character to the beginning of the current data.voidprependData(char[] aChars, int nOfs, int nLen)Add characters to the beginning of the current data.voidprependData(CharSequence sData)Add characters to the beginning of the current data.voidsetData(CharSequence sData)Change the character sequence.MicroTextsetEscape(boolean bEscape)StringtoString()-
Methods inherited from class com.helger.xml.microdom.AbstractMicroNode
appendChild, detachFromParent, findFirstChild, findFirstChildMapped, findParentElement, forAllChildren, forAllChildren, forAllChildrenBreakable, forAllChildrenMapped, getAllChildren, getAllEventTargets, getAllEventTargets, getChildAtIndex, getChildCount, getChildren, getFirstChild, getLastChild, getNextSibling, getParent, getPreviousSibling, hasChildren, hasParent, insertAfter, insertAtIndex, insertBefore, internalResetParentNode, internalSetParentNode, internalTriggerEvent, isCDATA, isComment, isContainer, isDocument, isDocumentType, isElement, isEntityReference, isProcessingInstruction, isText, onAppendChild, onEvent, onInsertAfter, onInsertAtIndex, onInsertBefore, onRemoveAllChildren, onRemoveChild, onRemoveChildAtIndex, 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.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, getParent, getParentElementWithName, getParentElementWithName, getPreviousSibling, hasParent, insertAfter, insertAtIndex, insertBefore, isCDATA, isComment, isContainer, isDocument, isDocumentType, isElement, isEntityReference, isProcessingInstruction, isText, registerEventTarget, removeAllChildren, removeChild, removeChildAtIndex, replaceChild, unregisterEventTarget
-
-
-
-
Field Detail
-
DEFAULT_IGNORABLE_WHITESPACE
public static final boolean DEFAULT_IGNORABLE_WHITESPACE
By default the text is not ignorable whitespaces- See Also:
- Constant Field Values
-
DEFAULT_ESCAPE
public static final boolean DEFAULT_ESCAPE
By default the text should be XML escaped when emitting to a file etc.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
MicroText
public MicroText(@Nonnull char[] aChars, @Nonnegative int nOfs, @Nonnegative int nLen, boolean bIgnorableWhitespace)
-
MicroText
public MicroText(@Nullable CharSequence sText)
-
MicroText
public MicroText(@Nullable CharSequence sText, boolean bIgnorableWhitespace)
-
-
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.
-
getNodeValue
@Nonnull public String getNodeValue()
- Specified by:
getNodeValuein interfaceIMicroNode- Returns:
- The value of this node. This depends on the concrete implementation
class. It is currently implemented for
IMicroText,IMicroCommentandIMicroEntityReference.
-
getData
@Nonnull public CharSequence getData()
- Specified by:
getDatain interfaceIMicroDataAware- Returns:
- The currently assigned character data. May not be
null.
-
appendData
public void appendData(@Nullable CharSequence sData)
Description copied from interface:IMicroDataAwareAppend characters to the string.- Specified by:
appendDatain interfaceIMicroDataAware- Parameters:
sData- The characters to be appended.
-
appendData
public void appendData(@Nonnull char[] aChars, @Nonnegative int nOfs, @Nonnegative int nLen)
Description copied from interface:IMicroDataAwareAppend characters to the string.- Specified by:
appendDatain interfaceIMicroDataAware- Parameters:
aChars- Base character array. May not benull.nOfs- Offset to start copying. Must be ≥ 0.nLen- Number of chars to take. Must be ≥ 0.
-
appendData
public void appendData(char cChar)
Description copied from interface:IMicroDataAwareAppend a character to the string.- Specified by:
appendDatain interfaceIMicroDataAware- Parameters:
cChar- The character to append
-
prependData
public void prependData(@Nullable CharSequence sData)
Description copied from interface:IMicroDataAwareAdd characters to the beginning of the current data.- Specified by:
prependDatain interfaceIMicroDataAware- Parameters:
sData- The characters to be added at the front.
-
prependData
public void prependData(@Nonnull char[] aChars, @Nonnegative int nOfs, @Nonnegative int nLen)
Description copied from interface:IMicroDataAwareAdd characters to the beginning of the current data.- Specified by:
prependDatain interfaceIMicroDataAware- Parameters:
aChars- Base character array. May not benull.nOfs- Offset to start copying. Must be ≥ 0.nLen- Number of chars to take. Must be ≥ 0.
-
prependData
public void prependData(char cChar)
Description copied from interface:IMicroDataAwareAdd a character to the beginning of the current data.- Specified by:
prependDatain interfaceIMicroDataAware- Parameters:
cChar- The character to preprend
-
setData
public void setData(@Nullable CharSequence sData)
Description copied from interface:IMicroDataAwareChange the character sequence. Any previously set characters are lost.- Specified by:
setDatain interfaceIMicroDataAware- Parameters:
sData- The new character sequence to be set.
-
isElementContentWhitespace
public boolean isElementContentWhitespace()
Description copied from interface:IMicroTextCheck whether the text node consists solely of whitespaces. This may be helpful in detecting XML that has been indented :)- Specified by:
isElementContentWhitespacein interfaceIMicroText- Returns:
trueif the text node consists solely of whitespaces (blank, tab etc.).
-
isEscape
public boolean isEscape()
- Specified by:
isEscapein interfaceIMicroText- Returns:
trueif the content of this text node should be masked, andfalseif not. By default a text node should always be masked.
-
getClone
@Nonnull public IMicroText getClone()
Description copied from interface:IMicroText- Specified by:
getClonein interfacecom.helger.commons.lang.ICloneable<IMicroNode>- Specified by:
getClonein interfaceIMicroText
-
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- 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 classAbstractMicroNode
-
-