websrv_pub/xml_fragment_api/tsrc/senfragmentTester/src/mainfragment.cpp
changeset 0 62f9d29f7211
equal deleted inserted replaced
-1:000000000000 0:62f9d29f7211
       
     1 /*
       
     2 * Copyright (c) 2009 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 #include "mainfragment.h"
       
    24 #include "SenFragmentBase.h"
       
    25 
       
    26 namespace
       
    27     {
       
    28 	const TInt KStateParsingDelegate    = 100;
       
    29     _LIT8(KMainFragmentXmlns,   "urn:main:fragment");
       
    30     _LIT8(KMainFragmentName,    "MainFragment");
       
    31     _LIT8(KMainFragmentQName,   "mn:MainFragment");
       
    32     _LIT8(KDelegateName,        "DelegateFragment");
       
    33     }
       
    34 
       
    35 CMainFragment* CMainFragment::NewL()
       
    36     {
       
    37     CMainFragment* pNew = NewLC();
       
    38     CleanupStack::Pop(); // pNew;
       
    39     return pNew;
       
    40     }
       
    41 
       
    42 CMainFragment* CMainFragment::NewLC()
       
    43     {
       
    44     CMainFragment* pNew = new (ELeave) CMainFragment;
       
    45     CleanupStack::PushL(pNew);
       
    46     pNew->BaseConstructL();
       
    47     return pNew;
       
    48     }
       
    49 
       
    50 
       
    51 CMainFragment* CMainFragment::NewL(
       
    52     const TDesC8& aNsUri,
       
    53     const TDesC8& aLocalName,
       
    54     const TDesC8& aQName
       
    55     )
       
    56     {
       
    57     CMainFragment* pNew = NewLC( aNsUri, aLocalName, aQName );
       
    58     CleanupStack::Pop(); // pNew;
       
    59     return pNew;
       
    60     }
       
    61 
       
    62 CMainFragment* CMainFragment::NewLC(
       
    63     const TDesC8& aNsUri,
       
    64     const TDesC8& aLocalName,
       
    65     const TDesC8& aQName
       
    66     )
       
    67     {
       
    68     CMainFragment* pNew = new (ELeave) CMainFragment;
       
    69     CleanupStack::PushL(pNew);
       
    70     pNew->BaseConstructL(aNsUri, aLocalName, aQName);
       
    71     return pNew;
       
    72     }
       
    73 
       
    74 
       
    75 CMainFragment::CMainFragment()
       
    76 : ipDelegateFragment(NULL)
       
    77     {
       
    78     }
       
    79 
       
    80 void CMainFragment::BaseConstructL()
       
    81     {
       
    82     CSenFragmentBase::BaseConstructL(
       
    83         KMainFragmentXmlns,
       
    84         KMainFragmentName,
       
    85         KMainFragmentQName
       
    86         );
       
    87     }
       
    88 
       
    89 void CMainFragment::BaseConstructL(
       
    90     const TDesC8& aNsUri,
       
    91     const TDesC8& aLocalName,
       
    92     const TDesC8& aQName
       
    93     )
       
    94     {
       
    95     CSenFragmentBase::BaseConstructL(aNsUri, aLocalName, aQName);
       
    96     }
       
    97 
       
    98 CMainFragment::~CMainFragment()
       
    99     {
       
   100     delete ipDelegateFragment;
       
   101     }
       
   102 
       
   103 void CMainFragment::OnStartElementL(const RTagInfo& aElement,
       
   104                                     const RAttributeArray& aAttributes,
       
   105                                     TInt aErrorCode)
       
   106     {
       
   107     switch (iState)
       
   108         {
       
   109         case KSenStateSave:
       
   110             {
       
   111             const TPtrC8 saxLocalName   = aElement.LocalName().DesC();
       
   112 
       
   113             if (saxLocalName == KDelegateName)
       
   114                 {
       
   115                 const TPtrC8 saxNsUri       = aElement.Uri().DesC();
       
   116                 const TPtrC8 saxPrefix      = aElement.Prefix().DesC();
       
   117 
       
   118                 TXmlEngElement element = AsElementL();
       
   119 
       
   120 				ipDelegateFragment = CDelegateFragment::NewL(
       
   121 					                         saxNsUri, saxLocalName,
       
   122 					                         saxPrefix, aAttributes
       
   123 					                         );
       
   124 
       
   125                 iState = KStateParsingDelegate;
       
   126 
       
   127                 OnDelegateParsingL(*ipDelegateFragment);
       
   128                 }
       
   129             else
       
   130                 {
       
   131                 CSenFragmentBase::OnStartElementL(aElement, aAttributes,
       
   132                                                   aErrorCode);
       
   133                 }
       
   134             break;
       
   135             }
       
   136         default:
       
   137             {
       
   138             CSenFragmentBase::OnStartElementL(aElement, aAttributes,
       
   139                                             aErrorCode);
       
   140             break;
       
   141             }
       
   142         }
       
   143     }
       
   144 
       
   145 void CMainFragment::OnEndElementL(const RTagInfo& aElement,
       
   146         						          TInt aErrorCode)
       
   147 
       
   148     {
       
   149     switch(iState)
       
   150         {
       
   151         case KStateParsingDelegate:
       
   152             {
       
   153             iState = KSenStateSave;
       
   154             break;
       
   155             }
       
   156 
       
   157         default:
       
   158             {
       
   159             CSenFragmentBase::OnEndElementL(aElement, aErrorCode);
       
   160             break;
       
   161             }
       
   162         }
       
   163     }
       
   164     
       
   165 CDelegateFragment& CMainFragment::DelegateFragment()
       
   166     {
       
   167     return *ipDelegateFragment;
       
   168     }
       
   169 
       
   170 // End of File
       
   171