Project

Profile

Help

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

he / latest10 / hec / Saxon.C.API / Xslt30Processor.cpp @ 6304fb8b

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

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

    
156
        }
157
        parameters.clear();
158

    
159
        
160
}
161

    
162

    
163

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

    
169

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

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

    
185
const char* Xslt30Processor::checkException() {
186
        /*if(proc->exception == nullptr) {
187
         proc->exception = proc->checkForException(environi, cpp);
188
         }
189
         return proc->exception;*/
190
        return proc->checkException(cppXT);
191
}
192

    
193

    
194

    
195
void Xslt30Processor::compileFromXdmNodeAndSave(XdmNode * node, const char* filename) {
196
        static jmethodID cAndSNodemID = nullptr;
197

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

    
207
        } else {
208

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

    
216
    }
217

    
218

    
219

    
220
}
221

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

    
233
        } else {
234

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

    
243
    }
244
}
245

    
246

    
247

    
248
    void Xslt30Processor::compileFromFileAndSave(const char* xslFilename, const char* filename){
249
        static jmethodID cAndFStringmID =  nullptr;
250

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

    
260
        } else {
261

    
262
                
263
                SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cAndFStringmID,
264
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
265
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(xslFilename),SaxonProcessor::sxn_environ->env->NewStringUTF(filename));
266

    
267
                exception = proc->checkAndCreateException(cppClass);
268

    
269

    
270
     }
271
}
272

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

    
286
        } else {
287

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

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

    
309
}
310

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

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

    
338
        XsltExecutable * executable = new XsltExecutable(SaxonProcessor::sxn_environ->env->NewGlobalRef(executableObject));
339
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(executableObject);
340
                return executable;
341
        }
342

    
343
}
344

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

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

    
378
        XsltExecutable * executable = new XsltExecutable(SaxonProcessor::sxn_environ->env->NewGlobalRef(executableObject));
379
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(executableObject);
380
                return executable;
381
        }
382

    
383
}
384

    
385

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

    
398
        } else {
399
                
400
                if(stylesheet == nullptr) {
401
                        std::cerr << "Error in compileFromFile method - The Stylesheet file is nullptr" <<std::endl;
402
                        return;
403
                }
404
                JParameters comboArrays;
405
                comboArrays = SaxonProcessor::createParameterJArray2(parameters);
406
                jobject executableObject = (jobject)(
407
                                SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cFilemID,
408
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
409
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheet), jitCompilation, comboArrays.stringArray, comboArrays.objectArray));
410
                if (!executableObject) {
411
                        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
                return executable;
424
        }
425

    
426
}
427

    
428

    
429

    
430

    
431
XdmValue * Xslt30Processor::transformFileToValue(const char* sourcefile,
432
                const char* stylesheetfile) {
433

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

    
440
        if(sourcefile == nullptr && stylesheetfile == nullptr){
441
        
442
                return nullptr;
443
        }
444

    
445

    
446
        static jmethodID mtvID = nullptr;
447

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

    
457
        } else {
458
            JParameters comboArrays;
459
                comboArrays = SaxonProcessor::createParameterJArray2(parameters);
460

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

    
480

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

    
487
                                  } else if(SaxonProcessor::sxn_environ->env->IsInstanceOf(result, nodeClass)           == JNI_TRUE) {
488
                                          xdmItem = new XdmNode(SaxonProcessor::sxn_environ->env->NewGlobalRef(result));
489
                        xdmItem->setProcessor(proc);
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
                        xdmItem->setProcessor(proc);
496
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
497
                        return xdmItem;
498
#endif
499
                                  } else {
500
                                        value = new XdmValue(result, true);
501
                                        value->setProcessor(proc);
502
                                        for(int z=0;z<value->size();z++) {
503
                                                value->itemAt(z)->setProcessor(proc);
504
                                        }
505
                                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
506
                                        return value;
507
                                }
508
                                value = new XdmValue();
509
                                value->setProcessor(proc);
510
                      value->addUnderlyingValue(result);
511

    
512
                          SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
