Project

Profile

Help

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

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

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
    tunnel = false;
26
    jitCompilation = false;
27
    exception = nullptr;
28

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

    
35
        cppXT = createSaxonProcessor2(SaxonProcessor::sxn_environ->env, cppClass,
36
                        "(Lnet/sf/saxon/s9api/Processor;)V", proc->proc);
37

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

    
44
        if(cppXT == nullptr) {
45
            exception = proc->checkAndCreateException(cppClass);
46
        }
47

    
48
        if(!(proc->cwd.empty()) && curr.empty()){
49
                cwdXT = proc->cwd;
50
        } else if(!curr.empty()){
51
                cwdXT = curr;
52
        }
53
}
54

    
55
    Xslt30Processor::~Xslt30Processor(){
56
            clearParameters();
57
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(cppXT);
58
            cwdXT.erase();
59
    }
60

    
61

    
62
Xslt30Processor::Xslt30Processor(const Xslt30Processor &other) {
63
        proc = other.proc;
64
        cppClass = other.cppClass;
65
        cppXT = other.cppXT;
66
    cwdXT = other.cwdXT;
67
        tunnel = other.tunnel;
68

    
69
        std::map<std::string, XdmValue*>::const_iterator paramIter = other.parameters.begin();
70
    while(paramIter != other.parameters.end())
71
    {
72

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

    
82
        jitCompilation = other.jitCompilation;
83

    
84
}
85

    
86

    
87

    
88

    
89
bool Xslt30Processor::exceptionOccurred() {
90
        return proc->exceptionOccurred() || exception != nullptr;
91
}
92

    
93
const char * Xslt30Processor::getErrorCode() {
94
 if(exception == nullptr) {return nullptr;}
95
 return exception->getErrorCode();
96
 }
97

    
98

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

    
124
XdmValue* Xslt30Processor::getParameter(const char* name) {
125
        std::map<std::string, XdmValue*>::iterator it;
126
        it = parameters.find("sparam:"+std::string(name));
127
        if (it != parameters.end())
128
          return it->second;
129
            return nullptr;
130
}
131

    
132
bool Xslt30Processor::removeParameter(const char* name) {
133
        return (bool)(parameters.erase("param:"+std::string(name)));
134
}
135

    
136
void Xslt30Processor::setJustInTimeCompilation(bool jit){
137
    jitCompilation = jit;
138
}
139

    
140

    
141
void Xslt30Processor::clearParameters(bool delValues) {
142
        if(delValues){
143
        for(std::map<std::string, XdmValue*>::iterator itr = parameters.begin(); itr != parameters.end(); itr++){
144
            XdmValue * value = itr->second;
145
            if(value != nullptr) {
146
                value->decrementRefCount();
147
#ifdef DEBUG
148
                std::cout<<"clearParameter() - XdmValue refCount="<<value->getRefCount()<<std::endl;
149
#endif
150
                if (value->getRefCount() < 1) {
151
                    delete value;
152
                }
153
            }
154
        }
155

    
156
        } else {
157
                for(std::map<std::string, XdmValue*>::iterator itr = parameters.begin(); itr != parameters.end(); itr++){
158

    
159
                        parameters.erase(itr);
160
                
161
                }
162

    
163
        }
164
        parameters.clear();
165
        
166
}
167

    
168

    
169

    
170
std::map<std::string,XdmValue*>& Xslt30Processor::getParameters(){
171
        std::map<std::string,XdmValue*>& ptr = parameters;
172
        return ptr;
173
}
174

    
175

    
176
void Xslt30Processor::exceptionClear(){
177
 if(exception != nullptr) {
178
         delete exception;
179
         exception = nullptr;
180
        SaxonProcessor::sxn_environ->env->ExceptionClear();
181
 }
182
  
183
 }
184

    
185
   void Xslt30Processor::setcwd(const char* dir){
186
    if (dir!= nullptr) {
187
        cwdXT = std::string(dir);
188
    }
189
   }
190

    
191
SaxonApiException* Xslt30Processor::getException() {
192
    return exception;
193
}
194

    
195

    
196

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

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

    
208
        } else {
209
        if(cppXT == nullptr) {
210
#if defined(DEBUG)
211
            std::cerr << "The Java Xslt30Processor object (i.e. cppXT) is NULL - Possible exception thrown" << std::endl;
212
#endif
213
            return;
214
        }
215
                
216
                SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cAndSNodemID,
217
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
218
                                                node->getUnderlyingValue(), SaxonProcessor::sxn_environ->env->NewStringUTF(filename));
