simpleengine/xmlutils/src/simpleattribute.cpp
changeset 0 c8caa15ef882
equal deleted inserted replaced
-1:000000000000 0:c8caa15ef882
       
     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:    Simple Engine
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 
       
    23 #include <e32std.h>
       
    24 #include <SenBaseAttribute.h>
       
    25 #include <SenXmlUtils.h>
       
    26 #include "simpleattribute.h"
       
    27 
       
    28 
       
    29 
       
    30 // ================= MEMBER FUNCTIONS =======================
       
    31 //
       
    32 
       
    33 // ----------------------------------------------------------
       
    34 // CSimpleAttribute::CSimpleAttribute
       
    35 // ----------------------------------------------------------
       
    36 //
       
    37 CSimpleAttribute::CSimpleAttribute(  )
       
    38 : iBase( NULL )
       
    39     {
       
    40     }
       
    41 
       
    42 // ----------------------------------------------------------
       
    43 // CSimpleAttribute::~CSimpleAttribute
       
    44 // ----------------------------------------------------------
       
    45 //
       
    46 CSimpleAttribute::~CSimpleAttribute()
       
    47     {
       
    48     delete iBase;
       
    49     }
       
    50 
       
    51 // ----------------------------------------------------------
       
    52 // CSimpleAttribute::NewL
       
    53 // ----------------------------------------------------------
       
    54 //
       
    55 CSimpleAttribute* CSimpleAttribute::NewL(
       
    56     const TDesC8& aName,
       
    57     const TDesC8& aValue )
       
    58     {
       
    59     CSimpleAttribute* self = new (ELeave) CSimpleAttribute( );
       
    60     CleanupStack::PushL( self );
       
    61     self->ConstructL( aName, aValue );
       
    62     CleanupStack::Pop( self );
       
    63     return self;
       
    64     }
       
    65 
       
    66 // ----------------------------------------------------------
       
    67 // CSimpleElement::NewL
       
    68 // ----------------------------------------------------------
       
    69 //
       
    70 CSimpleAttribute* CSimpleAttribute::NewL(
       
    71     CSenBaseAttribute* aAttr )
       
    72     {
       
    73     CSimpleAttribute* self = new (ELeave) CSimpleAttribute( );
       
    74     CleanupStack::PushL( self );
       
    75     self->ConstructL( aAttr );
       
    76     CleanupStack::Pop( self );
       
    77     return self;
       
    78     }
       
    79 
       
    80 // ----------------------------------------------------------
       
    81 // CSimpleAttribute::ConstructL
       
    82 // ----------------------------------------------------------
       
    83 //
       
    84 void CSimpleAttribute::ConstructL(
       
    85     const TDesC8& aName,
       
    86     const TDesC8& aValue )
       
    87     {
       
    88     iBase = CSenBaseAttribute::NewL( aName, aValue );
       
    89     }
       
    90 
       
    91 // ----------------------------------------------------------
       
    92 // CSimpleAttribute::ConstructL
       
    93 // ----------------------------------------------------------
       
    94 //
       
    95 void CSimpleAttribute::ConstructL(
       
    96     CSenBaseAttribute* aAttr )
       
    97     {
       
    98     iRef = aAttr;
       
    99     }
       
   100 
       
   101 // ----------------------------------------------------------
       
   102 // CSimpleElement::BaseElement
       
   103 // ----------------------------------------------------------
       
   104 //
       
   105 CSenBaseAttribute* CSimpleAttribute::BaseElement()
       
   106     {
       
   107     return iBase ? iBase : iRef;
       
   108     }
       
   109 
       
   110 // ----------------------------------------------------------
       
   111 // CSimpleAttribute::Name
       
   112 // ----------------------------------------------------------
       
   113 //
       
   114 const TDesC8& CSimpleAttribute::Name()
       
   115     {
       
   116     return BaseElement()->Name();
       
   117     }
       
   118 
       
   119 // ----------------------------------------------------------
       
   120 // CSimpleAttribute::Value
       
   121 // ----------------------------------------------------------
       
   122 //
       
   123 const TDesC8& CSimpleAttribute::Value()
       
   124     {
       
   125     return BaseElement()->Value();
       
   126     }
       
   127 
       
   128 // ----------------------------------------------------------
       
   129 // CSimpleAttribute::ValueUniLC
       
   130 // ----------------------------------------------------------
       
   131 //
       
   132 HBufC* CSimpleAttribute::ValueUniLC()
       
   133     {
       
   134     // UTF-8 -> Unicode conversion
       
   135     // new buffer is created, ownership is transferred
       
   136     HBufC16* b16 = SenXmlUtils::ToUnicodeLC( BaseElement()->Value( ) );
       
   137     return b16;
       
   138     }
       
   139 
       
   140 // ----------------------------------------------------------
       
   141 // CSimpleAttribute::SetValueL
       
   142 // ----------------------------------------------------------
       
   143 //
       
   144 void CSimpleAttribute::SetValueL( const TDesC& aValue )
       
   145     {
       
   146     HBufC8* b8 = SenXmlUtils::ToUtf8LC( aValue);
       
   147     BaseElement()->SetValueL( b8->Des() );
       
   148     CleanupStack::PopAndDestroy( b8 );
       
   149     }
       
   150 
       
   151