513
                          return value;
514
                }else {
515
        
516
                        exception = proc->checkAndCreateException(cppClass);
517
                           
518
                     }
519
        }
520
        return nullptr;
521

    
522
}
523

    
524

    
525
void Xslt30Processor::transformFileToFile(const char* source,
526
                const char* stylesheet, const char* outputfile) {
527

    
528
        if(exceptionOccurred()) {
529
                //Possible error detected in the compile phase. Processor not in a clean state.
530
                //Require clearing exception.
531
                return;        
532
        }
533
        if(stylesheet==nullptr){
534
                std::cerr<< "Error: stylesheet has not been set."<<std::endl;
535
                return;
536
        }
537
        //
538
        static jmethodID mtfID = nullptr;
539

    
540
        if(mtfID == nullptr) {
541
                mtfID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
542
                                        "transformToFile",
543
                                        "(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");
544
        }
545
        if (!mtfID) {
546
                std::cerr << "Error: "<<getDllname() << "transformToFile" << " not found\n"
547
                                << std::endl;
548

    
549
        } else {
550
            JParameters comboArrays;
551
        comboArrays = SaxonProcessor::createParameterJArray2(parameters);
552

    
553
                SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, mtfID,
554
                                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()), cppXT, nullptr,
555
                                                                (source != nullptr ? SaxonProcessor::sxn_environ->env->NewStringUTF(source) : nullptr),
556
                                                                SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheet),        (outputfile != nullptr ? SaxonProcessor::sxn_environ->env->NewStringUTF(outputfile) :nullptr),
557
                                                                comboArrays.stringArray, comboArrays.objectArray);
558
                if (comboArrays.stringArray!= nullptr) {
559
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
560
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
561
                }
562
                }
563
                exception = proc->checkAndCreateException(cppClass);
564
        }
565

    
566

    
567
const char * Xslt30Processor::transformFileToString(const char* source,
568
                const char* stylesheet) {
569

    
570
        if(exceptionOccurred()) {
571
                //Possible error detected in the compile phase. Processor not in a clean state.
572
                //Require clearing exception.
573
                return nullptr;
574
        }
575
        if(source == nullptr && stylesheet == nullptr){
576
                std::cerr<< "Error: nullptr file name found in transformFiletoString."<<std::endl;
577
                return nullptr;
578
        }
579

    
580
        static jmethodID mtsID =  nullptr;
581

    
582
        if(mtsID == nullptr) {
583
                        mtsID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
584
                                        "transformToString",
585
                                        "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;");
586
        }
587
        if (!mtsID) {
588
                std::cerr << "Error: "<<getDllname() << "transformFileToString" << " not found\n"
589
                                << std::endl;
590

    
591
        } else {
592
    JParameters comboArrays;
593
    comboArrays = SaxonProcessor::createParameterJArray2(parameters);
594

    
595
        jstring result = nullptr;
596
        jobject obj = SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, mtsID,
597
                                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()), cppXT, nullptr,
598
                                                (source != nullptr ? SaxonProcessor::sxn_environ->env->NewStringUTF(
599
                                                                                                source) : nullptr),
600
                                                                (stylesheet != nullptr ? SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheet) : nullptr),
601
                                                                comboArrays.stringArray, comboArrays.objectArray);
602
    if (comboArrays.stringArray!= nullptr) {
603
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
604
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
605
    }
606
        if(obj) {
607
                        result = (jstring)obj;
608
        }
609

    
610
        if (result) {
611
                        const char * str = SaxonProcessor::sxn_environ->env->GetStringUTFChars(result,
612
                                        nullptr);
613
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(obj);
614
                        return str;
615
                } else  {
616
                        exception =proc->checkAndCreateException(cppClass);
617
                           
618
                     }
619
        }
620
        return nullptr;
621
}
622

    
623

    
624

    
625
const char * Xslt30Processor::getErrorMessage(){
626
         if(exception == nullptr) {return nullptr;}
627
         return exception->getMessage();
628
 }
629

    
(31-31/49)