219
                
220
                exception = proc->checkAndCreateException(cppClass);
221

    
222
    }
223

    
224

    
225

    
226
}
227

    
228
    void Xslt30Processor::compileFromStringAndSave(const char* stylesheetStr, const char* filename){
229
        static jmethodID cAndSStringmID = nullptr;
230
        if(cAndSStringmID == nullptr) {
231
           cAndSStringmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
232
                                        "compileFromStringAndSave",
233
                                        "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
234
        }
235
        if (!cAndSStringmID) {
236
                exception = new SaxonApiException("Error: compileFromStringAndSave function not found\n");
237

    
238
        } else {
239
        if(cppXT == nullptr) {
240
#if defined(DEBUG)
241
            std::cerr << "The Java Xslt30Processor object (i.e. cppXT) is NULL - Possible exception thrown" << std::endl;
242
#endif
243
            return;
244
        }
245
                
246
                SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cAndSStringmID,
247
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
248
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheetStr),
249
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(filename));
250
                
251
                exception = proc->checkAndCreateException(cppClass);
252

    
253
    }
254
}
255

    
256

    
257

    
258
    void Xslt30Processor::compileFromFileAndSave(const char* xslFilename, const char* filename){
259
        static jmethodID cAndFStringmID =  nullptr;
260

    
261
        if (cAndFStringmID == nullptr) {
262
            cAndFStringmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
263
                                        "compileFromFileAndSave",
264
                                        "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
265
        }
266
        if (!cAndFStringmID) {
267
                exception = new SaxonApiException("Error: compileFromFileAndSave function not found");
268

    
269
        } else {
270

    
271
        if(cppXT == nullptr) {
272
#if defined(DEBUG)
273
            std::cerr << "The Java Xslt30Processor object (i.e. cppXT) is NULL - Possible exception thrown" << std::endl;
274
#endif
275
            return;
276
        }
277
                SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cAndFStringmID,
278
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
279
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(xslFilename),SaxonProcessor::sxn_environ->env->NewStringUTF(filename));
280

    
281
                exception = proc->checkAndCreateException(cppClass);
282

    
283

    
284
     }
285
}
286

    
287
XsltExecutable * Xslt30Processor::compileFromString(const char* stylesheetStr) {
288
        static jmethodID cStringmID = nullptr;
289
        if (cStringmID == nullptr) {
290
                        cStringmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
291
                                        "compileFromString",
292
                                        "(Ljava/lang/String;Ljava/lang/String;Z[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XsltExecutable;");
293
        }
294
                                        
295
        if (cStringmID== nullptr) {
296
                exception = new SaxonApiException(strcat(getDllname(), ".compileFromString funtion not found"));
297
                return nullptr;
298

    
299
        } else {
300
        if(cppXT == nullptr) {
301
#if defined(DEBUG)
302
            std::cerr << "The Java Xslt30Processor object (i.e. cppXT) is NULL - Possible exception thrown" << std::endl;
303
#endif
304
            return nullptr;
305
        }
306
                JParameters comboArrays;
307
                comboArrays = SaxonProcessor::createParameterJArray2(parameters);
308
                jobject executableObject = (jobject)(
309
                                SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cStringmID,
310
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
311
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheetStr), jitCompilation, comboArrays.stringArray, comboArrays.objectArray));
312
                if (!executableObject) {
313
                        exception = proc->checkAndCreateException(cppClass);
314
                        return nullptr;
315
                }
316
                if (comboArrays.stringArray != nullptr) {
317
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
318
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
319
                }
320

    
321
                jobject obj = SaxonProcessor::sxn_environ->env->NewGlobalRef(executableObject);
322
        XsltExecutable * executable = new XsltExecutable(obj, cwdXT);
323
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(executableObject);
324
                return executable;
325
        }
326

    
327
}
328

    
329
XsltExecutable * Xslt30Processor::compileFromXdmNode(XdmNode * node) {
330
        static jmethodID cNodemID = nullptr;
331
    if(cNodemID == nullptr) {
332
                        cNodemID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,"compileFromXdmNode",
333
                        "(Ljava/lang/String;Ljava/lang/Object;Z[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XsltExecutable;");
334
        }
