Project

Profile

Help

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

he / src / main / c / Saxon.C.API / Xslt30Processor.cpp @ a69dd173

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

    
4
#include "Xslt30Processor.h"
5
#include "XdmValue.h"
6
#include "XdmItem.h"
7
#include "XdmNode.h"
8
#include "XdmAtomicValue.h"
9
#include "XdmFunctionItem.h"
10
#include "XsltExecutable.h"
11
#ifdef DEBUG
12
#include <typeinfo> //used for testing only
13
#endif
14

    
15
Xslt30Processor::Xslt30Processor() {
16

    
17
        SaxonProcessor *p = new SaxonProcessor(false);
18
        Xslt30Processor(p, "");
19

    
20
}
21

    
22
Xslt30Processor::Xslt30Processor(SaxonProcessor * p, std::string curr) {
23

    
24
        proc = p;
25

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

    
32
        cppXT = createSaxonProcessor2(SaxonProcessor::sxn_environ->env, cppClass,
33
                        "(Lnet/sf/saxon/s9api/Processor;)V", proc->proc);
34

    
35
#ifdef DEBUG
36
        jmethodID debugMID = SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass, "setDebugMode", "(Z)V");
37
        SaxonProcessor::sxn_environ->env->CallStaticVoidMethod(cppClass, debugMID, (jboolean)true);
38
    
39
#endif
40
        tunnel = false;
41
        jitCompilation = false;
42
        exception = nullptr;
43

    
44
        if(!(proc->cwd.empty()) && curr.empty()){
45
                cwdXT = proc->cwd;
46
        } else if(!curr.empty()){
47
                cwdXT = curr;
48
        }
49
}
50

    
51
    Xslt30Processor::~Xslt30Processor(){
52
            clearParameters();
53
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(cppXT);
54
            cwdXT.erase();
55
    }
56

    
57

    
58
Xslt30Processor::Xslt30Processor(const Xslt30Processor &other) {
59
        proc = other.proc;
60
        cppClass = other.cppClass;
61
        cppXT = other.cppXT;
62
    cwdXT = other.cwdXT;
63
        tunnel = other.tunnel;
64

    
65
        std::map<std::string, XdmValue*>::const_iterator paramIter = other.parameters.begin();
66
    while(paramIter != other.parameters.end())
67
    {
68

    
69
       XdmValue * valuei = paramIter->second;
70
       if(valuei == nullptr) {
71
                     //std::cerr<<"Error in Xslt30Processor copy constructor"<<std::endl;
72
       } else {
73
            parameters[paramIter->first] = new XdmValue(*(valuei));
74
       }
75
       paramIter++;
76
    }
77

    
78
        jitCompilation = other.jitCompilation;
79

    
80
}
81

    
82

    
83

    
84

    
85
bool Xslt30Processor::exceptionOccurred() {
86
        return proc->exceptionOccurred();
87
}
88

    
89
const char * Xslt30Processor::getErrorCode() {
90
 if(exception == nullptr) {return nullptr;}
91
 return exception->getErrorCode();
92
 }
