Project

Profile

Help

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

he / src / main / c / Saxon.C.API / XsltExecutable.cpp @ 03fcd3f9

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

    
18
XsltExecutable::XsltExecutable(jobject exObject, std::string curr) {
19

    
20

    
21

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

    
28
    messageListenerClass = lookForClass(SaxonProcessor::sxn_environ->env,
29
                                               "net/sf/saxon/option/cpp/SaxonCMessageListener");
30

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

    
35
#endif
36
    tunnel = false;
37
    selection = nullptr;
38
    selectionV = nullptr;
39
    saxonMessageListenerObj = nullptr;
40
    executableObject = exObject;
41
    cwdXE = curr;
42
}
43

    
44
XsltExecutable::~XsltExecutable() {
45
    clearProperties();
46
    clearParameters();
47
    if (selectionV != nullptr) {
48
        selectionV->decrementRefCount();
49
        if (selectionV->getRefCount() == 0) {
50
            delete selectionV;
51
        }
52
    } else {
53
        if (selection) {
54
            SaxonProcessor::sxn_environ->env->DeleteGlobalRef(selection);
55
        }
56
    }
57
    SaxonProcessor::sxn_environ->env->DeleteGlobalRef(executableObject);
58

    
59
}
60

    
61

    
62
XsltExecutable::XsltExecutable(const XsltExecutable &other) {
63

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

    
70
    executableObject = other.executableObject;
71
    selectionV = other.selectionV;
72
    if (selectionV != nullptr) {
73
        setInitialMatchSelection(other.selectionV);
74
    } else {
75
        selection = other.selection;
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
const char *XsltExecutable::getErrorCode() {
105
    SaxonApiException *exception = SaxonProcessor::checkForExceptionCPP(SaxonProcessor::sxn_environ->env, cppClass,
106
                                                                        nullptr);
107
    if (exception == nullptr) { return nullptr; }
108
    return exception->getErrorCode();
109
}
110

    
111

    
112
void XsltExecutable::setGlobalContextItem(XdmItem *value) {
113
    if (value != nullptr) {
114
        value->incrementRefCount();
115
        parameters["node"] = value;
116
    }
117
}
118

    
119
void XsltExecutable::setGlobalContextFromFile(const char *ifile) {
120
    if (ifile != nullptr) {
121
        setProperty("s", ifile);
122
    }
123
}
124

    
125
void XsltExecutable::setInitialMatchSelection(XdmValue *_selection) {
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 (filename != nullptr) {
136
        selection = SaxonProcessor::sxn_environ->env->NewGlobalRef(SaxonProcessor::sxn_environ->env->NewStringUTF(filename));
137

    
138
    }
139
}
140

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

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

    
151

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

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

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

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

    
204

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

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

    
215
}
216

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

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

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

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

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

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

    
259
        if(selection) {
260
            SaxonProcessor::sxn_environ->env->DeleteGlobalRef(selection);
261
            selection = nullptr;
262
        }
263
    } else {
264
        for (std::map<std::string, XdmValue *>::iterator itr = parameters.begin(); itr != parameters.end(); itr++) {
265

    
266
            XdmValue *value = itr->second;
267
            if(value != nullptr) {
268
                value->decrementRefCount();
269
            }
270

    
271
        }
272
        if(selection) {
273
            SaxonProcessor::sxn_environ->env->DeleteGlobalRef(selection);
274
            selection = nullptr;
275
        }
276
    }
277
    parameters.clear();
278

    
279

    
280
}
281

    
282
void XsltExecutable::clearProperties() {
283
    properties.clear();
284

    
285
}
286

    
287

    
288
std::map<std::string, XdmValue *> &XsltExecutable::getParameters() {
289
    std::map<std::string, XdmValue *> &ptr = parameters;
290
    return ptr;
291
}
292

    
293
std::map<std::string, std::string> &XsltExecutable::getProperties() {
294
    std::map<std::string, std::string> &ptr = properties;
295
    return ptr;
296
}
297

    
298
void XsltExecutable::exceptionClear() {
299
    SaxonProcessor::sxn_environ->env->ExceptionClear();
300
}
301

    
302
void XsltExecutable::setcwd(const char *dir) {
303
    if (dir != nullptr) {
304
        cwdXE = std::string(dir);
305
    }
306
}
307

    
308

    
309
void XsltExecutable::exportStylesheet(const char *filename) {
310

    
311

    
312
    static jmethodID exportmID = nullptr;
313

    
314
    if (!exportmID) {
315
        exportmID = SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass, "save",
316
                                                                        "(Ljava/lang/String;Lnet/sf/saxon/s9api/XsltExecutable;Ljava/lang/String;)V");
317
    }