335
        if (!cNodemID) {
336
                std::cerr << "Error: "<< getDllname() << ".compileFromXdmNode"
337
                                << " not found\n" << std::endl;
338
                return nullptr;
339

    
340
        } else {
341
            if(node == nullptr) {
342
                exception = new SaxonApiException("Error in compileFromXdmNode - node argument is NULL");
343
                return nullptr;
344
            }
345
        if(cppXT == nullptr) {
346
#if defined(DEBUG)
347
            std::cerr << "The Java Xslt30Processor object (i.e. cppXT) is NULL - Possible exception thrown" << std::endl;
348
#endif
349
            return nullptr;
350
        }
351
                JParameters comboArrays;
352
                comboArrays = SaxonProcessor::createParameterJArray2(parameters);
353
                jobject executableObject = (jobject)(
354
                                SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cNodemID,
355
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
356
                                                node->getUnderlyingValue(), jitCompilation, comboArrays.stringArray, comboArrays.objectArray));
357
                if (!executableObject) {
358
                        exception = proc->checkAndCreateException(cppClass);
359
                        return nullptr;
360
                }
361
                if (comboArrays.stringArray != nullptr) {
362
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
363
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
364
                }
365

    
366
        XsltExecutable * executable = new XsltExecutable(SaxonProcessor::sxn_environ->env->NewGlobalRef(executableObject));
367
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(executableObject);
368
                return executable;
369
        }
370

    
371
}
372

    
373
XsltExecutable * Xslt30Processor::compileFromAssociatedFile(const char* source) {
374
        static jmethodID cFilemID = nullptr;
375
    if(cFilemID == nullptr) {
376
            cFilemID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
377
                                        "compileFromAssociatedFile",
378
                                        "(Ljava/lang/String;Ljava/lang/String;Z;[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XsltExecutable;");
379
        }
380
        if (!cFilemID) {
381
                std::cerr << "Error: "<<getDllname() << ".compileFromAssociatedFile"
382
                                << " not found\n" << std::endl;
383
                return nullptr;
384

    
385
        } else {
386
                
387
                if(source == nullptr) {
388
                        exception = new SaxonApiException("Error in compileFromFile method - The Stylesheet file is NULL");
389
                        return nullptr;
390
                }
391
        if(cppXT == nullptr) {
392
#if defined(DEBUG)
393
            std::cerr << "The Java Xslt30Processor object (i.e. cppXT) is NULL - Possible exception thrown" << std::endl;
394
#endif
395
            return nullptr;
396
        }
397
                JParameters comboArrays;
398
                comboArrays = SaxonProcessor::createParameterJArray2(parameters);
399
                jobject executableObject = (jobject)(
400
                                SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cFilemID,
401
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
402
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(source), jitCompilation, comboArrays.stringArray, comboArrays.objectArray));
403
                if (!executableObject) {
404
                        exception = proc->checkAndCreateException(cppClass);
405
                     return nullptr;
406
                }
407
                if (comboArrays.stringArray != nullptr) {
408
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
409
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
410
                }
411

    
412
        XsltExecutable * executable = new XsltExecutable(SaxonProcessor::sxn_environ->env->NewGlobalRef(executableObject));
413
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(executableObject);
414
                return executable;
415
        }
416

    
417
}
418

    
419

    
420
XsltExecutable * Xslt30Processor::compileFromFile(const char* stylesheet) {
421
        static jmethodID cFilemID = nullptr;
422
        if(cFilemID == nullptr) {
423
            cFilemID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
424
                                        "compileFromFile",
425
                                        "(Ljava/lang/String;Ljava/lang/String;Z[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XsltExecutable;");
426
        }
427

    
428
        if (!cFilemID) {
429
                std::cerr << "Error: "<<getDllname() << ".compileFromFile"
430
                                << " not found\n" << std::endl;
431
        std::cerr<<"cp0 -testCatalog"<<std::endl;
432
                return nullptr;
433

    
434
        } else {
435
        if (stylesheet == nullptr) {
436
            exception = new SaxonApiException("Error in compileFromFile method - The Stylesheet file is nullptr");
437
            return nullptr;
438
        }
439
        if(cppXT == nullptr) {
440
#if defined(DEBUG)
441
            std::cerr << "The Java Xslt30Processor object (i.e. cppXT) is NULL - Possible exception thrown" << std::endl;
442
#endif
443

    
444
            return nullptr;
445
        }
446

    
447
        JParameters comboArrays;
448
        comboArrays = SaxonProcessor::createParameterJArray2(parameters);
449
        jobject executableObject = (jobject) (
450
                SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cFilemID,
451
                                                                   SaxonProcessor::sxn_environ->env->NewStringUTF(
452
                                                                           cwdXT.c_str()),
453
                                                                   SaxonProcessor::sxn_environ->env->NewStringUTF(
454
                                                                           stylesheet), jitCompilation,
455
                                                                   comboArrays.stringArray, comboArrays.objectArray));
