tizen 2.3.1 release
[framework/web/mobile/wrt-plugins-tizen.git] / src / Contact / JSContactAddress.cpp
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 #include "JSContactAddress.h"
19 #include "ContactAddress.h"
20 #include "ContactUtil.h"
21
22 #include <Logger.h>
23 #include <TimeTracer.h>
24 #include <Export.h>
25 #include <ArgumentValidator.h>
26 #include <JSUtil.h>
27 #include <algorithm>
28
29 namespace DeviceAPI {
30 namespace Contact {
31
32 using namespace DeviceAPI::Common;
33
34 struct ContactAddressHolder {
35     ContactAddressPtr ptr;
36 };
37
38 namespace {
39 const char* CONTACT_CONTACT_ADDRESS = "ContactAddress";
40
41 const char* CONTACT_CONTACT_ADDRESS_COUNTRY = "country";
42 const char* CONTACT_CONTACT_ADDRESS_REGION = "region";
43 const char* CONTACT_CONTACT_ADDRESS_CITY = "city";
44 const char* CONTACT_CONTACT_ADDRESS_STREET_ADDRESS = "streetAddress";
45 const char* CONTACT_CONTACT_ADDRESS_ADDITIONAL_INFORMATION = "additionalInformation";
46 const char* CONTACT_CONTACT_ADDRESS_POSTAL_CODE = "postalCode";
47 const char* CONTACT_CONTACT_ADDRESS_IS_DEFAULT = "isDefault";
48 const char* CONTACT_CONTACT_ADDRESS_TYPES = "types";
49 const char* CONTACT_CONTACT_ADDRESS_LABEL = "label";
50 }
51
52 JSClassDefinition JSContactAddress::m_classInfo = {
53         0,
54         kJSClassAttributeNone,
55         CONTACT_CONTACT_ADDRESS,
56         NULL,
57         JSContactAddress::m_property,
58         NULL, //m_function,
59         JSContactAddress::initialize,
60         JSContactAddress::finalize,
61         NULL, //hasProperty,
62         NULL, //getProperty,
63         NULL, //setProperty,
64         NULL, //deleteProperty,
65         NULL, //getPropertyNames,
66         NULL, //function,
67         NULL, //constructor,
68         NULL, //hasInstance,
69         NULL, //convertToType,
70 };
71
72 JSStaticValue JSContactAddress::m_property[] = {
73         { CONTACT_CONTACT_ADDRESS_COUNTRY, getCountry, setCountry, kJSPropertyAttributeDontDelete },
74         { CONTACT_CONTACT_ADDRESS_REGION, getRegion, setRegion, kJSPropertyAttributeDontDelete },
75         { CONTACT_CONTACT_ADDRESS_CITY, getCity, setCity, kJSPropertyAttributeDontDelete },
76         { CONTACT_CONTACT_ADDRESS_STREET_ADDRESS, getStreetAddress, setStreetAddress, kJSPropertyAttributeDontDelete },
77         { CONTACT_CONTACT_ADDRESS_ADDITIONAL_INFORMATION, getAdditionalInformation, setAdditionalInformation, kJSPropertyAttributeDontDelete },
78         { CONTACT_CONTACT_ADDRESS_POSTAL_CODE, getPostalCode, setPostalCode, kJSPropertyAttributeDontDelete },
79         { CONTACT_CONTACT_ADDRESS_IS_DEFAULT, getIsDefault, setIsDefault, kJSPropertyAttributeDontDelete },
80         { CONTACT_CONTACT_ADDRESS_TYPES, getTypes, setTypes, kJSPropertyAttributeDontDelete },
81         { CONTACT_CONTACT_ADDRESS_LABEL, getLabel, setLabel, kJSPropertyAttributeDontDelete },
82         { 0, 0, 0, 0 }
83 };
84
85 const JSClassDefinition* JSContactAddress::getClassInfo()
86 {
87     return &m_classInfo;
88 }
89
90 JSClassRef JSContactAddress::m_jsClassRef = JSClassCreate(JSContactAddress::getClassInfo());
91
92 JSClassRef DLL_EXPORT JSContactAddress::getClassRef()
93 {
94     if (!m_jsClassRef) {
95         m_jsClassRef = JSClassCreate(&m_classInfo);
96     }
97     return m_jsClassRef;
98 }
99
100 ContactAddressPtr JSContactAddress::getPrivateObject(JSContextRef context, JSValueRef value)
101 {
102     if (!JSValueIsObjectOfClass(context, value, getClassRef())) {
103         LOGE("Type mismatch");
104         throw TypeMismatchException("Type mismatch");
105     }
106
107     JSObjectRef object = JSUtil::JSValueToObject(context, value);
108     ContactAddressHolder* priv = static_cast<ContactAddressHolder*>(JSObjectGetPrivate(object));
109     if (!priv) {
110         LOGE("Priv is null");
111         throw UnknownException("Priv is null");
112     }
113     return priv->ptr;
114 }
115
116 void JSContactAddress::setPrivateObject(JSObjectRef object, ContactAddressPtr native)
117 {
118     ContactAddressHolder* priv = static_cast<ContactAddressHolder*>(JSObjectGetPrivate(object));
119     if (!priv) {
120         LOGE("Priv is null");
121         throw UnknownException("Priv is null");
122     }
123     priv->ptr = native;
124 }
125
126 JSObjectRef JSContactAddress::makeJSObject(JSContextRef context,
127         ContactAddressPtr native)
128 {
129     if (!native) {
130         LOGE("Native is null");
131         throw UnknownException("Native is null");
132     }
133
134     ContactAddressHolder* priv = new(std::nothrow) ContactAddressHolder();
135     if (!priv) {
136         LOGE("Priv is null");
137         throw UnknownException("Priv is null");
138     }
139     priv->ptr = native;
140
141     JSObjectRef obj = JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
142     return obj;
143 }
144
145 void JSContactAddress::initialize(JSContextRef context, JSObjectRef object)
146 {
147     LOGD("Entered");
148 }
149
150 void JSContactAddress::finalize(JSObjectRef object)
151 {
152     LOGD("Entered");
153     ContactAddressHolder* priv = static_cast<ContactAddressHolder*>(JSObjectGetPrivate(object));
154     if (priv) {
155         JSObjectSetPrivate(object, NULL);
156         delete priv;
157         priv = NULL;
158     }
159 }
160
161 JSObjectRef DLL_EXPORT JSContactAddress::constructor(JSContextRef context,
162         JSObjectRef constructor,
163         size_t argumentCount,
164         const JSValueRef arguments[],
165         JSValueRef* exception)
166 {
167     LOGD("Entered");
168
169     ArgumentValidator validator(context, argumentCount, arguments);
170
171     JSObjectRef jsObjRef = JSObjectMake(context, getClassRef(), NULL);
172
173     JSStringRef ctorName = JSStringCreateWithUTF8CString("constructor");
174     JSObjectSetProperty(context, jsObjRef, ctorName, constructor, kJSPropertyAttributeReadOnly
175             | kJSPropertyAttributeDontDelete | kJSPropertyAttributeDontEnum, NULL);
176     JSStringRelease(ctorName);
177
178     try {
179         JSObjectRef dictionary = NULL;
180         dictionary = validator.toObject(0, true);
181
182         ContactAddressPtr priv = ContactAddressPtr(new(std::nothrow) ContactAddress());
183         if (!priv) {
184             LOGE("Priv is null");
185             throw UnknownException("Priv is null");
186         }
187
188         if (dictionary) {
189             JSValueRef country = JSUtil::getProperty(context, dictionary, CONTACT_CONTACT_ADDRESS_COUNTRY);
190             JSValueRef region = JSUtil::getProperty(context, dictionary, CONTACT_CONTACT_ADDRESS_REGION);
191             JSValueRef city = JSUtil::getProperty(context, dictionary, CONTACT_CONTACT_ADDRESS_CITY);
192             JSValueRef street_address = JSUtil::getProperty(context, dictionary, CONTACT_CONTACT_ADDRESS_STREET_ADDRESS);
193             JSValueRef additional_information = JSUtil::getProperty(context, dictionary, CONTACT_CONTACT_ADDRESS_ADDITIONAL_INFORMATION);
194             JSValueRef postal_code = JSUtil::getProperty(context, dictionary, CONTACT_CONTACT_ADDRESS_POSTAL_CODE);
195             JSValueRef is_default = JSUtil::getProperty(context, dictionary, CONTACT_CONTACT_ADDRESS_IS_DEFAULT);
196             JSValueRef address_types = JSUtil::getProperty(context, dictionary, CONTACT_CONTACT_ADDRESS_TYPES);
197             JSValueRef label = JSUtil::getProperty(context, dictionary, CONTACT_CONTACT_ADDRESS_LABEL);
198
199             if (!JSValueIsUndefined(context, country)
200                     && !JSValueIsNull(context, country)) {
201                 priv->setAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_COUNTRY, JSUtil::JSValueToString(context, country));
202             }
203             if (!JSValueIsUndefined(context, region)
204                     && !JSValueIsNull(context, region)) {
205                 priv->setAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_REGION, JSUtil::JSValueToString(context, region));
206             }
207             if (!JSValueIsUndefined(context, city)
208                     && !JSValueIsNull(context, city)) {
209                 priv->setAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_CITY, JSUtil::JSValueToString(context, city));
210             }
211             if (!JSValueIsUndefined(context, street_address)
212                     && !JSValueIsNull(context, street_address)) {
213                 priv->setAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_STREETADDR, JSUtil::JSValueToString(context, street_address));
214             }
215             if (!JSValueIsUndefined(context, additional_information)
216                     && !JSValueIsNull(context, additional_information)) {
217                 priv->setAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_ADDITIONALINFO, JSUtil::JSValueToString(context, additional_information));
218             }
219             if (!JSValueIsUndefined(context, postal_code)
220                     && !JSValueIsNull(context, postal_code)) {
221                 priv->setAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_POSTALCODE, JSUtil::JSValueToString(context, postal_code));
222             }
223             if (!JSValueIsUndefined(context, is_default)) {
224                 priv->setIsDefault(JSUtil::JSValueToBoolean(context, is_default));
225             }
226             if (!JSValueIsUndefined(context, address_types)) {
227                 std::vector<std::string> str_types = JSUtil::JSArrayToStringVector(context, address_types);
228                 size_t size = str_types.size();
229                 if (size > 0) {
230                     for (size_t i = 0; i < size; i++) {
231                         // Verification if string is actual from ContactEmailAddressType
232                         ContactUtil::stringToContactAddressType(str_types[i]);
233                     }
234                     priv->setTypes(str_types);
235                 }
236             }
237             if (!JSValueIsUndefined(context, label)
238                     && !JSValueIsNull(context, label)) {
239                 priv->setAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_LABEL, JSUtil::JSValueToString(context, label));
240             }
241         }
242
243         ContactAddressHolder* holder = new(std::nothrow) ContactAddressHolder();
244         if (!holder) {
245             LOGE("Holder is null");
246             throw UnknownException("Holder is null");
247         }
248         holder->ptr = priv;
249         JSObjectSetPrivate(jsObjRef, static_cast<void*>(holder));
250     }
251     catch (const BasePlatformException &error) {
252         LOGE("ContactAddress creation failed: %s", error.getMessage().c_str());
253     }
254     catch (...) {
255         LOGE("ContactAddress creation failed");
256     }
257
258     return jsObjRef;
259 }
260
261 JSValueRef JSContactAddress::getCountry(JSContextRef context,
262         JSObjectRef object,
263         JSStringRef propertyName,
264         JSValueRef* exception)
265 {
266     LOGD("Entered");
267     try {
268         ContactAddressPtr priv = JSContactAddress::getPrivateObject(context, object);
269         if (!priv) {
270             LOGE("Priv is null");
271             throw UnknownException("Priv is null");
272         }
273         if (!priv->isSet(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_COUNTRY)) {
274             return JSValueMakeNull(context);
275         }
276         return JSUtil::toJSValueRef(context, priv->getAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_COUNTRY));
277     }
278     catch (const BasePlatformException &error) {
279         LOGE("Failed to get contact address country. %s : %s", error.getName().c_str(), error.getMessage().c_str());
280     }
281     catch (...) {
282         LOGE("Unsupported error while getting contact address country.");
283     }
284     return JSValueMakeUndefined(context);
285 }
286
287 JSValueRef JSContactAddress::getRegion(JSContextRef context,
288         JSObjectRef object,
289         JSStringRef propertyName,
290         JSValueRef* exception)
291 {
292     LOGD("Entered");
293     try {
294         ContactAddressPtr priv = JSContactAddress::getPrivateObject(context, object);
295         if (!priv) {
296             LOGE("Priv is null");
297             throw UnknownException("Priv is null");
298         }
299         if (!priv->isSet(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_REGION)) {
300             return JSValueMakeNull(context);
301         }
302         return JSUtil::toJSValueRef(context, priv->getAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_REGION));
303     }
304     catch (const BasePlatformException &error) {
305         LOGE("Failed to get contact address region. %s : %s", error.getName().c_str(), error.getMessage().c_str());
306     }
307     catch (...) {
308         LOGE("Unsupported error while getting contact address region.");
309     }
310     return JSValueMakeUndefined(context);
311 }
312
313 JSValueRef JSContactAddress::getCity(JSContextRef context,
314         JSObjectRef object,
315         JSStringRef propertyName,
316         JSValueRef* exception)
317 {
318     LOGD("Entered");
319     try {
320         ContactAddressPtr priv = JSContactAddress::getPrivateObject(context, object);
321         if (!priv) {
322             LOGE("Priv is null");
323             throw UnknownException("Priv is null");
324         }
325         if (!priv->isSet(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_CITY)) {
326             return JSValueMakeNull(context);
327         }
328         return JSUtil::toJSValueRef(context, priv->getAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_CITY));
329     }
330     catch (const BasePlatformException &error) {
331         LOGE("Failed to get contact address city. %s : %s", error.getName().c_str(), error.getMessage().c_str());
332     }
333     catch (...) {
334         LOGE("Unsupported error while getting contact address city.");
335     }
336     return JSValueMakeUndefined(context);
337 }
338
339 JSValueRef JSContactAddress::getStreetAddress(JSContextRef context,
340         JSObjectRef object,
341         JSStringRef propertyName,
342         JSValueRef* exception)
343 {
344     LOGD("Entered");
345     try {
346         ContactAddressPtr priv = JSContactAddress::getPrivateObject(context, object);
347         if (!priv) {
348             LOGE("Priv is null");
349             throw UnknownException("Priv is null");
350         }
351         if (!priv->isSet(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_STREETADDR)) {
352             return JSValueMakeNull(context);
353         }
354         return JSUtil::toJSValueRef(context, priv->getAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_STREETADDR));
355     }
356     catch (const BasePlatformException &error) {
357         LOGE("Failed to get contact address street address. %s : %s", error.getName().c_str(), error.getMessage().c_str());
358     }
359     catch (...) {
360         LOGE("Unsupported error while getting contact address street address.");
361     }
362     return JSValueMakeUndefined(context);
363 }
364
365 JSValueRef JSContactAddress::getAdditionalInformation(JSContextRef context,
366         JSObjectRef object,
367         JSStringRef propertyName,
368         JSValueRef* exception)
369 {
370     LOGD("Entered");
371     try {
372         ContactAddressPtr priv = JSContactAddress::getPrivateObject(context, object);
373         if (!priv) {
374             LOGE("Priv is null");
375             throw UnknownException("Priv is null");
376         }
377         if (!priv->isSet(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_ADDITIONALINFO)) {
378             return JSValueMakeNull(context);
379         }
380         return JSUtil::toJSValueRef(context, priv->getAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_ADDITIONALINFO));
381     }
382     catch (const BasePlatformException &error) {
383         LOGE("Failed to get contact address additional information. %s : %s", error.getName().c_str(), error.getMessage().c_str());
384     }
385     catch (...) {
386         LOGE("Unsupported error while getting contact address additional information.");
387     }
388     return JSValueMakeUndefined(context);
389 }
390
391 JSValueRef JSContactAddress::getPostalCode(JSContextRef context,
392         JSObjectRef object,
393         JSStringRef propertyName,
394         JSValueRef* exception)
395 {
396     LOGD("Entered");
397     try {
398         ContactAddressPtr priv = JSContactAddress::getPrivateObject(context, object);
399         if (!priv) {
400             LOGE("Priv is null");
401             throw UnknownException("Priv is null");
402         }
403         if (!priv->isSet(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_POSTALCODE)) {
404             return JSValueMakeNull(context);
405         }
406         return JSUtil::toJSValueRef(context, priv->getAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_POSTALCODE));
407     }
408     catch (const BasePlatformException &error) {
409         LOGE("Failed to get contact address postal code. %s : %s", error.getName().c_str(), error.getMessage().c_str());
410     }
411     catch (...) {
412         LOGE("Unsupported error while getting contact address postal code.");
413     }
414     return JSValueMakeUndefined(context);
415 }
416
417 JSValueRef JSContactAddress::getIsDefault(JSContextRef context,
418         JSObjectRef object,
419         JSStringRef propertyName,
420         JSValueRef* exception)
421 {
422     LOGD("Entered");
423     try {
424         ContactAddressPtr priv = JSContactAddress::getPrivateObject(context, object);
425         if (!priv) {
426             LOGE("Priv is null");
427             throw UnknownException("Priv is null");
428         }
429         return JSUtil::toJSValueRef(context, priv->getIsDefault());
430     }
431     catch (const BasePlatformException &error) {
432         LOGE("Failed to get contact address is default flag. %s : %s", error.getName().c_str(), error.getMessage().c_str());
433     }
434     catch (...) {
435         LOGE("Unsupported error while getting contact address is default flag.");
436     }
437     return JSValueMakeUndefined(context);
438 }
439
440 JSValueRef JSContactAddress::getTypes(JSContextRef context,
441         JSObjectRef object,
442         JSStringRef propertyName,
443         JSValueRef* exception)
444 {
445     LOGD("Entered");
446     try {
447         ContactAddressPtr priv = JSContactAddress::getPrivateObject(context, object);
448         if (!priv) {
449             LOGE("Priv is null");
450             throw UnknownException("Priv is null");
451         }
452         return priv->getJSTypes(GlobalContextManager::getInstance()->getGlobalContext(context));
453     }
454     catch (const BasePlatformException &error) {
455         LOGE("Failed to get contact address types. %s : %s", error.getName().c_str(), error.getMessage().c_str());
456     }
457     catch (...) {
458         LOGE("Unsupported error while getting contact address types.");
459     }
460     return JSValueMakeUndefined(context);
461 }
462
463 JSValueRef JSContactAddress::getLabel(JSContextRef context,
464         JSObjectRef object,
465         JSStringRef propertyName,
466         JSValueRef* exception)
467 {
468     LOGD("Entered");
469     try {
470         ContactAddressPtr priv = JSContactAddress::getPrivateObject(context, object);
471         if (!priv) {
472             LOGE("Priv is null");
473             throw UnknownException("Priv is null");
474         }
475         if(!priv->isSet(CONTACT_ADDRESS_ATTRIBUTE_LABEL)) {
476             return JSValueMakeNull(context);
477         }
478         return JSUtil::toJSValueRef(context, priv->getAttribute(CONTACT_ADDRESS_ATTRIBUTE_LABEL));
479     }
480     catch (const BasePlatformException &error) {
481         LOGE("Failed to get contact address label. %s : %s", error.getName().c_str(), error.getMessage().c_str());
482     }
483     catch (...) {
484         LOGE("Unsupported error while getting contact address label.");
485     }
486     return JSValueMakeUndefined(context);
487 }
488
489 bool JSContactAddress::setCountry(JSContextRef context,
490         JSObjectRef object,
491         JSStringRef propertyName,
492         JSValueRef value,
493         JSValueRef* exception)
494 {
495     LOGD("Entered");
496     try {
497         ContactAddressPtr priv = JSContactAddress::getPrivateObject(context, object);
498         if (!priv) {
499             LOGE("Priv is null");
500             throw UnknownException("Priv is null");
501         }
502         if (JSValueIsNull(context, value)) {
503             priv->setAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_COUNTRY, "");
504             priv->setIsSet(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_COUNTRY, false);
505             return true;
506         }
507         std::string _value = JSUtil::JSValueToString(context, value);
508         priv->setAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_COUNTRY, _value);
509     }
510     catch (const BasePlatformException &error) {
511         LOGE("Failed to set contact address country. %s : %s", error.getName().c_str(), error.getMessage().c_str());
512     }
513     catch (...) {
514         LOGE("Unsupported error while setting contact address country.");
515     }
516     return true;
517 }
518
519 bool JSContactAddress::setRegion(JSContextRef context,
520         JSObjectRef object,
521         JSStringRef propertyName,
522         JSValueRef value,
523         JSValueRef* exception)
524 {
525     LOGD("Entered");
526     try {
527         ContactAddressPtr priv = JSContactAddress::getPrivateObject(context, object);
528         if (!priv) {
529             LOGE("Priv is null");
530             throw UnknownException("Priv is null");
531         }
532         if (JSValueIsNull(context, value)) {
533             priv->setAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_REGION, "");
534             priv->setIsSet(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_REGION, false);
535             return true;
536         }
537         std::string _value = JSUtil::JSValueToString(context, value);
538         priv->setAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_REGION, _value);
539     }
540     catch (const BasePlatformException &error) {
541         LOGE("Failed to set contact address region. %s : %s", error.getName().c_str(), error.getMessage().c_str());
542     }
543     catch (...) {
544         LOGE("Unsupported error while setting contact address region.");
545     }
546     return true;
547 }
548
549 bool JSContactAddress::setCity(JSContextRef context,
550         JSObjectRef object,
551         JSStringRef propertyName,
552         JSValueRef value,
553         JSValueRef* exception)
554 {
555     LOGD("Entered");
556     try {
557         ContactAddressPtr priv = JSContactAddress::getPrivateObject(context, object);
558         if (!priv) {
559             LOGE("Priv is null");
560             throw UnknownException("Priv is null");
561         }
562         if (JSValueIsNull(context, value)) {
563             priv->setAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_CITY, "");
564             priv->setIsSet(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_CITY, false);
565             return true;
566         }
567         std::string _value = JSUtil::JSValueToString(context, value);
568         priv->setAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_CITY, _value);
569     }
570     catch (const BasePlatformException &error) {
571         LOGE("Failed to set contact address city. %s : %s", error.getName().c_str(), error.getMessage().c_str());
572     }
573     catch (...) {
574         LOGE("Unsupported error while setting contact address city.");
575     }
576     return true;
577 }
578
579 bool JSContactAddress::setStreetAddress(JSContextRef context,
580         JSObjectRef object,
581         JSStringRef propertyName,
582         JSValueRef value,
583         JSValueRef* exception)
584 {
585     LOGD("Entered");
586     try {
587         ContactAddressPtr priv = JSContactAddress::getPrivateObject(context, object);
588         if (!priv) {
589             LOGE("Priv is null");
590             throw UnknownException("Priv is null");
591         }
592         if (JSValueIsNull(context, value)) {
593             priv->setAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_STREETADDR, "");
594             priv->setIsSet(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_STREETADDR, false);
595             return true;
596         }
597         std::string _value = JSUtil::JSValueToString(context, value);
598         priv->setAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_STREETADDR, _value);
599     }
600     catch (const BasePlatformException &error) {
601         LOGE("Failed to set contact address street address. %s : %s", error.getName().c_str(), error.getMessage().c_str());
602     }
603     catch (...) {
604         LOGE("Unsupported error while setting contact address street address.");
605     }
606     return true;
607 }
608
609 bool JSContactAddress::setAdditionalInformation(JSContextRef context,
610         JSObjectRef object,
611         JSStringRef propertyName,
612         JSValueRef value,
613         JSValueRef* exception)
614 {
615     LOGD("Entered");
616     try {
617         ContactAddressPtr priv = JSContactAddress::getPrivateObject(context, object);
618         if (!priv) {
619             LOGE("Priv is null");
620             throw UnknownException("Priv is null");
621         }
622         if (JSValueIsNull(context, value)) {
623             priv->setAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_ADDITIONALINFO, "");
624             priv->setIsSet(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_ADDITIONALINFO, false);
625             return true;
626         }
627         std::string _value = JSUtil::JSValueToString(context, value);
628         priv->setAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_ADDITIONALINFO, _value);
629     }
630     catch (const BasePlatformException &error) {
631         LOGE("Failed to set contact address additional information. %s : %s", error.getName().c_str(), error.getMessage().c_str());
632     }
633     catch (...) {
634         LOGE("Unsupported error while setting contact address additional information.");
635     }
636     return true;
637 }
638
639 bool JSContactAddress::setPostalCode(JSContextRef context,
640         JSObjectRef object,
641         JSStringRef propertyName,
642         JSValueRef value,
643         JSValueRef* exception)
644 {
645     LOGD("Entered");
646     try {
647         ContactAddressPtr priv = JSContactAddress::getPrivateObject(context, object);
648         if (!priv) {
649             LOGE("Priv is null");
650             throw UnknownException("Priv is null");
651         }
652         if (JSValueIsNull(context, value)) {
653             priv->setAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_POSTALCODE, "");
654             priv->setIsSet(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_POSTALCODE, false);
655             return true;
656         }
657         std::string _value = JSUtil::JSValueToString(context, value);
658         priv->setAttribute(ContactAddressAttribute::CONTACT_ADDRESS_ATTRIBUTE_POSTALCODE, _value);
659     }
660     catch (const BasePlatformException &error) {
661         LOGE("Failed to set contact address postal code. %s : %s", error.getName().c_str(), error.getMessage().c_str());
662     }
663     catch (...) {
664         LOGE("Unsupported error while setting contact address postal code.");
665     }
666     return true;
667 }
668
669 bool JSContactAddress::setIsDefault(JSContextRef context,
670         JSObjectRef object,
671         JSStringRef propertyName,
672         JSValueRef value,
673         JSValueRef* exception)
674 {
675     LOGD("Entered");
676     try {
677         ContactAddressPtr priv = JSContactAddress::getPrivateObject(context, object);
678         if (!priv) {
679             LOGE("Priv is null");
680             throw UnknownException("Priv is null");
681         }
682         bool is_default = JSUtil::JSValueToBoolean(context, value);
683         priv->setIsDefault(is_default);
684     }
685     catch (const BasePlatformException &error) {
686         LOGE("Failed to set contact address is default flag. %s : %s", error.getName().c_str(), error.getMessage().c_str());
687     }
688     catch (...) {
689         LOGE("Unsupported error while setting contact address is default flag.");
690     }
691     return true;
692 }
693
694 bool JSContactAddress::setTypes(JSContextRef context,
695         JSObjectRef object,
696         JSStringRef propertyName,
697         JSValueRef value,
698         JSValueRef* exception)
699 {
700     LOGD("Entered");
701     try {
702         ContactAddressPtr priv = JSContactAddress::getPrivateObject(context, object);
703         if (!priv) {
704             LOGE("Priv is null");
705             throw UnknownException("Priv is null");
706         }
707         std::vector<std::string> str_types = JSUtil::JSArrayToStringVector(context, value);
708         size_t size = str_types.size();
709         if (size > 0) {
710             for (size_t i = 0; i < size; i++) {
711                 // Verification if string is actual from ContactEmailAddressType
712                 ContactUtil::stringToContactAddressType(str_types[i]);
713             }
714             priv->setTypes(str_types);
715         }
716     }
717     catch (const BasePlatformException &error) {
718         LOGE("Failed to set contact address types. %s : %s", error.getName().c_str(), error.getMessage().c_str());
719     }
720     catch (...) {
721         LOGE("Unsupported error while setting contact address types.");
722     }
723     return true;
724 }
725
726 bool JSContactAddress::setLabel(JSContextRef context,
727         JSObjectRef object,
728         JSStringRef propertyName,
729         JSValueRef value,
730         JSValueRef* exception)
731 {
732     LOGD("Entered");
733     try {
734         ContactAddressPtr priv = JSContactAddress::getPrivateObject(context, object);
735         if (!priv) {
736             LOGE("Priv is null");
737             throw UnknownException("Priv is null");
738         }
739         if (JSValueIsNull(context, value)) {
740             priv->setIsSet(CONTACT_ADDRESS_ATTRIBUTE_LABEL, false);
741             return true;
742         }
743         std::string _value = JSUtil::JSValueToString(context, value);
744         priv->setAttribute(CONTACT_ADDRESS_ATTRIBUTE_LABEL, _value);
745     }
746     catch (const BasePlatformException &error) {
747         LOGE("Failed to set contact address label. %s : %s", error.getName().c_str(), error.getMessage().c_str());
748     }
749     catch (...) {
750         LOGE("Unsupported error while setting contact address label.");
751     }
752     return true;
753 }
754
755 } // Contact
756 } // DeviceAPI