Package org.outerj.daisy.diff.html.dom
Class TagNode
java.lang.Object
org.outerj.daisy.diff.html.dom.Node
org.outerj.daisy.diff.html.dom.TagNode
- Direct Known Subclasses:
BodyNode
Node that can contain other nodes. Represents an HTML tag.
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Inserts provided node in the collection of children at the specified index ifthis
node is set as a parent for the parameter.void
appends the provided node to the collection of children ifthis
node is set as the parameter's parent.copyTree()
boolean
Considers tags from different trees equal if they have same name and equivalent attributes.void
getChild
(int i) int
getIndexOf
(Node child) If the provided parameter is in the same tree withthis
object then this method fetches index of the parameter object in the children collection.double
getMatchRatio
(TagNode other) getMinimalDeletedSet
(long id) This recursive method considers a descendant deleted if all its children hadTextNode
s that now are marked as removed with the provided id.int
ProducesString
for the opening HTML tag for this node.getQName()
int
hashCode()
Since we only consider so much information of the TagNode inequals
method, we need to re-writehashCode
method to correspond.boolean
static boolean
isBlockLevel
(String qName) static boolean
isBlockLevel
(Node node) boolean
isInline()
static boolean
static boolean
boolean
isPre()
boolean
checks tags for being semantically equivalent if it's from a different tree and for being the same object if it's from the same tree asthis
tag.protected boolean
isSimilarTag
(Node another) Returnstrue
if this tag is similar to the given other tag.iterator()
protected void
boolean
splitUntill
(TagNode parent, Node split, boolean includeLeft) Attempts to create 2TagNode
s with the same name and attributes as the originalthis
node.toString()
Methods inherited from class org.outerj.daisy.diff.html.dom.Node
detectIgnorableWhiteSpace, getLastCommonParent, getParent, getParentTree, getRoot, inPre, isWhiteAfter, isWhiteBefore, setParent, setWhiteAfter, setWhiteBefore
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
TagNode
-
-
Method Details
-
addChild
appends the provided node to the collection of children ifthis
node is set as the parameter's parent. This method is used in theNode
's constructor- Parameters:
node
- - child to add must havethis
node set as its parent.- Throws:
IllegalStateException
- - if the parameter has different parent thanthis
node.
-
setRoot
-
getIndexOf
If the provided parameter is in the same tree withthis
object then this method fetches index of the parameter object in the children collection. If the parameter is from a different tree, then this method attempts to return the index of first semantically equivalent node to the parameter.- Parameters:
child
- - the template of a tag we need an index for.- Returns:
- the index of first semantically equivalent child or -1 if couldn't find one
-
addChild
Inserts provided node in the collection of children at the specified index ifthis
node is set as a parent for the parameter.- Parameters:
index
- - desired position among the childrennode
- - the node to insert as a child.- Throws:
IllegalStateException
- - if the provided node has different parent fromthis
node.
-
getChild
-
iterator
- Specified by:
iterator
in interfaceIterable<Node>
- Returns:
Iterator<Node>
over children collection- Throws:
NullPointerException
- - if children collection is null
-
getNbChildren
public int getNbChildren()- Returns:
- number of elements in the children collection or 0 if
the collection is
null
-
getQName
-
getAttributes
-
isSameTag
checks tags for being semantically equivalent if it's from a different tree and for being the same object if it's from the same tree asthis
tag.- Parameters:
other
- - tag to compare to
-
equals
Considers tags from different trees equal if they have same name and equivalent attributes. No attention paid to the content (children) of the tag. Considers tags from the same tree equal if it is the same object. -
isSimilarTag
Returnstrue
if this tag is similar to the given other tag. The tags may be from different trees. If the tag name and attributes are the same, the result will betrue
.- Parameters:
another
- the tag to compare with- Returns:
- wether this tag is similar to the other node
-
hashCode
public int hashCode()Since we only consider so much information of the TagNode inequals
method, we need to re-writehashCode
method to correspond. OtherwiseHashTable
s andHashMaps
might behave unexpectedly. -
getOpeningTag
ProducesString
for the opening HTML tag for this node. Includes the attributes. This probably doesn't work for image tag.- Returns:
- the
String
representation of the corresponding opening HTML tag.
-
getEndTag
- Returns:
String
representation of the closing HTML tag that corresponds to the current node. Probably doesn't work for image tag.
-
getMinimalDeletedSet
This recursive method considers a descendant deleted if all its children had
TextNode
s that now are marked as removed with the provided id. If all children of a descendant is considered deleted, only that descendant is kept in the collection of the deleted nodes, and its children are removed from the collection of the deleted nodes.
The HTML tag nodes that never had any text content are never considered removedIt actually might have nothing to do with being really deleted, because the element might be kept after its text content was deleted.
Example:
table cells can be kept after its text content was deleted horizontal rule has never had text content, but can be deleted- Specified by:
getMinimalDeletedSet
in classNode
-
toString
-
splitUntill
Attempts to create 2TagNode
s with the same name and attributes as the originalthis
node. All children preceding split parameter are placed into the left part, all children following the split parameter are placed into the right part. Placement of the split node is determined by includeLeft flag parameter. The newly created nodes are only added to the parent ofthis
node if they have some children. The originalthis
node is removed afterwards. The process proceeds recursively hiking up the tree until the "parent" node is reached. "Parent" node will not be touched. This method is used when the parent tags of a deletedTextNode
can no longer be found in the new doc. (means they either has been deleted or changed arguments). The "parent" parameter in that case is the deepest common parent between the deleted node and its surrounding remaining siblings.- Parameters:
parent
- - the node that should not participate in split operation (where the split operation stops)split
- - the node-divider to divide children among splitted partsincludeLeft
- - iftrue
the "split" node will be included in the left part.- Returns:
true
if singlethis
node was substituted with 2 new similar nodes with original children divided among them.
-
isBlockLevel
-
isBlockLevel
-
isBlockLevel
public boolean isBlockLevel() -
isInline
-
isInline
-
isInline
public boolean isInline() -
copyTree
-
getMatchRatio
-
expandWhiteSpace
public void expandWhiteSpace() -
getLeftMostChild
- Specified by:
getLeftMostChild
in classNode
-
getRightMostChild
- Specified by:
getRightMostChild
in classNode
-
isPre
public boolean isPre()
-