Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

CSHTMLNode Class Reference

#include <CSHTMLHelper.h>


Detailed Description

Class that hold all information about a html-node.

CSHTMLNode holds all information of a single html-node and its children. (The root-node of a html-page e.g. holds the complete document structur.) The root node of a html-page can be got using the class CSHTMLHelper

For an example how CSHTMLNode is used see CSHTMLHelper.

See also:
CSHTMLHelper
Warning:
The corresponding CSHTMLHelper must not be deleted, as long as any node got from it is in any way active! DON'T delete the CSHTMLHelper!!!

Definition at line 33 of file CSHTMLHelper.h.

Public Member Functions

virtual std::string getType ()
 Get the unique class identifier.

 CSHTMLNode ()
 Builds an empty CSHTMLNode.

 CSHTMLNode (const CSHTMLNode &node)
 Copy constructor.

virtual ~CSHTMLNode ()
 Destructor.

CSHTMLNode nextSibling ()
 Get the next sibling node.

CSHTMLNode previousSibling ()
 Get the previous sibling node.

CSHTMLNode parent ()
 Get the parent node.

CSHTMLNode firstChild ()
 Get the first child node.

CSHTMLNode lastChild ()
 Get the last child node.

CSHTMLNode nextChild ()
 Get the next child node.

CSHTMLNode previousChild ()
 Get the previous child node.

bool isEmpty ()
 Whether the node actually exits!

bool isText ()
 Is the this node a "text" node?

std::string getValue ()
 Get the value of the node.

bool isSingleTag ()
 Is this node a single TAG node?

std::string getTag ()
 Get TAG (name).

std::string firstAttribut ()
 Get first attribute (name).

std::string nextAttribut ()
 Get next attribute (name).

std::string attributValue (const std::string &attribut)
 Get value of attribte (with name as in "attribut").


Static Public Attributes

const char * CLASS = "CSHTMLNode"
 The unique class identifier (the name of the class).


Constructor & Destructor Documentation

CSHTMLNode::CSHTMLNode  )  [inline]
 

Builds an empty CSHTMLNode.

Definition at line 65 of file CSHTMLHelper.h.

Referenced by firstChild(), lastChild(), nextChild(), nextSibling(), parent(), previousChild(), and previousSibling().

00066         {
00067             mNode = 0;
00068         }

CSHTMLNode::CSHTMLNode const CSHTMLNode node  )  [inline]
 

Copy constructor.

Parameters:
node the other CSHTMLNode that is copied.

Definition at line 73 of file CSHTMLHelper.h.

References mCurrentAttribute, mCurrentChild, mCurrentElement, and mNode.

00074         {
00075             // pointers are only copied!
00076             mNode = node.mNode;
00077             mCurrentChild = node.mCurrentChild;
00078             mCurrentElement = node.mCurrentElement;
00079             mCurrentAttribute = node.mCurrentAttribute;
00080         }

virtual CSHTMLNode::~CSHTMLNode  )  [inline, virtual]
 

Destructor.

Definition at line 83 of file CSHTMLHelper.h.

00083 {}  // pointers are never freed either!


Member Function Documentation

virtual std::string CSHTMLNode::getType  )  [inline, virtual]
 

Get the unique class identifier.

Definition at line 62 of file CSHTMLHelper.h.

References CLASS.

00062 {return (std::string) CLASS;}

CSHTMLNode CSHTMLNode::nextSibling  ) 
 

Get the next sibling node.

Return the next sibling-node (brother or sister :-)), if none is available an empty CSHTMLNode is returned.

Returns:
the next sibling-node (if available)

an empty CSHTMLNode otherwise

Definition at line 48 of file CSHTMLHelper.cpp.

References CSHTMLNode(), LOG_ENTER, and LOG_EXIT.

00049 {
00050     static char *functionName="nextSibling";
00051     LOG_ENTER 
00052     if (!mNode) 
00053     {
00054         LOG_EXIT
00055         return CSHTMLNode(0);
00056     }
00057     LOG_EXIT
00058     return CSHTMLNode(mNode->NextSibling());
00059 }

Here is the call graph for this function:

CSHTMLNode CSHTMLNode::previousSibling  ) 
 

Get the previous sibling node.

Return the previous sibling-node (brother or sister :-)), if none is available an empty CSHTMLNode is returned.

Returns:
the previous sibling-node (if available)