93

    
94

    
95
void Xslt30Processor::setParameter(const char* name, XdmValue * value) {
96
        if(value != nullptr && name != nullptr){
97
                value->incrementRefCount();
98
                int s = parameters.size();
99
                std::string skey = ("sparam:"+std::string(name));
100
                parameters[skey] = value;
101
                if(s == parameters.size()) {
102
            std::map<std::string, XdmValue*>::iterator it;
103
            it = parameters.find(skey);
104
            if (it != parameters.end()) {
105
                XdmValue * valuei = it->second;
106
                valuei->decrementRefCount();
107
                if(valuei != nullptr && valuei->getRefCount() < 1){
108
                    delete value;
109
                }
110
                parameters.erase(skey);
111
                parameters[skey] = value;
112
            }
113
                }
114
         }
115
}
116

    
117
XdmValue* Xslt30Processor::getParameter(const char* name) {
118
        std::map<std::string, XdmValue*>::iterator it;
119
        it = parameters.find("sparam:"+std::string(name));
120
        if (it != parameters.end())
121
          return it->second;
122
            return nullptr;
123
}
124

    
125
bool Xslt30Processor::removeParameter(const char* name) {
126
        return (bool)(parameters.erase("param:"+std::string(name)));
127
}
128

    
129
void Xslt30Processor::setJustInTimeCompilation(bool jit){
130
    jitCompilation = jit;
131
}
132

    
133

    
134
void Xslt30Processor::clearParameters(bool delValues) {
135

    
136
        if(delValues){
137
                       for(std::map<std::string, XdmValue*>::iterator itr = parameters.begin(); itr != parameters.end(); itr++){
138
                        
139
                        XdmValue * value = itr->second;
140
                        value->decrementRefCount();
141
#ifdef DEBUG
142
                        std::cout<<"clearParameter() - XdmValue refCount="<<value->getRefCount()<<std::endl;
143
#endif
144
                        if(value != nullptr && value->getRefCount() < 1){
145
                                delete value;
146
                        }
147
                }
148

    
149
        } else {
150
for(std::map<std::string, XdmValue*>::iterator itr = parameters.begin(); itr != parameters.end(); itr++){
151
                
152
                        XdmValue * value = itr->second;
153
                        value->decrementRefCount();
154
                
155
                }
156

    
157
        }
158
        parameters.clear();
159

    
160
        
161
}
162

    
163

    
164

    
165
std::map<std::string,XdmValue*>& Xslt30Processor::getParameters(){
166
        std::map<std::string,XdmValue*>& ptr = parameters;
167
        return ptr;
168
}
169

    
170

    
171
void Xslt30Processor::exceptionClear(){
172
 if(exception != nullptr) {
173
         delete exception;
174
         exception = nullptr;
175
        SaxonProcessor::sxn_environ->env->ExceptionClear();
176
 }
177
  
178
 }
179

    
180
   void Xslt30Processor::setcwd(const char* dir){
181
    if (dir!= nullptr) {
182
        cwdXT = std::string(dir);
183
    }
184
   }
185

    
186
SaxonApiException* Xslt30Processor::getException() {
187
    return exception;
188
}
189

    
190

    
191

    
192
void Xslt30Processor::compileFromXdmNodeAndSave(XdmNode * node, const char* filename) {
193
        static jmethodID cAndSNodemID = nullptr;
194

    
195
        if(cAndSNodemID == nullptr) {
196
                        cAndSNodemID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
197
                                        "compileFromXdmNodeAndSave",
198
                                        "(Ljava/lang/String;Ljava/lang/Object;Ljava/lang/String;)V");
199
        }
200
        if (!cAndSNodemID) {
201
                std::cerr << "Error: "<<getDllname() << ".compileFromStringAndSave"
202
                                << " not found\n" << std::endl;
203

    
204
        } else {
205

    
206
                
207
                SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cAndSNodemID,
208
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
209
                                                node->getUnderlyingValue(), SaxonProcessor::sxn_environ->env->NewStringUTF(filename));
210
                
211
                exception = proc->checkAndCreateException(cppClass);
212

    
213
    }
214

    
215

    
216

    
217
}
218

    
219
    void Xslt30Processor::compileFromStringAndSave(const char* stylesheetStr, const char* filename){
220
        static jmethodID cAndSStringmID = nullptr;
221
        if(cAndSStringmID == nullptr) {
222
           cAndSStringmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
223
                                        "compileFromStringAndSave",
224
                                        "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
225
        }
226
        if (!cAndSStringmID) {
227
                std::cerr << "Error: "<<getDllname() << ".compileFromStringAndSave"
228
                                << " not found\n" << std::endl;
229

    
230
        } else {
231

    
232
                
233
                SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cAndSStringmID,
234
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
235
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheetStr),
236
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(filename));
237
                
238
                exception = proc->checkAndCreateException(cppClass);
239

    
240
    }
241
}
242

    
243

    
244

    
245
    void Xslt30Processor::compileFromFileAndSave(const char* xslFilename, const char* filename){
246
        static jmethodID cAndFStringmID =  nullptr;
247

    
248
        if (cAndFStringmID == nullptr) {
249
            cAndFStringmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
250
                                        "compileFromFileAndSave",
251
                                        "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
252
        }
253
        if (!cAndFStringmID) {
254
                std::cerr << "Error: "<<getDllname() << ".compileFromFileAndSave"
255
                                << " not found\n" << std::endl;
256

    
257
        } else {
258

    
259
                
260
                SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cAndFStringmID,
261
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
262
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(xslFilename),SaxonProcessor::sxn_environ->env->NewStringUTF(filename));
263

    
264
                exception = proc->checkAndCreateException(cppClass);
265

    
266

    
267
     }