318

    
319
    if (filename == nullptr) {
320
        std::cerr << "Error: Error: export file name is nullptr" << std::endl;
321
        return;
322
    }
323
    SaxonProcessor::sxn_environ->env->CallStaticVoidMethod(cppClass, exportmID,
324
                                                           SaxonProcessor::sxn_environ->env->NewStringUTF(
325
                                                                   cwdXE.c_str()),
326
                                                           executableObject,
327
                                                           SaxonProcessor::sxn_environ->env->NewStringUTF(filename));
328

    
329
}
330

    
331
void XsltExecutable::applyTemplatesReturningFile(const char *output_filename) {
332

    
333
    if (selection == nullptr) {
334
        std::cerr
335
                << "Error: The initial match selection has not been set. Please set it using setInitialMatchSelection or setInitialMatchSelectionFile."
336
                << std::endl;
337
        return;
338
    }
339

    
340
    static jmethodID atmID = nullptr;
341

    
342
    if (atmID == nullptr) {
343
        atmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
344
                                                                        "applyTemplatesReturningFile",
345
                                                                        "(Ljava/lang/String;Lnet/sf/saxon/s9api/XsltExecutable;Ljava/lang/Object;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)V");
346
    }
347

    
348
    if (!atmID) {
349
        std::cerr << "Error: " << getDllname() << ".applyTemplatesReturningFile" << " not found\n"
350
                  << std::endl;
351

    
352
    } else {
353
        JParameters comboArrays;
354
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
355
        SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, atmID,
356
                                                                 SaxonProcessor::sxn_environ->env->NewStringUTF(
357
                                                                         cwdXE.c_str()), executableObject, selection,
358
                                                                 (output_filename != nullptr
359
                                                                  ? SaxonProcessor::sxn_environ->env->NewStringUTF(
360
                                                                                 output_filename) : nullptr),
361
                                                                 comboArrays.stringArray, comboArrays.objectArray);
362
        if (comboArrays.stringArray != nullptr) {
363
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
364
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
365
        }
366

    
367
    }
368
    return;
369

    
370
}
371

    
372
const char *XsltExecutable::applyTemplatesReturningString() {
373

    
374
    if (selection == nullptr) {
375
        std::cerr
376
                << "Error: The initial match selection has not been set. Please set it using setInitialMatchSelection or setInitialMatchSelectionFile."
377
                << std::endl;
378
        return nullptr;
379
    }
380

    
381

    
382
    static jmethodID atsmID = nullptr;
383

    
384
    if (atsmID == nullptr) {
385
        atsmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
386
                                                                             "applyTemplatesReturningString",
387
                                                                             "(Ljava/lang/String;Lnet/sf/saxon/s9api/XsltExecutable;Ljava/lang/Object;[Ljava/lang/String;[Ljava/lang/Object;)[B");
388
    }
389
    if (!atsmID) {
390
        std::cerr << "Error: " << getDllname() << "applyTemplatesAsString" << " not found\n"
391
                  << std::endl;
392

    
393
    } else {
394
        JParameters comboArrays;
395
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
396

    
397
        jbyteArray result = nullptr;
398
        jobject obj = (SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, atsmID,
399
                                                                                SaxonProcessor::sxn_environ->env->NewStringUTF(
400
                                                                                        cwdXE.c_str()), executableObject,selection,
401
                comboArrays.stringArray, comboArrays.objectArray));
402

    
403
        if (obj) {
404
            result = (jbyteArray) obj;
405
        }
406
        if (comboArrays.stringArray != nullptr) {
407
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
408
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
409
        }
