Project

Profile

Help

How to connect?
Download (50.8 KB) Statistics
| Branch: | Revision:

he / src / main / c / Saxon.C.API / XsltExecutable.cpp @ 5d25f10d

1
// XsltExecutable.cpp : Defines the exported functions for the DLL application.
2
//
3

    
4
#include "XsltExecutable.h"
5
#include "XdmValue.h"
6
#include "XdmItem.h"
7
#include "XdmNode.h"
8
#include "XdmFunctionItem.h"
9
#include "XdmMap.h"
10
#include "XdmArray.h"
11
#include "XdmAtomicValue.h"
12

    
13
#ifdef DEBUG
14
#include <typeinfo> //used for testing only
15
#endif
16

    
17
#ifdef MEM_DEBUG
18
#define new new(__FILE__, __LINE__)
19
#endif
20

    
21
XsltExecutable::XsltExecutable(jobject exObject, std::string curr) {
22

    
23

    
24

    
25
    /*
26
     * Look for class.
27
     */
28
    cppClass = lookForClass(SaxonProcessor::sxn_environ->env,
29
                            "net/sf/saxon/option/cpp/Xslt30Processor");
30

    
31
    messageListenerClass = lookForClass(SaxonProcessor::sxn_environ->env,
32
                                               "net/sf/saxon/option/cpp/SaxonCMessageListener");
33

    
34
#ifdef DEBUG
35
    jmethodID debugMID = SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass, "setDebugMode", "(Z)V");
36
    SaxonProcessor::sxn_environ->env->CallStaticVoidMethod(cppClass, debugMID, (jboolean)true);
37

    
38
#endif
39
    tunnel = false;
40
    selection = nullptr;
41
    selectionV = nullptr;
42
    saxonMessageListenerObj = nullptr;
43
    executableObject = SaxonProcessor::sxn_environ->env->NewGlobalRef(exObject);
44
    cwdXE = curr;