268
}
269

    
270
XsltExecutable * Xslt30Processor::compileFromString(const char* stylesheetStr) {
271
        static jmethodID cStringmID = nullptr;
272
        if (cStringmID == nullptr) {
273
                        cStringmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
274
                                        "compileFromString",
275
                                        "(Ljava/lang/String;Ljava/lang/String;Z[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XsltExecutable;");
276
        }
277
                                        
278
        if (cStringmID== nullptr) {
279
                std::cerr << "Error: "<<getDllname() << ".compileFromString"
280
                                << " not found\n" << std::endl;
281
                return nullptr;
282

    
283
        } else {
284

    
285
                JParameters comboArrays;
286
                comboArrays = SaxonProcessor::createParameterJArray2(parameters);
287
                jobject executableObject = (jobject)(
288
                                SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cStringmID,
289
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
290
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheetStr), jitCompilation, comboArrays.stringArray, comboArrays.objectArray));
291
                if (!executableObject) {
292
                        exception = proc->checkAndCreateException(cppClass);
293
                        return nullptr;
294
                }
295
                if (comboArrays.stringArray != nullptr) {
296
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
297
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
298
                }
299

    
300
                jobject obj = SaxonProcessor::sxn_environ->env->NewGlobalRef(executableObject);
301
        XsltExecutable * executable = new XsltExecutable(obj, cwdXT);
302
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(executableObject);
303
                return executable;
304
        }
305

    
306
}
307

    
308
XsltExecutable * Xslt30Processor::compileFromXdmNode(XdmNode * node) {
309
        static jmethodID cNodemID = nullptr;
310
    if(cNodemID == nullptr) {
311
                        cNodemID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,"compileFromXdmNode",
312
                        "(Ljava/lang/String;Ljava/lang/Object;Z[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XsltExecutable;");
313
        }
314
        if (!cNodemID) {
315
                std::cerr << "Error: "<< getDllname() << ".compileFromXdmNode"
316
                                << " not found\n" << std::endl;
317
                return nullptr;
318

    
319
        } else {
320
                JParameters comboArrays;
321
                comboArrays = SaxonProcessor::createParameterJArray2(parameters);
322
                jobject executableObject = (jobject)(
323
                                SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cNodemID,
324
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
325
                                                node->getUnderlyingValue(), jitCompilation, comboArrays.stringArray, comboArrays.objectArray));
326
                if (!executableObject) {
327
                        exception = proc->checkAndCreateException(cppClass);
328
                        return nullptr;
329
                }
330
                if (comboArrays.stringArray != nullptr) {
331
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
332
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
333
                }
334

    
335
        XsltExecutable * executable = new XsltExecutable(SaxonProcessor::sxn_environ->env->NewGlobalRef(executableObject));
336
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(executableObject);
337
                return executable;
338
        }
339

    
340
}
341

    
342
XsltExecutable * Xslt30Processor::compileFromAssociatedFile(const char* source) {
343
        static jmethodID cFilemID = nullptr;
344
    if(cFilemID == nullptr) {
345
            cFilemID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
346
                                        "compileFromAssociatedFile",
347
                                        "(Ljava/lang/String;Ljava/lang/String;Z;[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XsltExecutable;");
348
        }
349
        if (!cFilemID) {
350
                std::cerr << "Error: "<<getDllname() << ".compileFromAssociatedFile"
351
                                << " not found\n" << std::endl;
352
                return nullptr;
353

    
354
        } else {
355
                
356
                if(source == nullptr) {
357
                        std::cerr << "Error in compileFromFile method - The Stylesheet file is nullptr" <<std::endl;
358
                        return nullptr;
359
                }
360
                JParameters comboArrays;
361
                comboArrays = SaxonProcessor::createParameterJArray2(parameters);
362
                jobject executableObject = (jobject)(
363
                                SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cFilemID,
364
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
365
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(source), jitCompilation, comboArrays.stringArray, comboArrays.objectArray));
366
                if (!executableObject) {
367
                        exception = proc->checkAndCreateException(cppClass);
368
                     return nullptr;
369
                }
370
                if (comboArrays.stringArray != nullptr) {
371
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
372
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
373
                }
374

    
375
        XsltExecutable * executable = new XsltExecutable(SaxonProcessor::sxn_environ->env->NewGlobalRef(executableObject));
376
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(executableObject);
377
                return executable;
378
        }
379

    
380
}
381

    
382

    
383
XsltExecutable * Xslt30Processor::compileFromFile(const char* stylesheet) {
384
        static jmethodID cFilemID = nullptr;
385
        if(cFilemID == nullptr) {
386
            cFilemID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
387
                                        "compileFromFile",
388
                                        "(Ljava/lang/String;Ljava/lang/String;Z[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XsltExecutable;");
389
        }