410
        if (result) {
411
            jboolean isCopy = false;
412
            jbyte* b = SaxonProcessor::sxn_environ->env->GetByteArrayElements(result, &isCopy);
413
            jsize num_bytes = SaxonProcessor::sxn_environ->env->GetArrayLength(result);
414

    
415
            const char *str = new char[num_bytes];
416
            memcpy ((void *) str, b , num_bytes );
417

    
418
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(obj);
419
            return str;
420
        }
421
    }
422
    return nullptr;
423

    
424

    
425
}
426

    
427
XdmValue *XsltExecutable::applyTemplatesReturningValue() {
428

    
429
    if (selection == nullptr) {
430
        std::cerr
431
                << "Error: The initial match selection has not been set. Please set it using setInitialMatchSelection or setInitialMatchSelectionFile."
432
                << std::endl;
433
        return nullptr;
434
    }
435

    
436

    
437
    static jmethodID atsvmID = nullptr;
438
    if (atsvmID == nullptr) {
439
        atsvmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
440
                                                                                 "applyTemplatesReturningValue",
441
                                                                                 "(Ljava/lang/String;Lnet/sf/saxon/s9api/XsltExecutable;Ljava/lang/Object;[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XdmValue;");
442
    }
443
    if (!atsvmID) {
444
        std::cerr << "Error: " << getDllname() << "applyTemplatesAsValue" << " not found\n"
445
                  << std::endl;
446

    
447
    } else {
448
        JParameters comboArrays;
449
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
450

    
451

    
452
        // jstring result = nullptr;
453
        jobject result = (jobject) (SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, atsvmID,
454
                                                                                             SaxonProcessor::sxn_environ->env->NewStringUTF(
455
                                                                                                     cwdXE.c_str()),
456
                                                                                             executableObject,
457
                                                                                             selection,
458
                                                                                             comboArrays.stringArray,
459
                                                                                             comboArrays.objectArray));
460
        /*if(obj) {
461
            result = (jobject)obj;
462
        }*/
463
        if (comboArrays.stringArray != nullptr) {
464
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
465
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
466
        }
467
        if (result) {
468
            jclass atomicValueClass = lookForClass(SaxonProcessor::sxn_environ->env,
469
                                                   "net/sf/saxon/s9api/XdmAtomicValue");
470
            jclass nodeClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmNode");
471
            jclass functionItemClass = lookForClass(SaxonProcessor::sxn_environ->env,
472
                                                    "net/sf/saxon/s9api/XdmFunctionItem");
473
            XdmValue *value = nullptr;
474
            XdmItem *xdmItem = nullptr;
475

    
476

    
477
            if (SaxonProcessor::sxn_environ->env->IsInstanceOf(result, atomicValueClass) == JNI_TRUE) {
478
                xdmItem = new XdmAtomicValue(result);
479

    
480
                SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
481
                return xdmItem;
482

    
483
            } else if (SaxonProcessor::sxn_environ->env->IsInstanceOf(result, nodeClass) == JNI_TRUE) {
484
                xdmItem = new XdmNode(result);
485
                SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
486
                return xdmItem;
487
            } else if (SaxonProcessor::sxn_environ->env->IsInstanceOf(result, functionItemClass) == JNI_TRUE) {
488
                xdmItem = new XdmFunctionItem(result);
489
                SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
490
                return xdmItem;
491
            } else {
492
                value = new XdmValue(result, true);
493
                for (int z = 0; z < value->size(); z++) {
494
                }
495
                SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
496
                return value;
497
            }
498
        }
499
    }
500
    return nullptr;
501

    
502
}
503

    
504

    
505
void XsltExecutable::callFunctionReturningFile(const char *functionName, XdmValue **arguments, int argument_length,
506
                                               const char *outfile) {
507

    
508

    
509
    static jmethodID afmID = nullptr;
510

    
511
    if (afmID == nullptr) {
512
        afmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
513
                                                                                "callFunctionReturningFile",
514
                                                                                "(Ljava/lang/String;Lnet/sf/saxon/s9api/XsltExecutable;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;[Ljava/lang/String;[Ljava/lang/Object;)V");
515
    }