456
        if (!executableObject) {
457
            exception = proc->checkAndCreateException(cppClass);
458
            return nullptr;
459

    
460
        }
461
        if (comboArrays.stringArray != nullptr) {
462
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
463
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
464
        }
465

    
466
        XsltExecutable *executable;
467
        executable = new XsltExecutable(SaxonProcessor::sxn_environ->env->NewGlobalRef(executableObject), cwdXT);
468
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(executableObject);
469

    
470
        return executable;
471

    
472
        }
473

    
474
}
475

    
476

    
477

    
478

    
479
XdmValue * Xslt30Processor::transformFileToValue(const char* sourcefile,
480
                const char* stylesheetfile) {
481

    
482
        if(exceptionOccurred()) {
483
                //Possible error detected in the compile phase. Processor not in a clean state.
484
                //Require clearing exception.
485
                return nullptr;
486
        }
487

    
488
        if(sourcefile == nullptr && stylesheetfile == nullptr){
489
        
490
                return nullptr;
491
        }
492

    
493

    
494
        static jmethodID mtvID = nullptr;
495

    
496
        if(mtvID == nullptr) {
497
                        mtvID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
498
                                        "transformToValue",
499
                                        "(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;");
500
        }
501
        if (!mtvID) {
502
        std::cerr<<"Error: "<<getDllname()<<".transformtoValue function not found"<<std::endl;
503

    
504
        } else {
505
        if(cppXT == nullptr) {
506
#if defined(DEBUG)
507
            std::cerr << "The Java Xslt30Processor object (i.e. cppXT) is NULL - Possible exception thrown" << std::endl;
508
#endif
509
            return nullptr;
510
        }
511
            JParameters comboArrays;
512
                comboArrays = SaxonProcessor::createParameterJArray2(parameters);
513

    
514
                jobject result = (jobject)(
515
                                SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, mtvID,
516
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()), cppXT, nullptr,
517
                                                (sourcefile != nullptr ?SaxonProcessor::sxn_environ->env->NewStringUTF(sourcefile) : nullptr),
518
                                                (stylesheetfile != nullptr ?
519
                                                                SaxonProcessor::sxn_environ->env->NewStringUTF(
520
                                                                                stylesheetfile) :
521
                                                                nullptr), comboArrays.stringArray, comboArrays.objectArray));
522
                if (comboArrays.stringArray != nullptr) {
523
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
524
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
525
                }
526
                if (result) {
527
                        jclass atomicValueClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmAtomicValue");
528
                          jclass nodeClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmNode");
529
                          jclass functionItemClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmFunctionItem");
530
                        XdmValue * value = nullptr;
531
                          XdmItem * xdmItem = nullptr;
532

    
533

    
534
                                  if(SaxonProcessor::sxn_environ->env->IsInstanceOf(result, atomicValueClass)           == JNI_TRUE) {
535
                                          xdmItem = new XdmAtomicValue(SaxonProcessor::sxn_environ->env->NewGlobalRef(result));
536
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
537
                        return xdmItem;
538

    
539
                                  } else if(SaxonProcessor::sxn_environ->env->IsInstanceOf(result, nodeClass)           == JNI_TRUE) {
540
                                          xdmItem = new XdmNode(SaxonProcessor::sxn_environ->env->NewGlobalRef(result));
541
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
542
                        return xdmItem;
543
#if CVERSION_API_NO >= 123
544
                                  } else if (SaxonProcessor::sxn_environ->env->IsInstanceOf(result, functionItemClass)           == JNI_TRUE) {
545
                        xdmItem =  new XdmFunctionItem(SaxonProcessor::sxn_environ->env->NewGlobalRef(result));
546
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
547
                        return xdmItem;
548
#endif
549
                                  } else {
550
                                        value = new XdmValue(result, true);
551
                                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
552
                                        return value;
553
                                }
554
                                value = new XdmValue();
555
                      value->addUnderlyingValue(result);
556

    
557
                          SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
558
                          return value;
559
                }else {
560
        
561
                        exception = proc->checkAndCreateException(cppClass);
562
                           
563
                     }
