upnp/upnpstack/serviceframework/src/upnppropertysetcontenthandler.cpp
changeset 0 f5a58ecadc66
equal deleted inserted replaced
-1:000000000000 0:f5a58ecadc66
       
     1 /** @file
       
     2 * Copyright (c) 2007 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:  Implements the CUpnpPropertysetContentHandler class
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include "upnppropertysetcontenthandler.h"
       
    20 #include "upnpcontenthandlerscontroller.h"
       
    21 #include "upnpdescriptionproperty.h"
       
    22 #include "upnpsingletagcontenthandler.h"
       
    23 
       
    24 const TInt KDefaultPropertyLength( 32 );
       
    25 
       
    26 // -----------------------------------------------------------------------------
       
    27 // CUpnpPropertysetContentHandler::NewL
       
    28 // Two-phased constructor
       
    29 // -----------------------------------------------------------------------------
       
    30 //
       
    31 CUpnpPropertysetContentHandler* CUpnpPropertysetContentHandler::NewL(
       
    32     CUpnpContentHandlersController& aController,
       
    33     RPointerArray<CUpnpDescriptionProperty>& aResultPropertyset )
       
    34     {
       
    35     CUpnpPropertysetContentHandler* propertysetContentHandler =
       
    36         CUpnpPropertysetContentHandler::NewLC( aController, aResultPropertyset );
       
    37     CleanupStack::Pop( propertysetContentHandler );
       
    38     return propertysetContentHandler;
       
    39     }
       
    40 
       
    41 // -----------------------------------------------------------------------------
       
    42 // CUpnpPropertysetContentHandler::NewLC
       
    43 // Two-phased constructor. Leaves teh object on the CleanupStack
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 CUpnpPropertysetContentHandler* CUpnpPropertysetContentHandler::NewLC(
       
    47     CUpnpContentHandlersController& aController,
       
    48     RPointerArray<CUpnpDescriptionProperty>& aResultPropertyset )
       
    49     {
       
    50     CUpnpPropertysetContentHandler* propertysetContentHandler =
       
    51         new (ELeave) CUpnpPropertysetContentHandler( aController, aResultPropertyset );
       
    52     CleanupStack::PushL( propertysetContentHandler );
       
    53     propertysetContentHandler->ConstructL();
       
    54     return propertysetContentHandler;
       
    55     }
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // CUpnpPropertysetContentHandler::~CUpnpPropertysetContentHandler
       
    59 // Destructor of CUpnpPropertysetContentHandler class
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 CUpnpPropertysetContentHandler::~CUpnpPropertysetContentHandler()
       
    63     {
       
    64     iCurrentPropertyKey.Close();
       
    65     iCurrentPropertyValue.Close();
       
    66     }
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CUpnpPropertysetContentHandler::CUpnpPropertysetContentHandler
       
    70 // Constructor
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 CUpnpPropertysetContentHandler::CUpnpPropertysetContentHandler(
       
    74     CUpnpContentHandlersController& aController,
       
    75     RPointerArray<CUpnpDescriptionProperty>& aResultPropertyset ) :
       
    76     CUpnpContentHandler( aController ), iResultPropertyset( aResultPropertyset )
       
    77     {
       
    78     }
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CUpnpPropertysetContentHandler::ConstructL
       
    82 // Second phase constructor
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 void CUpnpPropertysetContentHandler::ConstructL()
       
    86     {
       
    87     iCurrentPropertyKey.CreateL( KDefaultPropertyLength );
       
    88     iCurrentPropertyValue.CreateL( KDefaultPropertyLength );
       
    89     }
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // CUpnpPropertysetContentHandler::OnStartElementL
       
    93 // This method is a callback to indicate an element has been parsed.
       
    94 // -----------------------------------------------------------------------------
       
    95 //
       
    96 void CUpnpPropertysetContentHandler::OnStartElementL(
       
    97     const RTagInfo& aElement, const RAttributeArray& /*aAttributes*/)
       
    98     {
       
    99     if ( iIsInsidePropertyset )
       
   100         {
       
   101         if ( aElement.LocalName().DesC().Compare( KUpnpProperty ) == 0 )
       
   102             {
       
   103             StoreCurrentPropertyL();
       
   104             iController.SetCurrentContentHandlerL( CUpnpSingleTagContentHandler::NewL(
       
   105                 iController, iCurrentPropertyKey, iCurrentPropertyValue ) );
       
   106             }
       
   107         else
       
   108             {
       
   109             SetIgnoreHandlerL();
       
   110             }
       
   111         }
       
   112     else
       
   113         {
       
   114         if ( aElement.LocalName().DesC().Compare( KUpnpPropertyset ) == 0 )
       
   115             {
       
   116             iIsInsidePropertyset = ETrue;
       
   117             }
       
   118         else
       
   119             {
       
   120             User::Leave( KErrArgument ); //wrong root node
       
   121             }
       
   122         }
       
   123     }
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // CUpnpPropertysetContentHandler::OnEndElementL
       
   127 // This method is a callback to indicate the end of the element has been reached.
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 void CUpnpPropertysetContentHandler::OnEndElementL( const RTagInfo& aElement )
       
   131     {
       
   132     if ( iIsInsidePropertyset )
       
   133         {
       
   134         ASSERT( aElement.LocalName().DesC().Compare(KUpnpPropertyset) == 0 );
       
   135         iIsInsidePropertyset = EFalse;
       
   136         StoreCurrentPropertyL();
       
   137         }
       
   138     else
       
   139         {
       
   140         ASSERT( EFalse );   
       
   141         }
       
   142     }
       
   143 
       
   144 // -----------------------------------------------------------------------------
       
   145 // CUpnpPropertysetContentHandler::OnContentL
       
   146 // This method is a callback that sends the content of the element.
       
   147 // -----------------------------------------------------------------------------
       
   148 //
       
   149 void CUpnpPropertysetContentHandler::OnContentL( const TDesC8& /*aBytes*/)
       
   150     {
       
   151     }
       
   152 
       
   153 // -----------------------------------------------------------------------------
       
   154 // CUpnpPropertysetContentHandler::StoreCurrentPropertyL
       
   155 // Store parsed current property values in result set, and reset its values.
       
   156 // -----------------------------------------------------------------------------
       
   157 //
       
   158 void CUpnpPropertysetContentHandler::StoreCurrentPropertyL()
       
   159     {
       
   160     if ( iCurrentPropertyKey.Length() > 0 )
       
   161         {
       
   162         CUpnpDescriptionProperty* currentProperty =
       
   163             CUpnpDescriptionProperty::NewL( iCurrentPropertyKey, iCurrentPropertyValue );
       
   164         CleanupStack::PushL( currentProperty );
       
   165         iResultPropertyset.AppendL( currentProperty );
       
   166         CleanupStack::Pop( currentProperty );
       
   167         iCurrentPropertyKey.Zero();
       
   168         iCurrentPropertyValue.Zero();
       
   169         }
       
   170     }
       
   171 //  End of File