webservices/wsxml/src/sendomfragment.cpp
changeset 0 62f9d29f7211
equal deleted inserted replaced
-1:000000000000 0:62f9d29f7211
       
     1 /*
       
     2 * Copyright (c) 2002-2005 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:        
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 // INCLUDE FILES
       
    26 #include "SenXmlElement.h"
       
    27 #include "SenDomFragment.h"
       
    28 #include "SenXmlConstants.h"
       
    29 #include "SenXmlUtils.h"
       
    30 #include "senxmldebug.h"
       
    31 
       
    32 EXPORT_C CSenDomFragment* CSenDomFragment::NewL()
       
    33     {
       
    34     CSenDomFragment* pNew = new (ELeave) CSenDomFragment;
       
    35     return pNew;
       
    36     }
       
    37 
       
    38 EXPORT_C CSenDomFragment* CSenDomFragment::NewL(const CSenElement& aElement)
       
    39     {
       
    40     CSenDomFragment* pNew = new (ELeave) CSenDomFragment;
       
    41     CleanupStack::PushL(pNew);
       
    42     pNew->BaseConstructL(aElement);
       
    43     CleanupStack::Pop(); // delete pNew;
       
    44     return pNew;
       
    45     }
       
    46 
       
    47 EXPORT_C CSenDomFragment* CSenDomFragment::NewL(const TDesC8& aLocalName)
       
    48     {
       
    49     CSenDomFragment* pNew = new (ELeave) CSenDomFragment;
       
    50     CleanupStack::PushL(pNew);
       
    51     pNew->BaseConstructL(aLocalName);
       
    52     CleanupStack::Pop(); // delete pNew;
       
    53     return pNew;
       
    54     }
       
    55 
       
    56 EXPORT_C CSenDomFragment* CSenDomFragment::NewL(
       
    57     const TDesC8& aNsUri,
       
    58     const TDesC8& aLocalName
       
    59     )
       
    60     {
       
    61     CSenDomFragment* pNew = new (ELeave) CSenDomFragment;
       
    62     CleanupStack::PushL(pNew);
       
    63     pNew->BaseConstructL(aNsUri, aLocalName);
       
    64     CleanupStack::Pop(); // delete pNew;
       
    65     return pNew;
       
    66     }
       
    67 
       
    68 EXPORT_C CSenDomFragment* CSenDomFragment::NewL(
       
    69     const TDesC8& aNsUri,
       
    70     const TDesC8& aLocalName,
       
    71     const TDesC8& aQName,
       
    72     const RAttributeArray& aAttrs
       
    73     )
       
    74     {
       
    75     CSenDomFragment* pNew = new (ELeave) CSenDomFragment;
       
    76     CleanupStack::PushL(pNew);
       
    77     pNew->BaseConstructL(aNsUri, aLocalName, aQName, aAttrs);
       
    78     CleanupStack::Pop(); // delete pNew;
       
    79     return pNew;
       
    80     }
       
    81 
       
    82 EXPORT_C CSenDomFragment* CSenDomFragment::NewL(
       
    83     const TDesC8& aNsUri,
       
    84     const TDesC8& aLocalName,
       
    85     const TDesC8& aQName,
       
    86     /* NOT IN JAVA */
       
    87     const RAttributeArray& aAttrs,
       
    88     CSenElement& aParent
       
    89     )
       
    90     {
       
    91     CSenDomFragment* pNew = new (ELeave) CSenDomFragment;
       
    92     CleanupStack::PushL(pNew);
       
    93     pNew->BaseConstructL(aNsUri, aLocalName, aQName, aAttrs, aParent);
       
    94     CleanupStack::Pop(); // delete pNew;
       
    95     return pNew;
       
    96     }
       
    97 
       
    98 EXPORT_C CSenDomFragment* CSenDomFragment::NewL(
       
    99     const TDesC8& aNsUri,
       
   100     const TDesC8& aLocalName,
       
   101     const TDesC8& aQName
       
   102     )
       
   103     {
       
   104     CSenDomFragment* pNew = new (ELeave) CSenDomFragment;
       
   105     CleanupStack::PushL(pNew);
       
   106     pNew->BaseConstructL(aNsUri, aLocalName, aQName);
       
   107     CleanupStack::Pop(); // delete pNew;
       
   108     return pNew;
       
   109     }
       
   110 
       
   111 EXPORT_C CSenDomFragment::~CSenDomFragment()
       
   112     {
       
   113     if(ipDomDelegate)
       
   114         {
       
   115         // We do not own the element, so remove it from the fragment.
       
   116         ipDomDelegate->ExtractElement();
       
   117         delete ipDomDelegate;
       
   118         ipDomDelegate = NULL;
       
   119         }
       
   120     }
       
   121 
       
   122 EXPORT_C CSenDomFragment::CSenDomFragment()
       
   123 :ipDomDelegate(NULL)
       
   124     {
       
   125     }
       
   126 
       
   127 EXPORT_C void CSenDomFragment::BaseConstructL(const CSenElement& aElement)
       
   128     {
       
   129     CSenBaseFragment::BaseConstructL(aElement);
       
   130     }
       
   131 
       
   132 EXPORT_C void CSenDomFragment::BaseConstructL(const TDesC8& aLocalName)
       
   133     {
       
   134     CSenBaseFragment::BaseConstructL(aLocalName);
       
   135     }
       
   136 
       
   137 EXPORT_C void CSenDomFragment::BaseConstructL(
       
   138     const TDesC8& aNsUri,
       
   139     const TDesC8& aLocalName
       
   140     )
       
   141     {
       
   142     CSenBaseFragment::BaseConstructL(aNsUri, aLocalName);
       
   143     }
       
   144 
       
   145 EXPORT_C void CSenDomFragment::BaseConstructL(
       
   146     const TDesC8& aNsUri,
       
   147     const TDesC8& aLocalName,
       
   148     const TDesC8& aQName,
       
   149     const RAttributeArray& aAttrs
       
   150     )
       
   151     {
       
   152     CSenBaseFragment::BaseConstructL(aNsUri, aLocalName, aQName, aAttrs);
       
   153     }
       
   154 
       
   155 EXPORT_C void CSenDomFragment::BaseConstructL(
       
   156     const TDesC8& aNsUri,
       
   157     const TDesC8& aLocalName,
       
   158     const TDesC8& aQName,
       
   159     const RAttributeArray& aAttrs,
       
   160     CSenElement& aParent
       
   161     )
       
   162     {
       
   163     CSenBaseFragment::BaseConstructL(   aNsUri,
       
   164                                         aLocalName,
       
   165                                         aQName,
       
   166                                         aAttrs,
       
   167                                         aParent);
       
   168     }
       
   169 
       
   170 EXPORT_C void CSenDomFragment::BaseConstructL(
       
   171     const TDesC8& aNsUri,
       
   172     const TDesC8& aLocalName,
       
   173     const TDesC8& aQName
       
   174     )
       
   175     {
       
   176     CSenBaseFragment::BaseConstructL(aNsUri, aLocalName, aQName);
       
   177     }
       
   178 
       
   179 
       
   180 EXPORT_C void CSenDomFragment::BaseConstructL(CSenXmlReader& aReader)
       
   181     {
       
   182     CSenBaseFragment::BaseConstructL(aReader);
       
   183     }
       
   184 
       
   185 
       
   186 EXPORT_C void CSenDomFragment::ParseWithL(CSenXmlReader& aReader) // IOP
       
   187     {
       
   188     CSenBaseFragment::ParseWithL(aReader);
       
   189     iState = KStateSave; // IOP
       
   190     }
       
   191 
       
   192 EXPORT_C void CSenDomFragment::StartElementL(const TDesC8& aNsUri,
       
   193                                              const TDesC8& aLocalName,
       
   194                                              const TDesC8& aQName,
       
   195                                              const RAttributeArray& aAttrs)
       
   196     {
       
   197 
       
   198     // 2004-09-10. moved out from KStateIgnore -code segment
       
   199     if(!ipElement)
       
   200         {
       
   201         ipElement = CSenXmlElement::NewL(aNsUri, aLocalName, aQName);
       
   202         }
       
   203     AllocContentSaverL();
       
   204 
       
   205     if(iState == KStateIgnore)
       
   206         {
       
   207         const TDesC8& localName = ipElement->LocalName();
       
   208         const TDesC8& nsUri = ipElement->NamespaceURI();
       
   209 
       
   210         if(localName == aLocalName && nsUri == aNsUri)
       
   211             {
       
   212             iState = KStateSave; // IOP
       
   213             SetAttributesL(aAttrs);
       
   214             }
       
   215         }
       
   216     else if((iState & KStateSave) == KStateSave)
       
   217         {
       
   218         ExpandL(aNsUri, aLocalName, aQName, aAttrs);
       
   219         }
       
   220     }
       
   221 
       
   222 EXPORT_C void CSenDomFragment::CharactersL(
       
   223     const TDesC8& aChars,
       
   224     const TInt /*aStart*/,
       
   225     const TInt /*aLength*/
       
   226     )
       
   227     {
       
   228     AllocContentSaverL();
       
   229 
       
   230 
       
   231     HBufC8* pCharsCopy = NULL;
       
   232     
       
   233     if (SenXmlUtils::EncodeHttpCharactersL(aChars, pCharsCopy))
       
   234         {
       
   235         CleanupStack::PushL(pCharsCopy);
       
   236         iWs.WriteL(*pCharsCopy);
       
   237         CleanupStack::PopAndDestroy(); // pCharsCopy
       
   238         }
       
   239     else
       
   240         {
       
   241         iWs.WriteL(aChars);
       
   242         }
       
   243     }
       
   244 
       
   245 EXPORT_C void CSenDomFragment::SetAttributesL(const RAttributeArray& aAttrs)
       
   246     {
       
   247     CSenBaseFragment::SetAttributesL(aAttrs);
       
   248     if(ipElement)
       
   249         {
       
   250         ((CSenXmlElement*)ipElement)->SetAttributesL(aAttrs);
       
   251         }
       
   252     }
       
   253 
       
   254 EXPORT_C void CSenDomFragment::ExpandL(
       
   255     const TDesC8& aNsUri,
       
   256     const TDesC8& aLocalName,
       
   257     const TDesC8& aQName,
       
   258     const RAttributeArray& aAttrs
       
   259     )
       
   260     {
       
   261 
       
   262     if(ipDomDelegate)
       
   263         {
       
   264         // We do not own the element, so remove it from the fragment.
       
   265         ipDomDelegate->ExtractElement();
       
   266         delete ipDomDelegate;
       
   267         ipDomDelegate = NULL;
       
   268         }
       
   269 
       
   270     // delegate parsing to a new DOMFragment,
       
   271     // until we encounter the end of an element with the given qualified name
       
   272     ipDomDelegate = CSenDomFragment::NewL(  aNsUri,
       
   273                                             aLocalName,
       
   274                                             aQName,
       
   275                                             aAttrs,
       
   276                                             *ipElement);
       
   277 
       
   278     ipElement->AddElementL(ipDomDelegate->AsElement());
       
   279 
       
   280     DelegateParsingL(*ipDomDelegate); // note that the parsing is actually
       
   281                                       // performed AFTER the StartElement()
       
   282                                       // method, which called this ExpandL()
       
   283                                       // has been fully executed (this is an
       
   284                                       // async signal send to the _same_
       
   285                                       // parser(!)
       
   286     }
       
   287 
       
   288 
       
   289 EXPORT_C void CSenDomFragment::WriteStartElementL(
       
   290                                                const TDesC8& /* aNsUri */,
       
   291                                                const TDesC8& /* aLocalName */,
       
   292                                                const TDesC8& /* aQName */,
       
   293                                                const RAttributeArray& /*aAttrs*/
       
   294                                                    )
       
   295     {
       
   296     // in DOM fragment: do nothing
       
   297     }
       
   298 
       
   299 EXPORT_C void CSenDomFragment::WriteEndElementL(
       
   300                                              const TDesC8& /* aNsUri */,
       
   301                                              const TDesC8& /* aLocalName */,
       
   302                                              const TDesC8& /* aQName */
       
   303                                                  )
       
   304     {
       
   305     // in DOM fragment: do nothing
       
   306     }
       
   307 
       
   308 
       
   309 // Overridden from CSenBaseFragment to be much more simple
       
   310 EXPORT_C void CSenDomFragment::ResumeParsingFromL( // IOP
       
   311                                                const TDesC8& /*aNsUri*/,
       
   312                                                const TDesC8& /*aLocalName*/,
       
   313                                                const TDesC8& /*aQName*/
       
   314                                                    )
       
   315     {
       
   316     iXmlReader->SetContentHandler(*this);
       
   317     if(ipDomDelegate)
       
   318         {
       
   319         // We do not own the element, so remove it from the fragment.
       
   320         ipDomDelegate->ExtractElement();
       
   321         delete ipDomDelegate;
       
   322         ipDomDelegate = NULL;
       
   323         }
       
   324     }
       
   325 
       
   326 // End of File