516

    
517
    if (!afmID) {
518
        std::cerr << "Error: " << getDllname() << "callFunctionReturningFile" << " not found\n"
519
                  << std::endl;
520
        return;
521
    } else {
522
        JParameters comboArrays;
523
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
524

    
525
        jobjectArray argumentJArray = SaxonProcessor::createJArray(arguments, argument_length);
526

    
527
        SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, afmID,
528
                                                                 SaxonProcessor::sxn_environ->env->NewStringUTF(
529
                                                                         cwdXE.c_str()),
530
                                                                 executableObject,
531
                                                                 (functionName != nullptr ?
532
                                                                  SaxonProcessor::sxn_environ->env->NewStringUTF(
533
                                                                          functionName) :
534
                                                                  nullptr), argumentJArray,
535
                                                                 (outfile != nullptr ?
536
                                                                  SaxonProcessor::sxn_environ->env->NewStringUTF(
537
                                                                          outfile) :
538
                                                                  nullptr),
539
                                                                 comboArrays.stringArray, comboArrays.objectArray);
540
        if (comboArrays.stringArray != nullptr) {
541
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
542
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
543
        }
544
        if (argumentJArray != nullptr) {
545
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(argumentJArray);
546
        }
547

    
548
    }
549
    return;
550

    
551

    
552
}
553

    
554
const char *
555
XsltExecutable::callFunctionReturningString(const char *functionName, XdmValue **arguments, int argument_length) {
556

    
557

    
558
    static jmethodID afsmID = nullptr;
559

    
560
    if(afsmID == nullptr) {
561
        (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
562
                                                                        "callFunctionReturningString",
563
                                                                        "(Ljava/lang/String;Lnet/sf/saxon/s9api/XsltExecutable;Ljava/lang/String;[Ljava/lang/Object;[Ljava/lang/String;[Ljava/lang/Object;)[B");
564
    }
565
    if (!afsmID) {
566
        std::cerr << "Error: " << getDllname() << "callFunctionReturningString" << " not found\n"
567
                  << std::endl;
568

    
569
    } else {
570
        JParameters comboArrays;
571
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
572
        jobjectArray argumentJArray = SaxonProcessor::createJArray(arguments, argument_length);
573

    
574
        jbyteArray result = nullptr;
575
        jobject obj = (SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, afsmID,
576
                                                                                SaxonProcessor::sxn_environ->env->NewStringUTF(
577
                                                                                        cwdXE.c_str()), executableObject,
578
                                                                                        (functionName != nullptr
579
                                                                                         ? SaxonProcessor::sxn_environ->env->NewStringUTF(
580
                                                                                                        functionName)
581
                                                                                         : nullptr),
582
                                                                                argumentJArray, comboArrays.stringArray,
583
                                                                                comboArrays.objectArray));
584
        if (obj) {
585
            result = (jbyteArray) obj;
586
        }
587
        if (comboArrays.stringArray != nullptr) {
588
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
589
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
590
        }
591
        if (result) {
592
            jboolean isCopy = false;
593
            jbyte* b = SaxonProcessor::sxn_environ->env->GetByteArrayElements(result, &isCopy);
594
            jsize num_bytes = SaxonProcessor::sxn_environ->env->GetArrayLength(result);
595

    
596
            const char *str = new char[num_bytes];
597
            memcpy ((void *) str, b , num_bytes );
598

    
599
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(obj);
600
            return str;
601
        }
602
    }
603
    return nullptr;
604
}
605

    
606

    
607
XdmValue *
608
XsltExecutable::callFunctionReturningValue(const char *functionName, XdmValue **arguments, int argument_length) {
609

    
610

    
611
    static jmethodID cfvmID = nullptr;
612
    if (cfvmID == nullptr) {
613
        cfvmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
614
                                                                                 "callFunctionReturningValue",
615
                                                                                 "(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;");
616
    }
