upnpmediaserver/contentdirectoryservice/src/upnpelementbean.cpp
changeset 0 7f85d04be362
child 12 cdcbf344a1d3
equal deleted inserted replaced
-1:000000000000 0:7f85d04be362
       
     1 /** @file
       
     2 * Copyright (c) 2005-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:  Element table data handler
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <xmlengdom.h>
       
    22 #include "upnpelementbean.h"
       
    23 #include "upnpcontentdirectoryglobals.h"
       
    24 #include "upnpcdutils.h"
       
    25 #include <upnpelement.h>
       
    26 #include <upnpobject.h>
       
    27 #include <uriutils.h>
       
    28 #include "upnpstring.h"
       
    29 
       
    30 // ============================ MEMBER FUNCTIONS ===============================
       
    31 
       
    32 // -----------------------------------------------------------------------------
       
    33 // CUpnpElementBean::CUpnpElementBean
       
    34 // C++ default constructor can NOT contain any code, that
       
    35 // might leave.
       
    36 // -----------------------------------------------------------------------------
       
    37 //
       
    38 CUpnpElementBean::CUpnpElementBean()
       
    39 {
       
    40 }
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // CUpnpElementBean::ConstructL
       
    44 // Symbian 2nd phase constructor can leave.
       
    45 // -----------------------------------------------------------------------------
       
    46 //
       
    47 void CUpnpElementBean::ConstructL()
       
    48 {
       
    49 	iElmValue = KNullString8().AllocL();
       
    50 }
       
    51 // -----------------------------------------------------------------------------
       
    52 // CUpnpElementBean::NewLC
       
    53 // Two-phased constructor.
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 CUpnpElementBean* CUpnpElementBean::NewLC()
       
    57 {
       
    58     CUpnpElementBean* self = new( ELeave ) CUpnpElementBean;
       
    59     CleanupStack::PushL( self );
       
    60     self->ConstructL();
       
    61     return self;
       
    62 }
       
    63 // -----------------------------------------------------------------------------
       
    64 // CUpnpElementBean::NewLC
       
    65 // Two-phased constructor.
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 CUpnpElementBean* CUpnpElementBean::NewLC(const RDbRowSet& aRowSet)
       
    69 {
       
    70     CUpnpElementBean* self = NewLC();
       
    71     self->SetL(aRowSet);
       
    72     return self;
       
    73 }    
       
    74 // -----------------------------------------------------------------------------
       
    75 // CUpnpElementBean::~CUpnpElementBean
       
    76 // Destructor
       
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 CUpnpElementBean::~CUpnpElementBean()
       
    80 {
       
    81     delete iElmName;
       
    82     delete iElmValue;
       
    83 }
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CUpnpElementBean::SetL
       
    87 // (other items were commented in a header).
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 void CUpnpElementBean::SetL(const RDbRowSet& aRowSet)
       
    91 {
       
    92     // get cols' ids
       
    93     CDbColSet* colSet = aRowSet.ColSetL();
       
    94     CleanupStack::PushL(colSet);
       
    95     const TInt  idColNo         = colSet->ColNo(KElmIdColName);
       
    96     const TInt  nameColNo       = colSet->ColNo(KElmNameColName);
       
    97     const TInt  hasAttrColNo    = colSet->ColNo(KElmHasAttrColName);
       
    98     const TInt  objIdColNo      = colSet->ColNo(KElmObjIdColName);
       
    99     const TInt  isRequiredColNo = colSet->ColNo(KElmIsRequiredColName);
       
   100     const TInt  valueColNo      = colSet->ColNo(KElmValueColName);
       
   101     CleanupStack::PopAndDestroy(colSet);
       
   102     
       
   103     // for each column call setter
       
   104     if( idColNo != KDbNullColNo )
       
   105     {
       
   106         SetElmId( aRowSet.ColInt(idColNo) );
       
   107     }
       
   108     if( nameColNo != KDbNullColNo )
       
   109     {
       
   110         SetElmNameL( aRowSet.ColDes8(nameColNo) );
       
   111     }
       
   112     if( hasAttrColNo != KDbNullColNo )
       
   113     {
       
   114         SetElmHasAttribute( aRowSet.ColUint8(hasAttrColNo) );
       
   115     }
       
   116     if( objIdColNo != KDbNullColNo )
       
   117     {
       
   118         SetElmObjId( aRowSet.ColInt(objIdColNo) );
       
   119     }
       
   120     if( isRequiredColNo != KDbNullColNo )
       
   121     {
       
   122         SetElmIsRequired( aRowSet.ColUint8(isRequiredColNo) );
       
   123     }
       
   124     if( valueColNo != KDbNullColNo )
       
   125     {
       
   126         SetElmValueL(aRowSet, valueColNo);
       
   127     }
       
   128 }
       
   129 // -----------------------------------------------------------------------------
       
   130 // CUpnpElementBean::SetElmNameL
       
   131 // (other items were commented in a header).
       
   132 // -----------------------------------------------------------------------------
       
   133 //
       
   134 void CUpnpElementBean::SetElmNameL(const TDesC8& aElmName)
       
   135 {
       
   136     delete iElmName;
       
   137     iElmName = NULL;
       
   138     iElmName = aElmName.AllocL();
       
   139 }
       
   140 // -----------------------------------------------------------------------------
       
   141 // CUpnpElementBean::SetElmValueL
       
   142 // (other items were commented in a header).
       
   143 // -----------------------------------------------------------------------------
       
   144 //
       
   145 void CUpnpElementBean::SetElmValueL(const RDbRowSet& aRowSet, const TInt aColNo)
       
   146 {
       
   147     delete iElmValue;
       
   148     iElmValue = NULL;
       
   149     iElmValue = ReadLongTextColL(aRowSet, aColNo);
       
   150 }
       
   151 // -----------------------------------------------------------------------------
       
   152 // CUpnpElementBean::SetElmValueL
       
   153 // (other items were commented in a header).
       
   154 // -----------------------------------------------------------------------------
       
   155 //
       
   156 void CUpnpElementBean::SetElmValueL(const TDesC8& aVal)
       
   157 {
       
   158 	delete iElmValue;
       
   159 	iElmValue = NULL;
       
   160 	iElmValue = aVal.AllocL();
       
   161 }
       
   162 // -----------------------------------------------------------------------------
       
   163 // CUpnpElementBean::ElmName
       
   164 // (other items were commented in a header).
       
   165 // -----------------------------------------------------------------------------
       
   166 //
       
   167 TDesC8& CUpnpElementBean::ElmName() const
       
   168 {
       
   169     return *iElmName;
       
   170 }
       
   171 // -----------------------------------------------------------------------------
       
   172 // CUpnpElementBean::AttachToXmlElmL
       
   173 // (other items were commented in a header).
       
   174 // -----------------------------------------------------------------------------
       
   175 //
       
   176 TXmlEngElement CUpnpElementBean::AttachElmL(TXmlEngElement aElement) const
       
   177 {
       
   178     // new element
       
   179     TXmlEngElement element;
       
   180     
       
   181     // Check if it's local name or if it has a namespace prefix also
       
   182     TInt pos = iElmName->Find( KColon8 );
       
   183     if( pos == KErrNotFound )
       
   184     { //local name
       
   185         element = aElement.AddNewElementL( *iElmName );
       
   186     }
       
   187     else    
       
   188     { //local name with prefix
       
   189         element = aElement.AddNewElementUsePrefixL( 
       
   190                     iElmName->Right( iElmName->Length() - pos - 1 ), // name
       
   191                     iElmName->Left( pos ) ); // prefix
       
   192     }
       
   193 
       
   194     // value     
       
   195     element.SetValueL( *iElmValue );
       
   196 
       
   197     return element;
       
   198 }
       
   199 // -----------------------------------------------------------------------------
       
   200 // CUpnpElementBean::ValAsUriL
       
   201 // (other items were commented in a header).
       
   202 // -----------------------------------------------------------------------------
       
   203 //
       
   204 HBufC8* CUpnpElementBean::ValAsUriL() const 
       
   205 {    
       
   206     // uris have to be properly escaped
       
   207     HBufC* tmp = UpnpCdUtils::Des8ToDesLC(*iElmValue);        
       
   208     TUriParser uripar;
       
   209     uripar.Parse(*tmp);
       
   210     CUri8* uri = uri = UriUtils::ConvertToInternetFormL(uripar);
       
   211     CleanupStack::PopAndDestroy(tmp);        
       
   212     if (uri->Uri().UriDes().Length())
       
   213     {                
       
   214         HBufC8* tmp2 = UpnpString::StringReplaceL(uri->Uri().UriDes(),KHash8,KHashASCII8);        
       
   215         delete uri;
       
   216         return tmp2;                         
       
   217     }
       
   218     HBufC8* uriDes = uri->Uri().UriDes().Alloc();
       
   219     delete uri;
       
   220     return uriDes;
       
   221         
       
   222 }
       
   223 
       
   224 // -----------------------------------------------------------------------------
       
   225 // CUpnpElementBean::AttachElmL
       
   226 // (other items were commented in a header).
       
   227 // -----------------------------------------------------------------------------
       
   228 //
       
   229 CUpnpElement* CUpnpElementBean::AttachElmL(CUpnpObject* aObj)
       
   230 {
       
   231     // create element
       
   232     CUpnpElement* elm = CUpnpElement::NewLC(*iElmName);
       
   233 	
       
   234 	// copy values
       
   235     elm->SetValueL(*iElmValue);
       
   236 
       
   237 	// is required
       
   238 	elm->SetIsRequired( ElmIsRequired() );
       
   239 	// attach
       
   240 	aObj->AddElementL(elm);
       
   241 	
       
   242 	// clean up
       
   243 	CleanupStack::Pop(elm);
       
   244 	
       
   245 	return elm;
       
   246 }
       
   247 
       
   248 
       
   249 //  End of File