xml/xmldomandxpath/src/xmlenginedom/xmlengdombase.cpp
changeset 0 e35f40988205
equal deleted inserted replaced
-1:000000000000 0:e35f40988205
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Document & node callbacks
       
    15 //
       
    16 
       
    17 #include <stdapis/libxml2/xmlengconfig.h>
       
    18 #include <xml/utils/xmlengmem.h>
       
    19 #include <xml/dom/xmlenguserdata.h>
       
    20 #include <xml/dom/xmlengdocument.h>
       
    21 #include "xmlengdomdefs.h"
       
    22 #include "xmlengownednodescontainer.h"
       
    23 #include <xml/dom/xmlengnode.h>
       
    24 #include <xml/dom/xmlengnodefilter.h>
       
    25 #include <stdapis/libxml2/libxml2_tree.h>
       
    26 #include "libxml2_globals_private.h"
       
    27 #include <string.h>
       
    28 
       
    29 
       
    30 void NodeConstructCallback(
       
    31     xmlNodePtr aNode)
       
    32     {
       
    33     // NOTE for further evaluation of component _private is not copied by libxml
       
    34     if (aNode && aNode->_private) 
       
    35         {
       
    36         if (aNode->type == XML_ELEMENT_NODE || aNode->type == XML_ATTRIBUTE_NODE) 
       
    37             {
       
    38             MXmlEngUserData* data = static_cast<MXmlEngUserData*>(aNode->_private);
       
    39             TInt err;
       
    40             TRAP(err,aNode->_private = data->CloneL());
       
    41             if(err == KErrNoMemory)
       
    42             	xmlSetOOM();
       
    43             }
       
    44         }
       
    45     }
       
    46 
       
    47 void NodeDestructCallback(
       
    48     xmlNodePtr aNode )
       
    49     {
       
    50     if (aNode && aNode->_private) 
       
    51         {
       
    52         if (aNode->type == XML_ELEMENT_NODE || aNode->type == XML_ATTRIBUTE_NODE) 
       
    53             {
       
    54             MXmlEngUserData* data = static_cast<MXmlEngUserData*>(aNode->_private);
       
    55             aNode->_private = NULL;
       
    56             data->Destroy();
       
    57             }
       
    58         }
       
    59     }
       
    60 
       
    61 int XMLCALL NodeFilterCallback(void* aFilter, xmlNodePtr aNode)
       
    62     { 
       
    63     MXmlEngNodeFilter* filter = reinterpret_cast<MXmlEngNodeFilter*>(aFilter);
       
    64     return (int)filter->AcceptNode(*reinterpret_cast<TXmlEngNode*>(&aNode));
       
    65     }
       
    66 
       
    67 void SetUserDataCallbacks()
       
    68     {
       
    69     xmlRegisterNodeDefault(NodeConstructCallback);
       
    70     xmlDeregisterNodeDefault(NodeDestructCallback);
       
    71     }
       
    72 
       
    73 xmlChar* xmlCharFromDesC8L(const TDesC8& aDesc)
       
    74     {
       
    75     if(!aDesc.Length())
       
    76         {
       
    77         return NULL;
       
    78         }
       
    79     xmlChar* newContent = (xmlChar*)new(ELeave) TUint8[aDesc.Length() + 1];
       
    80     *(Mem::Copy((TAny*)newContent, aDesc.Ptr(), aDesc.Length())) = 0;
       
    81     return newContent;
       
    82     }
       
    83 
       
    84 void xmlCharAssignToRbuf8L(RBuf8& aOutput,xmlChar* text)
       
    85 {
       
    86 if(aOutput.Length())
       
    87     {
       
    88     aOutput.Close();
       
    89     }
       
    90 if(text)
       
    91     {
       
    92     aOutput.Assign(text,strlen((char*)text),strlen((char*)text));
       
    93     }
       
    94 else
       
    95     {
       
    96     aOutput.Assign(text,0);
       
    97     }
       
    98 }
       
    99 //--------------------------------------------
       
   100 //using CXmlEngOwnedNodesContainer;
       
   101 
       
   102 void LibxmlDocumentCleanup(
       
   103     TAny* aDocPtr )
       
   104     {
       
   105     if(((xmlDocPtr)aDocPtr)->ownedNodes)
       
   106         {
       
   107         CXmlEngOwnedNodesContainer* nc = (CXmlEngOwnedNodesContainer*)(((xmlDocPtr)aDocPtr)->ownedNodes);
       
   108         nc->FreeAll();
       
   109         xmlFree(nc->iNodes);
       
   110         xmlFree(nc);
       
   111         } 
       
   112 	xmlFreeDoc((xmlDocPtr)aDocPtr);
       
   113     }
       
   114 
       
   115 void LibxmlNodeCleanup(
       
   116     TAny* aNodePtr )
       
   117     {
       
   118 	xmlFreeNode((xmlNodePtr)aNodePtr);
       
   119     }