45
}
46

    
47
XsltExecutable::~XsltExecutable() {
48
    clearProperties();
49
    clearParameters();
50

    
51
    if(selection) {
52
        SaxonProcessor::sxn_environ->env->DeleteGlobalRef(selection);
53
        selection = nullptr;
54
    }
55
    SaxonProcessor::sxn_environ->env->DeleteGlobalRef(executableObject);
56
    SaxonProcessor::sxn_environ->env->ExceptionClear(); // This is as a precaution to avoid crashing out if JNI gets into an unclean state.
57
}
58

    
59

    
60
XsltExecutable::XsltExecutable(const XsltExecutable &other) {
61

    
62
    /*
63
     * Look for class.
64
     */
65
    cppClass = lookForClass(SaxonProcessor::sxn_environ->env,
66
                            "net/sf/saxon/option/cpp/Xslt30Processor");
67

    
68
    executableObject = other.executableObject;
69
    selectionV = other.selectionV;
70
    if (selectionV != nullptr) {
71
        setInitialMatchSelection(other.selectionV);
72
    } else {
73
        selection = other.selection;
74
    }
75
    tunnel = other.tunnel;
76

    
77
    std::map<std::string, XdmValue *>::const_iterator paramIter = other.parameters.begin();
78
    while (paramIter != other.parameters.end()) {
79

    
80
        XdmValue *valuei = paramIter->second;
81
        if (valuei == nullptr) {
82
            std::cerr << "Error in XsltExecutable copy constructor - parameter value is NULL" << std::endl;
83
        } else {
84
            parameters[paramIter->first] = new XdmValue(*(valuei));
85
        }
86
        paramIter++;
87
    }
88

    
89
    std::map<std::string, std::string>::const_iterator propIter = other.properties.begin();
90
    while (propIter != other.properties.end()) {
91
        properties[propIter->first] = propIter->second;
92
        propIter++;
93
    }
94

    
95
}
96

    
97

    
98
bool XsltExecutable::exceptionOccurred() {
99
    return SaxonProcessor::sxn_environ->env->ExceptionCheck();
100
}
101

    
102

    
103
void XsltExecutable::setGlobalContextItem(XdmItem *value) {
104
    if (value != nullptr) {
105
        value->incrementRefCount();
106
        parameters["node"] = value;
107
    }
108
}
109

    
110
void XsltExecutable::setGlobalContextFromFile(const char *ifile) {
111
    if (ifile != nullptr) {
112
        setProperty("s", ifile);
113
    }
114
}
115

    
116
void XsltExecutable::setInitialMatchSelection(XdmValue *_selection) {
117
    if(selection) {
118
        SaxonProcessor::sxn_environ->env->DeleteGlobalRef(selection);
119
        selection = nullptr;
120
    }
121
    if(selectionV != nullptr) {
122
        selectionV->decrementRefCount();
123
    }
124
//    if (_selection != nullptr) {
125
        _selection->incrementRefCount();
126
        selectionV = _selection;
127
        selection = SaxonProcessor::sxn_environ->env->NewGlobalRef(_selection->getUnderlyingValue());
128
//    }
129
}
130

    
131

    
132
void XsltExecutable::setInitialMatchSelectionAsFile(const char *filename) {
133
    if(selection) {
134
        SaxonProcessor::sxn_environ->env->DeleteGlobalRef(selection);
135
        selection = nullptr;
136
    }
137
    if (filename != nullptr) {
138
        selection = SaxonProcessor::sxn_environ->env->NewGlobalRef(SaxonProcessor::sxn_environ->env->NewStringUTF(filename));
139

    
140
    }
141
}
142

    
143
void XsltExecutable::setOutputFile(const char *ofile) {
144
    setProperty("o", ofile);
145
}
146

    
147
void XsltExecutable::setBaseOutputURI(const char *baseURI) {
148
    if (baseURI != nullptr) {
149
        setProperty("baseoutput", baseURI);
150
    }
151
}
152

    
153

    
154
void XsltExecutable::setParameter(const char *name, XdmValue *value) {
155
    if (value != nullptr && name != nullptr) {
156
        value->incrementRefCount();
157
        int s = parameters.size();
158
        std::string skey = "param:" + std::string(name);
159
        parameters[skey] = value;
160
        if (s == parameters.size()) {
161
            std::map<std::string, XdmValue *>::iterator it;
162
            it = parameters.find(skey);
163
            if (it != parameters.end()) {
164
                XdmValue *valuei = it->second;
165
                if(valuei != nullptr) {
166
                    valuei->decrementRefCount();
167
                    parameters.erase(skey);
168
                    parameters[skey] = value;
169
                }
170
            }
171
        }
172
    }
173
}
174

    
175
void XsltExecutable::setInitialTemplateParameters(std::map<std::string, XdmValue *> _itparameters, bool _tunnel) {
176
    for (std::map<std::string, XdmValue *>::iterator itr = _itparameters.begin(); itr != _itparameters.end(); itr++) {
177
        parameters["itparam:" + std::string(itr->first)] = itr->second;
178
        itr->second->incrementRefCount();
179
    }
180
    tunnel = _tunnel;
181
    if (tunnel) {
182
        setProperty("tunnel", "true");
183
    }
184
}
185

    
186
XdmValue *XsltExecutable::getParameter(const char *name) {
187
    std::map<std::string, XdmValue *>::iterator it;
188
    it = parameters.find("param:" + std::string(name));
189
    if (it != parameters.end())
190
        return it->second;
191
    else {
192
        it = parameters.find("sparam:" + std::string(name));
193
        if (it != parameters.end())
194
            return it->second;
195
    }
196
    return nullptr;
197
}
198

    
199
bool XsltExecutable::removeParameter(const char *name) {
200
    return (bool) (parameters.erase("param:" + std::string(name)));
201
}
202

    
203

    
204
void XsltExecutable::setResultAsRawValue(bool option) {
205
    if (option) {
206
        setProperty("outvalue", "yes");
207
    }
208
}
209

    
210
XsltExecutable * XsltExecutable::clone() {
211
    XsltExecutable * executable = new XsltExecutable(*this);
212
    return executable;
213

    
214
}
215

    
216
void XsltExecutable::setProperty(const char *name, const char *value) {
217
    if (name != nullptr) {
218
        int s = properties.size();
219

    
220
        std::string skey = std::string(name);
221
        properties.insert(std::pair<std::string, std::string>(skey, std::string((value == nullptr ? "" : value))));
222

    
223
        if (s == properties.size()) {
224
            std::map<std::string, std::string>::iterator it;
225
            it = properties.find(skey);
226
            if (it != properties.end()) {
227
                properties.erase(skey);
228
                properties[skey] = std::string((value == nullptr ? "" : value));
229
            }
230
        }
231
    }
232
}
233

    
234
const char *XsltExecutable::getProperty(const char *name) {
235
    std::map<std::string, std::string>::iterator it;
236
    it = properties.find(std::string(name));
237
    if (it != properties.end())
238
        return it->second.c_str();
239
    return nullptr;
240
}
241

    
242
void XsltExecutable::clearParameters(bool delValues) {
243
    if (delValues) {
244
        for (std::map<std::string, XdmValue *>::iterator itr = parameters.begin(); itr != parameters.end(); itr++) {
245

    
246
            XdmValue *value = itr->second;
247
            if(value != nullptr) {
248
#ifdef DEBUG
249
                std::cout<<"clearParameter() - XdmValue refCount="<<value->getRefCount()<<std::endl;
250
#endif
251
                    delete value;
252
                    value = nullptr;
253
            }
254
        }
255
    }
256
    parameters.clear();
257
}
258

    
259
void XsltExecutable::clearProperties() {
260
    properties.clear();
261

    
262
}
263

    
264

    
265
std::map<std::string, XdmValue *> &XsltExecutable::getParameters() {
266
    std::map<std::string, XdmValue *> &ptr = parameters;
267
    return ptr;
268
}
269

    
270
std::map<std::string, std::string> &XsltExecutable::getProperties() {
271
    std::map<std::string, std::string> &ptr = properties;
272
    return ptr;
273
}
274

    
275
void XsltExecutable::exceptionClear() {
276
    SaxonProcessor::sxn_environ->env->ExceptionClear();
277
}
278

    
279
void XsltExecutable::setcwd(const char *dir) {
280
    if (dir != nullptr) {
281
        cwdXE = std::string(dir);
282
    }
283
}
284

    
285

    
286
void XsltExecutable::exportStylesheet(const char *filename) {
287

    
288

    
289
    static jmethodID exportmID = nullptr;
290

    
291
    if (!exportmID) {
292
        exportmID = SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass, "save",
293
                                                                        "(Ljava/lang/String;Lnet/sf/saxon/s9api/XsltExecutable;Ljava/lang/String;)V");
294
    }
295

    
296
    if (filename == nullptr) {
297
        std::cerr << "Error: Error: export file name is nullptr" << std::endl;
298
        return;
299
    }
300
    SaxonProcessor::sxn_environ->env->CallStaticVoidMethod(cppClass, exportmID,
301
                                                           SaxonProcessor::sxn_environ->env->NewStringUTF(
302
                                                                   cwdXE.c_str()),
303
                                                           executableObject,
304
                                                           SaxonProcessor::sxn_environ->env->NewStringUTF(filename));
