Project

Profile

Help

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

he / src / main / c / Saxon.C.API / XsltExecutable.cpp @ 6af44631

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
        if(selection) {
74
            selection = SaxonProcessor::sxn_environ->env->NewGlobalRef(other.selection);
75
        }
76
    }
77
    tunnel = other.tunnel;
78

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

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

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

    
97
}
98

    
99

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

    
104

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

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

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

    
133

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

    
142
    }
143
}
144

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

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

    
155

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

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

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

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

    
205

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

    
212
XsltExecutable * XsltExecutable::clone() {
213
    XsltExecutable * executable = new XsltExecutable(*this);
214
    return executable;
215

    
216
}
217

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

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

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

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

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

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

    
261
void XsltExecutable::clearProperties() {
262
    properties.clear();
263

    
264
}
265

    
266

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

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

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

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

    
287

    
288
void XsltExecutable::exportStylesheet(const char *filename) {
289

    
290

    
291
    static jmethodID exportmID = nullptr;
292

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

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

    
308
}
309

    
310
void XsltExecutable::applyTemplatesReturningFile(const char *output_filename) {
311

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

    
319
    static jmethodID atmID = nullptr;
320

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

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

    
346
    }
347
    return;
348

    
349
}
350

    
351
const char *XsltExecutable::applyTemplatesReturningString() {
352

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

    
360

    
361
    static jmethodID atsmID = nullptr;
362

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

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

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

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

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

    
403

    
404
}
405

    
406
XdmValue *XsltExecutable::applyTemplatesReturningValue() {
407

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

    
415

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

    
430

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

    
455

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

    
459
                SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
460
                return xdmItem;
461

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

    
481
}
482

    
483

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

    
487

    
488
    static jmethodID afmID = nullptr;
489

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

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

    
505
        jobjectArray argumentJArray = SaxonProcessor::createJArray(arguments, argument_length);
506

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

    
528
    }
529
    return;
530

    
531

    
532
}
533

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

    
537

    
538
    static jmethodID afsmID = nullptr;
539

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

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

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

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

    
586

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

    
590

    
591
    static jmethodID cfvmID = nullptr;
592
    if (cfvmID == nullptr) {
593
        cfvmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
594
                                                                                 "callFunctionReturningValue",
595
                                                                                 "(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;");
596
    }
597
    if (!cfvmID) {
598
        std::cerr << "Error: " << getDllname() << "callFunctionReturningValue" << " not found\n"
599
                  << std::endl;
600
        SaxonProcessor::sxn_environ->env->ExceptionClear();
601
    } else {
602
        JParameters comboArrays;
603
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
604
        jobjectArray argumentJArray = SaxonProcessor::createJArray(arguments, argument_length);
605

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

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

    
634

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

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

    
661
}
662

    
663

    
664
void XsltExecutable::callTemplateReturningFile(const char *templateName, const char *outfile) {
665

    
666

    
667
    static jmethodID ctmID = nullptr;
668

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

    
697

    
698
    }
699

    
700
}
701

    
702

    
703
const char *XsltExecutable::callTemplateReturningString(const char *templateName) {
704

    
705

    
706
    jmethodID ctsmID = nullptr;
707

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

    
721

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

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

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

    
754

    
755
}
756

    
757
XdmValue *XsltExecutable::callTemplateReturningValue(const char *templateName) {
758

    
759

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

    
778

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

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

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

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

    
846

    
847
XdmValue *XsltExecutable::transformFileToValue(const char *sourcefile) {
848

    
849
    if (sourcefile == nullptr) {
850

    
851
        return nullptr;
852
    }
853

    
854

    
855
    static jmethodID tfvMID = nullptr;
856

    
857
    if (tfvMID == nullptr) {
858
        tfvMID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
859
                                                                                 "transformToValue",
860
                                                                                 "(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;");
861
    }
862
    if (!tfvMID) {
863
        std::cerr << "Error: " << getDllname() << ".transformtoValue" << " not found\n"
864
                  << std::endl;
865
        SaxonProcessor::sxn_environ->env->ExceptionClear();
866
    } else {
867
        JParameters comboArrays;
868
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
869

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

    
896

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

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

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

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

    
932
}
933

    
934

    
935
void XsltExecutable::transformFileToFile(const char *source, const char *outputfile) {
936

    
937

    
938
    static jmethodID tffMID = nullptr;
939

    
940
    if (tffMID == nullptr) {
941
        tffMID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
942
                                                                                 "transformToFile",
943
                                                                                 "(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");
944
    }
945
    if (!tffMID) {
946
        std::cerr << "Error: " << getDllname() << "transformToFile" << " not found\n"
947
                  << std::endl;
948
        SaxonProcessor::sxn_environ->env->ExceptionClear();
949
    } else {
950
        JParameters comboArrays;
951
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
952

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

    
969
}
970

    
971

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

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

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

    
1005

    
1006
}
1007

    
1008
XdmValue * XsltExecutable::getXslMessages(){
1009

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

    
1023
            if (sizex > 0) {
1024
                XdmValue *value = new XdmValue();
1025

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

    
1037

    
1038
}
1039

    
1040

    
1041
const char *XsltExecutable::transformFileToString(const char *source) {
1042

    
1043

    
1044
    static jmethodID tftMID = tftMID;
1045
    if (tftMID == nullptr) {
1046
        tftMID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
1047
                                                                                 "transformToString",
1048
                                                                                 "(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");
1049
    }
1050
    if (!tftMID) {
1051
        std::cerr << "Error: " << getDllname() << "transformToString" << " not found\n"
1052
                  << std::endl;
1053
        SaxonProcessor::sxn_environ->env->ExceptionClear();
1054
    } else {
1055
        JParameters comboArrays;
1056
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
1057

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

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

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

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

    
1092

    
1093
const char *XsltExecutable::transformToString(XdmNode *source) {
1094

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

    
1102

    
1103
XdmValue *XsltExecutable::transformToValue(XdmNode *source) {
1104

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

    
1112
void XsltExecutable::transformToFile(XdmNode *source) {
1113

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

    
1121

    
1122
SaxonApiException *XsltExecutable::getException() {
1123
    return SaxonProcessor::checkForExceptionCPP(SaxonProcessor::sxn_environ->env, cppClass, nullptr);
1124
}
(40-40/51)