Project

Profile

Help

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

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

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
                valuei->decrementRefCount();
111
                if(valuei != nullptr && valuei->getRefCount() < 1){
112
                    delete value;
113
                }
114
                parameters.erase(skey);
115
                parameters[skey] = value;
116
            }
117
                }
118
         }
119
}
120

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

    
129
bool Xslt30Processor::removeParameter(const char* name) {
130
        return (bool)(parameters.erase("param:"+std::string(name)));
131
}
132

    
133
void Xslt30Processor::setJustInTimeCompilation(bool jit){
134
    jitCompilation = jit;
135
}
136

    
137

    
138
void Xslt30Processor::clearParameters(bool delValues) {
139

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

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

    
161
        }
162
        parameters.clear();
163

    
164
        
165
}
166

    
167

    
168

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

    
174

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

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

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

    
194

    
195

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

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

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

    
221
    }
222

    
223

    
224

    
225
}
226

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

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

    
252
    }
253
}
254

    
255

    
256

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

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

    
268
        } else {
269

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

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

    
282

    
283
     }
284
}
285

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

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

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

    
326
}
327

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

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

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

    
370
}
371

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

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

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

    
416
}
417

    
418

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

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

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

    
443
            return nullptr;
444
        }
445

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

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

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

    
469
        return executable;
470

    
471
        }
472

    
473
}
474

    
475

    
476

    
477

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

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

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

    
492

    
493
        static jmethodID mtvID = nullptr;
494

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

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

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

    
532

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

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

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

    
566
}
567

    
568

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

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

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

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

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

    
615

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

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

    
629
        static jmethodID mtsID =  nullptr;
630

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

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

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

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

    
677

    
678

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

    
(37-37/55)