|
1 /* |
|
2 * Copyright (c) 2006-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: Parsing one CParserProperty into the TVPbkFieldVersitProperty |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // Internal includes |
|
20 #include "CVPbkVCardPropertyParser.h" |
|
21 #include "CVPbkVCardContactFieldIterator.h" |
|
22 #include "TVPbkMappingsFindTool.h" |
|
23 #include "CVPbkVCardData.h" |
|
24 #include "CVPbkVCardFieldTypeProperty.h" |
|
25 #include "CVPbkVCardAttributeHandler.h" |
|
26 #include "VPbkVCardEngError.h" |
|
27 #include "CVPbkVCardParser.h" |
|
28 |
|
29 // System includes |
|
30 #include <vcard.h> |
|
31 |
|
32 // Local definitions |
|
33 namespace |
|
34 { |
|
35 const TInt KAtFirstIndex ( 0 ); |
|
36 } // unnamed namespace |
|
37 |
|
38 CVPbkVCardPropertyParser* CVPbkVCardPropertyParser::NewL( |
|
39 CVPbkVCardData& aData, CVPbkVCardAttributeHandler& aAttributeHandler) |
|
40 { |
|
41 CVPbkVCardPropertyParser* self = new (ELeave) |
|
42 CVPbkVCardPropertyParser(aData, aAttributeHandler); |
|
43 CleanupStack::PushL( self ); |
|
44 self->ConstructL(); |
|
45 CleanupStack::Pop( self ); |
|
46 return self; |
|
47 } |
|
48 |
|
49 CVPbkVCardPropertyParser::CVPbkVCardPropertyParser( |
|
50 CVPbkVCardData& aData, CVPbkVCardAttributeHandler& aAttributeHandler) |
|
51 : iData( aData ), iAttributeHandler( aAttributeHandler ) |
|
52 { |
|
53 } |
|
54 |
|
55 void CVPbkVCardPropertyParser::ConstructL() |
|
56 { |
|
57 // Do nothing |
|
58 } |
|
59 |
|
60 CVPbkVCardPropertyParser::~CVPbkVCardPropertyParser() |
|
61 { |
|
62 } |
|
63 |
|
64 CVPbkVCardContactFieldIterator* CVPbkVCardPropertyParser::ParseNextL( CParserProperty* aProperty ) |
|
65 { |
|
66 iCurrentProperty = aProperty; |
|
67 return ComposeVersitPropertyL(); |
|
68 } |
|
69 |
|
70 CVPbkVCardContactFieldIterator* CVPbkVCardPropertyParser::ComposeVersitPropertyL() |
|
71 { |
|
72 CVPbkVCardContactFieldIterator* iterator = |
|
73 CVPbkVCardContactFieldIterator::NewLC( *iCurrentProperty, iData ); |
|
74 if ( !Ignore( iCurrentProperty ) ) |
|
75 { |
|
76 ResolveNameL( iCurrentProperty, *iterator ); |
|
77 ResolveParamsL( iCurrentProperty, *iterator ); |
|
78 ResolveSubfieldsL( iCurrentProperty, *iterator ); |
|
79 } |
|
80 |
|
81 CleanupStack::Pop(); // iterator |
|
82 return iterator; |
|
83 } |
|
84 |
|
85 TBool CVPbkVCardPropertyParser::Ignore( CParserProperty* aProperty ) |
|
86 { |
|
87 // Check if this property is BEGIN/END/VERSION token |
|
88 if ( aProperty->NameUid() == TUid::Uid( KVersitTokenBeginUid ) || |
|
89 aProperty->NameUid() == TUid::Uid( KVersitTokenEndUid ) || |
|
90 aProperty->NameUid() == TUid::Uid( KVersitTokenVersionUid ) ) |
|
91 { |
|
92 return ETrue; |
|
93 } |
|
94 |
|
95 return EFalse; |
|
96 } |
|
97 |
|
98 void CVPbkVCardPropertyParser::ResolveNameL( CParserProperty* aProperty, |
|
99 CVPbkVCardContactFieldIterator& /*aIterator*/ ) |
|
100 { |
|
101 HBufC8* name = ConvertToUpperCaseLC( aProperty->Name() ); |
|
102 |
|
103 iVersitProperty.SetName( |
|
104 static_cast<TVPbkFieldTypeName>( |
|
105 TVPbkMappingsFindTool::FindIdByName( *name, |
|
106 iData.VNameIdNameMappings() ) ) ); |
|
107 // Set extension name if exists |
|
108 // All VCard properties |
|
109 for ( TInt i = 0; i < iData.Properties().Count(); ++i ) |
|
110 { |
|
111 CVPbkVCardFieldTypeProperty* vcardProperty = iData.Properties()[ i ]; |
|
112 if ( vcardProperty->Name().Compare( *name ) == 0 ) |
|
113 { |
|
114 const TVPbkVCardIndexedProperty& indexedProperty = |
|
115 vcardProperty->IndexedPropertyAt( KAtFirstIndex ); |
|
116 |
|
117 // Add extension name |
|
118 if ( indexedProperty.Property().ExtensionName().Length() > 0 ) |
|
119 { |
|
120 iVersitProperty.SetExtensionName |
|
121 ( indexedProperty.Property().ExtensionName() ); |
|
122 break; |
|
123 } |
|
124 } |
|
125 } |
|
126 CleanupStack::PopAndDestroy( name ); |
|
127 } |
|
128 |
|
129 void CVPbkVCardPropertyParser::ResolveParamsL( CParserProperty* aProperty, |
|
130 CVPbkVCardContactFieldIterator& aIterator ) |
|
131 { |
|
132 TArray< CVPbkVCardIdNameMapping* > paramArray = |
|
133 iData.ParamIdNameMappings(); |
|
134 TVPbkFieldTypeParameters parameters; |
|
135 |
|
136 for ( TInt n = 0; n < paramArray.Count(); ++n ) |
|
137 { |
|
138 CParserParam* param = aProperty->Param( paramArray[ n ]->Name() ); |
|
139 if ( param ) |
|
140 { |
|
141 HBufC8* name = ConvertToUpperCaseLC( param->Name() ); |
|
142 |
|
143 TVPbkFieldTypeParameter fieldTypeParam = |
|
144 static_cast<TVPbkFieldTypeParameter>( |
|
145 TVPbkMappingsFindTool::FindIdByName( *name, paramArray ) ); |
|
146 if (!iAttributeHandler.CreateAttributeL(fieldTypeParam)) |
|
147 { |
|
148 // No attribute created from fieldTypeParam, |
|
149 // so add to parameters list |
|
150 parameters.Add(fieldTypeParam); |
|
151 } |
|
152 aIterator.AppendAttribute( iAttributeHandler.Attribute() ); |
|
153 CleanupStack::PopAndDestroy( name ); |
|
154 } |
|
155 else |
|
156 { |
|
157 // If EMAIL property not include default parameter then we need to |
|
158 // set it here, because otherwise it not mapped to any field in VPbk |
|
159 if ( paramArray[ n ]->Id() == EVPbkVersitParamINTERNET ) |
|
160 { |
|
161 HBufC8* name = ConvertToUpperCaseLC( paramArray[ n ]->Name() ); |
|
162 |
|
163 TVPbkFieldTypeParameter fieldTypeParam = |
|
164 static_cast<TVPbkFieldTypeParameter>( |
|
165 TVPbkMappingsFindTool::FindIdByName( *name, paramArray ) ); |
|
166 if (!iAttributeHandler.CreateAttributeL(fieldTypeParam)) |
|
167 { |
|
168 // No attribute created from fieldTypeParam, |
|
169 // so add to parameters list |
|
170 parameters.Add(fieldTypeParam); |
|
171 } |
|
172 aIterator.AppendAttribute( iAttributeHandler.Attribute() ); |
|
173 CleanupStack::PopAndDestroy( name ); |
|
174 } |
|
175 } |
|
176 } |
|
177 |
|
178 iVersitProperty.SetParameters( parameters ); |
|
179 } |
|
180 |
|
181 void CVPbkVCardPropertyParser::ResolveSubfieldsL( CParserProperty* aProperty, |
|
182 CVPbkVCardContactFieldIterator& aIterator ) |
|
183 { |
|
184 CParserPropertyValue* value = aProperty->Value(); |
|
185 |
|
186 if ( value->Uid() == TUid::Uid( KVersitPropertyHBufCUid ) || |
|
187 value->Uid() == TUid::Uid( KVersitPropertyBinaryUid ) || |
|
188 value->Uid() == TUid::Uid( KVersitPropertyDateUid ) ) |
|
189 { |
|
190 iVersitProperty.SetSubField( |
|
191 static_cast<TVPbkSubFieldType>( |
|
192 EVPbkVersitSubFieldNone ) ); |
|
193 aIterator.AppendVersitProperty( iVersitProperty ); |
|
194 } |
|
195 else if ( value->Uid() == TUid::Uid( KVersitPropertyCDesCArrayUid ) ) |
|
196 { |
|
197 CParserPropertyValue* value = aProperty->Value(); |
|
198 CParserPropertyValueCDesCArray* arrayProperty = |
|
199 static_cast<CParserPropertyValueCDesCArray*>( value ); |
|
200 CDesCArray* values = arrayProperty->Value(); |
|
201 |
|
202 for ( TInt i = 0; i < values->MdcaCount(); ++i ) |
|
203 { |
|
204 iVersitProperty.SetSubField( |
|
205 static_cast<TVPbkSubFieldType>( i ) ); |
|
206 aIterator.AppendVersitProperty( iVersitProperty ); |
|
207 } |
|
208 } |
|
209 } |
|
210 |
|
211 HBufC8* CVPbkVCardPropertyParser::ConvertToUpperCaseLC( |
|
212 const TDesC8& aOriginalDesC ) |
|
213 { |
|
214 __ASSERT_DEBUG( aOriginalDesC.Length() > 0, |
|
215 VPbkVCardEngError::Panic( VPbkVCardEngError::EInvalidDescriptor ) ); |
|
216 |
|
217 HBufC8* buffer = HBufC8::NewLC( aOriginalDesC.Length() ); |
|
218 TPtr8 bufferPtr( buffer->Des() ); |
|
219 bufferPtr.Copy( aOriginalDesC ); |
|
220 bufferPtr.UpperCase(); |
|
221 return buffer; |
|
222 } |
|
223 |
|
224 // End of file |