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/log/log.h>
26 #include <dpl/shared_ptr.h>
27 #include <CommonsJavaScript/Validator.h>
28 #include <JSTizenExceptionFactory.h>
29 #include <JSTizenException.h>
30 #include <SecurityExceptions.h>
31 #include "ContactFactory.h"
32 #include "plugin_config.h"
33 #include "ContactConverter.h"
34 #include "JSContact.h"
37 #define FILTER_CLASS_NAME "Contact"
39 #define CONTACT_ATTR_ID "id"
40 #define CONTACT_ATTR_ADDRESSBOOK_ID "addressBookId"
41 #define CONTACT_ATTR_PERSON_ID "personId"
42 #define CONTACT_ATTR_LAST_UPDATED "lastUpdated"
43 #define CONTACT_ATTR_IS_FAVORITE "isFavorite"
44 #define CONTACT_ATTR_NAME "name"
45 #define CONTACT_ATTR_ADDRESSES "addresses"
46 #define CONTACT_ATTR_PHOTO_URI "photoURI"
47 #define CONTACT_ATTR_PHONE_NUMBERS "phoneNumbers"
48 #define CONTACT_ATTR_EMAILS "emails"
49 #define CONTACT_ATTR_BIRTHDAY "birthday"
50 #define CONTACT_ATTR_ANNIVERSARIES "anniversaries"
51 #define CONTACT_ATTR_ORGANIZATIONS "organizations"
52 #define CONTACT_ATTR_NOTES "notes"
53 #define CONTACT_ATTR_URLS "urls"
54 #define CONTACT_ATTR_LAST_UPDATED "lastUpdated"
55 #define CONTACT_ATTR_RINGTONE_URI "ringtoneURI"
56 #define CONTACT_ATTR_GROUP_IDS "groupIds"
57 #define CONTACT_FUNC_CONVERT_TO_STRING "convertToString"
58 #define CONTACT_FUNC_CLONE "clone"
63 using namespace DeviceAPI::Common;
64 using namespace WrtDeviceApis::Commons;
65 using namespace WrtDeviceApis::CommonsJavaScript;
67 JSClassDefinition JSContact::m_classInfo =
70 kJSClassAttributeNone,
80 NULL, //DeleteProperty,
81 NULL, //getPropertyNames,
82 NULL, //CallAsFunction,
83 constructor, //CallAsConstructor,
84 hasInstance, //HasInstance,
85 NULL, //ConvertToType,
88 JSStaticValue JSContact::m_property[] = {
89 { CONTACT_ATTR_ID, getId, NULL, kJSPropertyAttributeReadOnly },
90 { CONTACT_ATTR_ADDRESSBOOK_ID, getAddressBookId, NULL, kJSPropertyAttributeReadOnly },
91 { CONTACT_ATTR_PERSON_ID, getPersonId, NULL, kJSPropertyAttributeReadOnly },
92 { CONTACT_ATTR_LAST_UPDATED, getLastUpdated, NULL, kJSPropertyAttributeReadOnly },
93 { CONTACT_ATTR_IS_FAVORITE, getIsFavorite, NULL, kJSPropertyAttributeReadOnly },
94 { CONTACT_ATTR_NAME, getName, setName, kJSPropertyAttributeNone },
95 { CONTACT_ATTR_ADDRESSES, getAddresses, setAddresses, kJSPropertyAttributeNone },
96 { CONTACT_ATTR_PHOTO_URI, getPhotoURI, setPhotoURI, kJSPropertyAttributeNone },
97 { CONTACT_ATTR_PHONE_NUMBERS, getPhoneNumbers, setPhoneNumbers, kJSPropertyAttributeNone },
98 { CONTACT_ATTR_EMAILS, getEmails, setEmails, kJSPropertyAttributeNone },
99 { CONTACT_ATTR_BIRTHDAY, getBirthday, setBirthday, kJSPropertyAttributeNone },
100 { CONTACT_ATTR_ANNIVERSARIES, getAnniversaries, setAnniversaries, kJSPropertyAttributeNone },
101 { CONTACT_ATTR_ORGANIZATIONS, getOrganizations, setOrganizations, kJSPropertyAttributeNone },
102 { CONTACT_ATTR_NOTES, getNotes, setNotes, kJSPropertyAttributeNone },
103 { CONTACT_ATTR_URLS, getUrls, setUrls, kJSPropertyAttributeNone },
104 { CONTACT_ATTR_RINGTONE_URI, getRingtoneURI, setRingtoneURI, kJSPropertyAttributeNone },
105 { CONTACT_ATTR_GROUP_IDS, getGroupIds, setGroupIds, kJSPropertyAttributeNone },
109 JSStaticFunction JSContact::m_functions[] =
111 { CONTACT_FUNC_CONVERT_TO_STRING, convertToString, kJSPropertyAttributeNone },
112 { CONTACT_FUNC_CLONE, clone, kJSPropertyAttributeNone },
116 JSClassRef JSContact::m_classRef = JSClassCreate(&m_classInfo);
118 JSClassRef JSContact::getClassRef() {
120 m_classRef = JSClassCreate(&m_classInfo);
125 bool JSContact::isObjectOfClass(JSContextRef context, JSValueRef value)
127 return JSValueIsObjectOfClass(context, value, getClassRef());
130 ContactPtr JSContact::getContact(JSContextRef context, JSValueRef value)
132 if (!isObjectOfClass(context, value)) {
133 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
135 JSObjectRef object = JSValueToObject(context, value, NULL);
137 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
139 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
141 Throw(WrtDeviceApis::Commons::NullPointerException);
143 return priv->getObject();
146 void JSContact::Initialize(JSContextRef context, JSObjectRef object)
148 if (!JSObjectGetPrivate(object))
150 ContactPtr contact = ContactFactory::getInstance().createContact();
151 JSContactPriv *priv = new JSContactPriv(context, ContactPtr(contact));
152 if (!JSObjectSetPrivate(object, priv)) {
158 void JSContact::Finalize(JSObjectRef object)
160 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
166 JSObjectRef JSContact::createJSObject(JSContextRef context, ContactPtr contact)
168 JSContactPriv *priv = new JSContactPriv(context, contact);
169 JSObjectRef jsObjectRef = JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
170 if (NULL == jsObjectRef) {
171 LogError("object creation error");
177 ContactPtr JSContact::getPrivData(JSObjectRef object)
179 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
181 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
183 ContactPtr result = priv->getObject();
185 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null.");
190 JSObjectRef JSContact::constructor(JSContextRef context,
191 JSObjectRef constructor,
192 size_t argumentCount,
193 const JSValueRef arguments[],
194 JSValueRef* exception)
198 bool jsNoParam = false;
199 bool js1stParamIsObject = false;
200 bool js1stParamIsString = false;
202 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(constructor));
204 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
206 JSContextRef gContext = priv->getContext();
208 BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
209 if (argumentCount == 0)
215 if (JSValueIsNull(gContext, arguments[0]) || JSValueIsUndefined(gContext, arguments[0]))
217 else if (JSValueIsObject(gContext, arguments[0]))
218 js1stParamIsObject = true;
219 else if (JSValueIsString(gContext, arguments[0]))
220 js1stParamIsString = true;
223 LogError("Argument type mismatch : 1nd argument must be ContactInit object or string");
224 *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "2nd argument must be 'ContactTextFormat'");
229 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
231 ContactPtr contact(NULL);
232 if(js1stParamIsObject)
235 contact = converter->toContactFromInit(arguments[0]);
237 } Catch(ConversionException) {
238 LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
239 *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be 'ContactInit object'");
242 LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
243 *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, "Internal error");
247 else if(js1stParamIsString)
250 std::string stringRepresentation; // vCard string
252 stringRepresentation = converter->toString(arguments[0]);
254 contact = ContactFactory::getInstance().createContact();
255 contact->setContactFromString(stringRepresentation);
257 } Catch(ConversionException) {
258 LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
259 *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "2nd argument must be 'ContactTextFormat'");
261 } Catch(InvalidArgumentException) {
262 LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
263 *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, "1st argument must be vCard string");
265 } Catch(UnsupportedException) {
266 LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
267 *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::NOT_SUPPORTED_ERROR, "Only support vCard 3.0");
270 LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
271 *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, "Internal error");
278 contact = ContactFactory::getInstance().createContact();
280 LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
281 *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, "Internal error");
286 JSObjectRef jsobject;
289 jsobject = createJSObject(gContext, contact);
291 LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
292 *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, "Internal error");
299 bool JSContact::hasInstance(JSContextRef context,
300 JSObjectRef constructor,
301 JSValueRef possibleInstance,
302 JSValueRef* exception)
304 return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
307 JSValueRef JSContact::getId(JSContextRef context,
309 JSStringRef propertyName,
310 JSValueRef* exception)
314 ContactConverterFactory::ConverterType converter =
315 ContactConverterFactory::getConverter(context);
316 ContactPtr contact = getPrivData(object);
317 if(!contact->getIdIsSet())
318 return JSValueMakeNull(context);
320 return converter->toJSValueRef(contact->getId());
322 Catch(WrtDeviceApis::Commons::Exception)
324 LogWarning("trying to get incorrect value");
326 return JSValueMakeUndefined(context);
329 JSValueRef JSContact::getAddressBookId(JSContextRef context,
331 JSStringRef propertyName,
332 JSValueRef* exception)
336 ContactConverterFactory::ConverterType converter =
337 ContactConverterFactory::getConverter(context);
338 ContactPtr contact = getPrivData(object);
339 if(!contact->getAddressBookIdIsSet())
340 return JSValueMakeNull(context);
342 return converter->toJSValueRef(contact->getAddressBookId());
344 Catch(WrtDeviceApis::Commons::Exception)
346 LogWarning("trying to get incorrect value");
348 return JSValueMakeUndefined(context);
351 JSValueRef JSContact::getPersonId(JSContextRef context,
353 JSStringRef propertyName,
354 JSValueRef* exception)
358 ContactConverterFactory::ConverterType converter =
359 ContactConverterFactory::getConverter(context);
360 ContactPtr contact = getPrivData(object);
361 if(!contact->getPersonIdIsSet())
362 return JSValueMakeNull(context);
364 return converter->toJSValueRef(contact->getPersonId());
366 Catch(WrtDeviceApis::Commons::Exception)
368 LogWarning("trying to get incorrect value");
370 return JSValueMakeUndefined(context);
373 JSValueRef JSContact::getLastUpdated(JSContextRef context,
375 JSStringRef propertyName,
376 JSValueRef* exception)
380 ContactConverterFactory::ConverterType converter =
381 ContactConverterFactory::getConverter(context);
382 ContactPtr contact = getPrivData(object);
383 if(!contact->getLastUpdatedIsSet())
384 return JSValueMakeNull(context);
386 return converter->toJSValueRef(contact->getLastUpdated());
388 Catch(WrtDeviceApis::Commons::Exception)
390 LogWarning("trying to get incorrect value");
393 return JSValueMakeUndefined(context);
396 JSValueRef JSContact::getIsFavorite(JSContextRef context,
398 JSStringRef propertyName,
399 JSValueRef* exception)
403 ContactConverterFactory::ConverterType converter =
404 ContactConverterFactory::getConverter(context);
405 ContactPtr contact = getPrivData(object);
406 return converter->toJSValueRef(contact->getIsFavorite());
408 Catch(WrtDeviceApis::Commons::Exception)
410 LogWarning("trying to get incorrect value");
413 return JSValueMakeUndefined(context);
416 JSValueRef JSContact::getName(JSContextRef context,
418 JSStringRef propertyName,
419 JSValueRef* exception)
423 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
425 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
427 JSContextRef gContext = priv->getContext();
429 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
430 ContactPtr contact = getPrivData(object);
431 ContactNamePtr contactName = contact->getName();
432 if(contactName == NULL)
433 return JSValueMakeNull(context);
435 return converter->toJSValueRef(contactName);
437 Catch(WrtDeviceApis::Commons::Exception)
439 LogWarning("trying to get incorrect value");
442 return JSValueMakeUndefined(context);
445 bool JSContact::setName(JSContextRef context,
447 JSStringRef propertyName,
449 JSValueRef* exception)
453 ContactPtr contact = getPrivData(object);
454 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
455 BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
456 if(validator->isNullOrUndefined(value))
457 contact->unsetName();
459 contact->setName(converter->toContactName(value));
462 Catch(WrtDeviceApis::Commons::Exception)
464 LogWarning("trying to set incorrect value");
467 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
471 JSValueRef JSContact::getAddresses(JSContextRef context,
473 JSStringRef propertyName,
474 JSValueRef* exception)
478 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
480 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
482 JSContextRef gContext = priv->getContext();
483 ContactConverterFactory::ConverterType converter =
484 ContactConverterFactory::getConverter(gContext);
485 ContactPtr contact = getPrivData(object);
486 return converter->toJSValueRef(contact->getAddresses());
488 Catch(WrtDeviceApis::Commons::Exception)
490 LogWarning("trying to get incorrect value");
493 return JSValueMakeUndefined(context);
496 bool JSContact::setAddresses(JSContextRef context,
498 JSStringRef propertyName,
500 JSValueRef* exception)
504 ContactPtr contact = getPrivData(object);
505 ContactConverterFactory::ConverterType converter =
506 ContactConverterFactory::getConverter(context);
507 contact->setAddresses(converter->toContactAddressArray(value));
510 Catch(WrtDeviceApis::Commons::Exception)
512 LogWarning("trying to set incorrect value");
515 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
519 JSValueRef JSContact::getPhotoURI(JSContextRef context,
521 JSStringRef propertyName,
522 JSValueRef* exception)
526 ContactConverterFactory::ConverterType converter =
527 ContactConverterFactory::getConverter(context);
528 ContactPtr contact = getPrivData(object);
529 if(!contact->getPhotoURIIsSet())
530 return JSValueMakeNull(context);
532 return converter->toJSValueRef(contact->getPhotoURI());
534 Catch(WrtDeviceApis::Commons::Exception)
536 LogWarning("trying to get incorrect value");
539 return JSValueMakeUndefined(context);
542 bool JSContact::setPhotoURI(JSContextRef context,
544 JSStringRef propertyName,
546 JSValueRef* exception)
550 ContactPtr contact = getPrivData(object);
551 ContactConverterFactory::ConverterType converter =
552 ContactConverterFactory::getConverter(context);
553 BasicValidator validator =
554 BasicValidatorFactory::getValidator(context, exception);
555 if(validator->isNullOrUndefined(value))
556 contact->unsetPhotoURI();
558 contact->setPhotoURI(converter->toString(value));
561 Catch(WrtDeviceApis::Commons::Exception)
563 LogWarning("trying to set incorrect value");
566 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
570 JSValueRef JSContact::getPhoneNumbers(JSContextRef context,
572 JSStringRef propertyName,
573 JSValueRef* exception)
577 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
579 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
581 JSContextRef gContext = priv->getContext();
582 ContactConverterFactory::ConverterType converter =
583 ContactConverterFactory::getConverter(gContext);
584 ContactPtr contact = getPrivData(object);
585 return converter->toJSValueRef(contact->getPhoneNumbers());
587 Catch(WrtDeviceApis::Commons::Exception)
589 LogWarning("trying to get incorrect value");
592 return JSValueMakeUndefined(context);
595 bool JSContact::setPhoneNumbers(JSContextRef context,
597 JSStringRef propertyName,
599 JSValueRef* exception)
603 ContactPtr contact = getPrivData(object);
604 ContactConverterFactory::ConverterType converter =
605 ContactConverterFactory::getConverter(context);
606 contact->setPhoneNumbers(
607 converter->toContactPhoneNumberArray(value));
610 Catch(WrtDeviceApis::Commons::Exception)
612 LogWarning("trying to set incorrect value");
615 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
619 JSValueRef JSContact::getEmails(JSContextRef context,
621 JSStringRef propertyName,
622 JSValueRef* exception)
626 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
628 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
630 JSContextRef gContext = priv->getContext();
632 ContactConverterFactory::ConverterType converter =
633 ContactConverterFactory::getConverter(gContext);
634 ContactPtr contact = getPrivData(object);
635 return converter->toJSValueRef(contact->getEmails());
637 Catch(WrtDeviceApis::Commons::Exception)
639 LogWarning("trying to get incorrect value");
642 return JSValueMakeUndefined(context);
645 bool JSContact::setEmails(JSContextRef context,
647 JSStringRef propertyName,
649 JSValueRef* exception)
653 ContactPtr contact = getPrivData(object);
654 ContactConverterFactory::ConverterType converter =
655 ContactConverterFactory::getConverter(context);
656 contact->setEmails(converter->toContactEmailAddressArray(value));
659 Catch(WrtDeviceApis::Commons::Exception)
661 LogWarning("trying to set incorrect value");
664 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
668 JSValueRef JSContact::getBirthday(JSContextRef context,
670 JSStringRef propertyName,
671 JSValueRef* exception)
675 ContactConverterFactory::ConverterType converter =
676 ContactConverterFactory::getConverter(context);
677 ContactPtr contact = getPrivData(object);
678 if(!contact->getBirthdayIsSet())
679 return JSValueMakeNull(context);
681 return converter->toJSValueRef(contact->getBirthday());
683 Catch(WrtDeviceApis::Commons::Exception)
685 LogWarning("trying to get incorrect value");
688 return JSValueMakeUndefined(context);
691 bool JSContact::setBirthday(JSContextRef context,
693 JSStringRef propertyName,
695 JSValueRef* exception)
699 ContactPtr contact = getPrivData(object);
700 ContactConverterFactory::ConverterType converter =
701 ContactConverterFactory::getConverter(context);
702 BasicValidator validator =
703 BasicValidatorFactory::getValidator(context, exception);
704 if(validator->isNullOrUndefined(value))
705 contact->unsetBirthday();
707 contact->setBirthday(converter->toDateTm(value));
710 Catch(WrtDeviceApis::Commons::Exception)
712 LogWarning("trying to set incorrect value");
715 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
719 JSValueRef JSContact::getAnniversaries(JSContextRef context,
721 JSStringRef propertyName,
722 JSValueRef* exception)
726 ContactConverterFactory::ConverterType converter =
727 ContactConverterFactory::getConverter(context);
728 ContactPtr contact = getPrivData(object);
729 return converter->toJSValueRef(contact->getAnniversaries());
731 Catch(WrtDeviceApis::Commons::Exception)
733 LogWarning("trying to get incorrect value");
736 return JSValueMakeUndefined(context);
739 bool JSContact::setAnniversaries(JSContextRef context,
741 JSStringRef propertyName,
743 JSValueRef* exception)
747 ContactPtr contact = getPrivData(object);
748 ContactConverterFactory::ConverterType converter =
749 ContactConverterFactory::getConverter(context);
750 contact->setAnniversaries(
751 converter->toContactAnniversaryArray(value));
754 Catch(WrtDeviceApis::Commons::Exception)
756 LogWarning("trying to set incorrect value");
759 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
763 JSValueRef JSContact::getOrganizations(JSContextRef context,
765 JSStringRef propertyName,
766 JSValueRef* exception)
770 ContactConverterFactory::ConverterType converter =
771 ContactConverterFactory::getConverter(context);
772 ContactPtr contact = getPrivData(object);
773 return converter->toJSValueRef(contact->getOrganizations());
775 Catch(WrtDeviceApis::Commons::Exception)
777 LogWarning("trying to get incorrect value");
780 return JSValueMakeUndefined(context);
783 bool JSContact::setOrganizations(JSContextRef context,
785 JSStringRef propertyName,
787 JSValueRef* exception)
791 ContactPtr contact = getPrivData(object);
792 ContactConverterFactory::ConverterType converter =
793 ContactConverterFactory::getConverter(context);
794 contact->setOrganizations(
795 converter->toContactOrganizationArray(value));
798 Catch(WrtDeviceApis::Commons::Exception)
800 LogWarning("trying to set incorrect value");
803 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
807 JSValueRef JSContact::getNotes(JSContextRef context,
809 JSStringRef propertyName,
810 JSValueRef* exception)
814 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
816 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
818 JSContextRef gContext = priv->getContext();
820 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
821 ContactPtr contact = getPrivData(object);
823 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
824 if(newContactT->notesJSObjIsSet()){
825 return newContactT->getNotesJSObj();
827 JSValueRef tempJSValue = newContactT->getNotesJSValue();
828 tempJSValue = converter->toJSValueRef(newContactT->getNotes());
830 JSObjectRef convertedJSObject = newContactT->getNotesJSObj();
831 convertedJSObject = JSValueToObject( gContext, tempJSValue, NULL );
832 newContactT->setNotesJSObj(true, convertedJSObject);
834 JSValueProtect(gContext, convertedJSObject);
835 newContactT->setContext(gContext);
839 Catch(WrtDeviceApis::Commons::Exception)
841 LogWarning("trying to get incorrect value");
844 return JSValueMakeUndefined(context);
847 bool JSContact::setNotes(JSContextRef context,
849 JSStringRef propertyName,
851 JSValueRef* exception)
855 ContactPtr contact = getPrivData(object);
856 ContactConverterFactory::ConverterType converter =
857 ContactConverterFactory::getConverter(context);
858 contact->setNotes(converter->toStringArray(value));
861 Catch(WrtDeviceApis::Commons::Exception)
863 LogWarning("trying to set incorrect value");
866 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
870 JSValueRef JSContact::getUrls(JSContextRef context,
872 JSStringRef propertyName,
873 JSValueRef* exception)
877 ContactConverterFactory::ConverterType converter =
878 ContactConverterFactory::getConverter(context);
879 ContactPtr contact = getPrivData(object);
880 return converter->toJSValueRef(contact->getUrls());
882 Catch(WrtDeviceApis::Commons::Exception)
884 LogWarning("trying to get incorrect value");
887 return JSValueMakeUndefined(context);
890 bool JSContact::setUrls(JSContextRef context,
892 JSStringRef propertyName,
894 JSValueRef* exception)
898 ContactPtr contact = getPrivData(object);
899 ContactConverterFactory::ConverterType converter =
900 ContactConverterFactory::getConverter(context);
901 contact->setUrls(converter->toContactWebSiteArray(value));
904 Catch(WrtDeviceApis::Commons::Exception)
906 LogWarning("trying to set incorrect value");
909 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
913 JSValueRef JSContact::getRingtoneURI(JSContextRef context,
915 JSStringRef propertyName,
916 JSValueRef* exception)
920 ContactConverterFactory::ConverterType converter =
921 ContactConverterFactory::getConverter(context);
922 ContactPtr contact = getPrivData(object);
923 if(!contact->getRingtoneURIIsSet())
924 return JSValueMakeNull(context);
926 return converter->toJSValueRef(contact->getRingtoneURI());
928 Catch(WrtDeviceApis::Commons::Exception)
930 LogWarning("trying to get incorrect value");
933 return JSValueMakeUndefined(context);
936 bool JSContact::setRingtoneURI(JSContextRef context,
938 JSStringRef propertyName,
940 JSValueRef* exception)
944 ContactPtr contact = getPrivData(object);
945 ContactConverterFactory::ConverterType converter =
946 ContactConverterFactory::getConverter(context);
947 BasicValidator validator =
948 BasicValidatorFactory::getValidator(context, exception);
949 if(validator->isNullOrUndefined(value))
950 contact->unsetRingtoneURI();
952 contact->setRingtoneURI(converter->toString(value));
955 Catch(WrtDeviceApis::Commons::Exception)
957 LogWarning("trying to set incorrect value");
960 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
964 JSValueRef JSContact::getGroupIds(JSContextRef context,
966 JSStringRef propertyName,
967 JSValueRef* exception)
971 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
973 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
975 JSContextRef gContext = priv->getContext();
977 ContactConverterFactory::ConverterType converter =
978 ContactConverterFactory::getConverter(gContext);
979 ContactPtr contact = getPrivData(object);
980 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
982 if(newContactT->groupIdsJSObjIsSet()){
983 return newContactT->getGroupIdsJSObj();
985 JSValueRef tempJSValue = newContactT->getGroupIdsJSValue();
986 tempJSValue = converter->toJSValueRef(newContactT->getGroupIds());
988 JSObjectRef convertedJSObject = newContactT->getGroupIdsJSObj();
989 convertedJSObject = JSValueToObject( gContext, tempJSValue, NULL );
990 newContactT->setGroupIdsJSObj(true, convertedJSObject);
992 JSValueProtect(gContext, convertedJSObject);
993 newContactT->setContext(gContext);
997 Catch(WrtDeviceApis::Commons::Exception)
999 LogWarning("trying to get incorrect value");
1002 return JSValueMakeUndefined(context);
1005 bool JSContact::setGroupIds(JSContextRef context,
1007 JSStringRef propertyName,
1009 JSValueRef* exception)
1013 ContactPtr contact = getPrivData(object);
1014 ContactConverterFactory::ConverterType converter =
1015 ContactConverterFactory::getConverter(context);
1016 contact->setGroupIds(converter->toStringArray(value));
1019 Catch(WrtDeviceApis::Commons::Exception)
1021 LogWarning("trying to set incorrect value");
1024 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
1028 JSValueRef JSContact::convertToString(JSContextRef context,
1030 JSObjectRef thisObject,
1031 size_t argumentCount,
1032 const JSValueRef arguments[],
1033 JSValueRef* exception)
1035 LogDebug("entered");
1036 ContactPtr contact(NULL);
1039 contact = getPrivData(thisObject);
1040 if (contact == NULL) {
1041 ThrowMsg(InvalidArgumentException, "No private object.");
1043 } Catch(Exception) {
1044 LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
1045 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
1048 // AceSecurityStatus status = CONTACT_CHECK_ACCESS(
1049 // CONTACT_FUNCTION_API_CONVERT_TO_STRING);
1050 // TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1052 BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
1054 if (argumentCount >= 1 &&
1055 ( !JSValueIsUndefined(context, arguments[0] ) &&
1056 ( !JSValueIsNull(context, arguments[0]) ) &&
1057 ( !JSValueIsString(context, arguments[0] )) ))
1058 ThrowMsg(ConversionException, "1st argument must be 'ContactTextFormat string'");
1059 } Catch (Exception) {
1060 LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
1061 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be 'ContactTextFormat string'");
1066 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
1068 if(argumentCount >= 1)
1069 format = converter->toString(arguments[0]);
1070 } Catch(Exception) {
1071 LogError("Error on conversion : " << _rethrown_exception.GetMessage());
1072 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be 'ContactTextFormat string'");
1077 vCard = contact->convertToString(format);
1078 } Catch(ConversionException) {
1079 LogError("Error on platform : " << _rethrown_exception.GetMessage());
1080 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be 'ContactTextFormat string'");
1081 } Catch(UnsupportedException) {
1082 LogError("Error on platform : " << _rethrown_exception.GetMessage());
1083 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, "Only support vCard 3.0");
1084 } Catch(Exception) {
1085 LogError("Error on platform : " << _rethrown_exception.GetMessage());
1086 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
1091 result = converter->toJSValueRef(vCard);
1092 } Catch(Exception) {
1093 LogError("Error on conversion : " << _rethrown_exception.GetMessage());
1094 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
1100 JSValueRef JSContact::clone(JSContextRef context,
1102 JSObjectRef thisObject,
1103 size_t argumentCount,
1104 const JSValueRef arguments[],
1105 JSValueRef* exception)
1107 LogDebug("entered");
1108 ContactPtr contact(NULL);
1111 contact = getPrivData(thisObject);
1112 if (contact == NULL) {
1113 ThrowMsg(InvalidArgumentException, "No private object.");
1115 } Catch(Exception) {
1116 LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
1117 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
1120 // AceSecurityStatus status = CONTACT_CHECK_ACCESS(
1121 // CONTACT_FUNCTION_API_CONVERT_TO_STRING);
1122 // TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1124 ContactPtr clonedContact(NULL);
1126 clonedContact = contact->clone();
1127 } Catch(Exception) {
1128 LogError("Error on conversion : " << _rethrown_exception.GetMessage());
1129 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
1134 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(thisObject));
1136 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
1138 JSContextRef gContext = priv->getContext();
1139 result = createJSObject(gContext, clonedContact);
1140 } Catch(Exception) {
1141 LogError("Error on conversion : " << _rethrown_exception.GetMessage());
1142 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");