2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
20 * @author Kisub Song (kisubs.song@samsung.com)
22 * @brief Implementation of the JSContact class
25 #include <dpl/shared_ptr.h>
26 #include <CommonsJavaScript/Validator.h>
27 #include <JSTizenExceptionFactory.h>
28 #include <JSTizenException.h>
29 #include <SecurityExceptions.h>
30 #include "ContactFactory.h"
31 #include "plugin_config.h"
32 #include "ContactConverter.h"
33 #include "JSContact.h"
35 #include <ArgumentValidator.h>
36 #include <JSWebAPIError.h>
37 #include <TimeTracer.h>
40 #define FILTER_CLASS_NAME "Contact"
42 #define CONTACT_ATTR_ID "id"
43 #define CONTACT_ATTR_ADDRESSBOOK_ID "addressBookId"
44 #define CONTACT_ATTR_PERSON_ID "personId"
45 #define CONTACT_ATTR_LAST_UPDATED "lastUpdated"
46 #define CONTACT_ATTR_IS_FAVORITE "isFavorite"
47 #define CONTACT_ATTR_NAME "name"
48 #define CONTACT_ATTR_ADDRESSES "addresses"
49 #define CONTACT_ATTR_PHOTO_URI "photoURI"
50 #define CONTACT_ATTR_PHONE_NUMBERS "phoneNumbers"
51 #define CONTACT_ATTR_EMAILS "emails"
52 #define CONTACT_ATTR_BIRTHDAY "birthday"
53 #define CONTACT_ATTR_ANNIVERSARIES "anniversaries"
54 #define CONTACT_ATTR_ORGANIZATIONS "organizations"
55 #define CONTACT_ATTR_NOTES "notes"
56 #define CONTACT_ATTR_URLS "urls"
57 #define CONTACT_ATTR_LAST_UPDATED "lastUpdated"
58 #define CONTACT_ATTR_RINGTONE_URI "ringtoneURI"
59 #define CONTACT_ATTR_GROUP_IDS "groupIds"
60 #define CONTACT_FUNC_CONVERT_TO_STRING "convertToString"
61 #define CONTACT_FUNC_CLONE "clone"
66 using namespace DeviceAPI::Common;
67 using namespace WrtDeviceApis::Commons;
68 using namespace WrtDeviceApis::CommonsJavaScript;
70 JSClassDefinition JSContact::m_classInfo =
73 kJSClassAttributeNone,
83 NULL, //DeleteProperty,
84 NULL, //getPropertyNames,
85 NULL, //CallAsFunction,
86 constructor, //CallAsConstructor,
87 hasInstance, //HasInstance,
88 NULL, //ConvertToType,
91 JSStaticValue JSContact::m_property[] = {
92 { CONTACT_ATTR_ID, getId, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete},
93 { CONTACT_ATTR_ADDRESSBOOK_ID, getAddressBookId, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete},
94 { CONTACT_ATTR_PERSON_ID, getPersonId, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete},
95 { CONTACT_ATTR_LAST_UPDATED, getLastUpdated, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
96 { CONTACT_ATTR_IS_FAVORITE, getIsFavorite, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
97 { CONTACT_ATTR_NAME, getName, setName, kJSPropertyAttributeNone },
98 { CONTACT_ATTR_ADDRESSES, getAddresses, setAddresses, kJSPropertyAttributeNone },
99 { CONTACT_ATTR_PHOTO_URI, getPhotoURI, setPhotoURI, kJSPropertyAttributeNone },
100 { CONTACT_ATTR_PHONE_NUMBERS, getPhoneNumbers, setPhoneNumbers, kJSPropertyAttributeNone },
101 { CONTACT_ATTR_EMAILS, getEmails, setEmails, kJSPropertyAttributeNone },
102 { CONTACT_ATTR_BIRTHDAY, getBirthday, setBirthday, kJSPropertyAttributeNone },
103 { CONTACT_ATTR_ANNIVERSARIES, getAnniversaries, setAnniversaries, kJSPropertyAttributeNone },
104 { CONTACT_ATTR_ORGANIZATIONS, getOrganizations, setOrganizations, kJSPropertyAttributeNone },
105 { CONTACT_ATTR_NOTES, getNotes, setNotes, kJSPropertyAttributeNone },
106 { CONTACT_ATTR_URLS, getUrls, setUrls, kJSPropertyAttributeNone },
107 { CONTACT_ATTR_RINGTONE_URI, getRingtoneURI, setRingtoneURI, kJSPropertyAttributeNone },
108 { CONTACT_ATTR_GROUP_IDS, getGroupIds, setGroupIds, kJSPropertyAttributeNone },
112 JSStaticFunction JSContact::m_functions[] =
114 { CONTACT_FUNC_CONVERT_TO_STRING, convertToString, kJSPropertyAttributeNone },
115 { CONTACT_FUNC_CLONE, clone, kJSPropertyAttributeNone },
119 JSClassRef JSContact::m_classRef = JSClassCreate(&m_classInfo);
121 JSClassRef JSContact::getClassRef() {
123 m_classRef = JSClassCreate(&m_classInfo);
128 bool JSContact::isObjectOfClass(JSContextRef context, JSValueRef value)
130 return JSValueIsObjectOfClass(context, value, getClassRef());
133 ContactPtr JSContact::getContact(JSContextRef context, JSValueRef value)
135 if (!isObjectOfClass(context, value)) {
136 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
138 JSObjectRef object = JSValueToObject(context, value, NULL);
140 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
142 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
144 Throw(WrtDeviceApis::Commons::NullPointerException);
146 return priv->getObject();
149 void JSContact::Initialize(JSContextRef context, JSObjectRef object)
151 if (!JSObjectGetPrivate(object))
153 ContactPtr contact = ContactFactory::getInstance().createContact();
154 JSContactPriv *priv = new JSContactPriv(context, ContactPtr(contact));
155 if (!JSObjectSetPrivate(object, priv)) {
161 void JSContact::Finalize(JSObjectRef object)
163 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
169 JSObjectRef JSContact::createJSObject(JSContextRef context, ContactPtr contact)
171 JSContactPriv *priv = new JSContactPriv(context, contact);
172 JSObjectRef jsObjectRef = JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
173 if (NULL == jsObjectRef) {
174 LoggerE("object creation error");
180 ContactPtr JSContact::getPrivData(JSObjectRef object)
182 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
184 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
186 ContactPtr result = priv->getObject();
188 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null.");
193 JSObjectRef JSContact::constructor(JSContextRef context,
194 JSObjectRef constructor,
195 size_t argumentCount,
196 const JSValueRef arguments[],
197 JSValueRef* exception)
201 bool jsNoParam = false;
202 bool js1stParamIsObject = false;
203 bool js1stParamIsString = false;
205 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(constructor));
207 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
209 JSContextRef gContext = priv->getContext();
211 BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
212 if (argumentCount == 0)
218 if (JSValueIsNull(gContext, arguments[0]) || JSValueIsUndefined(gContext, arguments[0]))
220 else if (JSValueIsObject(gContext, arguments[0]))
221 js1stParamIsObject = true;
222 else if (JSValueIsString(gContext, arguments[0]))
223 js1stParamIsString = true;
226 LoggerE("Argument type mismatch : 1nd argument must be ContactInit object or string");
227 *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "2nd argument must be 'ContactTextFormat'");
232 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
234 ContactPtr contact(NULL);
235 if(js1stParamIsObject)
238 contact = converter->toContactFromInit(arguments[0]);
240 } Catch(ConversionException) {
241 LoggerE("Argument type mismatch : " << _rethrown_exception.GetMessage());
242 *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be 'ContactInit object'");
245 LoggerE("Argument type mismatch : " << _rethrown_exception.GetMessage());
246 *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, "Internal error");
250 else if(js1stParamIsString)
253 std::string stringRepresentation; // vCard string
255 stringRepresentation = converter->toString(arguments[0]);
257 contact = ContactFactory::getInstance().createContact();
258 contact->setContactFromString(stringRepresentation);
260 } Catch(ConversionException) {
261 LoggerE("Argument type mismatch : " << _rethrown_exception.GetMessage());
262 *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "2nd argument must be 'ContactTextFormat'");
264 } Catch(InvalidArgumentException) {
265 LoggerE("Argument type mismatch : " << _rethrown_exception.GetMessage());
266 *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, "1st argument must be vCard string");
268 } Catch(UnsupportedException) {
269 LoggerE("Argument type mismatch : " << _rethrown_exception.GetMessage());
270 *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::NOT_SUPPORTED_ERROR, "Only support vCard 3.0");
273 LoggerE("Argument type mismatch : " << _rethrown_exception.GetMessage());
274 *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, "Internal error");
281 contact = ContactFactory::getInstance().createContact();
283 LoggerE("Argument type mismatch : " << _rethrown_exception.GetMessage());
284 *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, "Internal error");
289 JSObjectRef jsobject;
292 jsobject = createJSObject(gContext, contact);
294 LoggerE("Argument type mismatch : " << _rethrown_exception.GetMessage());
295 *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, "Internal error");
302 bool JSContact::hasInstance(JSContextRef context,
303 JSObjectRef constructor,
304 JSValueRef possibleInstance,
305 JSValueRef* exception)
307 return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
310 JSValueRef JSContact::getId(JSContextRef context,
312 JSStringRef propertyName,
313 JSValueRef* exception)
317 ContactConverterFactory::ConverterType converter =
318 ContactConverterFactory::getConverter(context);
319 ContactPtr contact = getPrivData(object);
320 if(!contact->getIdIsSet())
321 return JSValueMakeNull(context);
323 return converter->toJSValueRef(contact->getId());
325 Catch(WrtDeviceApis::Commons::Exception)
327 LoggerW("trying to get incorrect value");
329 return JSValueMakeUndefined(context);
332 JSValueRef JSContact::getAddressBookId(JSContextRef context,
334 JSStringRef propertyName,
335 JSValueRef* exception)
339 ContactConverterFactory::ConverterType converter =
340 ContactConverterFactory::getConverter(context);
341 ContactPtr contact = getPrivData(object);
342 if(!contact->getAddressBookIdIsSet())
343 return JSValueMakeNull(context);
345 return converter->toJSValueRef(contact->getAddressBookId());
347 Catch(WrtDeviceApis::Commons::Exception)
349 LoggerW("trying to get incorrect value");
351 return JSValueMakeUndefined(context);
354 JSValueRef JSContact::getPersonId(JSContextRef context,
356 JSStringRef propertyName,
357 JSValueRef* exception)
361 ContactConverterFactory::ConverterType converter =
362 ContactConverterFactory::getConverter(context);
363 ContactPtr contact = getPrivData(object);
364 if(!contact->getPersonIdIsSet())
365 return JSValueMakeNull(context);
367 return converter->toJSValueRef(contact->getPersonId());
369 Catch(WrtDeviceApis::Commons::Exception)
371 LoggerW("trying to get incorrect value");
373 return JSValueMakeUndefined(context);
376 JSValueRef JSContact::getLastUpdated(JSContextRef context,
378 JSStringRef propertyName,
379 JSValueRef* exception)
383 ContactConverterFactory::ConverterType converter =
384 ContactConverterFactory::getConverter(context);
385 ContactPtr contact = getPrivData(object);
386 if(!contact->getLastUpdatedIsSet())
387 return JSValueMakeNull(context);
389 return converter->toJSValueRef(contact->getLastUpdated());
391 Catch(WrtDeviceApis::Commons::Exception)
393 LoggerW("trying to get incorrect value");
396 return JSValueMakeUndefined(context);
399 JSValueRef JSContact::getIsFavorite(JSContextRef context,
401 JSStringRef propertyName,
402 JSValueRef* exception)
406 ContactConverterFactory::ConverterType converter =
407 ContactConverterFactory::getConverter(context);
408 ContactPtr contact = getPrivData(object);
409 return converter->toJSValueRef(contact->getIsFavorite());
411 Catch(WrtDeviceApis::Commons::Exception)
413 LoggerW("trying to get incorrect value");
416 return JSValueMakeUndefined(context);
419 JSValueRef JSContact::getName(JSContextRef context,
421 JSStringRef propertyName,
422 JSValueRef* exception)
426 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
428 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
430 JSContextRef gContext = priv->getContext();
432 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
433 ContactPtr contact = getPrivData(object);
434 ContactNamePtr contactName = contact->getName();
435 if(contactName == NULL)
436 return JSValueMakeNull(context);
438 return converter->toJSValueRef(contactName);
440 Catch(WrtDeviceApis::Commons::Exception)
442 LoggerW("trying to get incorrect value");
445 return JSValueMakeUndefined(context);
448 bool JSContact::setName(JSContextRef context,
450 JSStringRef propertyName,
452 JSValueRef* exception)
456 ContactPtr contact = getPrivData(object);
457 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
458 BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
459 if(validator->isNullOrUndefined(value))
460 contact->unsetName();
462 contact->setName(converter->toContactName(value));
464 Catch(WrtDeviceApis::Commons::Exception)
466 LoggerW("trying to set incorrect value");
467 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
473 JSValueRef JSContact::getAddresses(JSContextRef context,
475 JSStringRef propertyName,
476 JSValueRef* exception)
480 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
482 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
484 JSContextRef gContext = priv->getContext();
485 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
486 ContactPtr contact = getPrivData(object);
488 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
489 if(newContactT->addressesJSObjIsSet()){
490 return newContactT->getAddressesJSObj();
492 JSValueRef tempJSValue = newContactT->getAddressesJSValue();
493 tempJSValue = converter->toJSValueRef(newContactT->getAddresses());
495 JSObjectRef convertedJSObject = newContactT->getAddressesJSObj();
496 convertedJSObject = JSValueToObject( gContext, tempJSValue, NULL );
497 newContactT->setAddressesJSObj(true, convertedJSObject);
499 JSValueProtect(gContext, convertedJSObject);
500 newContactT->setContext(gContext);
504 Catch(WrtDeviceApis::Commons::Exception)
506 LoggerW("trying to get incorrect value");
509 return JSValueMakeUndefined(context);
512 bool JSContact::setAddresses(JSContextRef context,
514 JSStringRef propertyName,
516 JSValueRef* exception)
520 ContactPtr contact = getPrivData(object);
521 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
522 contact->setAddresses(converter->toContactAddressArray(value));
523 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
524 newContactT->resetAddressesJSObj();
526 Catch(WrtDeviceApis::Commons::Exception)
528 LoggerW("trying to set incorrect value");
529 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
535 JSValueRef JSContact::getPhotoURI(JSContextRef context,
537 JSStringRef propertyName,
538 JSValueRef* exception)
542 ContactConverterFactory::ConverterType converter =
543 ContactConverterFactory::getConverter(context);
544 ContactPtr contact = getPrivData(object);
545 if(!contact->getPhotoURIIsSet())
546 return JSValueMakeNull(context);
548 return converter->toJSValueRef(contact->getPhotoURI());
550 Catch(WrtDeviceApis::Commons::Exception)
552 LoggerW("trying to get incorrect value");
555 return JSValueMakeUndefined(context);
558 bool JSContact::setPhotoURI(JSContextRef context,
560 JSStringRef propertyName,
562 JSValueRef* exception)
566 ContactPtr contact = getPrivData(object);
567 ContactConverterFactory::ConverterType converter =
568 ContactConverterFactory::getConverter(context);
569 BasicValidator validator =
570 BasicValidatorFactory::getValidator(context, exception);
571 if(validator->isNullOrUndefined(value))
572 contact->unsetPhotoURI();
574 contact->setPhotoURI(converter->toString(value));
576 Catch(WrtDeviceApis::Commons::Exception)
578 LoggerW("trying to set incorrect value");
579 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
585 JSValueRef JSContact::getPhoneNumbers(JSContextRef context,
587 JSStringRef propertyName,
588 JSValueRef* exception)
592 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
594 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
596 JSContextRef gContext = priv->getContext();
597 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
598 ContactPtr contact = getPrivData(object);
600 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
601 if(newContactT->numbersJSObjIsSet()){
602 return newContactT->getNumbersJSObj();
604 JSValueRef tempJSValue = newContactT->getNumbersJSValue();
605 tempJSValue = converter->toJSValueRef(newContactT->getPhoneNumbers());
607 JSObjectRef convertedJSObject = newContactT->getNumbersJSObj();
608 convertedJSObject = JSValueToObject( gContext, tempJSValue, NULL );
609 newContactT->setNumbersJSObj(true, convertedJSObject);
611 JSValueProtect(gContext, convertedJSObject);
612 newContactT->setContext(gContext);
616 Catch(WrtDeviceApis::Commons::Exception)
618 LoggerW("trying to get incorrect value");
621 return JSValueMakeUndefined(context);
624 bool JSContact::setPhoneNumbers(JSContextRef context,
626 JSStringRef propertyName,
628 JSValueRef* exception)
632 ContactPtr contact = getPrivData(object);
633 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
634 contact->setPhoneNumbers(converter->toContactPhoneNumberArray(value));
635 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
636 newContactT->resetNumbersJSObj();
638 Catch(WrtDeviceApis::Commons::Exception)
640 LoggerW("trying to set incorrect value");
641 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
647 JSValueRef JSContact::getEmails(JSContextRef context,
649 JSStringRef propertyName,
650 JSValueRef* exception)
654 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
656 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
658 JSContextRef gContext = priv->getContext();
660 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
661 ContactPtr contact = getPrivData(object);
663 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
664 if(newContactT->EmailsJSObjIsSet()){
665 LoggerD("return init value");
666 return newContactT->getEmailsJSObj();
668 LoggerD("new array");
669 JSValueRef tempJSValue = newContactT->getEmailsJSValue();
670 tempJSValue = converter->toJSValueRef(newContactT->getEmails());
672 JSObjectRef convertedJSObject = newContactT->getEmailsJSObj();
673 convertedJSObject = JSValueToObject( gContext, tempJSValue, NULL );
674 newContactT->setEmailsJSObj(true, convertedJSObject);
676 JSValueProtect(gContext, convertedJSObject);
677 newContactT->setContext(gContext);
681 Catch(WrtDeviceApis::Commons::Exception)
683 LoggerW("trying to get incorrect value");
686 return JSValueMakeUndefined(context);
689 bool JSContact::setEmails(JSContextRef context,
691 JSStringRef propertyName,
693 JSValueRef* exception)
697 ContactPtr contact = getPrivData(object);
698 ContactConverterFactory::ConverterType converter =
699 ContactConverterFactory::getConverter(context);
700 contact->setEmails(converter->toContactEmailAddressArray(value));
701 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
702 newContactT->resetEmailsJSObj();
704 Catch(WrtDeviceApis::Commons::Exception)
706 LoggerW("trying to set incorrect value");
707 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
713 JSValueRef JSContact::getBirthday(JSContextRef context,
715 JSStringRef propertyName,
716 JSValueRef* exception)
720 ContactConverterFactory::ConverterType converter =
721 ContactConverterFactory::getConverter(context);
722 ContactPtr contact = getPrivData(object);
723 if(!contact->getBirthdayIsSet())
724 return JSValueMakeNull(context);
726 return converter->toJSValueRef(contact->getBirthday());
728 Catch(WrtDeviceApis::Commons::Exception)
730 LoggerW("trying to get incorrect value");
733 return JSValueMakeUndefined(context);
736 bool JSContact::setBirthday(JSContextRef context,
738 JSStringRef propertyName,
740 JSValueRef* exception)
744 ContactPtr contact = getPrivData(object);
745 ContactConverterFactory::ConverterType converter =
746 ContactConverterFactory::getConverter(context);
747 BasicValidator validator =
748 BasicValidatorFactory::getValidator(context, exception);
749 if(validator->isNullOrUndefined(value))
750 contact->unsetBirthday();
752 contact->setBirthday(converter->toDateTm(value));
754 Catch(WrtDeviceApis::Commons::Exception)
756 LoggerW("trying to set incorrect value");
757 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
763 JSValueRef JSContact::getAnniversaries(JSContextRef context,
765 JSStringRef propertyName,
766 JSValueRef* exception)
770 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
772 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
774 JSContextRef gContext = priv->getContext();
776 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
777 ContactPtr contact = getPrivData(object);
779 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
780 if(newContactT->anniversariesJSObjIsSet()){
781 return newContactT->getAnniversariesJSObj();
783 JSValueRef tempJSValue = newContactT->getAnniversariesJSValue();
784 tempJSValue = converter->toJSValueRef(newContactT->getAnniversaries());
786 JSObjectRef convertedJSObject = newContactT->getAnniversariesJSObj();
787 convertedJSObject = JSValueToObject( gContext, tempJSValue, NULL );
788 newContactT->setAnniversariesJSObj(true, convertedJSObject);
790 JSValueProtect(gContext, convertedJSObject);
791 newContactT->setContext(gContext);
795 Catch(WrtDeviceApis::Commons::Exception)
797 LoggerW("trying to get incorrect value");
800 return JSValueMakeUndefined(context);
803 bool JSContact::setAnniversaries(JSContextRef context,
805 JSStringRef propertyName,
807 JSValueRef* exception)
811 ContactPtr contact = getPrivData(object);
812 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
813 contact->setAnniversaries(converter->toContactAnniversaryArray(value));
814 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
815 newContactT->resetAnniversariesJSObj();
817 Catch(WrtDeviceApis::Commons::Exception)
819 LoggerW("trying to set incorrect value");
820 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
826 JSValueRef JSContact::getOrganizations(JSContextRef context,
828 JSStringRef propertyName,
829 JSValueRef* exception)
833 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
835 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
837 JSContextRef gContext = priv->getContext();
839 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
840 ContactPtr contact = getPrivData(object);
842 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
843 if(newContactT->organizationsJSObjIsSet()){
844 return newContactT->getOrganizationsJSObj();
846 JSValueRef tempJSValue = newContactT->getOrganizationsJSValue();
847 tempJSValue = converter->toJSValueRef(newContactT->getOrganizations());
849 JSObjectRef convertedJSObject = newContactT->getOrganizationsJSObj();
850 convertedJSObject = JSValueToObject( gContext, tempJSValue, NULL );
851 newContactT->setOrganizationsJSObj(true, convertedJSObject);
853 JSValueProtect(gContext, convertedJSObject);
854 newContactT->setContext(gContext);
858 Catch(WrtDeviceApis::Commons::Exception)
860 LoggerW("trying to get incorrect value");
863 return JSValueMakeUndefined(context);
866 bool JSContact::setOrganizations(JSContextRef context,
868 JSStringRef propertyName,
870 JSValueRef* exception)
874 ContactPtr contact = getPrivData(object);
875 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
876 contact->setOrganizations(converter->toContactOrganizationArray(value));
877 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
878 newContactT->resetOrganizationsJSObj();
880 Catch(WrtDeviceApis::Commons::Exception)
882 LoggerW("trying to set incorrect value");
883 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
889 JSValueRef JSContact::getNotes(JSContextRef context,
891 JSStringRef propertyName,
892 JSValueRef* exception)
896 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
898 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
900 JSContextRef gContext = priv->getContext();
902 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
903 ContactPtr contact = getPrivData(object);
905 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
906 if(newContactT->notesJSObjIsSet()){
907 return newContactT->getNotesJSObj();
909 JSValueRef tempJSValue = newContactT->getNotesJSValue();
910 tempJSValue = converter->toJSValueRef(newContactT->getNotes());
912 JSObjectRef convertedJSObject = newContactT->getNotesJSObj();
913 convertedJSObject = JSValueToObject( gContext, tempJSValue, NULL );
914 newContactT->setNotesJSObj(true, convertedJSObject);
916 JSValueProtect(gContext, convertedJSObject);
917 newContactT->setContext(gContext);
921 Catch(WrtDeviceApis::Commons::Exception)
923 LoggerW("trying to get incorrect value");
926 return JSValueMakeUndefined(context);
929 bool JSContact::setNotes(JSContextRef context,
931 JSStringRef propertyName,
933 JSValueRef* exception)
937 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
939 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
941 JSContextRef gContext = priv->getContext();
942 ContactPtr contact = getPrivData(object);
944 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
945 contact->setNotes(converter->toStringArray(value));
946 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
947 newContactT->resetNotesJSObj();
949 Catch(WrtDeviceApis::Commons::Exception)
951 LoggerW("trying to set incorrect value");
952 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
958 JSValueRef JSContact::getUrls(JSContextRef context,
960 JSStringRef propertyName,
961 JSValueRef* exception)
965 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
967 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
969 JSContextRef gContext = priv->getContext();
971 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
972 ContactPtr contact = getPrivData(object);
974 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
975 if(newContactT->urlsJSObjIsSet()){
976 return newContactT->getUrlsJSObj();
978 JSValueRef tempJSValue = newContactT->getUrlsJSValue();
979 tempJSValue = converter->toJSValueRef(newContactT->getUrls());
981 JSObjectRef convertedJSObject = newContactT->getUrlsJSObj();
982 convertedJSObject = JSValueToObject( gContext, tempJSValue, NULL );
983 newContactT->setUrlsJSObj(true, convertedJSObject);
985 JSValueProtect(gContext, convertedJSObject);
986 newContactT->setContext(gContext);
990 Catch(WrtDeviceApis::Commons::Exception)
992 LoggerW("trying to get incorrect value");
995 return JSValueMakeUndefined(context);
998 bool JSContact::setUrls(JSContextRef context,
1000 JSStringRef propertyName,
1002 JSValueRef* exception)
1006 ContactPtr contact = getPrivData(object);
1007 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
1008 contact->setUrls(converter->toContactWebSiteArray(value));
1009 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
1010 newContactT->resetUrlsJSObj();
1012 Catch(WrtDeviceApis::Commons::Exception)
1014 LoggerW("trying to set incorrect value");
1015 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
1021 JSValueRef JSContact::getRingtoneURI(JSContextRef context,
1023 JSStringRef propertyName,
1024 JSValueRef* exception)
1028 ContactConverterFactory::ConverterType converter =
1029 ContactConverterFactory::getConverter(context);
1030 ContactPtr contact = getPrivData(object);
1031 if(!contact->getRingtoneURIIsSet())
1032 return JSValueMakeNull(context);
1034 return converter->toJSValueRef(contact->getRingtoneURI());
1036 Catch(WrtDeviceApis::Commons::Exception)
1038 LoggerW("trying to get incorrect value");
1041 return JSValueMakeUndefined(context);
1044 bool JSContact::setRingtoneURI(JSContextRef context,
1046 JSStringRef propertyName,
1048 JSValueRef* exception)
1052 ContactPtr contact = getPrivData(object);
1053 ContactConverterFactory::ConverterType converter =
1054 ContactConverterFactory::getConverter(context);
1055 BasicValidator validator =
1056 BasicValidatorFactory::getValidator(context, exception);
1057 if(validator->isNullOrUndefined(value))
1058 contact->unsetRingtoneURI();
1060 contact->setRingtoneURI(converter->toString(value));
1062 Catch(WrtDeviceApis::Commons::Exception)
1064 LoggerW("trying to set incorrect value");
1065 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
1071 JSValueRef JSContact::getGroupIds(JSContextRef context,
1073 JSStringRef propertyName,
1074 JSValueRef* exception)
1078 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
1080 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
1082 JSContextRef gContext = priv->getContext();
1084 ContactConverterFactory::ConverterType converter =
1085 ContactConverterFactory::getConverter(gContext);
1086 ContactPtr contact = getPrivData(object);
1087 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
1089 if(newContactT->groupIdsJSObjIsSet()){
1090 return newContactT->getGroupIdsJSObj();
1092 JSValueRef tempJSValue = newContactT->getGroupIdsJSValue();
1093 tempJSValue = converter->toJSValueRef(newContactT->getGroupIds());
1095 JSObjectRef convertedJSObject = newContactT->getGroupIdsJSObj();
1096 convertedJSObject = JSValueToObject( gContext, tempJSValue, NULL );
1097 newContactT->setGroupIdsJSObj(true, convertedJSObject);
1099 JSValueProtect(gContext, convertedJSObject);
1100 newContactT->setContext(gContext);
1104 Catch(WrtDeviceApis::Commons::Exception)
1106 LoggerW("trying to get incorrect value");
1109 return JSValueMakeUndefined(context);
1112 bool JSContact::setGroupIds(JSContextRef context,
1114 JSStringRef propertyName,
1116 JSValueRef* exception)
1120 ContactPtr contact = getPrivData(object);
1121 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
1122 contact->setGroupIds(converter->toStringArray(value));
1123 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
1124 newContactT->resetGroupIdsJSObj();
1126 Catch(WrtDeviceApis::Commons::Exception)
1128 LoggerW("trying to set incorrect value");
1129 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
1135 JSValueRef JSContact::convertToString(JSContextRef context,
1137 JSObjectRef thisObject,
1138 size_t argumentCount,
1139 const JSValueRef arguments[],
1140 JSValueRef* exception)
1143 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
1144 ContactPtr contact(NULL);
1147 contact = getPrivData(thisObject);
1148 if (contact == NULL) {
1149 ThrowMsg(InvalidArgumentException, "No private object.");
1151 } Catch(Exception) {
1152 LoggerE("Argument type mismatch : " << _rethrown_exception.GetMessage());
1153 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
1156 // AceSecurityStatus status = CONTACT_CHECK_ACCESS(
1157 // CONTACT_FUNCTION_API_CONVERT_TO_STRING);
1158 // TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1160 ArgumentValidator validator(context, argumentCount, arguments);
1163 format = validator.toString(0, false);
1164 } catch (const TypeMismatchException& err ) {
1165 return JSWebAPIError::throwException(context, exception, err);
1166 } catch(const BasePlatformException& err) {
1167 return JSWebAPIError::throwException(context, exception, err);
1168 } catch(const ConversionException& err) {
1169 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
1170 } catch(const NullPointerException& err) {
1171 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
1176 vCard = contact->convertToString(format);
1177 } Catch(ConversionException) {
1178 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
1179 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be 'ContactTextFormat string'");
1180 } Catch(UnsupportedException) {
1181 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
1182 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, "Only support vCard 3.0");
1183 } Catch(Exception) {
1184 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
1185 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
1188 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
1191 result = converter->toJSValueRef(vCard);
1192 } Catch(Exception) {
1193 LoggerE("Error on conversion : " << _rethrown_exception.GetMessage());
1194 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
1196 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
1200 JSValueRef JSContact::clone(JSContextRef context,
1202 JSObjectRef thisObject,
1203 size_t argumentCount,
1204 const JSValueRef arguments[],
1205 JSValueRef* exception)
1208 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
1209 ContactPtr contact(NULL);
1212 contact = getPrivData(thisObject);
1213 if (contact == NULL) {
1214 ThrowMsg(InvalidArgumentException, "No private object.");
1216 } Catch(Exception) {
1217 LoggerE("Argument type mismatch : " << _rethrown_exception.GetMessage());
1218 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
1221 // AceSecurityStatus status = CONTACT_CHECK_ACCESS(
1222 // CONTACT_FUNCTION_API_CONVERT_TO_STRING);
1223 // TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1225 ContactPtr clonedContact(NULL);
1227 clonedContact = contact->clone();
1228 } Catch(Exception) {
1229 LoggerE("Error on conversion : " << _rethrown_exception.GetMessage());
1230 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
1235 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(thisObject));
1237 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
1239 JSContextRef gContext = priv->getContext();
1240 result = createJSObject(gContext, clonedContact);
1241 } Catch(Exception) {
1242 LoggerE("Error on conversion : " << _rethrown_exception.GetMessage());
1243 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
1245 TIME_TRACER_ITEM_END(__FUNCTION__, 0);