305

    
306
}
307

    
308
void XsltExecutable::applyTemplatesReturningFile(const char *output_filename) {
309

    
310
    if (selection == nullptr) {
311
        std::cerr
312
                << "Error: The initial match selection has not been set. Please set it using setInitialMatchSelection or setInitialMatchSelectionFile."
313
                << std::endl;
314
        return;
315
    }
316

    
317
    static jmethodID atmID = nullptr;
318

    
319
    if (atmID == nullptr) {
320
        atmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
321
                                                                        "applyTemplatesReturningFile",
322
                                                                        "(Ljava/lang/String;Lnet/sf/saxon/s9api/XsltExecutable;Ljava/lang/Object;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)V");
323
    }
324

    
325
    if (!atmID) {
326
        std::cerr << "Error: " << getDllname() << ".applyTemplatesReturningFile" << " not found\n"
327
                  << std::endl;
328
        SaxonProcessor::sxn_environ->env->ExceptionClear();
329
    } else {
330
        JParameters comboArrays;
331
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
332
        SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, atmID,
333
                                                                 SaxonProcessor::sxn_environ->env->NewStringUTF(
334
                                                                         cwdXE.c_str()), executableObject, selection,
335
                                                                 (output_filename != nullptr
336
                                                                  ? SaxonProcessor::sxn_environ->env->NewStringUTF(
337
                                                                                 output_filename) : nullptr),
338
                                                                 comboArrays.stringArray, comboArrays.objectArray);
339
        if (comboArrays.stringArray != nullptr) {
340
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
341
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
342
        }
343

    
344
    }
345
    return;
346

    
347
}
348

    
349
const char *XsltExecutable::applyTemplatesReturningString() {
350

    
351
    if (selection == nullptr) {
352
        std::cerr
353
                << "Error: The initial match selection has not been set. Please set it using setInitialMatchSelection or setInitialMatchSelectionFile."
354
                << std::endl;
355
        return nullptr;
356
    }
357

    
358

    
359
    static jmethodID atsmID = nullptr;
360

    
361
    if (atsmID == nullptr) {
362
        atsmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
363
                                                                             "applyTemplatesReturningString",
364
                                                                             "(Ljava/lang/String;Lnet/sf/saxon/s9api/XsltExecutable;Ljava/lang/Object;[Ljava/lang/String;[Ljava/lang/Object;)[B");
365
    }
366
    if (!atsmID) {
367
        std::cerr << "Error: " << getDllname() << "applyTemplatesAsString" << " not found\n"
368
                  << std::endl;
369
        SaxonProcessor::sxn_environ->env->ExceptionClear();
370
    } else {
371
        JParameters comboArrays;
372
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
373

    
374
        jbyteArray result = nullptr;
375
        jobject obj = (SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, atsmID,
376
                                                                                SaxonProcessor::sxn_environ->env->NewStringUTF(
377
                                                                                        cwdXE.c_str()), executableObject,selection,
378
                comboArrays.stringArray, comboArrays.objectArray));
379

    
380
        if (obj) {
381
            result = (jbyteArray) obj;
382
        }
383
        if (comboArrays.stringArray != nullptr) {
384
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
385
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
386
        }
387
        if (result) {
388
            jboolean isCopy = false;
389
            jbyte* b = SaxonProcessor::sxn_environ->env->GetByteArrayElements(result, &isCopy);
390
            jsize num_bytes = SaxonProcessor::sxn_environ->env->GetArrayLength(result);
391

    
392
            const char *str = new char[num_bytes];
393
            memcpy ((void *) str, b , num_bytes );
394

    
395
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(obj);
396
            return str;
397
        }
398
    }
399
    return nullptr;
400

    
401

    
402
}
403

    
404
XdmValue *XsltExecutable::applyTemplatesReturningValue() {
405

    
406
    if (selection == nullptr) {
407
        std::cerr
408
                << "Error: The initial match selection has not been set. Please set it using setInitialMatchSelection or setInitialMatchSelectionFile."
409
                << std::endl;
410
        return nullptr;
411
    }
412

    
413

    
414
    static jmethodID atsvmID = nullptr;
415
    if (atsvmID == nullptr) {
416
        atsvmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
417
                                                                                 "applyTemplatesReturningValue",
418
                                                                                 "(Ljava/lang/String;Lnet/sf/saxon/s9api/XsltExecutable;Ljava/lang/Object;[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XdmValue;");
419
    }
420
    if (!atsvmID) {
421
        std::cerr << "Error: " << getDllname() << "applyTemplatesAsValue" << " not found\n"
422
                  << std::endl;
423
        SaxonProcessor::sxn_environ->env->ExceptionClear();
424
    } else {
425
        JParameters comboArrays;
426
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
427

    
428

    
429
        // jstring result = nullptr;
430
        jobject result = (jobject) (SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, atsvmID,
431
                                                                                             SaxonProcessor::sxn_environ->env->NewStringUTF(
432
                                                                                                     cwdXE.c_str()),
433
                                                                                             executableObject,
434
                                                                                             selection,
435
                                                                                             comboArrays.stringArray,
436
                                                                                             comboArrays.objectArray));
437
        /*if(obj) {
438
            result = (jobject)obj;
439
        }*/
440
        if (comboArrays.stringArray != nullptr) {
441
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
442
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
443
        }
