svgtopt/SVG/Xmldomimpl/src/SVGXmlElementImpl.cpp
changeset 46 88edb906c587
equal deleted inserted replaced
-1:000000000000 46:88edb906c587
       
     1 /*
       
     2 * Copyright (c) 2003 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:  XML DOM Implementation source file
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include "SVGXmlElementImpl.h"
       
    20 #include "SVGXmlDocument.h"
       
    21 
       
    22 // ---------------------------------------------------------------------------
       
    23 // This method acts like a ConstructL.
       
    24 // This class is never instantiated
       
    25 // The derived classes that are instantiated, call this method within
       
    26 // their ConstructL methods
       
    27 // ---------------------------------------------------------------------------
       
    28 
       
    29 void CXmlElementImpl::InitializeL(  const TUint8 aElemID )
       
    30     {
       
    31     iElemID=aElemID;
       
    32     }
       
    33 
       
    34 // ---------------------------------------------------------------------------
       
    35 // Accessor for the integer ID of the current element
       
    36 // ---------------------------------------------------------------------------
       
    37 TUint8 CXmlElementImpl::ElemID()
       
    38     {
       
    39     return iElemID;
       
    40     }
       
    41 
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 // Destructor
       
    45 // ---------------------------------------------------------------------------
       
    46 CXmlElementImpl::~CXmlElementImpl()
       
    47     {
       
    48 
       
    49     CXmlElementImpl* child = (CXmlElementImpl*)FirstChild();
       
    50     while ( child != NULL )
       
    51         {
       
    52         CXmlElementImpl* sibling = (CXmlElementImpl*)child->NextSibling();
       
    53         delete child;
       
    54         child = sibling;
       
    55         }
       
    56     }
       
    57 
       
    58 // ---------------------------------------------------------------------------
       
    59 // Set the value for a given attribute
       
    60 // ---------------------------------------------------------------------------
       
    61 TInt CXmlElementImpl::SetAttributeL( const TDesC& /* aName */,
       
    62                                      const TDesC& /* aValue */ )
       
    63     {
       
    64     return KErrNone;
       
    65     }
       
    66 
       
    67 // ---------------------------------------------------------------------------
       
    68 // Remove a given attribute
       
    69 // At this time this method is not implemented
       
    70 // ---------------------------------------------------------------------------
       
    71 TInt CXmlElementImpl::RemoveAttribute( const TDesC& /* aName */ )
       
    72     {
       
    73     return KErrNone;
       
    74     }
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // Accessor for the tag name of the current element
       
    78 // ---------------------------------------------------------------------------
       
    79 const TDesC& CXmlElementImpl::TagName()
       
    80     {
       
    81 
       
    82     HBufC *lEmptyBuf = NULL;
       
    83     return *lEmptyBuf;
       
    84 
       
    85     }
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 // Find out if the current element has child elements
       
    89 // ---------------------------------------------------------------------------
       
    90 TBool CXmlElementImpl::HasChildNodes()
       
    91     {
       
    92     return ( iFirstChild != NULL );
       
    93     }
       
    94 
       
    95 // ---------------------------------------------------------------------------
       
    96 // Accessor for the first child object of the current element
       
    97 // ---------------------------------------------------------------------------
       
    98 MXmlElement* CXmlElementImpl::FirstChild()
       
    99     {
       
   100     return iFirstChild;
       
   101     }
       
   102 
       
   103 // ---------------------------------------------------------------------------
       
   104 // Accessor for the last child object of the current element
       
   105 // ---------------------------------------------------------------------------
       
   106 MXmlElement* CXmlElementImpl::LastChild()
       
   107     {
       
   108     return iLastChild;
       
   109     }
       
   110 
       
   111 // ---------------------------------------------------------------------------
       
   112 // Accessor for the document object of the current element
       
   113 // ---------------------------------------------------------------------------
       
   114 MXmlDocument* CXmlElementImpl::OwnerDocument()
       
   115     {
       
   116     return iOwnerDocument;
       
   117     }
       
   118 
       
   119 // ---------------------------------------------------------------------------
       
   120 // Accessor for the next sibling (element) object of the current element
       
   121 // ---------------------------------------------------------------------------
       
   122 MXmlElement* CXmlElementImpl::NextSibling()
       
   123     {
       
   124     return iNextSibling;
       
   125     }
       
   126 
       
   127 // ---------------------------------------------------------------------------
       
   128 // Accessor for the previous sibling (element) object of the current element
       
   129 // ---------------------------------------------------------------------------
       
   130 MXmlElement* CXmlElementImpl::PreviousSibling()
       
   131     {
       
   132     CXmlElementImpl* sibling = this; 
       
   133     CXmlElementImpl* previousSibling = NULL;
       
   134     
       
   135     while ( sibling != NULL )
       
   136         {
       
   137         sibling = (CXmlElementImpl*)sibling->NextSibling();
       
   138 
       
   139         if (sibling == this)
       
   140         {
       
   141         	return previousSibling;
       
   142         }
       
   143 
       
   144         	previousSibling = sibling;
       
   145         }
       
   146 
       
   147     return NULL;
       
   148     }
       
   149 
       
   150 // ---------------------------------------------------------------------------
       
   151 // Accessor for the parent element object of the current element
       
   152 // ---------------------------------------------------------------------------
       
   153 MXmlElement* CXmlElementImpl::ParentNode()
       
   154     {
       
   155     return iParentNode;
       
   156     }
       
   157 
       
   158 // ---------------------------------------------------------------------------
       
   159 // Accessor to set the first child object of the current element
       
   160 // ---------------------------------------------------------------------------
       
   161 void CXmlElementImpl::SetFirstChild( MXmlElement* aElement )
       
   162     {
       
   163     iFirstChild = aElement;
       
   164     }
       
   165 
       
   166 // ---------------------------------------------------------------------------
       
   167 // Accessor to set the last child object of the current element
       
   168 // ---------------------------------------------------------------------------
       
   169 void CXmlElementImpl::SetLastChild( MXmlElement* aElement )
       
   170     {
       
   171     iLastChild = aElement;
       
   172     }
       
   173 
       
   174 // ---------------------------------------------------------------------------
       
   175 // Accessor to set the document object of the current element
       
   176 // ---------------------------------------------------------------------------
       
   177 void CXmlElementImpl::SetOwnerDocument( MXmlDocument* aElement )
       
   178     {
       
   179     iOwnerDocument = aElement;
       
   180     }
       
   181 
       
   182 // ---------------------------------------------------------------------------
       
   183 // Accessor to set the next sibling (element) object of the current element
       
   184 // ---------------------------------------------------------------------------
       
   185 void CXmlElementImpl::SetNextSibling( MXmlElement* aElement )
       
   186     {
       
   187     iNextSibling = aElement;
       
   188     }
       
   189 
       
   190 // ---------------------------------------------------------------------------
       
   191 // Accessor to set the parent element object of the current element
       
   192 // ---------------------------------------------------------------------------
       
   193 void CXmlElementImpl::SetParentNode( MXmlElement* aElement )
       
   194     {
       
   195     iParentNode = aElement;
       
   196     }
       
   197 
       
   198 // ---------------------------------------------------------------------------
       
   199 // Append a new object as the child of the current element
       
   200 // Place the new object in the proper location, as the last child
       
   201 // ---------------------------------------------------------------------------
       
   202 MXmlElement* CXmlElementImpl::AppendChildL( MXmlElement* aNewChild, TBool /*aIsJSR226Element*/ )
       
   203     {
       
   204     // if no node was passed, then nothing to do
       
   205     if ( aNewChild == NULL )
       
   206         {
       
   207         return NULL;
       
   208         }
       
   209 
       
   210     // first remove the node from its parent if it has one
       
   211     MXmlElement* lparent = aNewChild->ParentNode();
       
   212 
       
   213     
       
   214     //AJD the parent != this needs to be removed so AppendChild works correctly
       
   215 //	if ( parent != NULL && parent != this)
       
   216 
       
   217     if ( lparent != NULL )
       
   218         {
       
   219         lparent->RemoveChild(aNewChild);
       
   220         }
       
   221 
       
   222     // Set the new node's parent
       
   223     aNewChild->SetParentNode( this );
       
   224     // Set the new node's next sibling
       
   225     aNewChild->SetNextSibling( NULL );
       
   226     // If previous sibling is tracked:
       
   227     // Set the new node's previous sibling
       
   228     //        aNewChild->SetPreviousSibling(iXmlElementImpl->LastChild());
       
   229     // Set new node as the first child, if it is
       
   230     if ( FirstChild() == NULL )
       
   231         {
       
   232         SetFirstChild( aNewChild );
       
   233         }
       
   234     // Set the new node as the next sibling of previously last child
       
   235     MXmlElement* lLast   = LastChild();
       
   236     if ( lLast )
       
   237         {
       
   238         lLast->SetNextSibling( aNewChild );
       
   239         }
       
   240     // Set the new node as last child
       
   241     SetLastChild( aNewChild );
       
   242 
       
   243     // notity of change to document
       
   244     if ( iOwnerDocument )
       
   245         {
       
   246         aNewChild->SetOwnerDocument(iOwnerDocument);
       
   247 
       
   248         iOwnerDocument->ElementAppendedOrRemoved();
       
   249         }
       
   250 
       
   251     return aNewChild;
       
   252     }
       
   253 
       
   254 // ---------------------------------------------------------------------------
       
   255 // Remove a given object from the list of child elements
       
   256 // ---------------------------------------------------------------------------
       
   257 void CXmlElementImpl::RemoveChild ( MXmlElement* aRemoveChild )
       
   258     {
       
   259     if ( aRemoveChild )
       
   260         {
       
   261         // the remove child is the first child
       
   262         if ( FirstChild() == aRemoveChild )
       
   263             {
       
   264             if( aRemoveChild->NextSibling() )
       
   265                 {
       
   266                 SetFirstChild( aRemoveChild->NextSibling() );
       
   267                 }
       
   268             else
       
   269                 {
       
   270                 // the remove child is the only child
       
   271                 SetFirstChild( NULL );
       
   272                 SetLastChild ( NULL );
       
   273                 }
       
   274             }
       
   275         // the remove child is any sibling
       
   276         else
       
   277             {
       
   278             // find the child pointing to remove child
       
   279             MXmlElement*preSibling   = FirstChild();
       
   280             if (preSibling)
       
   281             {
       
   282             		while ( preSibling && (( preSibling->NextSibling() ) != aRemoveChild) )
       
   283                 	{
       
   284                 	preSibling = preSibling->NextSibling();
       
   285                 	}
       
   286 					
       
   287 					if (preSibling)
       
   288 					{
       
   289             			// check if the remove child is the end child
       
   290             			if ( LastChild() != aRemoveChild  )
       
   291                 		{
       
   292                 			preSibling->SetNextSibling(aRemoveChild->NextSibling());
       
   293                 		}
       
   294             			else
       
   295                 		{
       
   296                 			SetLastChild(preSibling);
       
   297                 		preSibling->SetNextSibling(NULL);
       
   298                 		}
       
   299                 	}
       
   300                 }
       
   301             }
       
   302 
       
   303         // remove child
       
   304         aRemoveChild->SetParentNode( NULL );
       
   305         aRemoveChild->SetNextSibling( NULL );
       
   306         }
       
   307 
       
   308     // notity of change to document
       
   309     if ( iOwnerDocument )
       
   310         {
       
   311         iOwnerDocument->ElementAppendedOrRemoved();
       
   312         }
       
   313     }
       
   314 
       
   315 // ---------------------------------------------------------------------------
       
   316 // Perform a deep clone of this object
       
   317 // This method is not currently implemented
       
   318 // ---------------------------------------------------------------------------
       
   319 MXmlElement* CXmlElementImpl::CloneL(MXmlElement* )
       
   320     {
       
   321     return NULL;
       
   322     }
       
   323 
       
   324 // ---------------------------------------------------------------------------
       
   325 // Copy the contents of this object to the passed object
       
   326 // This method assumes that the passed object has already been
       
   327 // Created using the proper NewL method.
       
   328 // ---------------------------------------------------------------------------
       
   329 void CXmlElementImpl::CopyL( CXmlElementImpl* aDestElement )
       
   330     {
       
   331 
       
   332     // copy the children and everything down the tree
       
   333     MXmlElement* currentChild = FirstChild();
       
   334 
       
   335     while ( currentChild != NULL)
       
   336         {
       
   337         MXmlElement* newElement = currentChild->CloneL(aDestElement);
       
   338 		if( newElement == NULL )/*Duplicate Cloning of Use returns NULL*/
       
   339 			{
       
   340 			break; //breaking out of the while in case of loop
       
   341 			}
       
   342         aDestElement->CXmlElementImpl::AppendChildL(newElement);
       
   343         currentChild = currentChild->NextSibling();
       
   344         }
       
   345     }