390
        if (!cFilemID) {
391
                std::cerr << "Error: "<<getDllname() << ".compileFromFile"
392
                                << " not found\n" << std::endl;
393
                return nullptr;
394

    
395
        } else {
396

    
397
        if (stylesheet == nullptr) {
398
            std::cerr << "Error in compileFromFile method - The Stylesheet file is nullptr" << std::endl;
399
            return nullptr;
400
        }
401
        JParameters comboArrays;
402
        comboArrays = SaxonProcessor::createParameterJArray2(parameters);
403
        jobject executableObject = (jobject) (
404
                SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cFilemID,
405
                                                                   SaxonProcessor::sxn_environ->env->NewStringUTF(
406
                                                                           cwdXT.c_str()),
407
                                                                   SaxonProcessor::sxn_environ->env->NewStringUTF(
408
                                                                           stylesheet), jitCompilation,
409
                                                                   comboArrays.stringArray, comboArrays.objectArray));
410
        if (!executableObject) {
411
            exception = proc->checkAndCreateException(cppClass);
412
            return nullptr;
413

    
414
        }
415
        if (comboArrays.stringArray != nullptr) {
416
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
417
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
418
        }
419

    
420
        XsltExecutable *executable;
421
        executable = new XsltExecutable(SaxonProcessor::sxn_environ->env->NewGlobalRef(executableObject), cwdXT);
422
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(executableObject);
423

    
424
        return executable;
425

    
426
        }
427

    
428
}
429

    
430

    
431

    
432

    
433
XdmValue * Xslt30Processor::transformFileToValue(const char* sourcefile,
434
                const char* stylesheetfile) {
435

    
436
        if(exceptionOccurred()) {
437
                //Possible error detected in the compile phase. Processor not in a clean state.
438
                //Require clearing exception.
439
                return nullptr;
440
        }
441

    
442
        if(sourcefile == nullptr && stylesheetfile == nullptr){
443
        
444
                return nullptr;
445
        }
446

    
447

    
448
        static jmethodID mtvID = nullptr;
449

    
450
        if(mtvID == nullptr) {
451
                        mtvID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
452
                                        "transformToValue",
453
                                        "(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;)Lnet/sf/saxon/s9api/XdmValue;");
454
        }
455
        if (!mtvID) {
456
                std::cerr << "Error: "<< getDllname() << ".transformtoValue" << " not found\n"
457
                                << std::endl;
458

    
459
        } else {
460
            JParameters comboArrays;
461
                comboArrays = SaxonProcessor::createParameterJArray2(parameters);
462

    
463
                jobject result = (jobject)(
464
                                SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, mtvID,
465
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()), cppXT, nullptr,
466
                                                (sourcefile != nullptr ?SaxonProcessor::sxn_environ->env->NewStringUTF(sourcefile) : nullptr),
467
                                                (stylesheetfile != nullptr ?
468
                                                                SaxonProcessor::sxn_environ->env->NewStringUTF(
469
                                                                                stylesheetfile) :
470
                                                                nullptr), comboArrays.stringArray, comboArrays.objectArray));
471
                if (comboArrays.stringArray != nullptr) {
472
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
473
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
474
                }
475
                if (result) {
476
                        jclass atomicValueClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmAtomicValue");
477
                          jclass nodeClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmNode");
478
                          jclass functionItemClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmFunctionItem");
479
                        XdmValue * value = nullptr;
480
                          XdmItem * xdmItem = nullptr;
481

    
482

    
483
                                  if(SaxonProcessor::sxn_environ->env->IsInstanceOf(result, atomicValueClass)           == JNI_TRUE) {
484
                                          xdmItem = new XdmAtomicValue(SaxonProcessor::sxn_environ->env->NewGlobalRef(result));
485
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
486
                        return xdmItem;
487

    
488
                                  } else if(SaxonProcessor::sxn_environ->env->IsInstanceOf(result, nodeClass)           == JNI_TRUE) {
489
                                          xdmItem = new XdmNode(SaxonProcessor::sxn_environ->env->NewGlobalRef(result));
490
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
491
                        return xdmItem;
492
#if CVERSION_API_NO >= 123
493
                                  } else if (SaxonProcessor::sxn_environ->env->IsInstanceOf(result, functionItemClass)           == JNI_TRUE) {
494
                        xdmItem =  new XdmFunctionItem(SaxonProcessor::sxn_environ->env->NewGlobalRef(result));
495
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
496
                        return xdmItem;
497
#endif
498
                                  } else {
499
                                        value = new XdmValue(result, true);
500
                                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
501
                                        return value;
502
                                }
503
                                value = new XdmValue();
504
                      value->addUnderlyingValue(result);
505

    
506
                          SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
507
                          return value;
508
                }else {
509
        
510
                        exception = proc->checkAndCreateException(cppClass);
511
                           
512
                     }