444
        if (result) {
445
            jclass atomicValueClass = lookForClass(SaxonProcessor::sxn_environ->env,
446
                                                   "net/sf/saxon/s9api/XdmAtomicValue");
447
            jclass nodeClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmNode");
448
            jclass functionItemClass = lookForClass(SaxonProcessor::sxn_environ->env,
449
                                                    "net/sf/saxon/s9api/XdmFunctionItem");
450
            XdmValue *value = nullptr;
451
            XdmItem *xdmItem = nullptr;
452

    
453

    
454
            if (SaxonProcessor::sxn_environ->env->IsInstanceOf(result, atomicValueClass) == JNI_TRUE) {
455
                xdmItem = new XdmAtomicValue(result);
456

    
457
                SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
458
                return xdmItem;
459

    
460
            } else if (SaxonProcessor::sxn_environ->env->IsInstanceOf(result, nodeClass) == JNI_TRUE) {
461
                xdmItem = new XdmNode(result);
462
                SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
463
                return xdmItem;
464
            } else if (SaxonProcessor::sxn_environ->env->IsInstanceOf(result, functionItemClass) == JNI_TRUE) {
465
                xdmItem = new XdmFunctionItem(result);
466
                SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
467
                return xdmItem;
468
            } else {
469
                value = new XdmValue(result, true);
470
                for (int z = 0; z < value->size(); z++) {
471
                }
472
                SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
473
                return value;
474
            }
475
        }
476
    }
477
    return nullptr;
478

    
479
}
480

    
481

    
482
void XsltExecutable::callFunctionReturningFile(const char *functionName, XdmValue **arguments, int argument_length,
483
                                               const char *outfile) {
484

    
485

    
486
    static jmethodID afmID = nullptr;
487

    
488
    if (afmID == nullptr) {
489
        afmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
490
                                                                                "callFunctionReturningFile",
491
                                                                                "(Ljava/lang/String;Lnet/sf/saxon/s9api/XsltExecutable;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;[Ljava/lang/String;[Ljava/lang/Object;)V");
492
    }
493

    
494
    if (!afmID) {
495
        std::cerr << "Error: " << getDllname() << "callFunctionReturningFile" << " not found\n"
496
                  << std::endl;
497
        SaxonProcessor::sxn_environ->env->ExceptionClear();
498
        return;
499
    } else {
500
        JParameters comboArrays;
501
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
502

    
503
        jobjectArray argumentJArray = SaxonProcessor::createJArray(arguments, argument_length);
504

    
505
        SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, afmID,
506
                                                                 SaxonProcessor::sxn_environ->env->NewStringUTF(
507
                                                                         cwdXE.c_str()),
508
                                                                 executableObject,
509
                                                                 (functionName != nullptr ?
510
                                                                  SaxonProcessor::sxn_environ->env->NewStringUTF(
511
                                                                          functionName) :
512
                                                                  nullptr), argumentJArray,
513
                                                                 (outfile != nullptr ?
514
                                                                  SaxonProcessor::sxn_environ->env->NewStringUTF(
515
                                                                          outfile) :
516
                                                                  nullptr),
517
                                                                 comboArrays.stringArray, comboArrays.objectArray);
518
        if (comboArrays.stringArray != nullptr) {
519
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
520
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
521
        }
522
        if (argumentJArray != nullptr) {
523
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(argumentJArray);
524
        }
525

    
526
    }
527
    return;
528

    
529

    
530
}
531

    
532
const char *
533
XsltExecutable::callFunctionReturningString(const char *functionName, XdmValue **arguments, int argument_length) {
534

    
535

    
536
    static jmethodID afsmID = nullptr;
537

    
538
    if(afsmID == nullptr) {
539
        (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
540
                                                                        "callFunctionReturningString",
541
                                                                        "(Ljava/lang/String;Lnet/sf/saxon/s9api/XsltExecutable;Ljava/lang/String;[Ljava/lang/Object;[Ljava/lang/String;[Ljava/lang/Object;)[B");
542
    }
543
    if (!afsmID) {
544
        std::cerr << "Error: " << getDllname() << "callFunctionReturningString" << " not found\n"
545
                  << std::endl;
546
        SaxonProcessor::sxn_environ->env->ExceptionClear();
547
    } else {
548
        JParameters comboArrays;
549
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
550
        jobjectArray argumentJArray = SaxonProcessor::createJArray(arguments, argument_length);
551

    
552
        jbyteArray result = nullptr;
553
        jobject obj = (SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, afsmID,
554
                                                                                SaxonProcessor::sxn_environ->env->NewStringUTF(
555
                                                                                        cwdXE.c_str()), executableObject,
556
                                                                                        (functionName != nullptr
557
                                                                                         ? SaxonProcessor::sxn_environ->env->NewStringUTF(
558
                                                                                                        functionName)
559
                                                                                         : nullptr),
560
                                                                                argumentJArray, comboArrays.stringArray,
561
                                                                                comboArrays.objectArray));
562
        if (obj) {
563
            result = (jbyteArray) obj;
564
        }
565
        if (comboArrays.stringArray != nullptr) {
566
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
567
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
568
        }
569
        if (result) {
570
            jboolean isCopy = false;
571
            jbyte* b = SaxonProcessor::sxn_environ->env->GetByteArrayElements(result, &isCopy);
572
            jsize num_bytes = SaxonProcessor::sxn_environ->env->GetArrayLength(result);
573

    
574
            const char *str = new char[num_bytes];
575
            memcpy ((void *) str, b , num_bytes );
576

    
577
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(obj);
578
            return str;
579
        }
580
    }
581
    return nullptr;
