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 = ContactConverterFactory::getConverter(gContext);
484 ContactPtr contact = getPrivData(object);
486 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
487 if(newContactT->addressesJSObjIsSet()){
488 return newContactT->getAddressesJSObj();
490 JSValueRef tempJSValue = newContactT->getAddressesJSValue();
491 tempJSValue = converter->toJSValueRef(newContactT->getAddresses());
493 JSObjectRef convertedJSObject = newContactT->getAddressesJSObj();
494 convertedJSObject = JSValueToObject( gContext, tempJSValue, NULL );
495 newContactT->setAddressesJSObj(true, convertedJSObject);
497 JSValueProtect(gContext, convertedJSObject);
498 newContactT->setContext(gContext);
502 Catch(WrtDeviceApis::Commons::Exception)
504 LogWarning("trying to get incorrect value");
507 return JSValueMakeUndefined(context);
510 bool JSContact::setAddresses(JSContextRef context,
512 JSStringRef propertyName,
514 JSValueRef* exception)
518 ContactPtr contact = getPrivData(object);
519 ContactConverterFactory::ConverterType converter =
520 ContactConverterFactory::getConverter(context);
521 contact->setAddresses(converter->toContactAddressArray(value));
524 Catch(WrtDeviceApis::Commons::Exception)
526 LogWarning("trying to set incorrect value");
529 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
533 JSValueRef JSContact::getPhotoURI(JSContextRef context,
535 JSStringRef propertyName,
536 JSValueRef* exception)
540 ContactConverterFactory::ConverterType converter =
541 ContactConverterFactory::getConverter(context);
542 ContactPtr contact = getPrivData(object);
543 if(!contact->getPhotoURIIsSet())
544 return JSValueMakeNull(context);
546 return converter->toJSValueRef(contact->getPhotoURI());
548 Catch(WrtDeviceApis::Commons::Exception)
550 LogWarning("trying to get incorrect value");
553 return JSValueMakeUndefined(context);
556 bool JSContact::setPhotoURI(JSContextRef context,
558 JSStringRef propertyName,
560 JSValueRef* exception)
564 ContactPtr contact = getPrivData(object);
565 ContactConverterFactory::ConverterType converter =
566 ContactConverterFactory::getConverter(context);
567 BasicValidator validator =
568 BasicValidatorFactory::getValidator(context, exception);
569 if(validator->isNullOrUndefined(value))
570 contact->unsetPhotoURI();
572 contact->setPhotoURI(converter->toString(value));
575 Catch(WrtDeviceApis::Commons::Exception)
577 LogWarning("trying to set incorrect value");
580 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
584 JSValueRef JSContact::getPhoneNumbers(JSContextRef context,
586 JSStringRef propertyName,
587 JSValueRef* exception)
591 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
593 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
595 JSContextRef gContext = priv->getContext();
596 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
597 ContactPtr contact = getPrivData(object);
599 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
600 if(newContactT->numbersJSObjIsSet()){
601 return newContactT->getNumbersJSObj();
603 JSValueRef tempJSValue = newContactT->getNumbersJSValue();
604 tempJSValue = converter->toJSValueRef(newContactT->getPhoneNumbers());
606 JSObjectRef convertedJSObject = newContactT->getNumbersJSObj();
607 convertedJSObject = JSValueToObject( gContext, tempJSValue, NULL );
608 newContactT->setNumbersJSObj(true, convertedJSObject);
610 JSValueProtect(gContext, convertedJSObject);
611 newContactT->setContext(gContext);
615 Catch(WrtDeviceApis::Commons::Exception)
617 LogWarning("trying to get incorrect value");
620 return JSValueMakeUndefined(context);
623 bool JSContact::setPhoneNumbers(JSContextRef context,
625 JSStringRef propertyName,
627 JSValueRef* exception)
631 ContactPtr contact = getPrivData(object);
632 ContactConverterFactory::ConverterType converter =
633 ContactConverterFactory::getConverter(context);
634 contact->setPhoneNumbers(
635 converter->toContactPhoneNumberArray(value));
638 Catch(WrtDeviceApis::Commons::Exception)
640 LogWarning("trying to set incorrect value");
643 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 LogDebug("return init value");
666 return newContactT->getEmailsJSObj();
668 LogDebug("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 LogWarning("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));
703 Catch(WrtDeviceApis::Commons::Exception)
705 LogWarning("trying to set incorrect value");
708 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
712 JSValueRef JSContact::getBirthday(JSContextRef context,
714 JSStringRef propertyName,
715 JSValueRef* exception)
719 ContactConverterFactory::ConverterType converter =
720 ContactConverterFactory::getConverter(context);
721 ContactPtr contact = getPrivData(object);
722 if(!contact->getBirthdayIsSet())
723 return JSValueMakeNull(context);
725 return converter->toJSValueRef(contact->getBirthday());
727 Catch(WrtDeviceApis::Commons::Exception)
729 LogWarning("trying to get incorrect value");
732 return JSValueMakeUndefined(context);
735 bool JSContact::setBirthday(JSContextRef context,
737 JSStringRef propertyName,
739 JSValueRef* exception)
743 ContactPtr contact = getPrivData(object);
744 ContactConverterFactory::ConverterType converter =
745 ContactConverterFactory::getConverter(context);
746 BasicValidator validator =
747 BasicValidatorFactory::getValidator(context, exception);
748 if(validator->isNullOrUndefined(value))
749 contact->unsetBirthday();
751 contact->setBirthday(converter->toDateTm(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::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 LogWarning("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 =
813 ContactConverterFactory::getConverter(context);
814 contact->setAnniversaries(
815 converter->toContactAnniversaryArray(value));
818 Catch(WrtDeviceApis::Commons::Exception)
820 LogWarning("trying to set incorrect value");
823 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
827 JSValueRef JSContact::getOrganizations(JSContextRef context,
829 JSStringRef propertyName,
830 JSValueRef* exception)
834 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
836 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
838 JSContextRef gContext = priv->getContext();
840 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
841 ContactPtr contact = getPrivData(object);
843 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
844 if(newContactT->organizationsJSObjIsSet()){
845 return newContactT->getOrganizationsJSObj();
847 JSValueRef tempJSValue = newContactT->getOrganizationsJSValue();
848 tempJSValue = converter->toJSValueRef(newContactT->getOrganizations());
850 JSObjectRef convertedJSObject = newContactT->getOrganizationsJSObj();
851 convertedJSObject = JSValueToObject( gContext, tempJSValue, NULL );
852 newContactT->setOrganizationsJSObj(true, convertedJSObject);
854 JSValueProtect(gContext, convertedJSObject);
855 newContactT->setContext(gContext);
859 Catch(WrtDeviceApis::Commons::Exception)
861 LogWarning("trying to get incorrect value");
864 return JSValueMakeUndefined(context);
867 bool JSContact::setOrganizations(JSContextRef context,
869 JSStringRef propertyName,
871 JSValueRef* exception)
875 ContactPtr contact = getPrivData(object);
876 ContactConverterFactory::ConverterType converter =
877 ContactConverterFactory::getConverter(context);
878 contact->setOrganizations(
879 converter->toContactOrganizationArray(value));
882 Catch(WrtDeviceApis::Commons::Exception)
884 LogWarning("trying to set incorrect value");
887 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
891 JSValueRef JSContact::getNotes(JSContextRef context,
893 JSStringRef propertyName,
894 JSValueRef* exception)
898 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
900 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
902 JSContextRef gContext = priv->getContext();
904 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
905 ContactPtr contact = getPrivData(object);
907 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
908 if(newContactT->notesJSObjIsSet()){
909 return newContactT->getNotesJSObj();
911 JSValueRef tempJSValue = newContactT->getNotesJSValue();
912 tempJSValue = converter->toJSValueRef(newContactT->getNotes());
914 JSObjectRef convertedJSObject = newContactT->getNotesJSObj();
915 convertedJSObject = JSValueToObject( gContext, tempJSValue, NULL );
916 newContactT->setNotesJSObj(true, convertedJSObject);
918 JSValueProtect(gContext, convertedJSObject);
919 newContactT->setContext(gContext);
923 Catch(WrtDeviceApis::Commons::Exception)
925 LogWarning("trying to get incorrect value");
928 return JSValueMakeUndefined(context);
931 bool JSContact::setNotes(JSContextRef context,
933 JSStringRef propertyName,
935 JSValueRef* exception)
939 ContactPtr contact = getPrivData(object);
940 ContactConverterFactory::ConverterType converter =
941 ContactConverterFactory::getConverter(context);
942 contact->setNotes(converter->toStringArray(value));
945 Catch(WrtDeviceApis::Commons::Exception)
947 LogWarning("trying to set incorrect value");
950 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
954 JSValueRef JSContact::getUrls(JSContextRef context,
956 JSStringRef propertyName,
957 JSValueRef* exception)
961 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
963 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
965 JSContextRef gContext = priv->getContext();
967 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
968 ContactPtr contact = getPrivData(object);
970 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
971 if(newContactT->urlsJSObjIsSet()){
972 return newContactT->getUrlsJSObj();
974 JSValueRef tempJSValue = newContactT->getUrlsJSValue();
975 tempJSValue = converter->toJSValueRef(newContactT->getUrls());
977 JSObjectRef convertedJSObject = newContactT->getUrlsJSObj();
978 convertedJSObject = JSValueToObject( gContext, tempJSValue, NULL );
979 newContactT->setUrlsJSObj(true, convertedJSObject);
981 JSValueProtect(gContext, convertedJSObject);
982 newContactT->setContext(gContext);
986 Catch(WrtDeviceApis::Commons::Exception)
988 LogWarning("trying to get incorrect value");
991 return JSValueMakeUndefined(context);
994 bool JSContact::setUrls(JSContextRef context,
996 JSStringRef propertyName,
998 JSValueRef* exception)
1002 ContactPtr contact = getPrivData(object);
1003 ContactConverterFactory::ConverterType converter =
1004 ContactConverterFactory::getConverter(context);
1005 contact->setUrls(converter->toContactWebSiteArray(value));
1008 Catch(WrtDeviceApis::Commons::Exception)
1010 LogWarning("trying to set incorrect value");
1013 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
1017 JSValueRef JSContact::getRingtoneURI(JSContextRef context,
1019 JSStringRef propertyName,
1020 JSValueRef* exception)
1024 ContactConverterFactory::ConverterType converter =
1025 ContactConverterFactory::getConverter(context);
1026 ContactPtr contact = getPrivData(object);
1027 if(!contact->getRingtoneURIIsSet())
1028 return JSValueMakeNull(context);
1030 return converter->toJSValueRef(contact->getRingtoneURI());
1032 Catch(WrtDeviceApis::Commons::Exception)
1034 LogWarning("trying to get incorrect value");
1037 return JSValueMakeUndefined(context);
1040 bool JSContact::setRingtoneURI(JSContextRef context,
1042 JSStringRef propertyName,
1044 JSValueRef* exception)
1048 ContactPtr contact = getPrivData(object);
1049 ContactConverterFactory::ConverterType converter =
1050 ContactConverterFactory::getConverter(context);
1051 BasicValidator validator =
1052 BasicValidatorFactory::getValidator(context, exception);
1053 if(validator->isNullOrUndefined(value))
1054 contact->unsetRingtoneURI();
1056 contact->setRingtoneURI(converter->toString(value));
1059 Catch(WrtDeviceApis::Commons::Exception)
1061 LogWarning("trying to set incorrect value");
1064 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
1068 JSValueRef JSContact::getGroupIds(JSContextRef context,
1070 JSStringRef propertyName,
1071 JSValueRef* exception)
1075 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
1077 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
1079 JSContextRef gContext = priv->getContext();
1081 ContactConverterFactory::ConverterType converter =
1082 ContactConverterFactory::getConverter(gContext);
1083 ContactPtr contact = getPrivData(object);
1084 DPL::SharedPtr<Contact> newContactT = DPL::StaticPointerCast<Contact>(contact);
1086 if(newContactT->groupIdsJSObjIsSet()){
1087 return newContactT->getGroupIdsJSObj();
1089 JSValueRef tempJSValue = newContactT->getGroupIdsJSValue();
1090 tempJSValue = converter->toJSValueRef(newContactT->getGroupIds());
1092 JSObjectRef convertedJSObject = newContactT->getGroupIdsJSObj();
1093 convertedJSObject = JSValueToObject( gContext, tempJSValue, NULL );
1094 newContactT->setGroupIdsJSObj(true, convertedJSObject);
1096 JSValueProtect(gContext, convertedJSObject);
1097 newContactT->setContext(gContext);
1101 Catch(WrtDeviceApis::Commons::Exception)
1103 LogWarning("trying to get incorrect value");
1106 return JSValueMakeUndefined(context);
1109 bool JSContact::setGroupIds(JSContextRef context,
1111 JSStringRef propertyName,
1113 JSValueRef* exception)
1117 ContactPtr contact = getPrivData(object);
1118 ContactConverterFactory::ConverterType converter =
1119 ContactConverterFactory::getConverter(context);
1120 contact->setGroupIds(converter->toStringArray(value));
1123 Catch(WrtDeviceApis::Commons::Exception)
1125 LogWarning("trying to set incorrect value");
1128 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
1132 JSValueRef JSContact::convertToString(JSContextRef context,
1134 JSObjectRef thisObject,
1135 size_t argumentCount,
1136 const JSValueRef arguments[],
1137 JSValueRef* exception)
1139 LogDebug("entered");
1140 ContactPtr contact(NULL);
1143 contact = getPrivData(thisObject);
1144 if (contact == NULL) {
1145 ThrowMsg(InvalidArgumentException, "No private object.");
1147 } Catch(Exception) {
1148 LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
1149 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
1152 // AceSecurityStatus status = CONTACT_CHECK_ACCESS(
1153 // CONTACT_FUNCTION_API_CONVERT_TO_STRING);
1154 // TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1156 BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
1158 if (argumentCount >= 1 &&
1159 ( !JSValueIsUndefined(context, arguments[0] ) &&
1160 ( !JSValueIsNull(context, arguments[0]) ) &&
1161 ( !JSValueIsString(context, arguments[0] )) ))
1162 ThrowMsg(ConversionException, "1st argument must be 'ContactTextFormat string'");
1163 } Catch (Exception) {
1164 LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
1165 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be 'ContactTextFormat string'");
1170 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
1172 if(argumentCount >= 1)
1173 format = converter->toString(arguments[0]);
1174 } Catch(Exception) {
1175 LogError("Error on conversion : " << _rethrown_exception.GetMessage());
1176 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be 'ContactTextFormat string'");
1181 vCard = contact->convertToString(format);
1182 } Catch(ConversionException) {
1183 LogError("Error on platform : " << _rethrown_exception.GetMessage());
1184 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be 'ContactTextFormat string'");
1185 } Catch(UnsupportedException) {
1186 LogError("Error on platform : " << _rethrown_exception.GetMessage());
1187 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, "Only support vCard 3.0");
1188 } Catch(Exception) {
1189 LogError("Error on platform : " << _rethrown_exception.GetMessage());
1190 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
1195 result = converter->toJSValueRef(vCard);
1196 } Catch(Exception) {
1197 LogError("Error on conversion : " << _rethrown_exception.GetMessage());
1198 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
1204 JSValueRef JSContact::clone(JSContextRef context,
1206 JSObjectRef thisObject,
1207 size_t argumentCount,
1208 const JSValueRef arguments[],
1209 JSValueRef* exception)
1211 LogDebug("entered");
1212 ContactPtr contact(NULL);
1215 contact = getPrivData(thisObject);
1216 if (contact == NULL) {
1217 ThrowMsg(InvalidArgumentException, "No private object.");
1219 } Catch(Exception) {
1220 LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
1221 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
1224 // AceSecurityStatus status = CONTACT_CHECK_ACCESS(
1225 // CONTACT_FUNCTION_API_CONVERT_TO_STRING);
1226 // TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1228 ContactPtr clonedContact(NULL);
1230 clonedContact = contact->clone();
1231 } Catch(Exception) {
1232 LogError("Error on conversion : " << _rethrown_exception.GetMessage());
1233 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
1238 JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(thisObject));
1240 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
1242 JSContextRef gContext = priv->getContext();
1243 result = createJSObject(gContext, clonedContact);
1244 } Catch(Exception) {
1245 LogError("Error on conversion : " << _rethrown_exception.GetMessage());
1246 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");