summaryrefslogtreecommitdiff
path: root/src/java/net_cp_jlibical_ICalValue_cxx.cpp
blob: f01a9338184e6fcf764362214a7c0f92a2668caf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
/*======================================================================
 FILE: net_cp_jlibical_ICalValue_cxx.cpp
 CREATOR: gnorman 1/10/02
 (C) COPYRIGHT 2002, Critical Path

 This library is free software; you can redistribute it and/or modify
 it under the terms of either:

    The LGPL as published by the Free Software Foundation, version
    2.1, available at: https://www.gnu.org/licenses/lgpl-2.1.html

 Or:

    The Mozilla Public License Version 2.0. You may obtain a copy of
    the License at https://www.mozilla.org/MPL/
======================================================================*/

#ifndef NET_CP_JLIBICAL_ICALVALUE_CXX_H
#include "net_cp_jlibical_ICalValue_cxx.h"
#endif

#ifndef JLIBICAL_CONSTS_CXX_H
#include "jlibical_consts_cxx.h"
#endif

#ifndef JLIBICAL_UTILS_CXX_H
#include "jlibical_utils_cxx.h"
#endif

#ifndef ICALVALUE_CXX_H
#include "icalvalue_cxx.h"
#endif

/*
 * Class:     net_cp_jlibical_ICalValue
 * Method:    as_ical_string
 * Signature: ()Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalValue_as_1ical_1string
  (JNIEnv *env, jobject jobj)
{
    jstring result = NULL;
    ICalValue* cObj = getSubjectAsICalValue(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL);

    if (cObj != NULL)
    {
        char* icalStr = cObj->as_ical_string();

        if (icalStr == NULL)
        {
            icalStr = "";
        }

        result = env->NewStringUTF(icalStr);
    }

    return(result);
}

/*
 * Class:     net_cp_jlibical_ICalValue
 * Method:    isa
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_net_cp_jlibical_ICalValue_isa
  (JNIEnv *env, jobject jobj)
{
    jint result = 0;
    ICalValue* cObj = getSubjectAsICalValue(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL);

    if (cObj != NULL)
    {
        result = cObj->isa();
    }

    return(result);
}

/*
 * Class:     net_cp_jlibical_ICalValue
 * Method:    isa_value
 * Signature: (Ljava/lang/Object;)Z
 */
JNIEXPORT jboolean JNICALL Java_net_cp_jlibical_ICalValue_isa_1value
  (JNIEnv *env, jobject jobj, jobject arg)
{
    jboolean result = 0;

    // get the c++ object from the jobj
    ICalValue* cObj = getSubjectAsICalValue(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL);
    if (cObj != NULL)
    {
        // get the c++ object from arg
        void* argObjPtr = 0;

        if (arg != NULL)
        {
            argObjPtr = getCObjectPtr(env,jobj);
        }

        // get the result from the c++ object
        result = cObj->isa_value(argObjPtr) != 0;
    }

    return(result);
}

/*
 * Class:     net_cp_jlibical_ICalValue
 * Method:    set_trigger
 * Signature: (Lnet/cp/jlibical/ICalTriggerType;)V
 */
JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalValue_set_1trigger
  (JNIEnv *env, jobject jobj, jobject arg)
{
    // get the c++ object from the jobj
    ICalValue* cObj = getSubjectAsICalValue(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL);
    if (cObj != NULL)
    {
        icaltriggertype aTrigger;

        if (copyObjToicaltriggertype(env,arg,&aTrigger))
        {
            cObj->set_trigger(aTrigger);
        }
    }
}

/*
 * Class:     net_cp_jlibical_ICalValue
 * Method:    get_trigger
 * Signature: ()Lnet/cp/jlibical/ICalTriggerType;
 */