582
}
583

    
584

    
585
XdmValue *
586
XsltExecutable::callFunctionReturningValue(const char *functionName, XdmValue **arguments, int argument_length) {
587

    
588

    
589
    static jmethodID cfvmID = nullptr;
590
    if (cfvmID == nullptr) {
591
        cfvmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
592
                                                                                 "callFunctionReturningValue",
593
                                                                                 "(Ljava/lang/String;Lnet/sf/saxon/s9api/XsltExecutable;Ljava/lang/String;[Ljava/lang/Object;[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XdmValue;");
594
    }
595
    if (!cfvmID) {
596
        std::cerr << "Error: " << getDllname() << "callFunctionReturningValue" << " not found\n"
597
                  << std::endl;
598
        SaxonProcessor::sxn_environ->env->ExceptionClear();
599
    } else {
600
        JParameters comboArrays;
601
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
602
        jobjectArray argumentJArray = SaxonProcessor::createJArray(arguments, argument_length);
603

    
604
        jobject result = (jobject) (SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, cfvmID,
605
                                                                                             SaxonProcessor::sxn_environ->env->NewStringUTF(
606
                                                                                                     cwdXE.c_str()),
607
                                                                                             executableObject,
608
                                                                                             (functionName != nullptr
609
                                                                                              ? SaxonProcessor::sxn_environ->env->NewStringUTF(
610
                                                                                                             functionName)
611
                                                                                              : nullptr),
612
                                                                                             argumentJArray,
613
                                                                                             comboArrays.stringArray,
614
                                                                                             comboArrays.objectArray));
615

    
616
        if (comboArrays.stringArray != nullptr) {
617
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
618
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
619
        }
620
        if (argumentJArray != nullptr) {
621
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(argumentJArray);
622
        }
623
        if (result) {
624
            jclass atomicValueClass = lookForClass(SaxonProcessor::sxn_environ->env,
625
                                                   "net/sf/saxon/s9api/XdmAtomicValue");
626
            jclass nodeClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmNode");
627
            jclass functionItemClass = lookForClass(SaxonProcessor::sxn_environ->env,
628
                                                    "net/sf/saxon/s9api/XdmFunctionItem");
629
            XdmValue *value = nullptr;
630
            XdmItem *xdmItem = nullptr;
631

    
632

    
633
            if (SaxonProcessor::sxn_environ->env->IsInstanceOf(result, atomicValueClass) == JNI_TRUE) {
634
                xdmItem = new XdmAtomicValue(result);
635
                SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
636
                return xdmItem;
637
            } else if (SaxonProcessor::sxn_environ->env->IsInstanceOf(result, nodeClass) == JNI_TRUE) {
638
                xdmItem = new XdmNode(result);
639
                SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
640
                return xdmItem;
641

    
642
            } else if (SaxonProcessor::sxn_environ->env->IsInstanceOf(result, functionItemClass) == JNI_TRUE) {
643
                xdmItem = new XdmFunctionItem(result);
644
                SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
645
                return xdmItem;
646
            } else {
647
                value = new XdmValue(result, true);
648
                SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
649
                return value;
650
            }
651
            value = new XdmValue();
652
            value->addUnderlyingValue(result);
653
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
654
            return value;
655
        }
656
    }
657
    return nullptr;
658

    
659
}
660

    
661

    
662
void XsltExecutable::callTemplateReturningFile(const char *templateName, const char *outfile) {
663

    
664

    
665
    static jmethodID ctmID = nullptr;
666

    
667
    if(ctmID == nullptr) {
668
        ctmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
669
                                                                        "callTemplateReturningFile",
670
                                                                        "(Ljava/lang/String;Lnet/sf/saxon/s9api/XsltExecutable;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)V");
671
    }
672
    if (!ctmID) {
673
        std::cerr << "Error: " << getDllname() << "callTemplateReturningFile" << " not found\n"
674
                  << std::endl;
675
        SaxonProcessor::sxn_environ->env->ExceptionClear();
676
    } else {
677
        JParameters comboArrays;
678
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
679
        SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, ctmID,
680
                                                                 SaxonProcessor::sxn_environ->env->NewStringUTF(
681
                                                                         cwdXE.c_str()),
682
                                                                 executableObject,
683
                                                                 (templateName != nullptr
684
                                                                  ? SaxonProcessor::sxn_environ->env->NewStringUTF(
685
                                                                                 templateName) : nullptr),
686
                                                                 (outfile != nullptr
687
                                                                  ? SaxonProcessor::sxn_environ->env->NewStringUTF(
688
                                                                                 outfile) : nullptr),
689
                                                                 comboArrays.stringArray, comboArrays.objectArray);
690
        if (comboArrays.stringArray != nullptr) {
691
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
692
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
693
        }
694

    
695

    
696
    }
697

    
698
}
699

    
700

    
701
const char *XsltExecutable::callTemplateReturningString(const char *templateName) {
702

    
703

    
704
    jmethodID ctsmID = nullptr;
705

    
706
    if(ctsmID == nullptr) {
707
        ctsmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
708
                                                                        "callTemplateReturningString",
709
                                                                        "(Ljava/lang/String;Lnet/sf/saxon/s9api/XsltExecutable;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)[B");
710
    }
711
    if (!ctsmID) {
712
        std::cerr << "Error: " << getDllname() << "callTemplateReturningString" << " not found\n"
713
                  << std::endl;
714
        SaxonProcessor::sxn_environ->env->ExceptionClear();
715
    } else {
716
        JParameters comboArrays;
717
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
718

    
719

    
720
        jbyteArray result = nullptr;
721
        jobject obj = (jobject) (SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, ctsmID,
722
                                                                                          SaxonProcessor::sxn_environ->env->NewStringUTF(
723
                                                                                                  cwdXE.c_str()),
724
                                                                                          executableObject,
725
                                                                                          (templateName != nullptr
726
                                                                                           ? SaxonProcessor::sxn_environ->env->NewStringUTF(
727
                                                                                                          templateName)
728
                                                                                           : nullptr),
729
                                                                                          comboArrays.stringArray,
730
                                                                                          comboArrays.objectArray));