564
        }
565
        return nullptr;
566

    
567
}
568

    
569

    
570
void Xslt30Processor::transformFileToFile(const char* source,
571
                const char* stylesheet, const char* outputfile) {
572

    
573
        if(exceptionOccurred()) {
574
                //Possible error detected in the compile phase. Processor not in a clean state.
575
                //Require clearing exception.
576
                return;        
577
        }
578
        if(stylesheet==nullptr){
579
                std::cerr<< "Error: stylesheet has not been set."<<std::endl;
580
                return;
581
        }
582
        //
583
        static jmethodID mtfID = nullptr;
584

    
585
        if(mtfID == nullptr) {
586
                mtfID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
587
                                        "transformToFile",
588
                                        "(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");
589
        }
590
        if (!mtfID) {
591
        std::cerr<<"Error: "<<getDllname()<<".transformToFile function not found"<<std::endl;
592

    
593
        } else {
594
        if(cppXT == nullptr) {
595
#if defined(DEBUG)
596
            std::cerr << "The Java Xslt30Processor object (i.e. cppXT) is NULL - Possible exception thrown" << std::endl;
597
#endif
598
            return;
599
        }
600
            JParameters comboArrays;
601
        comboArrays = SaxonProcessor::createParameterJArray2(parameters);
602

    
603
                SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, mtfID,
604
                                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()), cppXT, nullptr,
605
                                                                (source != nullptr ? SaxonProcessor::sxn_environ->env->NewStringUTF(source) : nullptr),
606
                                                                SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheet),        (outputfile != nullptr ? SaxonProcessor::sxn_environ->env->NewStringUTF(outputfile) :nullptr),
607
                                                                comboArrays.stringArray, comboArrays.objectArray);
608
                if (comboArrays.stringArray!= nullptr) {
609
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
610
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
611
                }
612
                }
613
                exception = proc->checkAndCreateException(cppClass);
614
        }
615

    
616

    
617
const char * Xslt30Processor::transformFileToString(const char* source,
618
                const char* stylesheet) {
619

    
620
        if(exceptionOccurred()) {
621
                //Possible error detected in the compile phase. Processor not in a clean state.
622
                //Require clearing exception.
623
                return nullptr;
624
        }
625
        if(source == nullptr && stylesheet == nullptr){
626
                std::cerr<< "Error: nullptr file name found in transformFiletoString."<<std::endl;
627
                return nullptr;
628
        }
629

    
630
        static jmethodID mtsID =  nullptr;
631

    
632
        if(mtsID == nullptr) {
633
                        mtsID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
634
                                        "transformToString",
635
                                        "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;");
636
        }
637
        if (!mtsID) {
638
        std::cerr<<"Error: "<<getDllname()<<".transformFileToString not found"<<std::endl;
639

    
640
        } else {
641
        if(cppXT == nullptr) {
642
#if defined(DEBUG)
643
            std::cerr << "The Java Xslt30Processor object (i.e. cppXT) is NULL - Possible exception thrown" << std::endl;
644
#endif
645
            return nullptr;
646
        }
647
    JParameters comboArrays;
648
    comboArrays = SaxonProcessor::createParameterJArray2(parameters);
649

    
650
        jstring result = nullptr;
651
        jobject obj = SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, mtsID,
652
                                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()), cppXT, nullptr,
653
                                                (source != nullptr ? SaxonProcessor::sxn_environ->env->NewStringUTF(
654
                                                                                                source) : nullptr),
655
                                                                (stylesheet != nullptr ? SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheet) : nullptr),
656
                                                                comboArrays.stringArray, comboArrays.objectArray);
657
    if (comboArrays.stringArray!= nullptr) {
658
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
659
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
660
    }
661
        if(obj) {
662
                        result = (jstring)obj;
663
        }
664

    
665
        if (result) {
666
                        const char * str = SaxonProcessor::sxn_environ->env->GetStringUTFChars(result,
667
                                        nullptr);
668
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(obj);
669
                        return str;
670
                } else  {
671
                        exception =proc->checkAndCreateException(cppClass);
672
                           
673
                     }
674
        }
675
        return nullptr;
676
}
677

    
678

    
679

    
680
const char * Xslt30Processor::getErrorMessage(){
681
         if(exception == nullptr) {return nullptr;}
682
         return exception->getMessage();
683
 }
684

    
(37-37/55)