513
        }
514
        return nullptr;
515

    
516
}
517

    
518

    
519
void Xslt30Processor::transformFileToFile(const char* source,
520
                const char* stylesheet, const char* outputfile) {
521

    
522
        if(exceptionOccurred()) {
523
                //Possible error detected in the compile phase. Processor not in a clean state.
524
                //Require clearing exception.
525
                return;        
526
        }
527
        if(stylesheet==nullptr){
528
                std::cerr<< "Error: stylesheet has not been set."<<std::endl;
529
                return;
530
        }
531
        //
532
        static jmethodID mtfID = nullptr;
533

    
534
        if(mtfID == nullptr) {
535
                mtfID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
536
                                        "transformToFile",
537
                                        "(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");
538
        }
539
        if (!mtfID) {
540
                std::cerr << "Error: "<<getDllname() << "transformToFile" << " not found\n"
541
                                << std::endl;
542

    
543
        } else {
544
            JParameters comboArrays;
545
        comboArrays = SaxonProcessor::createParameterJArray2(parameters);
546

    
547
                SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, mtfID,
548
                                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()), cppXT, nullptr,
549
                                                                (source != nullptr ? SaxonProcessor::sxn_environ->env->NewStringUTF(source) : nullptr),
550
                                                                SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheet),        (outputfile != nullptr ? SaxonProcessor::sxn_environ->env->NewStringUTF(outputfile) :nullptr),
551
                                                                comboArrays.stringArray, comboArrays.objectArray);
552
                if (comboArrays.stringArray!= nullptr) {
553
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
554
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
555
                }
556
                }
557
                exception = proc->checkAndCreateException(cppClass);
558
        }
559

    
560

    
561
const char * Xslt30Processor::transformFileToString(const char* source,
562
                const char* stylesheet) {
563

    
564
        if(exceptionOccurred()) {
565
                //Possible error detected in the compile phase. Processor not in a clean state.
566
                //Require clearing exception.
567
                return nullptr;
568
        }
569
        if(source == nullptr && stylesheet == nullptr){
570
                std::cerr<< "Error: nullptr file name found in transformFiletoString."<<std::endl;
571
                return nullptr;
572
        }
573

    
574
        static jmethodID mtsID =  nullptr;
575

    
576
        if(mtsID == nullptr) {
577
                        mtsID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
578
                                        "transformToString",
579
                                        "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;");
580
        }
581
        if (!mtsID) {
582
                std::cerr << "Error: "<<getDllname() << "transformFileToString" << " not found\n"
583
                                << std::endl;
584

    
585
        } else {
586
    JParameters comboArrays;
587
    comboArrays = SaxonProcessor::createParameterJArray2(parameters);
588

    
589
        jstring result = nullptr;
590
        jobject obj = SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, mtsID,
591
                                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()), cppXT, nullptr,
592
                                                (source != nullptr ? SaxonProcessor::sxn_environ->env->NewStringUTF(
593
                                                                                                source) : nullptr),
594
                                                                (stylesheet != nullptr ? SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheet) : nullptr),
595
                                                                comboArrays.stringArray, comboArrays.objectArray);
596
    if (comboArrays.stringArray!= nullptr) {
597
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
598
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
599
    }
600
        if(obj) {
601
                        result = (jstring)obj;
602
        }
603

    
604
        if (result) {
605
                        const char * str = SaxonProcessor::sxn_environ->env->GetStringUTFChars(result,
606
                                        nullptr);
607
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(obj);
608
                        return str;
609
                } else  {
610
                        exception =proc->checkAndCreateException(cppClass);
611
                           
612
                     }
613
        }
614
        return nullptr;
615
}
616

    
617

    
618

    
619
const char * Xslt30Processor::getErrorMessage(){
620
         if(exception == nullptr) {return nullptr;}
621
         return exception->getMessage();
622
 }
623

    
(37-37/55)