731
        if (obj) {
732
            result = (jbyteArray) obj;
733
        }
734
        if (comboArrays.stringArray != nullptr) {
735
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
736
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
737
        }
738
        if (result) {
739
            jboolean isCopy = false;
740
            jbyte* b = SaxonProcessor::sxn_environ->env->GetByteArrayElements(result, &isCopy);
741
            jsize num_bytes = SaxonProcessor::sxn_environ->env->GetArrayLength(result);
742

    
743
            const char *str = new char[num_bytes];
744
            memcpy ((void *) str, b , num_bytes );
745

    
746
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(obj);
747
            return str;
748
        }
749
    }
750
    return nullptr;
751

    
752

    
753
}
754

    
755
XdmValue *XsltExecutable::callTemplateReturningValue(const char *templateName) {
756

    
757

    
758
    if(templateName == nullptr) {
759
        std::cerr<<"template name given as null"<<std::endl;
760
        return nullptr;
761
    }
762
    static jmethodID ctsvmID = nullptr;
763
    if (ctsvmID == nullptr) {
764
        ctsvmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
765
                                                                                 "callTemplateReturningValue",
766
                                                                                 "(Ljava/lang/String;Lnet/sf/saxon/s9api/XsltExecutable;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XdmValue;");
767
    }
768
    if (!ctsvmID) {
769
        std::cerr << "Error: " << getDllname() << "callTemplateReturningValue" << " not found\n"
770
                  << std::endl;
771
        SaxonProcessor::sxn_environ->env->ExceptionClear();
772
    } else {
773
        JParameters comboArrays;
774
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
775

    
776

    
777
        jstring result = nullptr;
778
        jobject obj = (jobject) (SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, ctsvmID,
779
                                                                                          SaxonProcessor::sxn_environ->env->NewStringUTF(
780
                                                                                                  cwdXE.c_str()),
781
                                                                                          executableObject,
782
                                                                                          (templateName != nullptr
783
                                                                                           ? SaxonProcessor::sxn_environ->env->NewStringUTF(
784
                                                                                                          templateName)
785
                                                                                           : nullptr),
786
                                                                                          comboArrays.stringArray,
787
                                                                                          comboArrays.objectArray));
788
        if (obj) {
789
            result = (jstring) obj;
790
        }
791
        if (comboArrays.stringArray != nullptr) {
792
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
793
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
794
        }
795
        if (result) {
796
            jclass atomicValueClass = lookForClass(SaxonProcessor::sxn_environ->env,
797
                                                   "net/sf/saxon/s9api/XdmAtomicValue");
798
            jclass nodeClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmNode");
799
            jclass functionItemClass = lookForClass(SaxonProcessor::sxn_environ->env,
800
                                                    "net/sf/saxon/s9api/XdmFunctionItem");
801
            jclass mapItemClass = lookForClass(SaxonProcessor::sxn_environ->env,
802
                                                    "net/sf/saxon/s9api/XdmMap");
803
            jclass arrayItemClass = lookForClass(SaxonProcessor::sxn_environ->env,
804
                                               "net/sf/saxon/s9api/XdmArray");
805
            XdmValue *value = nullptr;
806

    
807
            XdmItem *xdmItem = nullptr;
808
            if (SaxonProcessor::sxn_environ->env->IsInstanceOf(result, atomicValueClass) == JNI_TRUE) {
809
                xdmItem = new XdmAtomicValue(result);
810
                SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
811
                return xdmItem;
812

    
813
            } else if (SaxonProcessor::sxn_environ->env->IsInstanceOf(result, nodeClass) == JNI_TRUE) {
814
                xdmItem = new XdmNode(result);
815
                SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
816
                return xdmItem;
817
            } else if (SaxonProcessor::sxn_environ->env->IsInstanceOf(result, functionItemClass) == JNI_TRUE) {
818
                xdmItem = new XdmFunctionItem(result);
819
                SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
820
                return xdmItem;
821

    
822
            } else if (SaxonProcessor::sxn_environ->env->IsInstanceOf(result, mapItemClass) == JNI_TRUE) {
823
                xdmItem = new XdmMap(result);
824
                SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
825
                return xdmItem;
826
            } else if (SaxonProcessor::sxn_environ->env->IsInstanceOf(result, arrayItemClass) == JNI_TRUE) {
827
                xdmItem = new XdmArray(result);
828
                SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
829
                return xdmItem;
830
            } else {
831
                value = new XdmValue(result, true);
832
                SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
833
                return value;
834
            }
835
            value = new XdmValue();
836
            value->addUnderlyingValue(result);
837
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
838
            return value;
839
        }
840
    }
841
    return nullptr;
842
}
843

    
844

    
845
XdmValue *XsltExecutable::transformFileToValue(const char *sourcefile) {
846

    
847
    if (sourcefile == nullptr) {
848

    
849
        return nullptr;
850
    }
851

    
852

    
853
    static jmethodID tfvMID = nullptr;
854

    
855
    if (tfvMID == nullptr) {
856
        tfvMID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
857
                                                                                 "transformToValue",
858
                                                                                 "(Ljava/lang/String;Lnet/sf/saxon/option/cpp/Xslt30Processor;Lnet/sf/saxon/s9api/XsltExecutable;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XdmValue;");
859
    }
