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