617
    if (!cfvmID) {
618
        std::cerr << "Error: " << getDllname() << "callFunctionReturningValue" << " not found\n"
619
                  << std::endl;
620

    
621
    } else {
622
        JParameters comboArrays;
623
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
624
        jobjectArray argumentJArray = SaxonProcessor::createJArray(arguments, argument_length);
625

    
626
        jobject result = (jobject) (SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, cfvmID,
627
                                                                                             SaxonProcessor::sxn_environ->env->NewStringUTF(
628
                                                                                                     cwdXE.c_str()),
629
                                                                                             executableObject,
630
                                                                                             (functionName != nullptr
631
                                                                                              ? SaxonProcessor::sxn_environ->env->NewStringUTF(
632
                                                                                                             functionName)
633
                                                                                              : nullptr),
634
                                                                                             argumentJArray,
635
                                                                                             comboArrays.stringArray,
636
                                                                                             comboArrays.objectArray));
637

    
638
        if (comboArrays.stringArray != nullptr) {
639
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
640
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
641
        }
642
        if (argumentJArray != nullptr) {
643
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(argumentJArray);
644
        }
645
        if (result) {
646
            jclass atomicValueClass = lookForClass(SaxonProcessor::sxn_environ->env,
647
                                                   "net/sf/saxon/s9api/XdmAtomicValue");
648
            jclass nodeClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmNode");
649
            jclass functionItemClass = lookForClass(SaxonProcessor::sxn_environ->env,
650
                                                    "net/sf/saxon/s9api/XdmFunctionItem");
651
            XdmValue *value = nullptr;
652
            XdmItem *xdmItem = nullptr;
653

    
654

    
655
            if (SaxonProcessor::sxn_environ->env->IsInstanceOf(result, atomicValueClass) == JNI_TRUE) {
656
                xdmItem = new XdmAtomicValue(result);
657
                SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
658
                return xdmItem;
659
            } else if (SaxonProcessor::sxn_environ->env->IsInstanceOf(result, nodeClass) == JNI_TRUE) {
660
                xdmItem = new XdmNode(result);
661
                SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
662
                return xdmItem;
663

    
664
            } else if (SaxonProcessor::sxn_environ->env->IsInstanceOf(result, functionItemClass) == JNI_TRUE) {
665
                xdmItem = new XdmFunctionItem(result);
666
                SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
667
                return xdmItem;
668
            } else {
669
                value = new XdmValue(result, true);
670
                SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
671
                return value;
672
            }
673
            value = new XdmValue();
674
            value->addUnderlyingValue(result);
675
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
676
            return value;
677
        }
678
    }
679
    return nullptr;
680

    
681
}
682

    
683

    
684
void XsltExecutable::callTemplateReturningFile(const char *templateName, const char *outfile) {
685

    
686

    
687
    static jmethodID ctmID = nullptr;
688

    
689
    if(ctmID == nullptr) {
690
        ctmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
691
                                                                        "callTemplateReturningFile",
692
                                                                        "(Ljava/lang/String;Lnet/sf/saxon/s9api/XsltExecutable;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)V");
693
    }
694
    if (!ctmID) {
695
        std::cerr << "Error: " << getDllname() << "callTemplateReturningFile" << " not found\n"
696
                  << std::endl;
697

    
698
    } else {
699
        JParameters comboArrays;
700
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
701
        SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, ctmID,
702
                                                                 SaxonProcessor::sxn_environ->env->NewStringUTF(
703
                                                                         cwdXE.c_str()),
704
                                                                 executableObject,
705
                                                                 (templateName != nullptr
706
                                                                  ? SaxonProcessor::sxn_environ->env->NewStringUTF(
707
                                                                                 templateName) : nullptr),
708
                                                                 (outfile != nullptr
709
                                                                  ? SaxonProcessor::sxn_environ->env->NewStringUTF(
710
                                                                                 outfile) : nullptr),
711
                                                                 comboArrays.stringArray, comboArrays.objectArray);
712
        if (comboArrays.stringArray != nullptr) {
713
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
714
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
715
        }
716

    
717

    
718
    }
719

    
720
}
721

    
722

    
723
const char *XsltExecutable::callTemplateReturningString(const char *templateName) {
724

    
725

    
726
    jmethodID ctsmID = nullptr;
727

    
728
    if(ctsmID == nullptr) {
729
        ctsmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
730
                                                                        "callTemplateReturningString",
731
                                                                        "(Ljava/lang/String;Lnet/sf/saxon/s9api/XsltExecutable;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)[B");
732
    }
