Package Torello.HTML
Class TextNode
- java.lang.Object
-
- Torello.HTML.HTMLNode
-
- Torello.HTML.TextNode
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.CharSequence
,java.lang.Cloneable
,java.lang.Comparable<TextNode>
public final class TextNode extends HTMLNode implements java.lang.CharSequence, java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<TextNode>
Concrete HTMLNode SubClasses:
The three inherited classes ofabstract class HTMLNode
are very light-weight, and contain some amount ofpublic
methods, but do not have heavy internal-state (either static, or non-static). Below is a list of the internal field's that are added to each of the three instantiations of the ancestorHTMLNode class
:class TagNode
adds a fieldpublic final boolean isClosing
- which tells a user if this tag has a forward-slash immediately following the '<' (less-than symbol) at character position 2. This is how one identifies a 'closing-version' of the element, for instance: '</DIV>
' and '</SPAN>
' would both have theirpublic final boolean isClosing
fields set to TRUE. There is also apublic final String tok
field added to instances ofTagNode
that identify what html element the TagNode represents. For example an HTML Element such as:<A HREF="http://My.URL.com" TARGET=_blank>
, would have it'sString 'tok'
field set to'a'
class TextNode
this inherited class fromclass HTMLNode
does not add any internal state at all. It has the exact same internally-maintained fields as its parent-class. Thepublic final String str
field merely states what text this text-node actually represents.
class CommentNode
for searching-purposes, and ease-of-use,class CommentNode
, which is the third and final class to inheritHTMLNode
keeps one extra internal-field, which ispublic final String body
. This field is a redundant, duplicate, of the internal stringpublic final String str
- which is inherited from the HTML Node class. The subtle difference is that, since comment nodes represent the HTML<!-- and -->
symbols, the'body'
of the comment sometimes needs to be searched, quickly. Thepublic final String body
leaves off these leading and ending comment delimiter symbols:<!-- and -->
Represents document text, and is one of only three HTML Element Classes provided by the Java HTML Library Tool, and also oneof the three classes that can be generated by the HTML Parser.
ClassTextNode
is a subclass ofabstract
classHTMLNode
, add does not add any methods or fields to the class-structure at all.
IMPORTANT:
Text that is found between both the HTML<SCRIPT> ...</SCRIPT>
, and also the HTML<STYLE> ... </STYLE>
is simply saved as an instance of classTextNode
. The real rationale behind this comes by way of the fact that these HTML Parse, Search, Update and Scrape classes are not capable executing script, yet...
As such, there is no parse performed on CSS, Java-Script, jQuery, or any other of the myriad scripting languages often found inside of HTML documents. Rather than creating any number of various and sundry "partial parses" or "attempted parses," this text is just left as an instance of classTextNode
, but of course whatever HTML<SCRIPT>
or<STYLE>
elements surrounding this text node shall of course be easily found.
Inheritance Tree Diagram:
Below is the inheritance diagram (with fields) of the three concrete-classes that extend theabstract
classHTMLNode:
- See Also:
HTMLNode
,TagNode
,CommentNode
, Serialized Form
Hi-Lited Source-Code:- View Here: Torello/HTML/TextNode.java
- Open New Browser-Tab: Torello/HTML/TextNode.java
File Size: 3,994 Bytes Line Count: 104 '\n' Characters Found
-
-
Field Summary
Serializable ID Modifier and Type Field static long
serialVersionUID
Alternate java.util.Comparator Modifier and Type Field static Comparator<TextNode>
comp2
-
Constructor Summary
Constructors Constructor Description TextNode(String s)
Constructs a newTextNode
with internal fieldString str
equal to parameter's'
-
Method Summary
Methods: interface java.lang.Cloneable Modifier and Type Method TextNode
clone()
Methods: interface java.lang.Comparable Modifier and Type Method int
compareTo(TextNode tn)
'instanceof' Operator Replacement Methods Modifier and Type Method TextNode
ifTextNode()
boolean
isTextNode()
-
Methods inherited from class Torello.HTML.HTMLNode
asCommentNode, asTagNode, asTextNode, charAt, equals, hashCode, ifCommentNode, ifTagNode, isCommentNode, isOpenTag, isOpenTagPWA, isTagNode, length, openTag, openTagPWA, subSequence, toString
-
-
-
-
Field Detail
-
serialVersionUID
public static final long serialVersionUID
This fulfils the SerialVersion UID requirement for all classes that implement Java'sinterface java.io.Serializable
. Using theSerializable
Implementation offered by java is very easy, and can make saving program state when debugging a lot easier. It can also be used in place of more complicated systems like "hibernate" to store data as well.- See Also:
- Constant Field Values
- Code:
- Exact Field Declaration Expression:
public static final long serialVersionUID = 1;
-
comp2
public static final java.util.Comparator<TextNode> comp2
This is an "alternative Comparitor" that can be used for sorting instances of this class. It should work with theCollections.sort(List, Comparator)
method in the standard JDK packagejava.util.*;
NOTE: This version utilizes the standard JDKString.compareToIgnoreCase(String)
method.- See Also:
HTMLNode.str
- Code:
- Exact Field Declaration Expression:
public static final Comparator<TextNode> comp2 = (TextNode txn1, TextNode txn2) -> txn1.str.compareToIgnoreCase(txn2.str);
-
-
Constructor Detail
-
TextNode
public TextNode(java.lang.String s)
Constructs a newTextNode
with internal fieldString str
equal to parameter's'
- Parameters:
s
- Any valid JavaString
may be passed here.- Code:
- Exact Constructor Body:
super(s);
-
-
Method Detail
-
isTextNode
public final boolean isTextNode()
This method identifies that'this'
instance of (abstract parent-class)HTMLNode
is, indeed, an instance of sub-classTextNode
.
Final Method:
This method is final, and cannot be modified by sub-classes.- Overrides:
isTextNode
in classHTMLNode
- Returns:
- This method shall always return
TRUE
It overrides the parent-classHTMLNode
methodisTextNode()
, which always returnsFALSE
. - See Also:
isTextNode()
- Code:
- Exact Method Body:
return true;
-
ifTextNode
public final TextNode ifTextNode()
This method identifies that'this'
instance of (abstract parent-class)HTMLNode
is, indeed, an instance of sub-classTextNode
.
Final Method:
This method is final, and cannot be modified by sub-classes.- Overrides:
ifTextNode
in classHTMLNode
- Returns:
'this'
reference. This method can be used inside loops for improving the readability of loop-condition expressions. See example below:
Example:
TextNode t; for (HTMLNode n : myHTMLVector) if ((t = n.ifTextNode()) != null) System.out.println("Text-Node Contains: " + t.str);
This method-version overrides the parent-class-version, which always returns null. This method is not overriden by otherHTMLNode
sub-classes.- See Also:
ifTextNode()
- Code:
- Exact Method Body:
return this;
-
clone
-
compareTo
public int compareTo(TextNode tn)
Java'sinterface Comparable<T>
requirements. This does a very simple comparison using the underlying fieldfinal String str
that all Text's contain.- Specified by:
compareTo
in interfacejava.lang.Comparable<TextNode>
- Parameters:
tn
- Any otherTextNode
to be compared to'this' TextNode
- Returns:
- An integer that fulfils Java's
interface Comparable<T> public boolean compareTo(T t)
method requirements. - Code:
- Exact Method Body:
return this.str.compareTo(tn.str);
-
-