860
    if (!tfvMID) {
861
        std::cerr << "Error: " << getDllname() << ".transformtoValue" << " not found\n"
862
                  << std::endl;
863
        SaxonProcessor::sxn_environ->env->ExceptionClear();
864
    } else {
865
        JParameters comboArrays;
866
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
867

    
868
        jobject result = (jobject) (
869
                SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, tfvMID,
870
                                                                         SaxonProcessor::sxn_environ->env->NewStringUTF(
871
                                                                                 cwdXE.c_str()), nullptr, executableObject,
872
                                                                         (sourcefile != nullptr
873
                                                                          ? SaxonProcessor::sxn_environ->env->NewStringUTF(
874
                                                                                         sourcefile) : nullptr),
875
                                                                         comboArrays.stringArray,
876
                                                                         comboArrays.objectArray));
877
        if (comboArrays.stringArray != nullptr) {
878
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
879
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
880
        }
881
        if (result) {
882
            jclass atomicValueClass = lookForClass(SaxonProcessor::sxn_environ->env,
883
                                                   "net/sf/saxon/s9api/XdmAtomicValue");
884
            jclass nodeClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmNode");
885
            jclass functionItemClass = lookForClass(SaxonProcessor::sxn_environ->env,
886
                                                    "net/sf/saxon/s9api/XdmFunctionItem");
887
            jclass mapItemClass = lookForClass(SaxonProcessor::sxn_environ->env,
888
                                                    "net/sf/saxon/s9api/XdmMap");
889
            jclass arrayItemClass = lookForClass(SaxonProcessor::sxn_environ->env,
890
                                               "net/sf/saxon/s9api/XdmArray");
891
            XdmValue *value = nullptr;
892
            XdmItem *xdmItem = nullptr;
893

    
894

    
895
            if (SaxonProcessor::sxn_environ->env->IsInstanceOf(result, atomicValueClass) == JNI_TRUE) {
896
                xdmItem = new XdmAtomicValue(result);
897
                SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
898
                return xdmItem;
899

    
900
            } else if (SaxonProcessor::sxn_environ->env->IsInstanceOf(result, nodeClass) == JNI_TRUE) {
901
                xdmItem = new XdmNode(result);
902
                SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
903
                return xdmItem;
904

    
905
            } else if (SaxonProcessor::sxn_environ->env->IsInstanceOf(result, functionItemClass) == JNI_TRUE) {
906
                xdmItem = new XdmFunctionItem(result);
907
                SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
908
                return xdmItem;
909
            } else if (SaxonProcessor::sxn_environ->env->IsInstanceOf(result, mapItemClass) == JNI_TRUE) {
910
                xdmItem = new XdmMap(result);
911
                SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
912
                return xdmItem;
913
            } else if (SaxonProcessor::sxn_environ->env->IsInstanceOf(result, arrayItemClass) == JNI_TRUE) {
914
                xdmItem = new XdmArray(result);
915
                SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
916
                return xdmItem;
917
            } else {
918
                value = new XdmValue(result);
919
                return value;
920
            }
921
            value = new XdmValue();
922
            value->addUnderlyingValue(result);
923

    
924
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
925
            return value;
926
        }
927
    }
928
    return nullptr;
929

    
930
}
931

    
932

    
933
void XsltExecutable::transformFileToFile(const char *source, const char *outputfile) {
934

    
935

    
936
    static jmethodID tffMID = nullptr;
937

    
938
    if (tffMID == nullptr) {
939
        tffMID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
940
                                                                                 "transformToFile",
941
                                                                                 "(Ljava/lang/String;Lnet/sf/saxon/option/cpp/Xslt30Processor;Lnet/sf/saxon/s9api/XsltExecutable;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)V");
942
    }
943
    if (!tffMID) {
944
        std::cerr << "Error: " << getDllname() << "transformToFile" << " not found\n"
945
                  << std::endl;
946
        SaxonProcessor::sxn_environ->env->ExceptionClear();
947
    } else {
948
        JParameters comboArrays;
949
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
950

    
951
        SaxonProcessor::sxn_environ->env->CallStaticVoidMethod(cppClass, tffMID,
952
                                                               SaxonProcessor::sxn_environ->env->NewStringUTF(
953
                                                                       cwdXE.c_str()), nullptr, executableObject,
954
                                                                       (source != nullptr
955
                                                                        ? SaxonProcessor::sxn_environ->env->NewStringUTF(
956
                                                                                       source) : nullptr), nullptr,
957
                                                               (outputfile != nullptr
958
                                                                ? SaxonProcessor::sxn_environ->env->NewStringUTF(
959
                                                                               outputfile) : nullptr),
960
                                                               comboArrays.stringArray, comboArrays.objectArray);
961
        if (comboArrays.stringArray != nullptr) {
962
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
963
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
964
        }
965
    }