733
    if (!ctsmID) {
734
        std::cerr << "Error: " << getDllname() << "callTemplateReturningString" << " not found\n"
735
                  << std::endl;
736

    
737
    } else {
738
        JParameters comboArrays;
739
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
740

    
741

    
742
        jbyteArray result = nullptr;
743
        jobject obj = (jobject) (SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, ctsmID,
744
                                                                                          SaxonProcessor::sxn_environ->env->NewStringUTF(
745
                                                                                                  cwdXE.c_str()),
746
                                                                                          executableObject,
747
                                                                                          (templateName != nullptr
748
                                                                                           ? SaxonProcessor::sxn_environ->env->NewStringUTF(
749
                                                                                                          templateName)
750
                                                                                           : nullptr),
751
                                                                                          comboArrays.stringArray,
752
                                                                                          comboArrays.objectArray));
753
        if (obj) {
754
            result = (jbyteArray) obj;
755
        }
756
        if (comboArrays.stringArray != nullptr) {
757
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
758
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
759
        }
760
        if (result) {
761
            jboolean isCopy = false;
762
            jbyte* b = SaxonProcessor::sxn_environ->env->GetByteArrayElements(result, &isCopy);
763
            jsize num_bytes = SaxonProcessor::sxn_environ->env->GetArrayLength(result);
764

    
765
            const char *str = new char[num_bytes];
766
            memcpy ((void *) str, b , num_bytes );
767

    
768
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(obj);
769
            return str;
770
        }
771
    }
772
    return nullptr;
773

    
774

    
775
}
776

    
777
XdmValue *XsltExecutable::callTemplateReturningValue(const char *templateName) {
778

    
779

    
780
    static jmethodID ctsvmID = nullptr;
781
    if (ctsvmID == nullptr) {
782
        ctsvmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
783
                                                                                 "callTemplateReturningValue",
784
                                                                                 "(Ljava/lang/String;Lnet/sf/saxon/s9api/XsltExecutable;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XdmValue;");
785
    }
786
    if (!ctsvmID) {
787
        std::cerr << "Error: " << getDllname() << "callTemplateReturningValue" << " not found\n"
788
                  << std::endl;
789

    
790
    } else {
791
        JParameters comboArrays;
792
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
793

    
794

    
795
        jstring result = nullptr;
796
        jobject obj = (jobject) (SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, ctsvmID,
797
                                                                                          SaxonProcessor::sxn_environ->env->NewStringUTF(
798
                                                                                                  cwdXE.c_str()),
799
                                                                                          executableObject,
800
                                                                                          (templateName != nullptr
801
                                                                                           ? SaxonProcessor::sxn_environ->env->NewStringUTF(
802
                                                                                                          templateName)
803
                                                                                           : nullptr),
804
                                                                                          comboArrays.stringArray,
805
                                                                                          comboArrays.objectArray));
806
        if (obj) {
807
            result = (jstring) obj;
808
        }
809
        if (comboArrays.stringArray != nullptr) {
810
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
811
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
812
        }
813
        if (result) {
814
            jclass atomicValueClass = lookForClass(SaxonProcessor::sxn_environ->env,
815
                                                   "net/sf/saxon/s9api/XdmAtomicValue");
816
            jclass nodeClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmNode");
817
            jclass functionItemClass = lookForClass(SaxonProcessor::sxn_environ->env,
818
                                                    "net/sf/saxon/s9api/XdmFunctionItem");
819
            XdmValue *value = nullptr;
820

    
821
            XdmItem *xdmItem = nullptr;
822
            if (SaxonProcessor::sxn_environ->env->IsInstanceOf(result, atomicValueClass) == JNI_TRUE) {
823
                xdmItem = new XdmAtomicValue(result);
824
                SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
825
                return xdmItem;
826

    
827
            } else if (SaxonProcessor::sxn_environ->env->IsInstanceOf(result, nodeClass) == JNI_TRUE) {
828
                xdmItem = new XdmNode(result);
829
                SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
830
                return xdmItem;
831
            } else if (SaxonProcessor::sxn_environ->env->IsInstanceOf(result, functionItemClass) == JNI_TRUE) {
832
                xdmItem = new XdmFunctionItem(result);
833
                SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
834
                return xdmItem;
835
            } else {
836
                value = new XdmValue(result, true);
837
                SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
838
                return value;
839
            }
840
            value = new XdmValue();
841
            value->addUnderlyingValue(result);
842
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
843
            return value;
844
        }