an empty CSHTMLNode otherwise

Todo:
This is not implemented! (returns allways an empty node!)

Definition at line 67 of file CSHTMLHelper.cpp.

References CSHTMLNode(), LOG_ENTER, and LOG_EXIT.

00068 {
00069     static char *functionName="previousSibling";
00070     LOG_ENTER 
00071     if (!mNode) 
00072     {
00073         LOG_EXIT
00074         return CSHTMLNode(0);
00075     }
00076     LOG_EXIT
00077     return CSHTMLNode(0);
00078 }

Here is the call graph for this function:

CSHTMLNode CSHTMLNode::parent  ) 
 

Get the parent node.

Return the parent-node (father or mother :-)), if none is available an empty CSHTMLNode is returned.

Returns:
the parent-node

an empty CSHTMLNode otherwise

Definition at line 84 of file CSHTMLHelper.cpp.

References CSHTMLNode(), LOG_ENTER, and LOG_EXIT.

00085 {
00086     static char *functionName="parent";
00087     LOG_ENTER 
00088     if (!mNode) 
00089     {
00090         LOG_EXIT
00091         return CSHTMLNode(0);
00092     }
00093     LOG_EXIT
00094     return CSHTMLNode(mNode->Parent());
00095 }

Here is the call graph for this function:

CSHTMLNode CSHTMLNode::firstChild  ) 
 

Get the first child node.

Return the first child-node (son or daughter :-)), if none is available an empty CSHTMLNode is returned. firstChild() or lastChild() must be called in order to successfully call nextChild() or previousChild().

Returns:
the first child-node

an empty CSHTMLNode otherwise

Definition at line 104 of file CSHTMLHelper.cpp.

References CSHTMLNode(), LOG_ENTER, and LOG_EXIT.

Referenced by HTMLElement::HTMLElement().

00105 {
00106     static char *functionName="firstChild";
00107     LOG_ENTER 
00108     if (!mNode) 
00109     {
00110         LOG_EXIT
00111         return CSHTMLNode(0);
00112     }
00113     mCurrentChild = mNode->FirstChild();
00114     LOG_EXIT
00115     return CSHTMLNode(mCurrentChild);
00116 }

Here is the call graph for this function:

CSHTMLNode CSHTMLNode::lastChild  ) 
 

Get the last child node.

Return the last child-node (son or daughter :-)), if none is available an empty CSHTMLNode is returned. firstChild() or lastChild() must be called in order to successfully call nextChild() or previousChild().

Returns:
the last child-node

an empty CSHTMLNode otherwise

Definition at line 125 of file CSHTMLHelper.cpp.

References CSHTMLNode(), LOG_ENTER, and LOG_EXIT.

00126 {
00127     static char *functionName="lastChild";
00128     LOG_ENTER 
00129     if (!mNode) 
00130     {
00131         LOG_EXIT
00132         return CSHTMLNode(0);
00133     }
00134     mCurrentChild = mNode->LastChild();
00135     LOG_EXIT
00136     return CSHTMLNode(mCurrentChild);
00137 }

Here is the call graph for this function:

CSHTMLNode CSHTMLNode::nextChild  ) 
 

Get the next child node.

Return the next child-node (son or daughter :-)), if none is available an empty CSHTMLNode is returned. firstChild() or lastChild() must be called in order to successfully call nextChild() or previousChild().

Returns:
a child-node

an empty CSHTMLNode otherwise

Definition at line 173 of file CSHTMLHelper.cpp.

References CSHTMLNode(), getTag(), getValue(), LOG_DEBUG_MESSAGE, LOG_ENTER, and LOG_EXIT.

Referenced by HTMLElement::HTMLElement().

00174 {
00175     static char *functionName="nextChild";
00176     LOG_ENTER 
00177     if (mCurrentChild)
00178     {
00179         mCurrentChild = mCurrentChild->NextSibling();
00180         if (!mCurrentChild)
00181         {
00182             std::string message="No next child found!\n";
00183             message += "Tag="+getTag();
00184             message += ", ";
00185             message += "Value="+getValue();
00186             LOG_DEBUG_MESSAGE(message) 
00187         }
00188     }
00189     LOG_EXIT
00190     return CSHTMLNode(mCurrentChild);
00191 }

Here is the call graph for this function:

CSHTMLNode CSHTMLNode::previousChild  ) 
 