966

    
967
}
968

    
969

    
970
void XsltExecutable::setupXslMessage(bool create, const char * filename) {
971
    if (create) {
972

    
973
        static jmethodID messageID =   nullptr;
974
        if(messageID == nullptr) {
975
            messageID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(messageListenerClass,
976
                                                                                  "<init>",
977
                                                                                  "(Ljava/lang/String;Ljava/lang/String;)V");
978
        }
979
        if (!messageID) {
980
            std::cerr << "Error: SaxonCMessageListener" << " in " <<getDllname() << " not found\n"
981
                      << std::endl;
982
            SaxonProcessor::sxn_environ->env->ExceptionClear();
983
        }
984

    
985
        jobject tempListenerObj;
986
        if (filename == nullptr) {
987
            tempListenerObj = (jobject)SaxonProcessor::sxn_environ->env->NewObject(messageListenerClass, messageID,
988
                                                                                           SaxonProcessor::sxn_environ->env->NewStringUTF("-:on"));
989
            //setProperty("m", "on");
990
        } else {
991
            tempListenerObj = (jobject)SaxonProcessor::sxn_environ->env->NewObject(messageListenerClass, messageID,
992
                                                                                           SaxonProcessor::sxn_environ->env->NewStringUTF(filename));
993
        }
994
        if(tempListenerObj) {
995
            saxonMessageListenerObj = SaxonProcessor::sxn_environ->env->NewGlobalRef(tempListenerObj);
996
        } else {
997
            std::cerr << "Error: Failed to create SaxonCMessageListener" <<  std::endl;
998
        }
999
    } else {
1000
        setProperty("m", "off");
1001
    }
1002

    
1003

    
1004
}
1005

    
1006
XdmValue * XsltExecutable::getXslMessages(){
1007

    
1008
    if(saxonMessageListenerObj) {
1009
        static jmethodID getmessageID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(messageListenerClass,
1010
                                                                                                  "getXslMessages",
1011
                                                                                                  "()[Lnet/sf/saxon/s9api/XdmNode;");
1012
        if (!getmessageID) {
1013
            std::cerr << "Error: " << getDllname() << ".getXslMessages" << " not found\n"
1014
                      << std::endl;
1015
            SaxonProcessor::sxn_environ->env->ExceptionClear();
1016
        } else {
1017
            jobjectArray results = (jobjectArray) (
1018
                    SaxonProcessor::sxn_environ->env->CallObjectMethod(saxonMessageListenerObj, getmessageID));
1019
            int sizex = SaxonProcessor::sxn_environ->env->GetArrayLength(results);
1020

    
1021
            if (sizex > 0) {
1022
                XdmValue *value = new XdmValue();
1023

    
1024
                for (int p = 0; p < sizex; ++p) {
1025
                    jobject resulti = SaxonProcessor::sxn_environ->env->GetObjectArrayElement(results, p);
1026
                    value->addUnderlyingValue(resulti);
1027
                }
1028
                SaxonProcessor::sxn_environ->env->DeleteLocalRef(results);
1029
                return value;
1030
            }
1031
        }
1032
    }
1033
    return NULL;
1034

    
1035

    
1036
}
1037

    
1038

    
1039
const char *XsltExecutable::transformFileToString(const char *source) {
1040

    
1041

    
1042
    static jmethodID tftMID = tftMID;
1043
    if (tftMID == nullptr) {
1044
        tftMID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
1045
                                                                                 "transformToString",
1046
                                                                                 "(Ljava/lang/String;Lnet/sf/saxon/option/cpp/Xslt30Processor;Lnet/sf/saxon/s9api/XsltExecutable;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)[B");
1047
    }
1048
    if (!tftMID) {
1049
        std::cerr << "Error: " << getDllname() << "transformToString" << " not found\n"
1050
                  << std::endl;
1051
        SaxonProcessor::sxn_environ->env->ExceptionClear();
1052
    } else {
1053
        JParameters comboArrays;
1054
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
1055

    
1056
        jbyteArray result = nullptr;
1057
        jobject obj = SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, tftMID,
1058
                                                                               SaxonProcessor::sxn_environ->env->NewStringUTF(
1059
                                                                                       cwdXE.c_str()), nullptr,
1060
                                                                               executableObject,
1061
                                                                               (source != nullptr
1062
                                                                                ? SaxonProcessor::sxn_environ->env->NewStringUTF(
1063
                                                                                               source) : nullptr),
1064
                                                                               nullptr,
1065
                                                                               comboArrays.stringArray,
1066
                                                                               comboArrays.objectArray);
1067
        if (comboArrays.stringArray != nullptr) {
1068
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
1069
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
1070
        }
1071
        if (obj) {
1072
            result = (jbyteArray) obj;
1073
        }
1074
        if (result) {
1075

    
1076
            jboolean isCopy = false;
1077
            jbyte* b = SaxonProcessor::sxn_environ->env->GetByteArrayElements(result, &isCopy);
1078
            jsize num_bytes = SaxonProcessor::sxn_environ->env->GetArrayLength(result);
1079

    
1080
            const char *str = new char[num_bytes];
1081
            memcpy ((void *) str, b , num_bytes );
1082

    
1083
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(obj);
1084
            return str;
1085
        }
1086
    }
1087
    return nullptr;
1088
}
1089

    
1090

    
1091
const char *XsltExecutable::transformToString(XdmNode *source) {
1092

    
1093
    if (source != nullptr) {
1094
        source->incrementRefCount();
1095
        parameters["node"] = source;
1096
    }
1097
    return transformFileToString(nullptr);
1098
}
1099

    
1100

    
1101
XdmValue *XsltExecutable::transformToValue(XdmNode *source) {
1102

    
1103
    if (source != nullptr) {
1104
        source->incrementRefCount();
1105
        parameters["node"] = source;
1106
    }
1107
    return transformFileToValue(nullptr);
1108
}
1109

    
1110
void XsltExecutable::transformToFile(XdmNode *source) {
1111

    
1112
    if (source != nullptr) {
1113
        source->incrementRefCount();
1114
        parameters["node"] = source;
1115
    }
1116
    transformFileToFile(nullptr, nullptr);
1117
}
1118

    
1119

    
1120
SaxonApiException *XsltExecutable::getException() {
1121
    return SaxonProcessor::checkForExceptionCPP(SaxonProcessor::sxn_environ->env, cppClass, nullptr);
1122
}
(40-40/56)