28c912ed19406ac5382df421f2642d68edfbba01
[framework/web/wrt-plugins-tizen.git] / src / Calendar / JSCalendarItemProperties.cpp
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 #include <ctime>
19 #include <CommonsJavaScript/PrivateObject.h>
20 #include <CommonsJavaScript/Converter.h>
21 #include <CommonsJavaScript/JSUtils.h>
22 #include <JSWebAPIErrorFactory.h>
23 #include <SecurityExceptions.h>
24 #include <TimeUtilConverter.h>
25 #include <JSTimeDuration.h>
26 #include <JSTZDate.h>
27 #include <JSSimpleCoordinates.h>
28 #include "EventAlarm.h"
29 #include "EventId.h"
30 #include "ICalendar.h"
31 #include "CalendarFactory.h"
32 #include <DurationProperties.h>
33 #include "JSCalendarItemProperties.h"
34 #include "CalendarConverter.h"
35 #include "JSCalendarEventId.h"
36 #include "JSCalendarAlarm.h"
37 #include "JSCalendarAttendee.h"
38 #include "JSCalendarEvent.h"
39 #include "JSCalendarTask.h"
40 #include "plugin_config.h"
41 #include <GlobalContextManager.h>
42 #include <TimeTracer.h>
43 #include <Logger.h>
44
45 using namespace WrtDeviceApis::Commons;
46 using namespace WrtDeviceApis::CommonsJavaScript;
47 using namespace DeviceAPI::Common;
48 using namespace DeviceAPI::Time;
49
50 namespace DeviceAPI {
51 namespace Calendar {
52
53 using WrtDeviceApis::Commons::UnknownException;
54 using WrtDeviceApis::Commons::NotFoundException;
55
56 #define TIZEN_CALENDAR_ITEM_PROPERTIES_ATTRIBUTENAME "CalendarItemProperties"
57
58 JSClassDefinition JSCalendarItemProperties::m_classInfo = {
59     0,
60     kJSClassAttributeNone,
61     TIZEN_CALENDAR_ITEM_PROPERTIES_ATTRIBUTENAME,
62     0,
63     m_property,
64     m_function,
65     initialize,
66     finalize,
67     NULL, //hasProperty,
68     NULL, //getProperty,
69     NULL, //setProperty,
70     NULL, //DeleteProperty,
71     NULL, //GetPropertyNames,
72     NULL, //CallAsFunction,
73     NULL, //CallAsConstructor,
74     NULL, //HasInstance,
75     NULL  //ConvertToType
76 };
77
78 JSStaticValue JSCalendarItemProperties::m_property[] = {
79     // Item Properties
80     { TIZEN_CALENDAR_ITEM_DESCRIPTION, getPropertyDescription, setPropertyDescription, kJSPropertyAttributeNone },
81     { TIZEN_CALENDAR_ITEM_SUMMARY, getPropertySummary, setPropertySummary, kJSPropertyAttributeNone },
82     { TIZEN_CALENDAR_ITEM_START_DATE, getPropertyStartTime, setPropertyStartTime, kJSPropertyAttributeNone },
83     { TIZEN_CALENDAR_ITEM_LOCATION, getPropertyLocation, setPropertyLocation, kJSPropertyAttributeNone },
84     { TIZEN_CALENDAR_ITEM_GEOLOCATION, getPropertyGeolocation, setPropertyGeolocation, kJSPropertyAttributeNone },
85     { TIZEN_CALENDAR_ITEM_ORGANIZER, getPropertyOrganizer, setPropertyOrganizer, kJSPropertyAttributeNone },
86     { TIZEN_CALENDAR_ITEM_VISIBILITY, getPropertyVisibility, setPropertyVisibility, kJSPropertyAttributeNone },
87     { TIZEN_CALENDAR_ITEM_STATUS, getPropertyStatus, setPropertyStatus, kJSPropertyAttributeNone },
88     { TIZEN_CALENDAR_ITEM_ALARMS, getPropertyAlarms, setPropertyAlarms, kJSPropertyAttributeNone },
89     { TIZEN_CALENDAR_ITEM_CATEGORIES, getPropertyCategories, setPropertyCategories, kJSPropertyAttributeNone },
90     { TIZEN_CALENDAR_ITEM_DURATION, getPropertyDuration, setPropertyDuration, kJSPropertyAttributeNone },
91     { TIZEN_CALENDAR_ITEM_IS_ALL_DAY, getPropertyIsAllDay, setPropertyIsAllDay, kJSPropertyAttributeNone },
92     { TIZEN_CALENDAR_ITEM_ATTENDEES, getPropertyAttendees, setPropertyAttendees, kJSPropertyAttributeNone },
93     { TIZEN_CALENDAR_EVENT_AVAILABILITY, getPropertyAvailability, setPropertyAvailability, kJSPropertyAttributeNone },
94     { TIZEN_CALENDAR_TASK_DUE_DATE, getPropertyDueDate, setPropertyDueDate, kJSPropertyAttributeNone },
95     { TIZEN_CALENDAR_TASK_COMPLETED_DATE, getPropertyCompletedDate, setPropertyCompletedDate, kJSPropertyAttributeNone },
96     { TIZEN_CALENDAR_TASK_PROGRESS, getPropertyProgress, setPropertyProgress, kJSPropertyAttributeNone },
97     { TIZEN_CALENDAR_ITEM_PRIORITY, getPropertyPriority, setPropertyPriority, kJSPropertyAttributeNone },
98     { TIZEN_CALENDAR_EVENT_END_DATE, getPropertyEndDate, setPropertyEndDate, kJSPropertyAttributeNone },
99     { TIZEN_CALENDAR_EVENT_LAST_MODIFICATION_DATE, getPropertyLastModificationDate, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
100         { TIZEN_CALENDAR_ITEM_CALENDAR_ID, getPropertyCalendarId, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
101
102     { 0, 0, 0, 0 }
103 };
104
105 JSStaticFunction JSCalendarItemProperties::m_function[] = {
106     { CALENDAR_FUNCTION_API_CONVERT_TO_STRING, convertToString, kJSPropertyAttributeNone },
107     { CALENDAR_FUNCTION_API_CLONE, clone, kJSPropertyAttributeNone },
108
109     { 0, 0, 0 }
110 };
111
112 JSClassRef JSCalendarItemProperties::m_jsClassRef = JSClassCreate(JSCalendarItemProperties::getClassInfo());
113
114 void JSCalendarItemProperties::initialize(JSContextRef context,
115         JSObjectRef object)
116 {
117     if (!JSObjectGetPrivate(object)) {
118         LoggerD("Create calendar item private object.");
119         CalendarEventPtr item( new CalendarEvent() );
120         CalendarItemPropertiesPrivObject *priv = new CalendarItemPropertiesPrivObject(context, item);
121         if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
122             delete priv;
123         }
124     } else {
125         LoggerD("Private object already set.");
126     }
127 }
128
129 void JSCalendarItemProperties::finalize(JSObjectRef object)
130 {
131     CalendarItemPropertiesPrivObject *priv = static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
132     if (priv) {
133         delete priv;
134         JSObjectSetPrivate(object, NULL);
135     }
136 }
137
138 const JSClassRef JSCalendarItemProperties::getClassRef()
139 {
140     if (!m_jsClassRef) {
141         m_jsClassRef = JSClassCreate(&m_classInfo);
142     }
143     return m_jsClassRef;
144 }
145
146 const JSClassDefinition* JSCalendarItemProperties::getClassInfo()
147 {
148     return &m_classInfo;
149 }
150
151 CalendarEventPtr JSCalendarItemProperties::getPrivateObject(JSObjectRef object)
152 {
153     CalendarItemPropertiesPrivObject *priv =
154         static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
155     if (!priv) {
156         ThrowMsg(NullPointerException, "Private object is null");
157     }
158     CalendarEventPtr result = priv->getObject();
159     if (!result) {
160         ThrowMsg(NullPointerException, "Private object is null");
161     }
162     return result;
163 }
164
165 void JSCalendarItemProperties::setPrivateObject(const CalendarEventPtr &event,
166         JSContextRef ctx,
167         const JSObjectRef object)
168 {
169     Try
170     {
171         CalendarItemPropertiesPrivObject *priv =
172             static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
173         delete priv;
174         priv = new CalendarItemPropertiesPrivObject(ctx, event);
175         if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
176             delete priv;
177         }
178     }
179     Catch(Exception)
180     {
181         LoggerE("Error during replacing event object");
182     }
183 }
184
185 JSObjectRef JSCalendarItemProperties::createJSCalendarItemProperties(JSContextRef context, CalendarEventPtr item)
186 {
187     CalendarItemPropertiesPrivObject *priv = new CalendarItemPropertiesPrivObject(context, item);
188     return JSObjectMake(context, getClassRef(), priv);
189 }
190
191 JSValueRef JSCalendarItemProperties::convertToString(JSContextRef context,
192         JSObjectRef object,
193         JSObjectRef thisObject,
194         size_t argumentCount,
195         const JSValueRef arguments[],
196         JSValueRef* exception)
197 {
198         TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
199     CalendarItemPropertiesPrivObject *privateObject =
200         static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(thisObject));
201
202     AceSecurityStatus status = CALENDAR_CHECK_ACCESS(CALENDAR_FUNCTION_API_CONVERT_TO_STRING);
203
204     TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
205
206     Try
207     {
208         if (!privateObject) {
209             ThrowMsg(ConversionException, "Object is null.");
210         }
211
212         CalendarEventPtr item = privateObject->getObject();
213         if (!item) {
214             ThrowMsg(ConversionException, "Parameter conversion failed.");
215         }
216
217         CalendarConverter converter(context);
218
219         CalendarEvent::VObjectFormat format = CalendarEvent::UNDEFINED_FORMAT;
220         if (argumentCount>=1) {
221             format = converter.toVObjectFormat(converter.toString(arguments[0]));
222         } else {
223             ThrowMsg(ConversionException, "Wrong parameter type.");
224         }
225
226         ICalendarPtr calendar = CalendarFactory::getInstance().createCalendarObject();
227         calendar->setType(item->getCalendarType());
228
229         IEventExportEventToStringPtr dplEvent(new IEventExportEventToString());
230         dplEvent->setEvent(item);
231         dplEvent->setFormat(format);
232         dplEvent->setForSynchronousCall();
233         calendar->exportEventToString(dplEvent);
234
235         if (dplEvent->getResult()) {
236                         TIME_TRACER_ITEM_END(__FUNCTION__, 0);
237             return converter.toJSValueRef(dplEvent->getEventString());
238         } else {
239             ThrowMsg(UnknownException, "Converting to string failed by unknown reason.");
240         }
241     }
242     Catch(UnsupportedException)
243     {
244                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
245         return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
246     }
247     Catch(InvalidArgumentException)
248     {
249                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
250         return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
251     }
252     Catch(ConversionException)
253     {
254                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
255         return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
256     }
257     Catch (NotFoundException)
258     {
259                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
260         return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
261     }
262     Catch(Exception)
263     {
264                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
265         return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
266     }
267 }
268
269 JSValueRef JSCalendarItemProperties::clone(JSContextRef context,
270         JSObjectRef object,
271         JSObjectRef thisObject,
272         size_t argumentCount,
273         const JSValueRef arguments[],
274         JSValueRef* exception)
275 {
276         TIME_TRACER_ITEM_BEGIN("clone(TASK)", 0);
277         TIME_TRACER_ITEM_BEGIN("clone(EVENT)", 0);
278     CalendarItemPropertiesPrivObject *privateObject =
279         static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(thisObject));
280
281     AceSecurityStatus status = CALENDAR_CHECK_ACCESS(CALENDAR_FUNCTION_API_CLONE);
282
283     TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
284
285     Try
286     {
287         if (!privateObject) {
288             ThrowMsg(ConversionException, "Object is null.");
289         }
290
291         CalendarEventPtr item = privateObject->getObject(); // item to copy
292         if (!item) {
293             ThrowMsg(ConversionException, "Parameter conversion failed.");
294         }
295         JSContextRef globalContext = GlobalContextManager::getInstance()->getGlobalContext(context);
296
297         // Call the copy constructor.
298         CalendarEventPtr clonedItem( new CalendarEvent(*item));
299
300         // Reset the id.
301         clonedItem->resetId();
302         clonedItem->setRecurrenceId(UNDEFINED_ITEM_ID);
303
304                 if (CalendarEvent::TASK_TYPE==clonedItem->getCalendarType()) {
305                         TIME_TRACER_ITEM_END("clone(TASK)", 0);
306                 return JSCalendarTask::createJSCalendarTask(context, clonedItem);
307                 } else if (CalendarEvent::EVENT_TYPE==clonedItem->getCalendarType()) {
308                         TIME_TRACER_ITEM_END("clone(EVENT)", 0);
309             // Use global context for potential async api invocation.
310             return JSCalendarEvent::createJSCalendarEvent(globalContext, clonedItem);
311                 } else {
312                         ThrowMsg(ConversionException, "Wrong object type.");
313                 }
314     }
315     Catch(UnsupportedException)
316     {
317                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
318         return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
319     }
320     Catch(InvalidArgumentException)
321     {
322                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
323         return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
324     }
325     Catch(ConversionException)
326     {
327                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
328         return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
329     }
330     Catch (NotFoundException)
331     {
332                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
333         return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
334     }
335     Catch(Exception)
336     {
337                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
338         return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
339     }
340 }
341
342 JSValueRef JSCalendarItemProperties::getPropertyDescription(JSContextRef context,
343         JSObjectRef object,
344         JSStringRef propertyName,
345         JSValueRef* exception)
346 {
347     Try
348     {
349         Converter converter(context);
350         CalendarEventPtr event = getPrivateObject(object);
351         return converter.toJSValueRef(event->getDescription());
352     }
353     Catch(Exception)
354     {
355                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
356     }
357     return JSValueMakeUndefined(context);
358 }
359
360 bool JSCalendarItemProperties::setPropertyDescription(JSContextRef context,
361         JSObjectRef object,
362         JSStringRef propertyName,
363         JSValueRef value,
364         JSValueRef* exception)
365 {
366     Try
367     {
368         Converter converter(context);
369         CalendarEventPtr event = getPrivateObject(object);
370         std::string description = converter.toString(value);
371         event->setDescription(description);
372         return true;
373     }
374     Catch(Exception)
375     {
376                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
377     }
378
379     return true;
380 }
381
382 JSValueRef JSCalendarItemProperties::getPropertySummary(JSContextRef context,
383         JSObjectRef object,
384         JSStringRef propertyName,
385         JSValueRef* exception)
386 {
387     Try
388     {
389         Converter converter(context);
390         CalendarEventPtr event = getPrivateObject(object);
391         return converter.toJSValueRef(event->getSubject());
392     }
393     Catch(Exception)
394     {
395                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
396     }
397     return JSValueMakeUndefined(context);
398 }
399
400 bool JSCalendarItemProperties::setPropertySummary(JSContextRef context,
401         JSObjectRef object,
402         JSStringRef propertyName,
403         JSValueRef value,
404         JSValueRef* exception)
405 {
406     Try
407     {
408         Converter converter(context);
409         CalendarEventPtr event = getPrivateObject(object);
410         std::string subject = converter.toString(value);
411         event->setSubject(subject);
412         return true;
413     }
414     Catch(Exception)
415     {
416                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
417     }
418
419     return true;
420 }
421
422 JSValueRef JSCalendarItemProperties::getPropertyStartTime(JSContextRef context,
423         JSObjectRef object,
424         JSStringRef propertyName,
425         JSValueRef* exception)
426 {
427     Try
428     {
429         CalendarItemPropertiesPrivObject *privateObject =
430             static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
431         TimeUtilConverter timeConverter(context);
432         CalendarEventPtr event = privateObject->getObject();
433
434         LoggerI("start time before converted to TZDate: "<<event->getStartTime()<<", time zone: "<<event->getTimeZone());
435         if (UNDEFINED_TIME==event->getStartTime()) {
436             return JSValueMakeUndefined(context);
437         } else {
438             return timeConverter.toJSValueRefTZDate((double)(event->getStartTime()*1000.0), event->getTimeZone());
439         }
440     }
441     Catch(Exception)
442     {
443                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
444     }
445     return JSValueMakeUndefined(context);
446 }
447
448 bool JSCalendarItemProperties::setPropertyStartTime(JSContextRef context,
449         JSObjectRef object,
450         JSStringRef propertyName,
451         JSValueRef value,
452         JSValueRef* exception)
453 {
454     Try
455     {
456         if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
457             ThrowMsg(ConversionException, "Wrong parameter type.");
458         }
459
460         CalendarEventPtr event = getPrivateObject(object);
461         TimeUtilConverter converter(context);
462         std::time_t duration = event->getEndTime() - event->getStartTime();
463         if (duration<0) {
464             duration = 0;
465         }
466
467         long long int startTime = (long long int) (converter.getTimeInMilliseconds(value)/1000);
468         event->setStartTime(startTime);
469         event->setEndTime(startTime + duration);
470
471         std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
472         event->setTimeZone(timeZone);
473         return true;
474     }
475     Catch(Exception)
476     {
477                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
478     }
479
480     return true;
481 }
482
483 JSValueRef JSCalendarItemProperties::getPropertyLocation(JSContextRef context,
484         JSObjectRef object,
485         JSStringRef propertyName,
486         JSValueRef* exception)
487 {
488     Try
489     {
490         Converter converter(context);
491         CalendarEventPtr event = getPrivateObject(object);
492         return converter.toJSValueRef(event->getLocation());
493     }
494     Catch(Exception)
495     {
496                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
497     }
498     return JSValueMakeUndefined(context);
499 }
500
501 bool JSCalendarItemProperties::setPropertyLocation(JSContextRef context,
502         JSObjectRef object,
503         JSStringRef propertyName,
504         JSValueRef value,
505         JSValueRef* exception)
506 {
507     Try
508     {
509         Converter converter(context);
510         CalendarEventPtr event = getPrivateObject(object);
511         std::string location = converter.toString(value);
512         event->setLocation(location);
513         return true;
514     }
515     Catch(Exception)
516     {
517                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
518     }
519
520     return true;
521 }
522
523 JSValueRef JSCalendarItemProperties::getPropertyCategories(JSContextRef context,
524         JSObjectRef object,
525         JSStringRef propertyName,
526         JSValueRef* exception)
527 {
528     Try
529     {
530             CalendarEventPtr item = getPrivateObject(object);
531                 JSContextRef globalContext = GlobalContextManager::getInstance()->getGlobalContext(context);
532
533         CalendarConverter converter(globalContext);
534
535                 if(item->getCategoriesJSRef()) {
536                         return item->getCategoriesJSRef();
537                 } else {
538                         LoggerD("Create a JS object for categories.");
539                 StringArrayPtr categories = item->getCategories();
540                         JSValueRef jsCategories = converter.toJSValueRefStringArray(categories);
541                         item->setCategoriesJSRef(converter.toJSObjectRef(jsCategories));
542
543                         JSValueProtect(globalContext, jsCategories);
544                         item->setContext(globalContext);
545             return jsCategories;
546                 }
547     }
548     Catch(Exception)
549     {
550                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
551     }
552     return JSValueMakeUndefined(context);
553 }
554
555 bool JSCalendarItemProperties::setPropertyCategories(JSContextRef context,
556         JSObjectRef object,
557         JSStringRef propertyName,
558         JSValueRef value,
559         JSValueRef* exception)
560 {
561     Try
562     {
563         CalendarEventPtr event = getPrivateObject(object);
564         CalendarConverter converter(context);
565                 event->setCategories(converter.toStringArray(value));
566         return true;
567     }
568     Catch(Exception)
569     {
570                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
571     }
572
573     return true;
574 }
575
576 JSValueRef JSCalendarItemProperties::getPropertyStatus(JSContextRef context,
577         JSObjectRef object,
578         JSStringRef propertyName,
579         JSValueRef* exception)
580 {
581     Try
582     {
583         CalendarConverter converter(context);
584         CalendarEventPtr event = getPrivateObject(object);
585         std::string status = converter.toTizenValue(event->getStatus());
586         return converter.toJSValueRef(status);
587     }
588     Catch(Exception)
589     {
590                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
591     }
592     return JSValueMakeUndefined(context);
593 }
594
595 bool JSCalendarItemProperties::setPropertyStatus(JSContextRef context,
596         JSObjectRef object,
597         JSStringRef propertyName,
598         JSValueRef value,
599         JSValueRef* exception)
600 {
601     CalendarEventPtr event(NULL);
602     Try
603     {
604         event = getPrivateObject(object);
605         CalendarConverter converter(context);
606         CalendarEvent::EventStatus status =
607             converter.toEventStatus(converter.toString(value));
608         event->setStatus(status);
609         return true;
610     }
611     Catch(Exception)
612     {
613                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
614     }
615
616     return true;
617 }
618
619 JSValueRef JSCalendarItemProperties::getPropertyAlarms(JSContextRef context,
620         JSObjectRef object,
621         JSStringRef propertyName,
622         JSValueRef* exception)
623 {
624     Try
625     {
626         CalendarEventPtr event = getPrivateObject(object);
627
628         JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
629         if (NULL == jsResult) {
630             ThrowMsg(NullPointerException, "Can not create array object.");
631         }
632         for( unsigned int i=0; i<event->getAlarms()->size(); i++) {
633             if (!JSSetArrayElement(context, jsResult, i, JSCalendarAlarm::createJSCalendarAlarm(context, event->getAlarms()->at(i)))) {
634                ThrowMsg(UnknownException, "Can not insert value into array.");
635             }
636         }
637         return jsResult;
638     }
639     Catch(Exception)
640     {
641                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
642     }
643     return JSValueMakeUndefined(context);
644 }
645
646 bool JSCalendarItemProperties::setPropertyAlarms(JSContextRef context,
647         JSObjectRef object,
648         JSStringRef propertyName,
649         JSValueRef value,
650         JSValueRef* exception)
651 {
652     CalendarEventPtr event(NULL);
653     Try
654     {
655         event = getPrivateObject(object);
656         CalendarConverter converter(context);
657
658         EventAlarmListPtr alarms = converter.toVectorOfEventAlarmsFromReference(value);
659
660         event->setAlarms(alarms);
661         return true;
662     }
663     Catch(Exception)
664     {
665                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
666     }
667
668     return true;
669 }
670
671 JSValueRef JSCalendarItemProperties::getPropertyOrganizer(JSContextRef context,
672         JSObjectRef object,
673         JSStringRef propertyName,
674         JSValueRef* exception)
675 {
676     Try
677     {
678         Converter converter(context);
679         CalendarEventPtr event = getPrivateObject(object);
680         return converter.toJSValueRef(event->getOrganizer());
681     }
682     Catch(Exception)
683     {
684                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
685     }
686     return JSValueMakeUndefined(context);
687 }
688
689 bool JSCalendarItemProperties::setPropertyOrganizer(JSContextRef context,
690         JSObjectRef object,
691         JSStringRef propertyName,
692         JSValueRef value,
693         JSValueRef* exception)
694 {
695     Try
696     {
697         Converter converter(context);
698         CalendarEventPtr event = getPrivateObject(object);
699         std::string organizer = converter.toString(value);
700         event->setOrganizer(organizer);
701         return true;
702     }
703     Catch(Exception)
704     {
705                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
706     }
707
708     return true;
709 }
710
711 JSValueRef JSCalendarItemProperties::getPropertyVisibility(JSContextRef context,
712         JSObjectRef object,
713         JSStringRef propertyName,
714         JSValueRef* exception)
715 {
716     Try
717     {
718         CalendarConverter converter(context);
719         CalendarEventPtr event = getPrivateObject(object);
720         std::string visibility = converter.toTizenValue(event->getVisibility());
721         return converter.toJSValueRef(visibility);
722     }
723     Catch(Exception)
724     {
725                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
726     }
727     return JSValueMakeUndefined(context);
728 }
729
730 bool JSCalendarItemProperties::setPropertyVisibility(JSContextRef context,
731         JSObjectRef object,
732         JSStringRef propertyName,
733         JSValueRef value,
734         JSValueRef* exception)
735 {
736     CalendarEventPtr event(NULL);
737     Try
738     {
739         event = getPrivateObject(object);
740         CalendarConverter converter(context);
741         CalendarEvent::EventVisibility visibility =
742             converter.toEventVisibility(converter.toString(value));
743         event->setVisibility(visibility);
744         return true;
745     }
746     Catch(Exception)
747     {
748                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
749     }
750
751     return true;
752 }
753
754 JSValueRef JSCalendarItemProperties::getPropertyGeolocation(JSContextRef context,
755         JSObjectRef object,
756         JSStringRef propertyName,
757         JSValueRef* exception)
758 {
759     Try
760     {
761         CalendarEventPtr item = getPrivateObject(object);
762         if( UNDEFINED_GEO==item->getGeolocation()->getLatitude() ) {
763                         return JSValueMakeUndefined(context);
764                 } else {
765                         return DeviceAPI::Tizen::JSSimpleCoordinates::createJSObject(context, item->getGeolocation());
766                 }
767     }
768     Catch(Exception)
769     {
770                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
771     }
772
773     return JSValueMakeUndefined(context);
774 }
775
776 bool JSCalendarItemProperties::setPropertyGeolocation(JSContextRef context,
777         JSObjectRef object,
778         JSStringRef propertyName,
779         JSValueRef value,
780         JSValueRef* exception)
781 {
782     Try
783     {
784         CalendarEventPtr item = getPrivateObject(object);
785
786                 if (JSValueIsNull(context, value) || JSValueIsUndefined(context, value)) {
787                 item->getGeolocation()->setLatitude(UNDEFINED_GEO);
788                 item->getGeolocation()->setLongitude(UNDEFINED_GEO);
789                 } else {
790                 DeviceAPI::Tizen::SimpleCoordinatesPtr geoLocation = DeviceAPI::Tizen::JSSimpleCoordinates::getSimpleCoordinates(context, value);
791
792                 item->setGeolocation(geoLocation);
793                 }
794         return true;
795     }
796     Catch(Exception)
797     {
798                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
799     }
800
801     return true;
802 }
803
804 JSValueRef JSCalendarItemProperties::getPropertyDuration(JSContextRef context,
805         JSObjectRef object,
806         JSStringRef propertyName,
807         JSValueRef* exception)
808 {
809     Try
810     {
811         CalendarEventPtr item = getPrivateObject(object);
812
813                 if(UNDEFINED_TIME!=item->getDuration()->length) {
814                         LoggerD("Duration length: "<<item->getDuration()->length<<", unit: "<<item->getDuration()->unit);
815                         return JSTimeDuration::createJSObject(context, item->getDuration());
816                 }
817
818                 // Alternatively generate the duration object using start/end time.
819                 if(UNDEFINED_TIME==item->getStartTime() || UNDEFINED_TIME==item->getEndTime()) {
820                         LoggerD("Start or end time is not defined.");
821                     return JSValueMakeUndefined(context);
822                 }
823
824         long long length = item->getEndTime() - item->getStartTime(); // in seconds only
825         LoggerD("item->getStartTime():"<< item->getStartTime() << ", length:" << length);
826
827                 DurationPropertiesPtr durationPtr(new DurationProperties());
828                 durationPtr->length = length;
829                 durationPtr->unit = SECONDS_UNIT;
830                 item->setDuration(durationPtr);
831
832                 return JSTimeDuration::createJSObject(context, durationPtr);
833     }
834     Catch(Exception)
835     {
836                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
837     }
838     return JSValueMakeUndefined(context);
839 }
840
841 bool JSCalendarItemProperties::setPropertyDuration(JSContextRef context,
842         JSObjectRef object,
843         JSStringRef propertyName,
844         JSValueRef value,
845         JSValueRef* exception)
846 {
847     Try
848     {
849         CalendarEventPtr event = getPrivateObject(object);
850         TimeUtilConverter timeUtilConverter(context);
851
852                 DurationPropertiesPtr duration = timeUtilConverter.getDuration(value);
853         long long length = duration->length;
854         int unit = duration->unit;
855         if (length < 0) {
856             DeviceAPI::Common::JSWebAPIErrorFactory::postException(context, exception, DeviceAPI::Common::JSWebAPIErrorFactory::INVALID_VALUES_ERROR);
857             return false;
858         }
859
860         LoggerD("length: "<<length<< ", unit:" <<unit);
861                 event->setDuration(duration);
862
863         return true;
864     }
865     Catch(Exception)
866     {
867                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
868     }
869
870     return true;
871 }
872
873 JSValueRef JSCalendarItemProperties::getPropertyIsAllDay(JSContextRef context,
874         JSObjectRef object,
875         JSStringRef propertyName,
876         JSValueRef* exception)
877 {
878     Try
879     {
880         CalendarConverter converter(context);
881         CalendarEventPtr event = getPrivateObject(object);
882         return converter.toJSValueRef(event->getIsAllDay());
883     }
884     Catch(Exception)
885     {
886                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
887     }
888     return JSValueMakeUndefined(context);
889 }
890
891 bool JSCalendarItemProperties::setPropertyIsAllDay(JSContextRef context,
892         JSObjectRef object,
893         JSStringRef propertyName,
894         JSValueRef value,
895         JSValueRef* exception)
896 {
897     Try
898     {
899         CalendarEventPtr event = getPrivateObject(object);
900         Converter converter(context);
901         event->setIsAllDay(converter.toBool(value));
902         return true;
903     }
904     Catch(Exception)
905     {
906                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
907     }
908
909     return true;
910 }
911
912 JSValueRef JSCalendarItemProperties::getPropertyAvailability(JSContextRef context,
913         JSObjectRef object,
914         JSStringRef propertyName,
915         JSValueRef* exception)
916 {
917     Try
918     {
919         CalendarConverter converter(context);
920         CalendarEventPtr event = getPrivateObject(object);
921         std::string availability = converter.toTizenValue(event->getAvailability());
922         return converter.toJSValueRef(availability);
923     }
924     Catch(Exception)
925     {
926                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
927     }
928     return JSValueMakeUndefined(context);
929 }
930
931 bool JSCalendarItemProperties::setPropertyAvailability(JSContextRef context,
932         JSObjectRef object,
933         JSStringRef propertyName,
934         JSValueRef value,
935         JSValueRef* exception)
936 {
937     CalendarEventPtr event(NULL);
938     Try
939     {
940         event = getPrivateObject(object);
941         CalendarConverter converter(context);
942         CalendarEvent::EventAvailability availability =
943             converter.toEventAvailability(converter.toString(value));
944         event->setAvailability(availability);
945         return true;
946     }
947     Catch(Exception)
948     {
949                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
950     }
951
952     return true;
953 }
954
955 JSValueRef JSCalendarItemProperties::getPropertyAttendees(JSContextRef context,
956         JSObjectRef object,
957         JSStringRef propertyName,
958         JSValueRef* exception)
959 {
960     Try
961     {
962         CalendarEventPtr event = getPrivateObject(object);
963         EventAttendeeListPtr attendees = event->getAttendees();
964         if (attendees) {
965             JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
966             if (NULL == jsResult) {
967                 ThrowMsg(NullPointerException, "Can not create array object.");
968             }
969             for(unsigned int i=0; i<attendees->size(); i++) {
970                 if (!JSSetArrayElement(context, jsResult, i, JSCalendarAttendee::createJSCalendarAttendee(context, attendees->at(i)))) {
971                    ThrowMsg(UnknownException, "Can not insert value into array.");
972                 }
973             }
974             return jsResult;
975         }
976     }
977     Catch(Exception)
978     {
979                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
980     }
981     return JSValueMakeUndefined(context);
982 }
983
984 bool JSCalendarItemProperties::setPropertyAttendees(JSContextRef context,
985         JSObjectRef object,
986         JSStringRef propertyName,
987         JSValueRef value,
988         JSValueRef* exception)
989 {
990     Try
991     {
992         CalendarEventPtr event = getPrivateObject(object);
993         CalendarConverter converter(context);
994         event->setAttendees(converter.toVectorOfAttendeesFromReference(value));
995         return true;
996     }
997     Catch(Exception)
998     {
999                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1000     }
1001
1002     return true;
1003 }
1004
1005 JSValueRef JSCalendarItemProperties::getPropertyDueDate(JSContextRef context,
1006         JSObjectRef object,
1007         JSStringRef propertyName,
1008         JSValueRef* exception)
1009 {
1010     Try
1011         {
1012         CalendarItemPropertiesPrivObject *privateObject =
1013             static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1014         CalendarEventPtr task = privateObject->getObject();
1015         if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1016             return JSValueMakeUndefined(context);
1017         }
1018         if (!task) {
1019             ThrowMsg(NullPointerException, "Task object is NULL.");
1020         }
1021
1022         if (UNDEFINED_TIME==task->getEndTime()) {
1023             return JSValueMakeUndefined(context);
1024         } else {
1025             TimeUtilConverter timeConverter(context);
1026             return timeConverter.toJSValueRefTZDate((double)(task->getEndTime()*1000.0), task->getTimeZone());
1027         }
1028     }
1029     Catch(Exception)
1030     {
1031                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1032     }
1033     return JSValueMakeUndefined(context);
1034 }
1035
1036 bool JSCalendarItemProperties::setPropertyDueDate(JSContextRef context,
1037         JSObjectRef object,
1038         JSStringRef propertyName,
1039         JSValueRef value,
1040         JSValueRef* exception)
1041 {
1042     Try
1043     {
1044         CalendarEventPtr task = getPrivateObject(object);
1045         if (!task) {
1046             ThrowMsg(NullPointerException, "Task object is NULL.");
1047         }
1048         if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1049             ThrowMsg(InvalidArgumentException, "Wrong type of calendar.");
1050         }
1051         if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
1052             ThrowMsg(ConversionException, "Wrong parameter type.");
1053         }
1054
1055         TimeUtilConverter converter(context);
1056         long long int dueDate = (long long int) (converter.getTimeInMilliseconds(value)/1000);
1057
1058         task->setEndTime(dueDate);
1059
1060         if( task->getTimeZone().empty() ) {
1061             std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
1062             task->setTimeZone(timeZone);
1063         }
1064         return true;
1065     }
1066     Catch(Exception)
1067     {
1068                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1069     }
1070
1071     return true;
1072 }
1073
1074 JSValueRef JSCalendarItemProperties::getPropertyCompletedDate(JSContextRef context,
1075         JSObjectRef object,
1076         JSStringRef propertyName,
1077         JSValueRef* exception)
1078 {
1079     Try
1080     {
1081         CalendarItemPropertiesPrivObject *privateObject =
1082             static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1083         CalendarEventPtr task = privateObject->getObject();
1084         if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1085             return JSValueMakeUndefined(context);
1086         }
1087         if (!task) {
1088             ThrowMsg(NullPointerException, "Task object is NULL.");
1089         }
1090
1091         if (UNDEFINED_TIME==task->getCompletedDate()) {
1092             return JSValueMakeUndefined(context);
1093         } else {
1094             TimeUtilConverter timeConverter(context);
1095             return timeConverter.toJSValueRefTZDate((double)(task->getCompletedDate()*1000.0), task->getTimeZone());
1096         }
1097     }
1098     Catch(Exception)
1099     {
1100                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1101     }
1102     return JSValueMakeUndefined(context);
1103 }
1104
1105 bool JSCalendarItemProperties::setPropertyCompletedDate(JSContextRef context,
1106         JSObjectRef object,
1107         JSStringRef propertyName,
1108         JSValueRef value,
1109         JSValueRef* exception)
1110 {
1111     Try
1112     {
1113         CalendarEventPtr task = getPrivateObject(object);
1114         if (!task) {
1115             ThrowMsg(NullPointerException, "Task object is NULL.");
1116         }
1117         if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1118             ThrowMsg(InvalidArgumentException, "Wrong calendar type.");
1119         }
1120         if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
1121             ThrowMsg(ConversionException, "Wrong parameter type.");
1122         }
1123
1124         TimeUtilConverter converter(context);
1125         long long int completedDate = (long long int) (converter.getTimeInMilliseconds(value)/1000);
1126
1127         task->setCompletedDate(completedDate);
1128
1129         if( task->getTimeZone().empty() ) {
1130             std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
1131             task->setTimeZone(timeZone);
1132         }
1133         return true;
1134     }
1135     Catch(Exception)
1136     {
1137                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1138     }
1139
1140     return true;
1141 }
1142
1143 JSValueRef JSCalendarItemProperties::getPropertyProgress(JSContextRef context,
1144         JSObjectRef object,
1145         JSStringRef propertyName,
1146         JSValueRef* exception)
1147 {
1148     Try
1149     {
1150         CalendarEventPtr task = getPrivateObject(object);
1151         if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1152             return JSValueMakeUndefined(context);
1153         }
1154
1155         Converter converter(context);
1156         return converter.toJSValueRef(task->getProgress());
1157     }
1158     Catch(Exception)
1159     {
1160                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1161     }
1162     return JSValueMakeUndefined(context);
1163 }
1164
1165 bool JSCalendarItemProperties::setPropertyProgress(JSContextRef context,
1166         JSObjectRef object,
1167         JSStringRef propertyName,
1168         JSValueRef value,
1169         JSValueRef* exception)
1170 {
1171     Try
1172     {
1173         CalendarEventPtr task = getPrivateObject(object);
1174         if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1175             return JSValueMakeUndefined(context);
1176         }
1177
1178         Converter converter(context);
1179         int progress = converter.toInt(value);
1180         task->setProgress(progress);
1181         return true;
1182     }
1183     Catch(Exception)
1184     {
1185                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1186     }
1187
1188     return true;
1189 }
1190
1191 JSValueRef JSCalendarItemProperties::getPropertyPriority(JSContextRef context,
1192         JSObjectRef object,
1193         JSStringRef propertyName,
1194         JSValueRef* exception)
1195 {
1196     Try
1197     {
1198         CalendarConverter converter(context);
1199         CalendarEventPtr item = getPrivateObject(object);
1200         if (!item) {
1201             ThrowMsg(NullPointerException, "Item object is NULL.");
1202         }
1203
1204         std::string priority = converter.toTizenValue(item->getPriority());
1205         return converter.toJSValueRef(priority);
1206     }
1207     Catch(Exception)
1208     {
1209                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1210     }
1211     return JSValueMakeUndefined(context);
1212 }
1213
1214 bool JSCalendarItemProperties::setPropertyPriority(JSContextRef context,
1215         JSObjectRef object,
1216         JSStringRef propertyName,
1217         JSValueRef value,
1218         JSValueRef* exception)
1219 {
1220     CalendarEventPtr item = getPrivateObject(object);
1221     Try
1222     {
1223         CalendarConverter converter(context);
1224         CalendarEvent::TaskPriority priority =
1225             converter.toTaskPriority(converter.toString(value));
1226         item->setPriority(priority);
1227         return true;
1228     }
1229     Catch(Exception)
1230     {
1231                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1232     }
1233
1234     return true;
1235 }
1236
1237 JSValueRef JSCalendarItemProperties::getPropertyEndDate(JSContextRef context,
1238         JSObjectRef object,
1239         JSStringRef propertyName,
1240         JSValueRef* exception)
1241 {
1242     Try
1243     {
1244         CalendarItemPropertiesPrivObject *privateObject =
1245             static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1246         CalendarEventPtr event = privateObject->getObject();
1247         if(CalendarEvent::EVENT_TYPE != event->getCalendarType()) {
1248             return JSValueMakeUndefined(context);
1249         }
1250         if (!event) {
1251             ThrowMsg(NullPointerException, "Event object is NULL.");
1252         }
1253
1254         if (UNDEFINED_TIME==event->getEndTime()) {
1255             return JSValueMakeUndefined(context);
1256         } else {
1257             TimeUtilConverter timeConverter(context);
1258             return timeConverter.toJSValueRefTZDate((double)(event->getEndTime()*1000.0), event->getTimeZone());
1259         }
1260     }
1261     Catch(Exception)
1262     {
1263                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1264     }
1265     return JSValueMakeUndefined(context);
1266 }
1267
1268 bool JSCalendarItemProperties::setPropertyEndDate(JSContextRef context,
1269         JSObjectRef object,
1270         JSStringRef propertyName,
1271         JSValueRef value,
1272         JSValueRef* exception)
1273 {
1274     Try
1275     {
1276         CalendarEventPtr event = getPrivateObject(object);
1277         if (!event) {
1278             ThrowMsg(NullPointerException, "Event object is NULL.");
1279         }
1280         if(CalendarEvent::EVENT_TYPE != event->getCalendarType()) {
1281             ThrowMsg(InvalidArgumentException, "Wrong calendar type.");
1282         }
1283         if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
1284             ThrowMsg(ConversionException, "Wrong parameter type.");
1285         }
1286
1287         TimeUtilConverter converter(context);
1288         long long int endDate = (long long int) (converter.getTimeInMilliseconds(value)/1000);
1289
1290         event->setEndTime(endDate);
1291
1292         if( event->getTimeZone().empty() ) {
1293             std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
1294             event->setTimeZone(timeZone);
1295         }
1296         return true;
1297     }
1298     Catch(Exception)
1299     {
1300                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1301     }
1302
1303     return true;
1304 }
1305
1306 JSValueRef JSCalendarItemProperties::getPropertyLastModificationDate(JSContextRef context,
1307         JSObjectRef object,
1308         JSStringRef propertyName,
1309         JSValueRef* exception)
1310 {
1311     Try
1312     {
1313         CalendarEventPtr item = getPrivateObject(object);
1314         if (!item) {
1315             ThrowMsg(NullPointerException, "Item object is NULL.");
1316         }
1317
1318         if (UNDEFINED_TIME==item->getLastModifiedDate()) {
1319             return JSValueMakeNull(context);
1320         } else {
1321             TimeUtilConverter timeConverter(context);
1322             return timeConverter.toJSValueRefTZDate((double)(item->getLastModifiedDate()*1000.0), item->getTimeZone());
1323         }
1324     }
1325     Catch(Exception)
1326     {
1327                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1328     }
1329     return JSValueMakeUndefined(context);
1330 }
1331
1332 JSValueRef JSCalendarItemProperties::getPropertyCalendarId(JSContextRef context,
1333         JSObjectRef object,
1334         JSStringRef propertyName,
1335         JSValueRef* exception)
1336 {
1337     Try
1338     {
1339         CalendarEventPtr item = getPrivateObject(object);
1340
1341             if (UNDEFINED_CALENDAR_ID==item->getCalendarId()) {
1342             return JSValueMakeNull(context);
1343             } else {
1344                 CalendarConverter converter(context);
1345                         std::stringstream ss;
1346                         ss<<item->getCalendarId();
1347                         return converter.toJSValueRef(ss.str());
1348             }
1349
1350     }
1351     Catch(Exception)
1352     {
1353                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1354     }
1355     return JSValueMakeUndefined(context);
1356 }
1357
1358 }
1359 }