Get the previous child node.

Return the previous child-node (son or daughter :-)), if none is available an empty CSHTMLNode is returned. firstChild() or lastChild() must be called in order to successfully call nextChild() or previousChild().

Returns:
a child-node

an empty CSHTMLNode otherwise

Definition at line 146 of file CSHTMLHelper.cpp.

References CSHTMLNode(), getTag(), getValue(), LOG_DEBUG_MESSAGE, LOG_ENTER, and LOG_EXIT.

00147 {
00148     static char *functionName="previousChild";
00149     LOG_ENTER 
00150     if (mCurrentChild)
00151     {
00152         mCurrentChild = mCurrentChild->PreviousSibling();
00153         if (!mCurrentChild)
00154         {
00155             std::string message="No previous child found!\n";
00156             message += "Tag="+getTag();
00157             message += ", ";
00158             message += "Value="+getValue();
00159             LOG_DEBUG_MESSAGE(message) 
00160         }
00161     }
00162     LOG_EXIT
00163     return CSHTMLNode(mCurrentChild);
00164 }

Here is the call graph for this function:

bool CSHTMLNode::isEmpty  )  [inline]
 

Whether the node actually exits!

All methods return a CSHTMLNode, if an error occured, or a node does not exist, an empty node is returned. An empty node can be checked with this method.

Returns:
true on an empty node

false on correct node

Definition at line 113 of file CSHTMLHelper.h.

Referenced by HTMLElement::HTMLElement().

00113 {return (mNode==0);}

bool CSHTMLNode::isText  ) 
 

Is the this node a "text" node?

A Text node is a node that does not hold TAG, or attribute information. The plain good old html-text!

Returns:
true if this node countains text

false if not

Definition at line 199 of file CSHTMLHelper.cpp.

Referenced by HTMLElement::buildDisplay(), and HTMLElement::getText().

00200 {
00201     return mNode->ToText() != 0;
00202 }

std::string CSHTMLNode::getValue  ) 
 

Get the value of the node.

If the node is a text-node, the string representing the text is returned. Known entities e.g. "&amp;" <-> "&" are mapped to their "meaning".

Returns:
text if textnode

an empty string otherwise

Definition at line 210 of file CSHTMLHelper.cpp.

References LOG_ENTER, and LOG_EXIT.

Referenced by HTMLElement::buildDisplay(), HTMLElement::getText(), nextChild(), and previousChild().

00211 {
00212     static char *functionName="getValue";
00213     LOG_ENTER 
00214     if (!mNode) 
00215     {
00216         LOG_EXIT
00217         return std::string();
00218     }
00219     if (mNode->ToText() != 0)
00220     {
00221         LOG_EXIT
00222         std::string text = mNode->ToText()->Value();
00223         std::string entityFreeText = replaceHTMLEntities(text);
00224         return entityFreeText;
00225     }
00226     LOG_EXIT
00227     return std::string();
00228 }

bool CSHTMLNode::isSingleTag  ) 
 

Is this node a single TAG node?

Check whether the current node is a single TAG-node (e.g. <HR>, <BR>).

Returns:
true if this node is a single TAG-node

false if not (also for text only nodes)

Definition at line 235 of file CSHTMLHelper.cpp.

References LOG_ENTER, and LOG_EXIT.

00236 {
00237     static char *functionName="isSingleTag";
00238     LOG_ENTER 
00239     if (!mNode) 
00240     {
00241         LOG_EXIT
00242         return false;
00243     }
00244     if (mNode->ToElement() != 0)
00245     {
00246         LOG_EXIT
00247         return mNode->ToElement()->isSingleTagElement();
00248     }
00249     LOG_EXIT
00250     return false;
00251 }

std::string CSHTMLNode::getTag  ) 
 

Get TAG (name).

Gets the TAG the current node is representing (e.g. HTML, BODY...)

Returns:
string that represents the TAG

empty string if not a TAG-node

Definition at line 258 of file CSHTMLHelper.cpp.

References LOG_ENTER, and LOG_EXIT.

Referenced by HTMLElement::buildDisplay(), nextChild(), and previousChild().

00259 {
00260     static char *functionName="getTag";
00261     LOG_ENTER 
00262     if (!mNode) 
00263     {
00264         LOG_EXIT
00265         return std::string();
00266     }
00267     if (mNode->ToElement() != 0)
00268     {
00269         LOG_EXIT
00270         return mNode->ToElement()->Value();
00271     }
00272     LOG_EXIT
00273     return std::string();
00274 }