JNIEXPORT jobject JNICALL Java_net_cp_jlibical_ICalValue_get_1trigger
  (JNIEnv *env, jobject jobj)
{
    jobject result = 0;

    // get the c++ object from the jobj
    ICalValue* cObj = getSubjectAsICalValue(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL);

    if (cObj != NULL)
    {
        // get the trigger from CObj
        icaltriggertype aTrigger = cObj->get_trigger();

        // create a new surrogate, using aTrigger as the subject.
        result = createNewICalTriggerType(env,&aTrigger);
    }

    return (result);
}

/*
 * Class:     net_cp_jlibical_ICalValue
 * Method:    get_method
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_net_cp_jlibical_ICalValue_get_1method
  (JNIEnv *env, jobject jobj)
{
    jint result = 0;
    ICalValue* cObj = getSubjectAsICalValue(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL);

    if (cObj != NULL)
    {
        result = cObj->get_method();
    }

    return(result);
}

/*
 * Class:     net_cp_jlibical_ICalValue
 * Method:    set_method
 * Signature: (I)V
 */
JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalValue_set_1method
  (JNIEnv *env, jobject jobj, jint value)
{
    ICalValue* cObj = getSubjectAsICalValue(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL);

    if (cObj != NULL)
    {
        cObj->set_method((icalproperty_method)value);
    }
}

/*
 * Class:     net_cp_jlibical_ICalValue
 * Method:    get_text
 * Signature: ()Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalValue_get_1text
  (JNIEnv *env, jobject jobj)
{
    jstring result = NULL;
    ICalValue* cObj = getSubjectAsICalValue(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL);

    if (cObj != NULL)
    {
        char* icalStr = cObj->get_text();

        if (icalStr == NULL)
        {
            icalStr = "";
        }

        result = env->NewStringUTF(icalStr);
    }

    return(result);
}

/*
 * Class:     net_cp_jlibical_ICalValue
 * Method:    set_text
 * Signature: (Ljava/lang/String;)V
 */
JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalValue_set_1text
  (JNIEnv *env, jobject jobj, jstring str)
{
    ICalValue* cObj = getSubjectAsICalValue(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL);

    if (cObj != NULL)
    {
        const char* szTemp = env->GetStringUTFChars(str,NULL);

        cObj->set_text((char*)szTemp);
        env->ReleaseStringUTFChars(str,szTemp);
    }
}

/*
 * Class:     net_cp_jlibical_ICalValue
 * Method:    get_duration
 * Signature: ()Lnet/cp/jlibical/ICalDurationType;
 */
JNIEXPORT jobject JNICALL Java_net_cp_jlibical_ICalValue_get_1duration
  (JNIEnv *env, jobject jobj)
{
    jobject result = 0;

    // get the c++ object from the jobj
    ICalValue* cObj = getSubjectAsICalValue(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL);

    if (cObj != NULL)
    {
        // get the duration from CObj
        icaldurationtype aDuration = cObj->get_duration();

        // create a new surrogate, using aDuration as the subject.
        result = createNewICalDurationType(env,&aDuration);
    }

    return (result);
}

/*
 * Class:     net_cp_jlibical_ICalValue
 * Method:    set_duration
 * Signature: (Lnet/cp/jlibical/ICalDurationType;)V
 */
JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalValue_set_1duration
  (JNIEnv *env, jobject jobj, jobject arg)
{
    // get the c++ object from the jobj
    ICalValue* cObj = getSubjectAsICalValue(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL);

    if (cObj != NULL)
    {
        icaldurationtype aDuration;

        if (copyObjToicaldurationtype(env,arg,&aDuration))
        {
            cObj->set_duration(aDuration);
        }
    }
}

/*
 * Class:     net_cp_jlibical_ICalValue
 * Method:    get_query
 * Signature: ()Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL Java_net_cp_jlibical_ICalValue_get_1query
  (JNIEnv *env, jobject jobj)
{
    jstring result = NULL;
    ICalValue* cObj = getSubjectAsICalValue(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL);

    if (cObj != NULL)
    {
        char* icalStr = cObj->get_query();

        if (icalStr == NULL)
        {
            icalStr = "";
        }

        result = env->NewStringUTF(icalStr);
    }

    return(result);
}

/*
 * Class:     net_cp_jlibical_ICalValue
 * Method:    set_query
 * Signature: (Ljava/lang/String;)V
 */
JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalValue_set_1query
  (JNIEnv *env, jobject jobj, jstring str)
{
    ICalValue* cObj = getSubjectAsICalValue(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL);

    if (cObj != NULL)
    {
        const char* szTemp = env->GetStringUTFChars(str,NULL);

        cObj->set_query((char*)szTemp);
        env->ReleaseStringUTFChars(str,szTemp);
    }
}

/*
 * Class:     net_cp_jlibical_ICalValue
 * Method:    get_datetime
 * Signature: ()Lnet/cp/jlibical/ICalTimeType;
 */
JNIEXPORT jobject JNICALL Java_net_cp_jlibical_ICalValue_get_1datetime
  (JNIEnv *env, jobject jobj)
{
    jobject result = NULL;

    // get the c++ object from the jobj
    ICalValue* cObj = getSubjectAsICalValue(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL);

    if (cObj != NULL)
    {
        icaltimetype aTime = cObj->get_datetime();
        result = createNewICalTimeType(env,&aTime);
    }

    return (result);
}

/*
 * Class:     net_cp_jlibical_ICalValue
 * Method:    set_datetime
 * Signature: (Lnet/cp/jlibical/ICalTimeType;)V
 */
JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalValue_set_1datetime
  (JNIEnv *env, jobject jobj, jobject arg)
{
    // get the c++ object from the jobj
    ICalValue* cObj = getSubjectAsICalValue(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL);

    if (cObj != NULL)
    {
        icaltimetype aTime;

        if (copyObjToicaltimetype(env,arg,&aTime))
        {
            cObj->set_datetime(aTime);
        }
    }
}

/*
 * Class:     net_cp_jlibical_ICalValue
 * Method:    get_action
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_net_cp_jlibical_ICalValue_get_1action
  (JNIEnv *env, jobject jobj)
{
    jint result = 0;
    ICalValue* cObj = getSubjectAsICalValue(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL);

    if (cObj != NULL)
    {
        result = cObj->get_action();
    }

    return(result);
}

/*
 * Class:     net_cp_jlibical_ICalValue
 * Method:    set_action
 * Signature: (I)V
 */
JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalValue_set_1action
  (JNIEnv *env, jobject jobj, jint value)
{
    ICalValue* cObj = getSubjectAsICalValue(env,jobj,JLIBICAL_ERR_CLIENT_INTERNAL);

    if (cObj != NULL)
    {
        cObj->set_action((icalproperty_action)value);
    }
}

/*
 * Class:     net_cp_jlibical_ICalValue
 * Method:    init
 * Signature: ()V
 */
JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalValue_init__
  (JNIEnv *env, jobject jobj)
{
    setCObjectPtr(env,jobj,new ICalValue());
}

/*
 * Class:     net_cp_jlibical_ICalValue
 * Method:    init
 * Signature: (ILjava/lang/String;)V
 */
JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalValue_init__ILjava_lang_String_2
  (JNIEnv *env, jobject jobj, jint kind, jstring str)
{
    if (str != NULL)
    {
        const char* szTemp = env->GetStringUTFChars(str,NULL);

        setCObjectPtr(env,jobj,new ICalValue((icalvalue_kind)kind,(char*)szTemp));
        env->ReleaseStringUTFChars(str,szTemp);
    }
    else
    {
        throwException( env, JLIBICAL_ERR_ILLEGAL_ARGUMENT );
    }
}

/*
 * Class:     net_cp_jlibical_ICalValue
 * Method:    init
 * Signature: (I)V
 */
JNIEXPORT void JNICALL Java_net_cp_jlibical_ICalValue_init__I
  (JNIEnv *env, jobject jobj, jint kind)
{
    setCObjectPtr(env,jobj,new ICalValue((icalvalue_kind)kind));
}