845
    }
846
    return nullptr;
847
}
848

    
849

    
850
XdmValue *XsltExecutable::transformFileToValue(const char *sourcefile) {
851

    
852
    if (sourcefile == nullptr) {
853

    
854
        return nullptr;
855
    }
856

    
857

    
858
    static jmethodID tfvMID = nullptr;
859

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

    
869
    } else {
870
        JParameters comboArrays;
871
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
872

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

    
899

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

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

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

    
929
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
930
            return value;
931
        }
932
    }
933
    return nullptr;
934

    
935
}
936

    
937

    
938
void XsltExecutable::transformFileToFile(const char *source, const char *outputfile) {
939

    
940

    
941
    static jmethodID tffMID = nullptr;
942

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

    
952
    } else {
953
        JParameters comboArrays;
954
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
955

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

    
972
}
973

    
974

    
975
void XsltExecutable::setupXslMessage(bool create, const char * filename) {
976
    if (create) {
977

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

    
988
        }
989

    
990
        if (filename == nullptr) {
991
            saxonMessageListenerObj = (jobject)SaxonProcessor::sxn_environ->env->NewObject(messageListenerClass, messageID,
992
                                                                                           SaxonProcessor::sxn_environ->env->NewStringUTF("-:on"));
993
            //setProperty("m", "on");
994
        } else {
995
            saxonMessageListenerObj = (jobject)SaxonProcessor::sxn_environ->env->NewObject(messageListenerClass, messageID,
996
                                                                                           SaxonProcessor::sxn_environ->env->NewStringUTF(filename));
997
        }
998
    } else {
999
        setProperty("m", "off");
1000
    }
1001

    
1002

    
1003
}
1004

    
1005
XdmValue * XsltExecutable::getXslMessages(){
1006

    
1007
    if(saxonMessageListenerObj) {
1008
        static jmethodID getmessageID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(messageListenerClass,
1009
                                                                                                  "getXslMessages",
1010
                                                                                                  "()[Lnet/sf/saxon/s9api/XdmNode;");
1011
        if (!getmessageID) {
1012
            std::cerr << "Error: " << getDllname() << ".getXslMessages" << " not found\n"
1013
                      << std::endl;
1014

    
1015
        } else {
1016
            jobjectArray results = (jobjectArray) (
1017
                    SaxonProcessor::sxn_environ->env->CallObjectMethod(saxonMessageListenerObj, getmessageID));
1018
            int sizex = SaxonProcessor::sxn_environ->env->GetArrayLength(results);
1019

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

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

    
1034

    
1035
}
1036

    
1037

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

    
1040

    
1041
    static jmethodID tftMID = tftMID;
1042
    if (tftMID == nullptr) {
1043
        tftMID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
1044
                                                                                 "transformToString",
1045
                                                                                 "(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");
1046
    }
1047
    if (!tftMID) {
1048
        std::cerr << "Error: " << getDllname() << "transformToString" << " not found\n"
1049
                  << std::endl;
1050

    
1051
    } else {
1052
        JParameters comboArrays;
1053
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
1054

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

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

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

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

    
1089

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

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

    
1099

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

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

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

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

    
1118
const char *XsltExecutable::getErrorMessage() {
1119
    SaxonApiException *exception = SaxonProcessor::checkForExceptionCPP(SaxonProcessor::sxn_environ->env, cppClass,
1120
                                                                        nullptr);
1121
    if (exception == nullptr) { return nullptr; }
1122
    return exception->getMessage();
1123
}
1124

    
1125

    
1126
SaxonApiException *XsltExecutable::getException() {
1127
    return SaxonProcessor::checkForExceptionCPP(SaxonProcessor::sxn_environ->env, cppClass, nullptr);
1128
}
(39-39/55)