xdmprotocols/XcapProtocol/XcapAppUsage/XcapDirectoryUsage/src/XcapDirectoryUsage.cpp
branchRCL_3
changeset 17 2669f8761a99
parent 16 2580314736af
child 18 fbd2e7cec7ef
equal deleted inserted replaced
16:2580314736af 17:2669f8761a99
     1 /*
       
     2 * Copyright (c) 2005 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:  CXcapDirectoryUsage
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include <XdmErrors.h>
       
    22 #include <XdmDocumentNode.h>
       
    23 #include <XdmNodeAttribute.h>
       
    24 #include "XcapDirectoryUsage.h"
       
    25 
       
    26 
       
    27 // Used specification
       
    28 // OMA-TS-XDM_Core-V1_0-20051103-C, 03 November 2005
       
    29 
       
    30 // ----------------------------------------------------
       
    31 // CXcapDirectoryUsage::CXcapDirectoryUsage
       
    32 // 
       
    33 // ----------------------------------------------------
       
    34 //
       
    35 CXcapDirectoryUsage::CXcapDirectoryUsage( const CXdmEngine& aXdmEngine ) :
       
    36                                           CXcapAppUsage( aXdmEngine )
       
    37     {
       
    38     }
       
    39 
       
    40 // ----------------------------------------------------
       
    41 // CXcapDirectoryUsage::NewL
       
    42 // 
       
    43 // ----------------------------------------------------
       
    44 //
       
    45 CXcapDirectoryUsage* CXcapDirectoryUsage::NewL( const TXcapAppUsageParams& aParameters )
       
    46     {
       
    47     CXcapDirectoryUsage* self = new ( ELeave ) CXcapDirectoryUsage( aParameters.iXdmEngine );
       
    48     CleanupStack::PushL( self );    // << self
       
    49     self->ConstructL();
       
    50     CleanupStack::Pop( self );      // >> self
       
    51     return self;
       
    52     }
       
    53 
       
    54 // ----------------------------------------------------
       
    55 // CXcapDirectoryUsage::~CXcapDirectoryUsage
       
    56 // 
       
    57 // ----------------------------------------------------
       
    58 //
       
    59 CXcapDirectoryUsage::~CXcapDirectoryUsage()
       
    60     {
       
    61     }
       
    62         
       
    63 // ----------------------------------------------------
       
    64 // CXcapDirectoryUsage::ConstructL
       
    65 // 
       
    66 // ----------------------------------------------------
       
    67 //
       
    68 void CXcapDirectoryUsage::ConstructL()
       
    69     {
       
    70     }
       
    71 
       
    72 // ----------------------------------------------------
       
    73 // CXcapDirectoryUsage::AUID
       
    74 // 
       
    75 // ----------------------------------------------------
       
    76 //
       
    77 TPtrC8 CXcapDirectoryUsage::AUID() const
       
    78     {
       
    79     return TPtrC8( KXdmDirectoryUsageAUID );
       
    80     }
       
    81                  
       
    82 // ----------------------------------------------------
       
    83 // CXcapDirectoryUsage::ContentType
       
    84 // 
       
    85 // ----------------------------------------------------
       
    86 //
       
    87 TPtrC8 CXcapDirectoryUsage::ContentType() const
       
    88     {
       
    89     return TPtrC8( KXdmDirectoryUsageContType );
       
    90     }
       
    91 
       
    92 // ----------------------------------------------------
       
    93 // CXcapDirectoryUsage::DefaultNamespace
       
    94 // 
       
    95 // ----------------------------------------------------
       
    96 //
       
    97 TPtrC8 CXcapDirectoryUsage::DefaultNamespace() const
       
    98     {
       
    99     return TPtrC8( KXdmDirectoryNamespace );
       
   100     }   
       
   101     
       
   102 // ----------------------------------------------------
       
   103 // CXcapDirectoryUsage::ValidateNodeL
       
   104 // 
       
   105 // ----------------------------------------------------
       
   106 //
       
   107 TBool CXcapDirectoryUsage::ValidateNodeL( CXdmDocumentNode& aXdmNode ) 
       
   108     {
       
   109     // This method is called by base class for each element
       
   110     // in document, here we have to declare every element, check element 
       
   111     // datatype, restrictions for values and also do all checking that concerns  
       
   112     // the structure of the element. If the datatype is some of
       
   113     // the common datatypes defined in xcapappusage.h, the node
       
   114     // can pe passed to the base class for value validation.
       
   115     // If the node belongs to this namespace, the return value
       
   116     // should be true, false otherwise.
       
   117 
       
   118     TBool found( EFalse );
       
   119     TPtrC element = aXdmNode.NodeName();
       
   120         
       
   121     // <xcap-directory>
       
   122     if ( Match( element, KXdmXcapDirectory ) ) 
       
   123         {
       
   124         found = ETrue;  
       
   125         }
       
   126     // <folder>
       
   127     else if ( Match( element, KXdmFolder ) )
       
   128         {
       
   129         // required attribute auid
       
   130         if ( !aXdmNode.HasAttribute( KXdmAuid ) )
       
   131             {
       
   132             LeaveWithErrorL( KXcapErrorMissingRequiredAttribute );
       
   133             }
       
   134         // there should be either <entry> or <error-code>
       
   135         // element, not both
       
   136         TBool entry( EFalse );
       
   137         TBool errorcode( EFalse ) ;
       
   138         TInt count( aXdmNode.NodeCount() );
       
   139         for ( TInt i(0); i < count; i++ )
       
   140             {
       
   141             TPtrC childName = aXdmNode.ChileNode(i)->NodeName();            
       
   142             if ( childName.CompareF( KXdmEntry ) ) 
       
   143                 {
       
   144                 entry = ETrue;
       
   145                 }
       
   146             else if ( childName.CompareF( KXdmErrorCode ) ) 
       
   147                 {
       
   148                 errorcode = ETrue;
       
   149                 }
       
   150             }
       
   151         if ( entry && errorcode )   
       
   152             {
       
   153             LeaveWithErrorL( KXcapErrorSchemaViolation );   
       
   154             }
       
   155         found = ETrue;  
       
   156         }
       
   157     // <entry>
       
   158     else if ( Match( element, KXdmEntry ) )
       
   159         {
       
   160         // required attributes uri and etag
       
   161         if ( !aXdmNode.HasAttribute( KXdmUri ) )
       
   162             {
       
   163             LeaveWithErrorL( KXcapErrorMissingRequiredAttribute );
       
   164             }
       
   165         if ( !aXdmNode.HasAttribute( KXdmEtag ) )
       
   166             {
       
   167             LeaveWithErrorL( KXcapErrorMissingRequiredAttribute);
       
   168             }
       
   169         found = ETrue;  
       
   170         }
       
   171     // <error-code>
       
   172     else if ( Match( element, KXdmErrorCode ) ) 
       
   173         {
       
   174         ValidateDataL( EDataTypeString, aXdmNode );
       
   175         found = ETrue;  
       
   176         }
       
   177     return found;
       
   178     }
       
   179         
       
   180 // ----------------------------------------------------
       
   181 // CXcapDirectoryUsage::ValidateAttributeL
       
   182 // 
       
   183 // ----------------------------------------------------
       
   184 //
       
   185 void CXcapDirectoryUsage::ValidateAttributeL( const CXdmNodeAttribute& aXdmNodeAttr )
       
   186     {
       
   187     // This method is called by base class for each attribute
       
   188     // in document, here we have to define data types
       
   189     // for attributes, and pass them to the base class
       
   190     // for the actual data checking.
       
   191     
       
   192     TDataType dataType ( EDataTypeUndefined );
       
   193     TPtrC attribute = aXdmNodeAttr.NodeName();
       
   194     // uri
       
   195     if ( Match( attribute, KXdmUri ) )
       
   196         {
       
   197         dataType = EDataTypeAnyURI;
       
   198         }
       
   199     // etag
       
   200     else if ( Match( attribute, KXdmEtag ) )
       
   201         {
       
   202         dataType = EDataTypeString;
       
   203         }
       
   204     // last-modified
       
   205     else if ( Match( attribute, KXdmLastModified ) )
       
   206         {
       
   207         dataType = EDataTypeDateTime;
       
   208         }
       
   209     // size
       
   210     else if ( Match( attribute, KXdmSize ) )
       
   211         {
       
   212         dataType = EDataTypeNonNegativeInteger;
       
   213         }
       
   214     // auid
       
   215     else if ( Match( attribute, KXdmAuid ) )
       
   216         {
       
   217         dataType = EDataTypeString;
       
   218         }
       
   219     // pass to base class for data validation
       
   220     ValidateDataL( dataType, aXdmNodeAttr );
       
   221     }
       
   222 
       
   223 // ----------------------------------------------------
       
   224 // CXcapDirectoryUsage::AddNamespaceInformationL
       
   225 // 
       
   226 // ----------------------------------------------------
       
   227 //
       
   228 void CXcapDirectoryUsage::AddNamespaceInformationL( CXdmDocument& aXdmDocument )
       
   229     {
       
   230     aXdmDocument.AppendNamespaceL( KXdmDirectoryNamespace, KNullDesC8 );
       
   231     }
       
   232     
       
   233 // End of File
       
   234