homescreenpluginsrv/inc/hspsdomnode.h
changeset 0 79c6a41cd166
child 12 502e5d91ad42
equal deleted inserted replaced
-1:000000000000 0:79c6a41cd166
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Primary datatype for the entire Document Object Model.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef hsps_DOM_NODE_H
       
    21 #define hsps_DOM_NODE_H
       
    22 
       
    23 //  INCLUDES
       
    24 #include <e32base.h>
       
    25 #include <s32strm.h>
       
    26 #include "mhspsdomlistitem.h"
       
    27 
       
    28 // FORWARD DECLARATIONS
       
    29 enum TContentType
       
    30     {
       
    31     EEmpty = 0,
       
    32     EAny,
       
    33     EPCData
       
    34     };
       
    35 
       
    36 class ChspsDomList;
       
    37 class ChspsDomStringPool;
       
    38 class ChspsNode;
       
    39 
       
    40 // CLASS DECLARATION
       
    41 
       
    42 /**
       
    43  * Class represents a single node in the document tree.
       
    44  *
       
    45  * @lib hspsdomdocument.lib
       
    46  * @since S60 5.0
       
    47  * @ingroup group_hspsdom
       
    48  */
       
    49 class ChspsDomNode : public CBase, public MhspsDomListItem
       
    50     {
       
    51 
       
    52     public:  // Constructors and destructor
       
    53         
       
    54         /**
       
    55         * Two-phased constructor.
       
    56         * 
       
    57         * @since S60 5.0
       
    58         * @param aName          Name of node.
       
    59         * @param aNS            Namespace.
       
    60         * @param aStringPool    Attached string pool.
       
    61         */
       
    62         static ChspsDomNode* NewL( 
       
    63             const TDesC8& aName, 
       
    64             const TDesC8& aNS,
       
    65             ChspsDomStringPool& aStringPool );
       
    66               
       
    67         /**
       
    68         * Two-phased stream constructor.
       
    69         * 
       
    70         * @since S60 5.0
       
    71         * @param aStream        Source stream.
       
    72         * @param aStringPool    Attached string pool.
       
    73         */
       
    74         static ChspsDomNode* NewL( RReadStream& aStream, ChspsDomStringPool& aStringPool );
       
    75         
       
    76         /**
       
    77         * Destructor.
       
    78         */
       
    79         virtual ~ChspsDomNode();
       
    80       
       
    81     public: // New functions
       
    82         /**
       
    83         * Makes a clone from this node and it's child nodes.
       
    84         * 
       
    85         * @since S60 5.0
       
    86         * @param aStringPool A new string pool.
       
    87         * @return Pointer to a clone node. Caller has the ownership.
       
    88         */
       
    89         IMPORT_C ChspsDomNode* CloneL( ChspsDomStringPool& aStringPool );
       
    90         
       
    91         /**
       
    92         * Makes a clone only from this node.
       
    93         * 
       
    94         * @since S60 5.0
       
    95         * @param aStringPool A new string pool.
       
    96         * @return Pointer to a clone node. Caller has the ownership.
       
    97         */
       
    98         IMPORT_C ChspsDomNode* CloneWithoutKidsL( ChspsDomStringPool& aStringPool );
       
    99         
       
   100         /**
       
   101         * Contructs a ref node from this node and its child's.
       
   102         * 
       
   103         * @since S60 5.0
       
   104         * @return Pointer to a ref node. Caller has the ownership.
       
   105         */
       
   106         IMPORT_C ChspsDomNode* CreateRefNodeL();
       
   107          
       
   108         /**
       
   109         * Get the namespace of this node.
       
   110         *  
       
   111         * @since S60 5.0
       
   112         * @return Pointer to the namespace buffer.
       
   113         */
       
   114         IMPORT_C const TDesC8& Namespace();
       
   115         
       
   116         /**
       
   117         * Node's attributes exist in a list.
       
   118         * 
       
   119         * @since S60 5.0
       
   120         * @return Reference to a attribute list. 
       
   121         */
       
   122         IMPORT_C ChspsDomList& AttributeList()const;
       
   123                 
       
   124         /**
       
   125         * Node need to know it's parent.
       
   126         * 
       
   127         * @since S60 5.0
       
   128         * @param aParent Pointer to this node parent.
       
   129         */
       
   130         IMPORT_C void SetParent( ChspsDomNode* aParent );
       
   131         
       
   132         /**
       
   133         * Node's parent is enquered e.g to traverse the document.
       
   134         * 
       
   135         * @since S60 5.0
       
   136         * @return Pointer to a parent node.
       
   137         */
       
   138         IMPORT_C ChspsDomNode* Parent() const;
       
   139         
       
   140         /**
       
   141         * Node id is for a uiengine use.
       
   142         * 
       
   143         * @since S60 5.0
       
   144         * @param aNodeId Unique identifier.
       
   145         */
       
   146         IMPORT_C void SetNodeId( const TInt aNodeId );
       
   147 
       
   148         /**
       
   149         * Get the node unique identifier.
       
   150         * 
       
   151         * @since S60 5.0
       
   152         * @return Node unique identifier.
       
   153         */
       
   154         IMPORT_C TInt NodeId() const;
       
   155 
       
   156         /**
       
   157         * Get the node unique identifier.
       
   158         * 
       
   159         * @since S60 5.0
       
   160         * @return Node unique identifier.
       
   161         */
       
   162         IMPORT_C TInt ItemIndex( const MhspsDomListItem& aItem )const;
       
   163 
       
   164         /**
       
   165         * Access to child nodes.
       
   166         * 
       
   167         * @since S60 5.0
       
   168         * @return Pointer to a list of child nodes.
       
   169         */
       
   170         IMPORT_C ChspsDomList& ChildNodes();
       
   171         
       
   172         /**
       
   173         * Child nodes of this node are needed to be able to 
       
   174         * traverse the document.
       
   175         * 
       
   176         * @since S60 5.0
       
   177         * @param aNode Node owns it's childs.
       
   178         */
       
   179         IMPORT_C void AddChildL( ChspsDomNode* aNode );
       
   180 
       
   181          /**
       
   182         * Child nodes of this node are needed to be able to 
       
   183         * traverse the document.
       
   184         * 
       
   185         * @since S60 5.0
       
   186         * @param aNode Node owns it's childs.
       
   187         * @param aIndex Index in list where the node is added.
       
   188         */
       
   189         IMPORT_C void AddChildL( ChspsDomNode* aNode, TInt aIndex );
       
   190        
       
   191         /**
       
   192         * Removes node from the child list and frees memory allocated  
       
   193         * for a child node and it descendants.
       
   194         * 
       
   195         * @since S60 5.0
       
   196         * @param aNode Node to be released.
       
   197         */
       
   198         IMPORT_C void DeleteChild( ChspsDomNode* aNode );
       
   199         
       
   200         /**
       
   201         * Replaces a child node with the other node. Memory allocated for 
       
   202         * the node is freed.
       
   203         *    
       
   204         * @since S60 5.0
       
   205         * @param aNode Node to be replaced.
       
   206         * @param aNewNode New node.
       
   207         */
       
   208         IMPORT_C void ReplaceChildL( ChspsDomNode* aNode, ChspsDomNode* aNewNode );
       
   209         
       
   210         /**
       
   211         * Get the character data.
       
   212         * 
       
   213         * @since S60 5.0
       
   214         * @return Reference to a buffer.
       
   215         */
       
   216         IMPORT_C const TDesC8& PCData();
       
   217         
       
   218         /**
       
   219         * Append PCData into node. Thus it is possible to have
       
   220         * "<root>a <first/> c <second/> e </root>" PCData.
       
   221         * 
       
   222         * @since S60 5.0
       
   223         * @param aPCData UTF-8 encoded parsed character data.
       
   224         */
       
   225         IMPORT_C void AppendPCDataL( const TDesC8& aPCData );
       
   226         
       
   227         /**
       
   228         * Set parsed character data.
       
   229         * 
       
   230         * @since S60 5.0
       
   231         * @param aPCData UTF-8 encoded parsed character data.
       
   232         */
       
   233         IMPORT_C void SetPCDataL( const TDesC8& aPCData );
       
   234         
       
   235         /**
       
   236         * Set content type.
       
   237         * 
       
   238         * @since S60 5.0
       
   239         * @return content type.
       
   240         */
       
   241         IMPORT_C const TContentType& ContentType();
       
   242         
       
   243         /**
       
   244         * Get content type.
       
   245         * 
       
   246         * @since S60 5.0
       
   247         * @param aContentType content type.
       
   248         */
       
   249         IMPORT_C void SetContentType( const TContentType& aContentType );
       
   250         
       
   251         /**
       
   252         * Recursive function to count all child nodes belonging
       
   253         * to this node. 
       
   254         * 
       
   255         * @since S60 5.0
       
   256         * @return This node and it's all childs count.
       
   257         */
       
   258         IMPORT_C TInt DescendantCount() const;
       
   259         
       
   260         /**
       
   261         * Get reference to the dom's string pool.
       
   262         * 
       
   263         * @since S60 5.0
       
   264         * @return Reference to string pool.
       
   265         */
       
   266         IMPORT_C ChspsDomStringPool& StringPool() const;
       
   267         
       
   268         /**
       
   269         * Mark this node as a reference node.
       
   270         * 
       
   271         * @since S60 5.0
       
   272         * @param aRefNode ETrue if node is a reference node.
       
   273         */
       
   274         IMPORT_C void SetRefNode( TBool aRefNode=ETrue );
       
   275         
       
   276         /**
       
   277         * Check if this node is referring to some global node.
       
   278         * 
       
   279         * @since S60 5.0
       
   280         * @return ETrue if this is a reference node.
       
   281         */
       
   282         IMPORT_C TBool IsRefNode() const;
       
   283         
       
   284         /**
       
   285         * Deletes attributes when they are not needed anymore.
       
   286         * I.e. UIEngine has copied them into property list.
       
   287         * 
       
   288         * @since S60 5.0
       
   289         */
       
   290         IMPORT_C void DeleteAttributeList();
       
   291         
       
   292         /**
       
   293         * Returns value of given attribute.
       
   294         * 
       
   295         * @param aAttribute Name of the attribute.
       
   296         * @since S60 5.0
       
   297         * @return Value of an attribute.
       
   298         */
       
   299         IMPORT_C const TDesC8& AttributeValue(const TDesC8& aAttribute) const;
       
   300    
       
   301    public: //From MhspsDomListItem
       
   302         
       
   303         
       
   304         /**
       
   305         * Documented in ChspsDomListItem::Size
       
   306         */
       
   307         TInt Size() const;
       
   308         
       
   309         /**
       
   310         * Documented in ChspsDomListItem::ExternalizeL
       
   311         */
       
   312         void ExternalizeL( RWriteStream& aStream ) const;
       
   313         
       
   314         /**
       
   315         * Documented in ChspsDomListItem::InternalizeL
       
   316         */
       
   317         void InternalizeL( RReadStream& aStream );
       
   318         
       
   319         
       
   320         /**
       
   321         * Documented in ChspsDomListItem::Name
       
   322         */
       
   323         IMPORT_C const TDesC8& Name();       
       
   324         
       
   325     
       
   326     public:          
       
   327     
       
   328         /**
       
   329         * Sets pointer to associated layout node.
       
   330         * 
       
   331         * @since S60 5.0
       
   332         * @param aNode Pointer to associated layout node.
       
   333         */
       
   334         IMPORT_C void SetLayoutNode(ChspsNode* aNode);
       
   335         
       
   336         /**
       
   337         * Returns pointer to associated layout node.
       
   338         * 
       
   339         * @since S60 5.0
       
   340         * @return Pointer to associated layout node.
       
   341         */
       
   342         IMPORT_C ChspsNode* LayoutNode();
       
   343     private:
       
   344         /**
       
   345         * C++ default constructor.
       
   346         */
       
   347         ChspsDomNode( ChspsDomStringPool& aStringPool );
       
   348         
       
   349         /**
       
   350         * By default Symbian 2nd phase constructor is private.
       
   351         */
       
   352         void ConstructL( const TDesC8& aName, const TDesC8& aNS );
       
   353         
       
   354     private:    // Data
       
   355         
       
   356         //iNameRef refers to a name string in a string pool 
       
   357         TInt                iNameRef;
       
   358         
       
   359         //iNSRef refers to a namespace string in a string pool 
       
   360         TInt                iNSRef;
       
   361         
       
   362         //iStringPool is used to resolve strings based on references
       
   363         ChspsDomStringPool&   iStringPool;
       
   364         
       
   365         //Type of the elements content
       
   366         TContentType        iContentType;
       
   367         
       
   368         //Parsed character data
       
   369         HBufC8*             iPCData;
       
   370         
       
   371         //Node's parent pointer 
       
   372         ChspsDomNode*         iParentNode;
       
   373         
       
   374         //Node unique identifier
       
   375         TInt                iNodeId;
       
   376         
       
   377         //Node's childs are collected into a list. Childs are owned by node
       
   378         ChspsDomList*         iChildList;
       
   379         
       
   380         //Node is the owner of the attributes
       
   381         ChspsDomList*         iAttributeList;
       
   382                 
       
   383         //Flag is set if this node is reference node
       
   384         TBool               iRefNode;
       
   385          
       
   386         // Not owned
       
   387         ChspsNode*            iLayoutNode;
       
   388     };
       
   389 
       
   390 #endif      // hsps_DOM_NODE_H 
       
   391             
       
   392 // End of File