std::string CSHTMLNode::firstAttribut  ) 
 

Get first attribute (name).

Return the first attribut of the node (e.g. "color", "HREF", ...). firstAttribut() must be called in order to successfully call nextAttribut().

Returns:
string that represents the attribute

empty string if not a TAG-node or no attribute was found

Definition at line 282 of file CSHTMLHelper.cpp.

References LOG_ENTER, and LOG_EXIT.

00283 {
00284     static char *functionName="firstAttribut";
00285     LOG_ENTER 
00286     if (!mCurrentElement)
00287     {
00288         LOG_EXIT
00289         return std::string();
00290     }
00291     mCurrentAttribute = mCurrentElement->FirstAttribute();
00292     if (!mCurrentAttribute)
00293     {
00294         LOG_EXIT
00295         return std::string();
00296     }
00297     LOG_EXIT
00298     return mCurrentAttribute->Name();
00299 }

std::string CSHTMLNode::nextAttribut  ) 
 

Get next attribute (name).

Return the next attribut of the node (e.g. "color", "HREF", ...). firstAttribut() must be called in order to successfully call nextAttribut().

Returns:
string that represents the attribute

empty string if not a TAG-node or no attribute was found

Definition at line 307 of file CSHTMLHelper.cpp.

References LOG_ENTER, and LOG_EXIT.

00308 {
00309     static char *functionName="nextAttribut";
00310     LOG_ENTER 
00311     if (!mCurrentElement)
00312     {
00313         LOG_EXIT
00314         return std::string();
00315     }
00316     if (!mCurrentAttribute)
00317     {
00318         LOG_EXIT
00319         return std::string();
00320     }
00321     mCurrentAttribute = mCurrentAttribute->Next();
00322     if (!mCurrentAttribute)
00323     {
00324         LOG_EXIT
00325         return std::string();
00326     }
00327     LOG_EXIT
00328     return mCurrentAttribute->Name();
00329 }

std::string CSHTMLNode::attributValue const std::string &  attribute  ) 
 

Get value of attribte (with name as in "attribut").

Return the value of an attribut of the node (e.g. for "color" -> "#ffffff"). Attribute value given is indepenedent of upper or lower case!

Returns:
string that represents the value of the attribute

empty string if not a TAG-node or no corresponding attribute was found

Definition at line 338 of file CSHTMLHelper.cpp.

References LOG_ENTER, and LOG_EXIT.

Referenced by HTMLElement::buildDisplay(), and HTMLElement::getAttributValue().

00339 {
00340     static char *functionName="attributValue";
00341     LOG_ENTER 
00342     const char *p;
00343     if (!mCurrentElement)
00344     {
00345         LOG_EXIT
00346         return std::string();
00347     }
00348 
00349     // case independency, make the given attribute name UPPER
00350     std::string upperAttribute;
00351     
00352     for( p = attribute.c_str(); p < attribute.c_str() + strlen( attribute.c_str() ); p++ )
00353     {
00354         upperAttribute += toupper(*p);
00355     }
00356 
00357     mCurrentAttribute = mCurrentElement->FirstAttribute();
00358     while (mCurrentAttribute)
00359     {
00360         std::string name =  mCurrentAttribute->Name();
00361 
00362         // case independency, make this attribute name UPPER
00363         std::string upperName;
00364         for( p = name.c_str(); p < name.c_str() + strlen( name.c_str() ); p++ )
00365         {
00366             upperName += toupper(*p);
00367         }
00368 
00369         // and compare them
00370         if (strcmp(upperAttribute.c_str(), upperName.c_str()) == 0)
00371         {
00372             // equal -> great, return it
00373             LOG_EXIT
00374             return mCurrentAttribute->Value();
00375         }
00376         mCurrentAttribute = mCurrentAttribute->Next();
00377     }
00378     LOG_EXIT
00379     return std::string();
00380 }


Field Documentation

const char * CSHTMLNode::CLASS = "CSHTMLNode" [static]
 

The unique class identifier (the name of the class).

Definition at line 9 of file CSHTMLHelper.cpp.

Referenced by getType().


Generated on Wed Jul 14 00:44:28 2004 for CSLib by doxygen 1.3.6