2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @file ContactConverter.cpp
19 * @author Kisub Song (kisubs.song@samsung.com)
24 #include <dpl/log/log.h>
25 #include <CommonsJavaScript/Validator.h>
26 #include <CommonsJavaScript/ScopedJSStringRef.h>
27 #include <CommonsJavaScript/JSUtils.h>
28 #include <Commons/RegexUtils.h>
30 #include "ContactConverter.h"
31 #include "AddressBookController.h"
32 #include "JSAddressBook.h"
33 #include "JSAddressBookArray.h"
34 #include "JSAttributesOfInterestArray.h"
35 #include "JSContact.h"
36 #include "JSContactArray.h"
37 #include "JSContactProperties.h"
38 #include "JSContactName.h"
39 #include "JSContactAccount.h"
40 #include "JSContactAnniversary.h"
41 #include "JSContactAnniversaryArray.h"
42 #include "JSContactAddress.h"
43 #include "JSContactAddressArray.h"
44 #include "JSContactAddressTypeArray.h"
45 #include "JSContactManager.h"
46 #include "JSContactPhoneNumber.h"
47 #include "JSContactPhoneNumberArray.h"
48 #include "JSContactPhoneNumberTypeArray.h"
49 #include "JSContactEmailAddress.h"
50 #include "JSContactEmailAddressArray.h"
51 #include "JSContactEmailAddressTypeArray.h"
52 #include "JSContactOrganization.h"
53 #include "JSContactOrganizationArray.h"
54 #include "JSContactWebSite.h"
55 #include "JSContactWebSiteArray.h"
56 #include "JSStringArray.h"
58 #define CONTACT_ATTRIBUTE_ACCOUNT "account"
59 #define CONTACT_ATTRIBUTE_ACCOUNT_ID "accountId"
60 #define CONTACT_ATTRIBUTE_ADDITIONAL_INFORMATION "additionalInformation"
61 #define CONTACT_ATTRIBUTE_ADDRESSES "addresses"
62 #define CONTACT_ATTRIBUTE_ANNIVERSARIES "anniversaries"
63 #define CONTACT_ATTRIBUTE_ATTRIBUTES_OF_INTEREST "attributesOfInterest"
64 #define CONTACT_ATTRIBUTE_BIRTHDAY "birthday"
65 #define CONTACT_ATTRIBUTE_CATEGORIES "categories"
66 #define CONTACT_ATTRIBUTE_CITY "city"
67 #define CONTACT_ATTRIBUTE_CONTACT_ID "contactId"
68 #define CONTACT_ATTRIBUTE_CONTACT_URI "contactURI"
69 #define CONTACT_ATTRIBUTE_COUNTRY "country"
70 #define CONTACT_ATTRIBUTE_COUNTY "county"
71 #define CONTACT_ATTRIBUTE_DATE "date"
72 #define CONTACT_ATTRIBUTE_DEPARTMENT "department"
73 #define CONTACT_ATTRIBUTE_DISPLAY_NAME "displayName"
74 #define CONTACT_ATTRIBUTE_EMAIL "email"
75 #define CONTACT_ATTRIBUTE_EMAILS "emails"
76 #define CONTACT_ATTRIBUTE_FIRST_NAME "firstName"
77 #define CONTACT_ATTRIBUTE_ID "id"
78 #define CONTACT_ATTRIBUTE_IS_FAVORITE "isFavorite"
79 #define CONTACT_ATTRIBUTE_LABEL "label"
80 #define CONTACT_ATTRIBUTE_LAST_NAME "lastName"
81 #define CONTACT_ATTRIBUTE_LAST_UPDATED "lastUpdated"
82 #define CONTACT_ATTRIBUTE_LOGO_URI "logoURI"
83 #define CONTACT_ATTRIBUTE_MIDDLE_NAME "middleName"
84 #define CONTACT_ATTRIBUTE_NAME "name"
85 #define CONTACT_ATTRIBUTE_NICKNAMES "nicknames"
86 #define CONTACT_ATTRIBUTE_NOTES "notes"
87 #define CONTACT_ATTRIBUTE_NUMBER "number"
88 #define CONTACT_ATTRIBUTE_OFFICE "office"
89 #define CONTACT_ATTRIBUTE_ORGANIZATION "organization"
90 #define CONTACT_ATTRIBUTE_PHONE_NUMBERS "phoneNumbers"
91 #define CONTACT_ATTRIBUTE_PHONETIC_NAME "phoneticName"
92 #define CONTACT_ATTRIBUTE_PHOTO_URI "photoURI"
93 #define CONTACT_ATTRIBUTE_POSITION "position"
94 #define CONTACT_ATTRIBUTE_POSTAL_CODE "postalCode"
95 #define CONTACT_ATTRIBUTE_PREFIX "prefix"
96 #define CONTACT_ATTRIBUTE_READ_ONLY "readOnly"
97 #define CONTACT_ATTRIBUTE_REGION "region"
98 #define CONTACT_ATTRIBUTE_RINGTONE_URI "ringtoneURI"
99 #define CONTACT_ATTRIBUTE_ROLE "role"
100 #define CONTACT_ATTRIBUTE_STREET_ADDRESS "streetAddress"
101 #define CONTACT_ATTRIBUTE_TITLE "title"
102 #define CONTACT_ATTRIBUTE_TYPE "type"
103 #define CONTACT_ATTRIBUTE_TYPES "types"
104 #define CONTACT_ATTRIBUTE_URL "url"
105 #define CONTACT_ATTRIBUTE_URLS "urls"
107 #define STR_CONTACT_EMAIL_TYPE_WORK "WORK"
108 #define STR_CONTACT_EMAIL_TYPE_PREF "PREF"
109 #define STR_CONTACT_EMAIL_TYPE_HOME "HOME"
111 #define STR_CONTACT_PHONE_NUMBER_TYPE_WORK "WORK"
112 #define STR_CONTACT_PHONE_NUMBER_TYPE_PREF "PREF"
113 #define STR_CONTACT_PHONE_NUMBER_TYPE_HOME "HOME"
114 #define STR_CONTACT_PHONE_NUMBER_TYPE_VOICE "VOICE"
115 #define STR_CONTACT_PHONE_NUMBER_TYPE_FAX "FAX"
116 #define STR_CONTACT_PHONE_NUMBER_TYPE_MSG "MSG"
117 #define STR_CONTACT_PHONE_NUMBER_TYPE_CELL "CELL"
118 #define STR_CONTACT_PHONE_NUMBER_TYPE_PAGER "PAGER"
119 #define STR_CONTACT_PHONE_NUMBER_TYPE_BBS "BBS"
120 #define STR_CONTACT_PHONE_NUMBER_TYPE_MODEM "MODEM"
121 #define STR_CONTACT_PHONE_NUMBER_TYPE_CAR "CAR"
122 #define STR_CONTACT_PHONE_NUMBER_TYPE_ISDN "ISDN"
123 #define STR_CONTACT_PHONE_NUMBER_TYPE_VIDEO "VIDEO"
124 #define STR_CONTACT_PHONE_NUMBER_TYPE_PCS "PCS"
126 #define STR_CONTACT_ADDRESS_TYPE_WORK "WORK"
127 #define STR_CONTACT_ADDRESS_TYPE_PREF "PREF"
128 #define STR_CONTACT_ADDRESS_TYPE_HOME "HOME"
130 #define STR_WEBSITE_TYPE_HOMEPAGE "HOMEPAGE"
131 #define STR_WEBSITE_TYPE_BLOG "BLOG"
133 namespace TizenApis {
137 using namespace TizenApis::Api::Contact;
138 using namespace WrtDeviceApis::Commons;
139 using namespace WrtDeviceApis::CommonsJavaScript;
141 std::vector<std::string> ContactConverter::m_allowedAddressBookProperties;
142 std::vector<std::string> ContactConverter::m_allowedContactProperties;
143 std::vector<std::string> ContactConverter::m_allowedContactPropertiesProperties;
144 std::vector<std::string> ContactConverter::m_allowedContactNameProperties;
145 std::vector<std::string> ContactConverter::m_allowedContactAccountProperties;
146 std::vector<std::string> ContactConverter::m_allowedContactOrganizationProperties;
147 std::vector<std::string> ContactConverter::m_allowedContactWebSiteProperties;
148 std::vector<std::string> ContactConverter::m_allowedContactAnniversaryProperties;
149 std::vector<std::string> ContactConverter::m_allowedContactAddressProperties;
150 std::vector<std::string> ContactConverter::m_allowedContactPhoneNumberProperties;
151 std::vector<std::string> ContactConverter::m_allowedContactEmailAddressProperties;
153 ContactConverter::ContactConverter(JSContextRef context) : Converter(context)
155 // //LogDebug("entered");
156 static bool init = initializeAllowedProperties();
160 ContactConverter::~ContactConverter()
162 // //LogDebug("entered");
165 StringArrayPtr ContactConverter::toStringArray(const JSValueRef &jsValue)
167 if(JSStringArray::isObjectOfClass(m_context, jsValue))
168 return JSStringArray::getStringArray(m_context, jsValue);
170 StringArrayPtr result = StringArrayPtr(new StringArray());
171 JSObjectRef jsObject = toJSObjectRef(jsValue);
172 for (std::size_t i = 0; i < JSGetArrayLength(m_context, jsObject); ++i) {
173 JSValueRef element = JSGetArrayElement(m_context, jsObject, i);
174 result->push_back(toString(element));
179 JSValueRef ContactConverter::toJSValueRef(const StringArrayPtr &arg)
181 return JSStringArray::createArray(m_context, arg);
185 ContactEmailAddressType ContactConverter::toContactEmailAddressType(const std::string &arg)
187 // //LogDebug("entered");
188 if (arg == STR_CONTACT_EMAIL_TYPE_WORK) {
189 return CONTACT_EMAIL_TYPE_WORK;
190 } else if (arg == STR_CONTACT_EMAIL_TYPE_PREF) {
191 return CONTACT_EMAIL_TYPE_PREF;
192 } else if (arg == STR_CONTACT_EMAIL_TYPE_HOME) {
193 return CONTACT_EMAIL_TYPE_HOME;
195 Throw(WrtDeviceApis::Commons::ConversionException);
197 return CONTACT_EMAIL_TYPE_PREF;
200 std::string ContactConverter::toContactEmailAddressTypeStr(ContactEmailAddressType arg)
202 // //LogDebug("entered");
203 if (arg == CONTACT_EMAIL_TYPE_WORK) {
204 return STR_CONTACT_EMAIL_TYPE_WORK;
205 } else if (arg == CONTACT_EMAIL_TYPE_PREF) {
206 return STR_CONTACT_EMAIL_TYPE_PREF;
207 } else if (arg == CONTACT_EMAIL_TYPE_HOME) {
208 return STR_CONTACT_EMAIL_TYPE_HOME;
210 Throw(WrtDeviceApis::Commons::ConversionException);
212 return STR_CONTACT_EMAIL_TYPE_PREF;
215 ContactEmailAddressType ContactConverter::toContactEmailAddressType(const JSValueRef &value)
217 return toContactEmailAddressType(toString(value));
220 JSValueRef ContactConverter::toJSValueRef(ContactEmailAddressType arg)
222 return toJSValueRef(toContactEmailAddressTypeStr(arg));
225 ContactPhoneNumberType ContactConverter::toContactPhoneNumberType(const std::string &arg)
227 // //LogDebug("entered");
228 if (arg == STR_CONTACT_PHONE_NUMBER_TYPE_WORK) {
229 return CONTACT_PHONE_NUMBER_TYPE_WORK;
230 } else if (arg == STR_CONTACT_PHONE_NUMBER_TYPE_PREF) {
231 return CONTACT_PHONE_NUMBER_TYPE_PREF;
232 } else if (arg == STR_CONTACT_PHONE_NUMBER_TYPE_HOME) {
233 return CONTACT_PHONE_NUMBER_TYPE_HOME;
234 } else if (arg == STR_CONTACT_PHONE_NUMBER_TYPE_VOICE) {
235 return CONTACT_PHONE_NUMBER_TYPE_VOICE;
236 } else if (arg == STR_CONTACT_PHONE_NUMBER_TYPE_FAX) {
237 return CONTACT_PHONE_NUMBER_TYPE_FAX;
238 } else if (arg == STR_CONTACT_PHONE_NUMBER_TYPE_MSG) {
239 return CONTACT_PHONE_NUMBER_TYPE_MSG;
240 } else if (arg == STR_CONTACT_PHONE_NUMBER_TYPE_CELL) {
241 return CONTACT_PHONE_NUMBER_TYPE_CELL;
242 } else if (arg == STR_CONTACT_PHONE_NUMBER_TYPE_PAGER) {
243 return CONTACT_PHONE_NUMBER_TYPE_PAGER;
244 } else if (arg == STR_CONTACT_PHONE_NUMBER_TYPE_BBS) {
245 return CONTACT_PHONE_NUMBER_TYPE_BBS;
246 } else if (arg == STR_CONTACT_PHONE_NUMBER_TYPE_MODEM) {
247 return CONTACT_PHONE_NUMBER_TYPE_MODEM;
248 } else if (arg == STR_CONTACT_PHONE_NUMBER_TYPE_CAR) {
249 return CONTACT_PHONE_NUMBER_TYPE_CAR;
250 } else if (arg == STR_CONTACT_PHONE_NUMBER_TYPE_ISDN) {
251 return CONTACT_PHONE_NUMBER_TYPE_ISDN;
252 } else if (arg == STR_CONTACT_PHONE_NUMBER_TYPE_VIDEO) {
253 return CONTACT_PHONE_NUMBER_TYPE_VIDEO;
254 } else if (arg == STR_CONTACT_PHONE_NUMBER_TYPE_PCS) {
255 return CONTACT_PHONE_NUMBER_TYPE_PCS;
257 Throw(WrtDeviceApis::Commons::ConversionException);
259 return CONTACT_PHONE_NUMBER_TYPE_WORK;
262 std::string ContactConverter::toContactPhoneNumberTypeStr(ContactPhoneNumberType arg)
264 // //LogDebug("entered");
265 if (arg == CONTACT_PHONE_NUMBER_TYPE_WORK) {
266 return STR_CONTACT_PHONE_NUMBER_TYPE_WORK;
267 } else if (arg == CONTACT_PHONE_NUMBER_TYPE_PREF) {
268 return STR_CONTACT_PHONE_NUMBER_TYPE_PREF;
269 } else if (arg == CONTACT_PHONE_NUMBER_TYPE_HOME) {
270 return STR_CONTACT_PHONE_NUMBER_TYPE_HOME;
271 } else if (arg == CONTACT_PHONE_NUMBER_TYPE_VOICE) {
272 return STR_CONTACT_PHONE_NUMBER_TYPE_VOICE;
273 } else if (arg == CONTACT_PHONE_NUMBER_TYPE_FAX) {
274 return STR_CONTACT_PHONE_NUMBER_TYPE_FAX;
275 } else if (arg == CONTACT_PHONE_NUMBER_TYPE_MSG) {
276 return STR_CONTACT_PHONE_NUMBER_TYPE_MSG;
277 } else if (arg == CONTACT_PHONE_NUMBER_TYPE_CELL) {
278 return STR_CONTACT_PHONE_NUMBER_TYPE_CELL;
279 } else if (arg == CONTACT_PHONE_NUMBER_TYPE_PAGER) {
280 return STR_CONTACT_PHONE_NUMBER_TYPE_PAGER;
281 } else if (arg == CONTACT_PHONE_NUMBER_TYPE_BBS) {
282 return STR_CONTACT_PHONE_NUMBER_TYPE_BBS;
283 } else if (arg == CONTACT_PHONE_NUMBER_TYPE_MODEM) {
284 return STR_CONTACT_PHONE_NUMBER_TYPE_MODEM;
285 } else if (arg == CONTACT_PHONE_NUMBER_TYPE_CAR) {
286 return STR_CONTACT_PHONE_NUMBER_TYPE_CAR;
287 } else if (arg == CONTACT_PHONE_NUMBER_TYPE_ISDN) {
288 return STR_CONTACT_PHONE_NUMBER_TYPE_ISDN;
289 } else if (arg == CONTACT_PHONE_NUMBER_TYPE_VIDEO) {
290 return STR_CONTACT_PHONE_NUMBER_TYPE_VIDEO;
291 } else if (arg == CONTACT_PHONE_NUMBER_TYPE_PCS) {
292 return STR_CONTACT_PHONE_NUMBER_TYPE_PCS;
294 Throw(WrtDeviceApis::Commons::ConversionException);
296 return STR_CONTACT_PHONE_NUMBER_TYPE_WORK;
299 ContactPhoneNumberType ContactConverter::toContactPhoneNumberType(const JSValueRef &value)
301 return toContactPhoneNumberType(toString(value));
304 JSValueRef ContactConverter::toJSValueRef(ContactPhoneNumberType arg)
306 return toJSValueRef(toContactPhoneNumberTypeStr(arg));
309 ContactAddressType ContactConverter::toContactAddressType(const std::string &arg)
311 // //LogDebug("entered");
312 if (arg == STR_CONTACT_ADDRESS_TYPE_WORK) {
313 return CONTACT_ADDRESS_TYPE_WORK;
314 } else if (arg == STR_CONTACT_ADDRESS_TYPE_PREF) {
315 return CONTACT_ADDRESS_TYPE_PREF;
316 } else if (arg == STR_CONTACT_ADDRESS_TYPE_HOME) {
317 return CONTACT_ADDRESS_TYPE_HOME;
319 Throw(WrtDeviceApis::Commons::ConversionException);
321 return CONTACT_ADDRESS_TYPE_PREF;
323 std::string ContactConverter::toContactAddressTypeStr(ContactAddressType arg)
325 // //LogDebug("entered");
326 if (arg == CONTACT_ADDRESS_TYPE_WORK) {
327 return STR_CONTACT_ADDRESS_TYPE_WORK;
328 } else if (arg == CONTACT_ADDRESS_TYPE_PREF) {
329 return STR_CONTACT_ADDRESS_TYPE_PREF;
330 } else if (arg == CONTACT_ADDRESS_TYPE_HOME) {
331 return STR_CONTACT_ADDRESS_TYPE_HOME;
333 Throw(WrtDeviceApis::Commons::ConversionException);
335 return STR_CONTACT_ADDRESS_TYPE_PREF;
338 ContactAddressType ContactConverter::toContactAddressType(const JSValueRef &value)
340 return toContactAddressType(toString(value));
343 JSValueRef ContactConverter::toJSValueRef(ContactAddressType arg)
345 return toJSValueRef(toContactAddressTypeStr(arg));
348 ContactWebSiteType ContactConverter::toContactWebSiteType(const std::string &arg)
350 //LogDebug("entered");
351 if (arg == STR_WEBSITE_TYPE_HOMEPAGE) {
352 return WEBSITE_TYPE_HOMEPAGE;
353 } else if (arg == STR_WEBSITE_TYPE_BLOG) {
354 return WEBSITE_TYPE_BLOG;
356 Throw(WrtDeviceApis::Commons::ConversionException);
358 return WEBSITE_TYPE_HOMEPAGE;
361 std::string ContactConverter::toContactWebSiteTypeStr(ContactWebSiteType arg)
363 //LogDebug("entered");
364 if (arg == WEBSITE_TYPE_HOMEPAGE) {
365 return STR_WEBSITE_TYPE_HOMEPAGE;
366 } else if (arg == WEBSITE_TYPE_BLOG) {
367 return STR_WEBSITE_TYPE_BLOG;
369 Throw(WrtDeviceApis::Commons::ConversionException);
371 return STR_WEBSITE_TYPE_HOMEPAGE;
374 ContactWebSiteType ContactConverter::toContactWebSiteType(const JSValueRef &value)
376 return toContactWebSiteType(toString(value));
379 JSValueRef ContactConverter::toJSValueRef(ContactWebSiteType arg)
381 return toJSValueRef(toContactWebSiteTypeStr(arg));
384 ContactCapabilityType ContactConverter::toContactCapabilityType(const JSValueRef &value)
386 int result = toInt(value);
387 if(HAS_VIDEO_CAPABILITY != result &&
388 HAS_VOICE_CAPABILITY != result &&
389 HAS_CAMERA_CAPABILITY != result)
390 Throw(WrtDeviceApis::Commons::ConversionException);
392 return static_cast<ContactCapabilityType>(result);
395 std::string ContactConverter::toAttributesOfInterest(const JSValueRef &value)
398 return toString(value);
401 JSValueRef ContactConverter::toJSValueRef(const IAddressBookPtr &arg)
403 //LogDebug("entered");
404 AddressBookController *priv = new AddressBookController(m_context, arg);
405 return JSObjectMake(m_context, JSAddressBook::getClassRef(), priv);
408 IAddressBookPtr ContactConverter::toAddressBook(const JSValueRef &jsValue)
410 if(!JSAddressBook::isObjectOfClass(m_context, jsValue))
411 ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute");
413 return JSAddressBook::getAddressBook(m_context, jsValue);
416 JSValueRef ContactConverter::toJSValueRef(const IAddressBookArrayPtr &arg)
418 int size = arg->size();
420 return JSValueMakeNull(m_context);
422 JSObjectRef resultObject = JSCreateArrayObject(m_context, 0, NULL);
424 ThrowMsg(ConversionException, "Can not create array object.");
426 for(int i = 0; i < size; i++)
428 JSValueRef jsvalue = toJSValueRef(arg->at(i));
429 if (!JSSetArrayElement(m_context, resultObject, i, jsvalue))
430 ThrowMsg(ConversionException, "Can not fill address book array.");
433 return static_cast<JSValueRef>(resultObject);
436 IAddressBookArrayPtr ContactConverter::toAddressBookArray(const JSValueRef &jsValue)
438 if(JSAddressBookArray::isObjectOfClass(m_context, jsValue))
439 return JSAddressBookArray::getAddressBookArray(m_context, jsValue);
441 IAddressBookArrayPtr result(new IAddressBookArray());
443 JSObjectRef jsObject = toJSObjectRef(jsValue);
444 for (std::size_t i = 0; i < JSGetArrayLength(m_context, jsObject); ++i) {
445 JSValueRef element = JSGetArrayElement(m_context, jsObject, i);
446 result->push_back(toAddressBook(element));
451 JSValueRef ContactConverter::toJSValueRef(const ContactPtr &arg)
453 //LogDebug("entered");
454 return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContact::getClassRef(), arg);
457 ContactPtr ContactConverter::toContact(const JSValueRef &jsValue)
459 if(!JSContact::isObjectOfClass(m_context, jsValue))
460 ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute");
462 return JSContact::getContact(m_context, jsValue);
465 JSValueRef ContactConverter::toJSValueRef(const ContactArrayPtr &arg)
467 //LogDebug("entered");
468 return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactArray::getClassRef(), arg);
471 ContactArrayPtr ContactConverter::toContactArray(const JSValueRef &jsValue)
473 if(JSContactArray::isObjectOfClass(m_context, jsValue))
474 return JSContactArray::getContactArray(m_context, jsValue);
476 ContactArrayPtr result = ContactArrayPtr(new ContactArray());
478 JSObjectRef jsObject = toJSObjectRef(jsValue);
479 for (std::size_t i = 0; i < JSGetArrayLength(m_context, jsObject); ++i) {
480 JSValueRef element = JSGetArrayElement(m_context, jsObject, i);
481 result->push_back(toContact(element));
486 JSValueRef ContactConverter::toJSValueRef(const ContactPropertiesPtr &arg)
488 // TODO make user object
489 return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactProperties::getClassRef(), arg);
492 ContactPropertiesPtr ContactConverter::toContactProperties(const JSValueRef &jsValue)
494 if(JSContactProperties::isObjectOfClass(m_context, jsValue))
495 return JSContactProperties::getContactProperties(m_context, jsValue);
497 Validator validator(m_context);
498 if (!validator.checkArrayKeys(m_allowedContactPropertiesProperties, jsValue)) {
499 LogError("invalid properties in contact object");
500 ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute");
503 const ScopedJSStringRef nameStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_NAME));
504 const ScopedJSStringRef accountStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_ACCOUNT));
505 const ScopedJSStringRef addressesStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_ADDRESSES));
506 const ScopedJSStringRef photoURIStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_PHOTO_URI));
507 const ScopedJSStringRef phoneNumbersStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_PHONE_NUMBERS));
508 const ScopedJSStringRef emailsStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_EMAILS));
509 const ScopedJSStringRef birthdayStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_BIRTHDAY));
510 const ScopedJSStringRef anniversariesStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_ANNIVERSARIES));
511 const ScopedJSStringRef organizationStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_ORGANIZATION));
512 const ScopedJSStringRef notesStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_NOTES));
513 const ScopedJSStringRef urlsStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_URLS));
514 const ScopedJSStringRef isFavoriteStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_IS_FAVORITE));
515 const ScopedJSStringRef ringtoneURIStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_RINGTONE_URI));
516 const ScopedJSStringRef categoriesStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_CATEGORIES));
518 JSObjectRef jsObject = toJSObjectRef(jsValue);
520 JSValueRef nameData = JSObjectGetProperty(m_context, jsObject, nameStr.get(), NULL);
521 JSValueRef accountData = JSObjectGetProperty(m_context, jsObject, accountStr.get(), NULL);
522 JSValueRef addressesData = JSObjectGetProperty(m_context, jsObject, addressesStr.get(), NULL);
523 JSValueRef photoURIData = JSObjectGetProperty(m_context, jsObject, photoURIStr.get(), NULL);
524 JSValueRef phoneNumbersData = JSObjectGetProperty(m_context, jsObject, phoneNumbersStr.get(), NULL);
525 JSValueRef emailsData = JSObjectGetProperty(m_context, jsObject, emailsStr.get(), NULL);
526 JSValueRef birthdayData = JSObjectGetProperty(m_context, jsObject, birthdayStr.get(), NULL);
527 JSValueRef anniversariesData = JSObjectGetProperty(m_context, jsObject, anniversariesStr.get(), NULL);
528 JSValueRef organizationData = JSObjectGetProperty(m_context, jsObject, organizationStr.get(), NULL);
529 JSValueRef notesData = JSObjectGetProperty(m_context, jsObject, notesStr.get(), NULL);
530 JSValueRef urlsData = JSObjectGetProperty(m_context, jsObject, urlsStr.get(), NULL);
531 JSValueRef isFavoriteData = JSObjectGetProperty(m_context, jsObject, isFavoriteStr.get(), NULL);
532 JSValueRef ringtoneURIData = JSObjectGetProperty(m_context, jsObject, ringtoneURIStr.get(), NULL);
533 JSValueRef categoriesData = JSObjectGetProperty(m_context, jsObject, categoriesStr.get(), NULL);
536 ContactAccountPtr account;
537 ContactAddressArrayPtr addresses;
538 std::string photoURI;
539 ContactPhoneNumberArrayPtr phoneNumbers;
540 ContactEmailAddressArrayPtr emails;
542 ContactAnniversaryArrayPtr anniversaries;
543 ContactOrganizationPtr organization;
544 StringArrayPtr notes;
545 ContactWebSiteArrayPtr urls;
547 std::string ringtoneURI;
548 StringArrayPtr categories;
550 ContactPropertiesPtr result = ContactPropertiesPtr(new ContactProperties());
552 Throw(WrtDeviceApis::Commons::ConversionException);
555 if (!JSValueIsUndefined(m_context, nameData)) {
556 name = toContactName(nameData);
557 result->setName(name);
560 if (!JSValueIsUndefined(m_context, accountData)) {
561 account = toContactAccount(accountData);
562 result->setAccount(account);
565 if (!JSValueIsUndefined(m_context, addressesData)) {
566 addresses = toContactAddressArray(addressesData);
567 result->setAddresses(addresses);
570 if (!JSValueIsUndefined(m_context, photoURIData)) {
571 photoURI = toString(photoURIData);
572 result->setPhotoURI(photoURI);
575 if (!JSValueIsUndefined(m_context, phoneNumbersData)) {
576 phoneNumbers = toContactPhoneNumberArray(phoneNumbersData);
577 result->setPhoneNumbers(phoneNumbers);
580 if (!JSValueIsUndefined(m_context, emailsData)) {
581 emails = toContactEmailAddressArray(emailsData);
582 result->setEmails(emails);
585 if (!JSValueIsUndefined(m_context, birthdayData)) {
586 birthday = toDateTm(birthdayData);
587 result->setBirthday(birthday);
590 if (!JSValueIsUndefined(m_context, anniversariesData)) {
591 anniversaries = toContactAnniversaryArray(anniversariesData);
592 result->setAnniversaries(anniversaries);
595 if (!JSValueIsUndefined(m_context, organizationData)) {
596 organization = toContactOrganization(organizationData);
597 result->setOrganization(organization);
600 if (!JSValueIsUndefined(m_context, notesData)) {
601 notes = toStringArray(notesData);
602 result->setNotes(notes);
605 if (!JSValueIsUndefined(m_context, urlsData)) {
606 urls = toContactWebSiteArray(urlsData);
607 result->setUrls(urls);
610 if (!JSValueIsUndefined(m_context, isFavoriteData)) {
611 isFavorite = toBool(isFavoriteData);
612 result->setIsFavorite(isFavorite);
615 if (!JSValueIsUndefined(m_context, ringtoneURIData)) {
616 ringtoneURI = toString(ringtoneURIData);
617 result->setRingtoneURI(ringtoneURI);
620 if (!JSValueIsUndefined(m_context, categoriesData)) {
621 categories = toStringArray(categoriesData);
622 result->setCategories(categories);
628 JSValueRef ContactConverter::toJSValueRef(const ContactPropertiesArrayPtr &arg)
630 //LogDebug("entered");
631 int size = arg->size();
633 return JSValueMakeNull(m_context);
635 JSObjectRef resultObject = JSCreateArrayObject(m_context, 0, NULL);
637 ThrowMsg(ConversionException, "Can not create array object.");
639 for(int i = 0; i < size; i++)
641 JSValueRef jsvalue = toJSValueRef(arg->at(i));
642 if (!JSSetArrayElement(m_context, resultObject, i, jsvalue))
643 ThrowMsg(ConversionException, "Can not fill contact properties array.");
646 return static_cast<JSValueRef>(resultObject);
649 ContactPropertiesArrayPtr ContactConverter::toContactPropertiesArray(const JSValueRef &jsValue)
651 ContactPropertiesArrayPtr result = ContactPropertiesArrayPtr(new ContactPropertiesArray());
653 JSObjectRef jsObject = toJSObjectRef(jsValue);
654 for (std::size_t i = 0; i < JSGetArrayLength(m_context, jsObject); ++i) {
655 JSValueRef element = JSGetArrayElement(m_context, jsObject, i);
656 result->push_back(toContactProperties(element));
661 JSValueRef ContactConverter::toJSValueRef(const ContactNamePtr &arg)
663 // TODO make user object
664 return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactName::getClassRef(), arg);
667 ContactNamePtr ContactConverter::toContactName(const JSValueRef &jsValue)
669 if(JSContactName::isObjectOfClass(m_context, jsValue))
670 return JSContactName::getContactName(m_context, jsValue);
672 Validator validator(m_context);
673 if (!validator.checkArrayKeys(m_allowedContactNameProperties, jsValue)) {
674 LogError("invalid properties in contact object");
675 ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute");
678 const ScopedJSStringRef prefixStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_PREFIX));
679 const ScopedJSStringRef firstNameStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_FIRST_NAME));
680 const ScopedJSStringRef middleNameStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_MIDDLE_NAME));
681 const ScopedJSStringRef lastNameStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_LAST_NAME));
682 const ScopedJSStringRef nicknamesStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_NICKNAMES));
683 const ScopedJSStringRef phoneticNameStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_PHONETIC_NAME));
684 const ScopedJSStringRef displayNameStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_DISPLAY_NAME));
686 JSObjectRef jsObject = toJSObjectRef(jsValue);
688 JSValueRef prefixData = JSObjectGetProperty(m_context, jsObject, prefixStr.get(), NULL);
689 JSValueRef firstNameData = JSObjectGetProperty(m_context, jsObject, firstNameStr.get(), NULL);
690 JSValueRef middleNameData = JSObjectGetProperty(m_context, jsObject, middleNameStr.get(), NULL);
691 JSValueRef lastNameData = JSObjectGetProperty(m_context, jsObject, lastNameStr.get(), NULL);
692 JSValueRef nicknamesData = JSObjectGetProperty(m_context, jsObject, nicknamesStr.get(), NULL);
693 JSValueRef phoneticNameData = JSObjectGetProperty(m_context, jsObject, phoneticNameStr.get(), NULL);
694 JSValueRef displayNameData = JSObjectGetProperty(m_context, jsObject, displayNameStr.get(), NULL);
697 std::string firstName;
698 std::string middleName;
699 std::string lastName;
700 StringArrayPtr nicknames;
701 std::string phoneticName;
702 std::string displayName;
704 ContactNamePtr result = ContactNamePtr(new ContactName());
706 Throw(WrtDeviceApis::Commons::ConversionException);
709 if (!JSValueIsUndefined(m_context, prefixData)) {
710 prefix = toString(prefixData);
711 result->setPrefix(prefix);
714 if (!JSValueIsUndefined(m_context, firstNameData)) {
715 firstName = toString(firstNameData);
716 result->setFirstName(firstName);
719 if (!JSValueIsUndefined(m_context, middleNameData)) {
720 middleName = toString(middleNameData);
721 result->setMiddleName(middleName);
724 if (!JSValueIsUndefined(m_context, lastNameData)) {
725 lastName = toString(lastNameData);
726 result->setLastName(lastName);
729 if (!JSValueIsUndefined(m_context, nicknamesData)) {
730 nicknames = toStringArray(nicknamesData);
731 result->setNicknames(nicknames);
734 if (!JSValueIsUndefined(m_context, phoneticNameData)) {
735 phoneticName = toString(phoneticNameData);
736 result->setPhoneticName(phoneticName);
739 if (!JSValueIsUndefined(m_context, displayNameData)) {
740 displayName = toString(displayNameData);
741 result->setDisplayName(displayName);
747 JSValueRef ContactConverter::toJSValueRef(const ContactAccountPtr &arg)
749 //LogDebug("entered");
750 return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactAccount::getClassRef(), arg);
753 ContactAccountPtr ContactConverter::toContactAccount(const JSValueRef &jsValue)
755 if(JSContactAccount::isObjectOfClass(m_context, jsValue))
756 return JSContactAccount::getContactAccount(m_context, jsValue);
758 Validator validator(m_context);
759 if (!validator.checkArrayKeys(m_allowedContactAccountProperties, jsValue)) {
760 LogError("invalid properties in contact object");
761 ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute");
764 const ScopedJSStringRef accountIdStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_ACCOUNT_ID));
765 const ScopedJSStringRef contactURIStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_CONTACT_URI));
767 JSObjectRef jsObject = toJSObjectRef(jsValue);
769 JSValueRef accountIdData = JSObjectGetProperty(m_context, jsObject, accountIdStr.get(), NULL);
770 JSValueRef contactURIData = JSObjectGetProperty(m_context, jsObject, contactURIStr.get(), NULL);
772 std::string accountId;
773 std::string contactURI;
775 ContactAccountPtr result(new ContactAccount());
777 Throw(WrtDeviceApis::Commons::ConversionException);
780 if (!JSValueIsUndefined(m_context, accountIdData)) {
781 accountId = toString(accountIdData);
782 result->setAccountId(accountId);
785 if (!JSValueIsUndefined(m_context, contactURIData)) {
786 contactURI = toString(contactURIData);
787 result->setContactURI(contactURI);
793 JSValueRef ContactConverter::toJSValueRef(const ContactAnniversaryPtr &arg)
795 //LogDebug("entered");
796 return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactAnniversary::getClassRef(), arg);
799 ContactAnniversaryPtr ContactConverter::toContactAnniversary(const JSValueRef &jsValue)
801 if(JSContactAnniversary::isObjectOfClass(m_context, jsValue))
802 return JSContactAnniversary::getContactAnniversary(m_context, jsValue);
804 Validator validator(m_context);
805 if (!validator.checkArrayKeys(m_allowedContactAnniversaryProperties, jsValue)) {
806 LogError("invalid properties in contact object");
807 ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute");
810 const ScopedJSStringRef dateStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_DATE));
811 const ScopedJSStringRef labelStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_LABEL));
813 JSObjectRef jsObject = toJSObjectRef(jsValue);
815 JSValueRef dateData = JSObjectGetProperty(m_context, jsObject, dateStr.get(), NULL);
816 JSValueRef labelData = JSObjectGetProperty(m_context, jsObject, labelStr.get(), NULL);
821 ContactAnniversaryPtr result(new ContactAnniversary());
823 Throw(WrtDeviceApis::Commons::ConversionException);
826 if (!JSValueIsUndefined(m_context, dateData)) {
827 date = toDateTm(dateData);
828 result->setDate(date);
831 if (!JSValueIsUndefined(m_context, labelData)) {
832 label = toString(labelData);
833 result->setLabel(label);
839 JSValueRef ContactConverter::toJSValueRef(const ContactAnniversaryArrayPtr &arg)
841 //LogDebug("entered");
842 return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactAnniversaryArray::getClassRef(), arg);
845 ContactAnniversaryArrayPtr ContactConverter::toContactAnniversaryArray(const JSValueRef &jsValue)
847 if(JSContactAnniversaryArray::isObjectOfClass(m_context, jsValue))
848 return JSContactAnniversaryArray::getContactAnniversaryArray(m_context, jsValue);
850 ContactAnniversaryArrayPtr result(new ContactAnniversaryArray());
852 JSObjectRef jsObject = toJSObjectRef(jsValue);
853 for (std::size_t i = 0; i < JSGetArrayLength(m_context, jsObject); ++i) {
854 JSValueRef element = JSGetArrayElement(m_context, jsObject, i);
855 result->push_back(toContactAnniversary(element));
860 JSValueRef ContactConverter::toJSValueRefAttributesOfInterestArray(const AttributesOfInterestArrayPtr &arg)
862 //LogDebug("entered");
863 return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSAttributesOfInterestArray::getClassRef(), arg);
866 AttributesOfInterestArrayPtr ContactConverter::toAttributesOfInterestArray(const JSValueRef &jsValue)
868 if(JSAttributesOfInterestArray::isObjectOfClass(m_context, jsValue))
869 return JSAttributesOfInterestArray::getAttributesOfInterestArray(m_context, jsValue);
871 AttributesOfInterestArrayPtr result(new AttributesOfInterestArray());
873 JSObjectRef jsObject = toJSObjectRef(jsValue);
874 for (std::size_t i = 0; i < JSGetArrayLength(m_context, jsObject); ++i) {
875 JSValueRef element = JSGetArrayElement(m_context, jsObject, i);
876 result->push_back(toAttributesOfInterest(element));
881 JSValueRef ContactConverter::toJSValueRef(const ContactAddressPtr &arg)
883 //LogDebug("entered");
884 return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactAddress::getClassRef(), arg);
887 ContactAddressPtr ContactConverter::toContactAddress(const JSValueRef &jsValue)
889 if(JSContactAddress::isObjectOfClass(m_context, jsValue))
890 return JSContactAddress::getContactAddress(m_context, jsValue);
892 Validator validator(m_context);
893 if (!validator.checkArrayKeys(m_allowedContactAddressProperties, jsValue)) {
894 LogError("invalid properties in contact object");
895 ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute");
898 const ScopedJSStringRef countryStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_COUNTRY));
899 const ScopedJSStringRef regionStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_REGION));
900 const ScopedJSStringRef cityStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_CITY));
901 const ScopedJSStringRef streetAddressStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_STREET_ADDRESS));
902 const ScopedJSStringRef additionalInformationStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_ADDITIONAL_INFORMATION));
903 const ScopedJSStringRef postalCodeStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_POSTAL_CODE));
904 const ScopedJSStringRef typesStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_TYPES));
906 JSObjectRef jsObject = toJSObjectRef(jsValue);
908 JSValueRef countryData = JSObjectGetProperty(m_context, jsObject, countryStr.get(), NULL);
909 JSValueRef regionData = JSObjectGetProperty(m_context, jsObject, regionStr.get(), NULL);
910 JSValueRef cityData = JSObjectGetProperty(m_context, jsObject, cityStr.get(), NULL);
911 JSValueRef streetAddressData = JSObjectGetProperty(m_context, jsObject, streetAddressStr.get(), NULL);
912 JSValueRef additionalInformationData = JSObjectGetProperty(m_context, jsObject, additionalInformationStr.get(), NULL);
913 JSValueRef postalCodeData = JSObjectGetProperty(m_context, jsObject, postalCodeStr.get(), NULL);
914 JSValueRef typesData = JSObjectGetProperty(m_context, jsObject, typesStr.get(), NULL);
919 std::string streetAddress;
920 std::string additionalInformation;
921 std::string postalCode;
922 ContactAddressTypeArrayPtr types;
924 ContactAddressPtr result(new ContactAddress());
926 Throw(WrtDeviceApis::Commons::ConversionException);
929 if (!JSValueIsUndefined(m_context, countryData)) {
930 country = toString(countryData);
931 result->setCountry(country);
934 if (!JSValueIsUndefined(m_context, regionData)) {
935 region = toString(regionData);
936 result->setRegion(region);
939 if (!JSValueIsUndefined(m_context, cityData)) {
940 city = toString(cityData);
941 result->setCity(city);
944 if (!JSValueIsUndefined(m_context, streetAddressData)) {
945 streetAddress = toString(streetAddressData);
946 result->setStreetAddress(streetAddress);
949 if (!JSValueIsUndefined(m_context, additionalInformationData)) {
950 additionalInformation = toString(additionalInformationData);
951 result->setAdditionalInformation(additionalInformation);
954 if (!JSValueIsUndefined(m_context, postalCodeData)) {
955 postalCode = toString(postalCodeData);
956 result->setPostalCode(postalCode);
959 if (!JSValueIsUndefined(m_context, typesData)) {
960 types = toContactAddressTypeArray(typesData);
961 result->setTypes(types);
967 JSValueRef ContactConverter::toJSValueRef(const ContactAddressArrayPtr &arg)
969 //LogDebug("entered");
970 return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactAddressArray::getClassRef(), arg);
973 ContactAddressArrayPtr ContactConverter::toContactAddressArray(const JSValueRef &jsValue)
975 if(JSContactAddressArray::isObjectOfClass(m_context, jsValue))
976 return JSContactAddressArray::getContactAddressArray(m_context, jsValue);
978 ContactAddressArrayPtr result(new ContactAddressArray());
980 JSObjectRef jsObject = toJSObjectRef(jsValue);
981 for (std::size_t i = 0; i < JSGetArrayLength(m_context, jsObject); ++i) {
982 JSValueRef element = JSGetArrayElement(m_context, jsObject, i);
983 result->push_back(toContactAddress(element));
988 JSValueRef ContactConverter::toJSValueRef(const ContactAddressTypeArrayPtr &arg)
990 //LogDebug("entered");
991 return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactAddressTypeArray::getClassRef(), arg);
994 ContactAddressTypeArrayPtr ContactConverter::toContactAddressTypeArray(const JSValueRef &jsValue)
996 if(JSContactAddressTypeArray::isObjectOfClass(m_context, jsValue))
997 return JSContactAddressTypeArray::getContactAddressTypeArray(m_context, jsValue);
999 ContactAddressTypeArrayPtr result(new ContactAddressTypeArray());
1001 JSObjectRef jsObject = toJSObjectRef(jsValue);
1002 for (std::size_t i = 0; i < JSGetArrayLength(m_context, jsObject); ++i) {
1003 JSValueRef element = JSGetArrayElement(m_context, jsObject, i);
1004 result->push_back(toContactAddressType(element));
1009 //JSValueRef ContactConverter::toJSValueRef(const ContactCapabilityTypeArrayPtr &arg)
1011 // //LogDebug("entered");
1012 // return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactCapabilityTypeArray::getClassRef(), arg);
1015 //ContactCapabilityTypeArrayPtr ContactConverter::toContactCapabilityTypeArray(const JSValueRef &jsValue)
1017 // if(JSContactCapabilityTypeArray::isObjectOfClass(m_context, jsValue))
1018 // return JSContactCapabilityTypeArray::getContactCapabilityTypeArray(m_context, jsValue);
1020 // ContactCapabilityTypeArrayPtr result(new ContactCapabilityTypeArray());
1022 // JSObjectRef jsObject = toJSObjectRef(jsValue);
1023 // for (std::size_t i = 0; i < JSGetArrayLength(m_context, jsObject); ++i) {
1024 // JSValueRef element = JSGetArrayElement(m_context, jsObject, i);
1025 // result->push_back(toContactCapabilityType(element));
1030 JSValueRef ContactConverter::toJSValueRef(const ContactPhoneNumberPtr &arg)
1032 //LogDebug("entered");
1033 return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactPhoneNumber::getClassRef(), arg);
1036 ContactPhoneNumberPtr ContactConverter::toContactPhoneNumber(const JSValueRef &jsValue)
1038 if(JSContactPhoneNumber::isObjectOfClass(m_context, jsValue))
1039 return JSContactPhoneNumber::getContactPhoneNumber(m_context, jsValue);
1041 Validator validator(m_context);
1042 if (!validator.checkArrayKeys(m_allowedContactPhoneNumberProperties, jsValue)) {
1043 LogError("invalid properties in contact object");
1044 ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute");
1047 const ScopedJSStringRef numberStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_NUMBER));
1048 const ScopedJSStringRef typesStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_TYPES));
1050 JSObjectRef jsObject = toJSObjectRef(jsValue);
1052 JSValueRef numberData = JSObjectGetProperty(m_context, jsObject, numberStr.get(), NULL);
1053 JSValueRef typesData = JSObjectGetProperty(m_context, jsObject, typesStr.get(), NULL);
1056 StringArrayPtr types;
1058 ContactPhoneNumberPtr result(new ContactPhoneNumber());
1060 Throw(WrtDeviceApis::Commons::ConversionException);
1063 if (!JSValueIsUndefined(m_context, numberData)) {
1064 number = toString(numberData);
1065 result->setNumber(number);
1068 if (!JSValueIsUndefined(m_context, typesData)) {
1069 types = toStringArray(typesData);
1070 result->setTypes(types);
1072 result->addType("VOICE");
1078 JSValueRef ContactConverter::toJSValueRef(const ContactPhoneNumberArrayPtr &arg)
1080 //LogDebug("entered");
1081 return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactPhoneNumberArray::getClassRef(), arg);
1084 ContactPhoneNumberArrayPtr ContactConverter::toContactPhoneNumberArray(const JSValueRef &jsValue)
1086 if(JSContactPhoneNumberArray::isObjectOfClass(m_context, jsValue))
1087 return JSContactPhoneNumberArray::getContactPhoneNumberArray(m_context, jsValue);
1089 ContactPhoneNumberArrayPtr result(new ContactPhoneNumberArray());
1091 JSObjectRef jsObject = toJSObjectRef(jsValue);
1092 for (std::size_t i = 0; i < JSGetArrayLength(m_context, jsObject); ++i) {
1093 JSValueRef element = JSGetArrayElement(m_context, jsObject, i);
1094 result->push_back(toContactPhoneNumber(element));
1099 JSValueRef ContactConverter::toJSValueRef(const ContactPhoneNumberTypeArrayPtr &arg)
1101 //LogDebug("entered");
1102 return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactPhoneNumberTypeArray::getClassRef(), arg);
1105 ContactPhoneNumberTypeArrayPtr ContactConverter::toContactPhoneNumberTypeArray(const JSValueRef &jsValue)
1107 if(JSContactPhoneNumberTypeArray::isObjectOfClass(m_context, jsValue))
1108 return JSContactPhoneNumberTypeArray::getContactPhoneNumberTypeArray(m_context, jsValue);
1110 ContactPhoneNumberTypeArrayPtr result(new ContactPhoneNumberTypeArray());
1112 JSObjectRef jsObject = toJSObjectRef(jsValue);
1113 for (std::size_t i = 0; i < JSGetArrayLength(m_context, jsObject); ++i) {
1114 JSValueRef element = JSGetArrayElement(m_context, jsObject, i);
1115 result->push_back(toContactPhoneNumberType(element));
1120 JSValueRef ContactConverter::toJSValueRef(const ContactEmailAddressPtr &arg)
1122 //LogDebug("entered");
1123 return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactEmailAddress::getClassRef(), arg);
1126 ContactEmailAddressPtr ContactConverter::toContactEmailAddress(const JSValueRef &jsValue)
1128 if(JSContactEmailAddress::isObjectOfClass(m_context, jsValue))
1129 return JSContactEmailAddress::getContactEmailAddress(m_context, jsValue);
1131 Validator validator(m_context);
1132 if (!validator.checkArrayKeys(m_allowedContactEmailAddressProperties, jsValue)) {
1133 LogError("invalid properties in contact object");
1134 ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute");
1137 const ScopedJSStringRef emailStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_EMAIL));
1138 const ScopedJSStringRef typesStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_TYPES));
1140 JSObjectRef jsObject = toJSObjectRef(jsValue);
1143 JSValueRef emailData = JSObjectGetProperty(m_context, jsObject, emailStr.get(), NULL);
1144 JSValueRef typesData = JSObjectGetProperty(m_context, jsObject, typesStr.get(), NULL);
1148 ContactEmailAddressTypeArrayPtr types;
1150 ContactEmailAddressPtr result(new ContactEmailAddress());
1152 Throw(WrtDeviceApis::Commons::ConversionException);
1155 if (!JSValueIsUndefined(m_context, emailData)) {
1156 email = toString(emailData);
1157 result->setEmail(email);
1160 if (!JSValueIsUndefined(m_context, typesData)) {
1161 types = toContactEmailAddressTypeArray(typesData);
1162 result->setTypes(types);
1164 result->addType(CONTACT_EMAIL_TYPE_PREF);
1169 JSValueRef ContactConverter::toJSValueRef(const ContactEmailAddressArrayPtr &arg)
1171 //LogDebug("entered");
1172 return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactEmailAddressArray::getClassRef(), arg);
1175 ContactEmailAddressArrayPtr ContactConverter::toContactEmailAddressArray(const JSValueRef &jsValue)
1177 if(JSContactEmailAddressArray::isObjectOfClass(m_context, jsValue))
1178 return JSContactEmailAddressArray::getContactEmailAddressArray(m_context, jsValue);
1180 ContactEmailAddressArrayPtr result(new ContactEmailAddressArray());
1182 JSObjectRef jsObject = toJSObjectRef(jsValue);
1183 for (std::size_t i = 0; i < JSGetArrayLength(m_context, jsObject); ++i) {
1184 JSValueRef element = JSGetArrayElement(m_context, jsObject, i);
1185 result->push_back(toContactEmailAddress(element));
1190 JSValueRef ContactConverter::toJSValueRef(const ContactEmailAddressTypeArrayPtr &arg)
1192 //LogDebug("entered");
1193 return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactEmailAddressTypeArray::getClassRef(), arg);
1196 ContactEmailAddressTypeArrayPtr ContactConverter::toContactEmailAddressTypeArray(const JSValueRef &jsValue)
1198 if(JSContactEmailAddressTypeArray::isObjectOfClass(m_context, jsValue))
1199 return JSContactEmailAddressTypeArray::getContactEmailAddressTypeArray(m_context, jsValue);
1201 ContactEmailAddressTypeArrayPtr result(new ContactEmailAddressTypeArray());
1203 JSObjectRef jsObject = toJSObjectRef(jsValue);
1204 for (std::size_t i = 0; i < JSGetArrayLength(m_context, jsObject); ++i) {
1205 JSValueRef element = JSGetArrayElement(m_context, jsObject, i);
1206 result->push_back(toContactEmailAddressType(element));
1211 JSValueRef ContactConverter::toJSValueRef(const ContactOrganizationPtr &arg)
1213 //LogDebug("entered");
1214 return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactOrganization::getClassRef(), arg);
1217 ContactOrganizationPtr ContactConverter::toContactOrganization(const JSValueRef &jsValue)
1219 if(JSContactOrganization::isObjectOfClass(m_context, jsValue))
1220 return JSContactOrganization::getContactOrganization(m_context, jsValue);
1222 Validator validator(m_context);
1223 if (!validator.checkArrayKeys(m_allowedContactOrganizationProperties, jsValue)) {
1224 LogError("invalid properties in contact object");
1225 ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute");
1228 const ScopedJSStringRef nameStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_NAME));
1229 const ScopedJSStringRef departmentStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_DEPARTMENT));
1230 const ScopedJSStringRef titleStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_TITLE));
1231 const ScopedJSStringRef roleStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_ROLE));
1233 JSObjectRef jsObject = toJSObjectRef(jsValue);
1235 JSValueRef nameData = JSObjectGetProperty(m_context, jsObject, nameStr.get(), NULL);
1236 JSValueRef departmentData = JSObjectGetProperty(m_context, jsObject, departmentStr.get(), NULL);
1237 JSValueRef titleData = JSObjectGetProperty(m_context, jsObject, titleStr.get(), NULL);
1238 JSValueRef roleData = JSObjectGetProperty(m_context, jsObject, roleStr.get(), NULL);
1241 std::string department;
1245 ContactOrganizationPtr result(new ContactOrganization());
1247 Throw(WrtDeviceApis::Commons::ConversionException);
1250 if (!JSValueIsUndefined(m_context, nameData)) {
1251 name = toString(nameData);
1252 result->setName(name);
1255 if (!JSValueIsUndefined(m_context, departmentData)) {
1256 department = toString(departmentData);
1257 result->setDepartment(department);
1260 if (!JSValueIsUndefined(m_context, titleData)) {
1261 title = toString(titleData);
1262 result->setTitle(title);
1265 if (!JSValueIsUndefined(m_context, roleData)) {
1266 role = toString(roleData);
1267 result->setRole(role);
1273 JSValueRef ContactConverter::toJSValueRef(const ContactOrganizationArrayPtr &arg)
1275 //LogDebug("entered");
1276 return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactOrganizationArray::getClassRef(), arg);
1279 ContactOrganizationArrayPtr ContactConverter::toContactOrganizationArray(const JSValueRef &jsValue)
1281 if(JSContactOrganizationArray::isObjectOfClass(m_context, jsValue))
1282 return JSContactOrganizationArray::getContactOrganizationArray(m_context, jsValue);
1284 ContactOrganizationArrayPtr result(new ContactOrganizationArray());
1286 JSObjectRef jsObject = toJSObjectRef(jsValue);
1287 for (std::size_t i = 0; i < JSGetArrayLength(m_context, jsObject); ++i) {
1288 JSValueRef element = JSGetArrayElement(m_context, jsObject, i);
1289 result->push_back(toContactOrganization(element));
1294 JSValueRef ContactConverter::toJSValueRef(const ContactWebSitePtr &arg)
1296 //LogDebug("entered");
1297 return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactWebSite::getClassRef(), arg);
1300 ContactWebSitePtr ContactConverter::toContactWebSite(const JSValueRef &jsValue)
1302 if(JSContactWebSite::isObjectOfClass(m_context, jsValue))
1303 return JSContactWebSite::getContactWebSite(m_context, jsValue);
1305 Validator validator(m_context);
1306 if (!validator.checkArrayKeys(m_allowedContactWebSiteProperties, jsValue)) {
1307 LogError("invalid properties in contact object");
1308 ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute");
1311 const ScopedJSStringRef urlStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_URL));
1312 const ScopedJSStringRef typeStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_TYPE));
1314 JSObjectRef jsObject = toJSObjectRef(jsValue);
1316 JSValueRef urlData = JSObjectGetProperty(m_context, jsObject, urlStr.get(), NULL);
1317 JSValueRef typeData = JSObjectGetProperty(m_context, jsObject, typeStr.get(), NULL);
1320 ContactWebSiteType type;
1322 ContactWebSitePtr result(new ContactWebSite());
1324 Throw(WrtDeviceApis::Commons::ConversionException);
1327 if (!JSValueIsUndefined(m_context, urlData)) {
1328 url = toString(urlData);
1329 result->setUrl(url);
1332 if (!JSValueIsUndefined(m_context, typeData)) {
1333 type = toContactWebSiteType(typeData);
1334 result->setType(type);
1340 JSValueRef ContactConverter::toJSValueRef(const ContactWebSiteArrayPtr &arg)
1342 //LogDebug("entered");
1343 return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactWebSiteArray::getClassRef(), arg);
1346 ContactWebSiteArrayPtr ContactConverter::toContactWebSiteArray(const JSValueRef &jsValue)
1348 if(JSContactWebSiteArray::isObjectOfClass(m_context, jsValue))
1349 return JSContactWebSiteArray::getContactWebSiteArray(m_context, jsValue);
1351 ContactWebSiteArrayPtr result(new ContactWebSiteArray());
1353 JSObjectRef jsObject = toJSObjectRef(jsValue);
1354 for (std::size_t i = 0; i < JSGetArrayLength(m_context, jsObject); ++i) {
1355 JSValueRef element = JSGetArrayElement(m_context, jsObject, i);
1356 result->push_back(toContactWebSite(element));
1361 bool ContactConverter::initializeAllowedProperties()
1363 m_allowedAddressBookProperties.push_back(CONTACT_ATTRIBUTE_NAME);
1365 m_allowedContactProperties.push_back(CONTACT_ATTRIBUTE_ID);
1366 m_allowedContactProperties.push_back(CONTACT_ATTRIBUTE_READ_ONLY);
1367 m_allowedContactProperties.push_back(CONTACT_ATTRIBUTE_LAST_UPDATED);
1368 m_allowedContactProperties.push_back(CONTACT_ATTRIBUTE_NAME);
1369 m_allowedContactProperties.push_back(CONTACT_ATTRIBUTE_ACCOUNT);
1370 m_allowedContactProperties.push_back(CONTACT_ATTRIBUTE_ADDRESSES);
1371 m_allowedContactProperties.push_back(CONTACT_ATTRIBUTE_PHOTO_URI );
1372 m_allowedContactProperties.push_back(CONTACT_ATTRIBUTE_PHONE_NUMBERS);
1373 m_allowedContactProperties.push_back(CONTACT_ATTRIBUTE_EMAILS);
1374 m_allowedContactProperties.push_back(CONTACT_ATTRIBUTE_BIRTHDAY);
1375 m_allowedContactProperties.push_back(CONTACT_ATTRIBUTE_ANNIVERSARIES);
1376 m_allowedContactProperties.push_back(CONTACT_ATTRIBUTE_ORGANIZATION);
1377 m_allowedContactProperties.push_back(CONTACT_ATTRIBUTE_NOTES);
1378 m_allowedContactProperties.push_back(CONTACT_ATTRIBUTE_URLS);
1379 m_allowedContactProperties.push_back(CONTACT_ATTRIBUTE_IS_FAVORITE);
1380 m_allowedContactProperties.push_back(CONTACT_ATTRIBUTE_RINGTONE_URI);
1381 m_allowedContactProperties.push_back(CONTACT_ATTRIBUTE_CATEGORIES);
1383 m_allowedContactPropertiesProperties.push_back(CONTACT_ATTRIBUTE_NAME);
1384 m_allowedContactPropertiesProperties.push_back(CONTACT_ATTRIBUTE_ACCOUNT);
1385 m_allowedContactPropertiesProperties.push_back(CONTACT_ATTRIBUTE_ADDRESSES);
1386 m_allowedContactPropertiesProperties.push_back(CONTACT_ATTRIBUTE_PHOTO_URI );
1387 m_allowedContactPropertiesProperties.push_back(CONTACT_ATTRIBUTE_PHONE_NUMBERS);
1388 m_allowedContactPropertiesProperties.push_back(CONTACT_ATTRIBUTE_EMAILS);
1389 m_allowedContactPropertiesProperties.push_back(CONTACT_ATTRIBUTE_BIRTHDAY);
1390 m_allowedContactPropertiesProperties.push_back(CONTACT_ATTRIBUTE_ANNIVERSARIES);
1391 m_allowedContactPropertiesProperties.push_back(CONTACT_ATTRIBUTE_ORGANIZATION);
1392 m_allowedContactPropertiesProperties.push_back(CONTACT_ATTRIBUTE_NOTES);
1393 m_allowedContactPropertiesProperties.push_back(CONTACT_ATTRIBUTE_URLS);
1394 m_allowedContactPropertiesProperties.push_back(CONTACT_ATTRIBUTE_IS_FAVORITE);
1395 m_allowedContactPropertiesProperties.push_back(CONTACT_ATTRIBUTE_RINGTONE_URI);
1396 m_allowedContactPropertiesProperties.push_back(CONTACT_ATTRIBUTE_CATEGORIES);
1398 m_allowedContactNameProperties.push_back(CONTACT_ATTRIBUTE_PREFIX);
1399 m_allowedContactNameProperties.push_back(CONTACT_ATTRIBUTE_FIRST_NAME);
1400 m_allowedContactNameProperties.push_back(CONTACT_ATTRIBUTE_MIDDLE_NAME);
1401 m_allowedContactNameProperties.push_back(CONTACT_ATTRIBUTE_LAST_NAME);
1402 m_allowedContactNameProperties.push_back(CONTACT_ATTRIBUTE_NICKNAMES);
1403 m_allowedContactNameProperties.push_back(CONTACT_ATTRIBUTE_PHONETIC_NAME);
1404 m_allowedContactNameProperties.push_back(CONTACT_ATTRIBUTE_DISPLAY_NAME);
1406 m_allowedContactAccountProperties.push_back(CONTACT_ATTRIBUTE_ACCOUNT_ID);
1407 m_allowedContactAccountProperties.push_back(CONTACT_ATTRIBUTE_CONTACT_URI);
1409 m_allowedContactOrganizationProperties.push_back(CONTACT_ATTRIBUTE_NAME);
1410 m_allowedContactOrganizationProperties.push_back(CONTACT_ATTRIBUTE_DEPARTMENT);
1411 m_allowedContactOrganizationProperties.push_back(CONTACT_ATTRIBUTE_OFFICE);
1412 m_allowedContactOrganizationProperties.push_back(CONTACT_ATTRIBUTE_TITLE);
1413 m_allowedContactOrganizationProperties.push_back(CONTACT_ATTRIBUTE_ROLE);
1414 m_allowedContactOrganizationProperties.push_back(CONTACT_ATTRIBUTE_LOGO_URI);
1416 m_allowedContactWebSiteProperties.push_back(CONTACT_ATTRIBUTE_URL);
1417 m_allowedContactWebSiteProperties.push_back(CONTACT_ATTRIBUTE_TYPE);
1419 m_allowedContactAnniversaryProperties.push_back(CONTACT_ATTRIBUTE_DATE);
1420 m_allowedContactAnniversaryProperties.push_back(CONTACT_ATTRIBUTE_LABEL);
1422 m_allowedContactAddressProperties.push_back(CONTACT_ATTRIBUTE_COUNTRY);
1423 m_allowedContactAddressProperties.push_back(CONTACT_ATTRIBUTE_REGION);
1424 m_allowedContactAddressProperties.push_back(CONTACT_ATTRIBUTE_CITY);
1425 m_allowedContactAddressProperties.push_back(CONTACT_ATTRIBUTE_STREET_ADDRESS);
1426 m_allowedContactAddressProperties.push_back(CONTACT_ATTRIBUTE_ADDITIONAL_INFORMATION);
1427 m_allowedContactAddressProperties.push_back(CONTACT_ATTRIBUTE_POSTAL_CODE);
1428 m_allowedContactAddressProperties.push_back(CONTACT_ATTRIBUTE_TYPES);
1430 m_allowedContactPhoneNumberProperties.push_back(CONTACT_ATTRIBUTE_NUMBER);
1431 m_allowedContactPhoneNumberProperties.push_back(CONTACT_ATTRIBUTE_TYPES);
1433 m_allowedContactEmailAddressProperties.push_back(CONTACT_ATTRIBUTE_EMAIL);
1434 m_allowedContactEmailAddressProperties.push_back(CONTACT_ATTRIBUTE_TYPES);