Project

Profile

Help

Download (24.1 KB) Statistics
| Branch: | Revision:

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

1 72bf04c6 Norman Walsh
// 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 ead48a5d O'Neil Delpratt
#include "XsltExecutable.h"
11 72bf04c6 Norman Walsh
#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 00082f6f O'Neil Delpratt
    tunnel = false;
26
    jitCompilation = false;
27
    exception = nullptr;
28 72bf04c6 Norman Walsh
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 00082f6f O'Neil Delpratt
44
        if(cppXT == nullptr) {
45
            exception = proc->checkAndCreateException(cppClass);
46
        }
47 72bf04c6 Norman Walsh
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 ead48a5d O'Neil Delpratt
       if(valuei == nullptr) {
75 72bf04c6 Norman Walsh
                     //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 00082f6f O'Neil Delpratt
        return proc->exceptionOccurred() || exception != nullptr;
91 72bf04c6 Norman Walsh
}
92
93
const char * Xslt30Processor::getErrorCode() {
94 ead48a5d O'Neil Delpratt
 if(exception == nullptr) {return nullptr;}
95 72bf04c6 Norman Walsh
 return exception->getErrorCode();
96
 }
97
98
99
void Xslt30Processor::setParameter(const char* name, XdmValue * value) {
100 ead48a5d O'Neil Delpratt
        if(value != nullptr && name != nullptr){
101 72bf04c6 Norman Walsh
                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 146cfacb O'Neil Delpratt
                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 72bf04c6 Norman Walsh
                }
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 ead48a5d O'Neil Delpratt
            return nullptr;
130 72bf04c6 Norman Walsh
}
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 146cfacb O'Neil Delpratt
    std::cout<<"clearParameter" <<std::endl;
143 72bf04c6 Norman Walsh
        if(delValues){
144 146cfacb O'Neil Delpratt
        for(std::map<std::string, XdmValue*>::iterator itr = parameters.begin(); itr != parameters.end(); itr++){
145
            XdmValue * value = itr->second;
146
            std::cout<<"clearParameter cp0" <<"ob ref="<<(value)<<std::endl;
147
            if(value != nullptr) {
148
                std::cout<<"clearParameter cp0-1" <<std::endl;
149
                value->decrementRefCount();
150 72bf04c6 Norman Walsh
#ifdef DEBUG
151 146cfacb O'Neil Delpratt
                std::cout<<"clearParameter() - XdmValue refCount="<<value->getRefCount()<<std::endl;
152 72bf04c6 Norman Walsh
#endif
153 146cfacb O'Neil Delpratt
                if (value->getRefCount() < 1) {
154
                    delete value;
155
                }
156
            }
157
            std::cout<<"clearParameter cp0-2" <<std::endl;
158
        }
159 72bf04c6 Norman Walsh
160
        } else {
161 146cfacb O'Neil Delpratt
        std::cout<<"clearParameter cp1-0" <<std::endl;
162
        for(std::map<std::string, XdmValue*>::iterator itr = parameters.begin(); itr != parameters.end(); itr++){
163
164 72bf04c6 Norman Walsh
                        XdmValue * value = itr->second;
165 146cfacb O'Neil Delpratt
            std::cout<<"clearParameter cp1" <<"ob ref="<<(value)<<std::endl;
166
167
            if(value == NULL) {
168
                std::cout<<"clearParameter cp1-0 after itr NULL found!!!!!" <<std::endl;
169
            }
170
                        if(value != nullptr) {
171
                std::cout<<"clearParameter cp1-1" <<std::endl;
172
                value->decrementRefCount();
173
            }
174 72bf04c6 Norman Walsh
                
175
                }
176
177
        }
178 146cfacb O'Neil Delpratt
    std::cout<<"clearParameter cp1" <<std::endl;
179 72bf04c6 Norman Walsh
        parameters.clear();
180 146cfacb O'Neil Delpratt
    std::cout<<"clearParameter cp2" <<std::endl;
181 72bf04c6 Norman Walsh
182
        
183
}
184
185
186
187
std::map<std::string,XdmValue*>& Xslt30Processor::getParameters(){
188
        std::map<std::string,XdmValue*>& ptr = parameters;
189
        return ptr;
190
}
191
192
193
void Xslt30Processor::exceptionClear(){
194 ead48a5d O'Neil Delpratt
 if(exception != nullptr) {
195 72bf04c6 Norman Walsh
         delete exception;
196 ead48a5d O'Neil Delpratt
         exception = nullptr;
197 72bf04c6 Norman Walsh
        SaxonProcessor::sxn_environ->env->ExceptionClear();
198
 }
199
  
200
 }
201
202
   void Xslt30Processor::setcwd(const char* dir){
203 ead48a5d O'Neil Delpratt
    if (dir!= nullptr) {
204 72bf04c6 Norman Walsh
        cwdXT = std::string(dir);
205
    }
206
   }
207
208 79d12c83 O'Neil Delpratt
SaxonApiException* Xslt30Processor::getException() {
209
    return exception;
210 72bf04c6 Norman Walsh
}
211
212
213
214
void Xslt30Processor::compileFromXdmNodeAndSave(XdmNode * node, const char* filename) {
215 ead48a5d O'Neil Delpratt
        static jmethodID cAndSNodemID = nullptr;
216 72bf04c6 Norman Walsh
217 ead48a5d O'Neil Delpratt
        if(cAndSNodemID == nullptr) {
218 72bf04c6 Norman Walsh
                        cAndSNodemID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
219
                                        "compileFromXdmNodeAndSave",
220
                                        "(Ljava/lang/String;Ljava/lang/Object;Ljava/lang/String;)V");
221
        }
222
        if (!cAndSNodemID) {
223 990eca02 O'Neil Delpratt
                std::cerr<<"Error: "<<getDllname()<<"compileFromStringAndSave funtion not found"<<std::endl;
224 72bf04c6 Norman Walsh
225
        } else {
226 00082f6f O'Neil Delpratt
        if(cppXT == nullptr) {
227
#if defined(DEBUG)
228
            std::cerr << "The Java Xslt30Processor object (i.e. cppXT) is NULL - Possible exception thrown" << std::endl;
229
#endif
230
            return;
231
        }
232 72bf04c6 Norman Walsh
                
233
                SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cAndSNodemID,
234
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
235
                                                node->getUnderlyingValue(), SaxonProcessor::sxn_environ->env->NewStringUTF(filename));
236
                
237
                exception = proc->checkAndCreateException(cppClass);
238
239
    }
240
241
242
243
}
244
245
    void Xslt30Processor::compileFromStringAndSave(const char* stylesheetStr, const char* filename){
246 ead48a5d O'Neil Delpratt
        static jmethodID cAndSStringmID = nullptr;
247
        if(cAndSStringmID == nullptr) {
248 72bf04c6 Norman Walsh
           cAndSStringmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
249
                                        "compileFromStringAndSave",
250
                                        "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
251
        }
252
        if (!cAndSStringmID) {
253 00082f6f O'Neil Delpratt
                exception = new SaxonApiException("Error: compileFromStringAndSave function not found\n");
254 72bf04c6 Norman Walsh
255
        } else {
256 00082f6f O'Neil Delpratt
        if(cppXT == nullptr) {
257
#if defined(DEBUG)
258
            std::cerr << "The Java Xslt30Processor object (i.e. cppXT) is NULL - Possible exception thrown" << std::endl;
259
#endif
260
            return;
261
        }
262 72bf04c6 Norman Walsh
                
263
                SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cAndSStringmID,
264
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
265
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheetStr),
266
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(filename));
267
                
268
                exception = proc->checkAndCreateException(cppClass);
269
270
    }
271
}
272
273
274
275
    void Xslt30Processor::compileFromFileAndSave(const char* xslFilename, const char* filename){
276 ead48a5d O'Neil Delpratt
        static jmethodID cAndFStringmID =  nullptr;
277 72bf04c6 Norman Walsh
278 ead48a5d O'Neil Delpratt
        if (cAndFStringmID == nullptr) {
279 72bf04c6 Norman Walsh
            cAndFStringmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
280
                                        "compileFromFileAndSave",
281
                                        "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
282
        }
283
        if (!cAndFStringmID) {
284 00082f6f O'Neil Delpratt
                exception = new SaxonApiException("Error: compileFromFileAndSave function not found");
285 72bf04c6 Norman Walsh
286
        } else {
287
288 00082f6f O'Neil Delpratt
        if(cppXT == nullptr) {
289
#if defined(DEBUG)
290
            std::cerr << "The Java Xslt30Processor object (i.e. cppXT) is NULL - Possible exception thrown" << std::endl;
291
#endif
292
            return;
293
        }
294 72bf04c6 Norman Walsh
                SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cAndFStringmID,
295
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
296
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(xslFilename),SaxonProcessor::sxn_environ->env->NewStringUTF(filename));
297
298
                exception = proc->checkAndCreateException(cppClass);
299
300
301
     }
302
}
303
304
XsltExecutable * Xslt30Processor::compileFromString(const char* stylesheetStr) {
305 ead48a5d O'Neil Delpratt
        static jmethodID cStringmID = nullptr;
306
        if (cStringmID == nullptr) {
307 72bf04c6 Norman Walsh
                        cStringmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
308
                                        "compileFromString",
309 e05bbe34 O'Neil Delpratt
                                        "(Ljava/lang/String;Ljava/lang/String;Z[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XsltExecutable;");
310 72bf04c6 Norman Walsh
        }
311
                                        
312 e05bbe34 O'Neil Delpratt
        if (cStringmID== nullptr) {
313 00082f6f O'Neil Delpratt
                exception = new SaxonApiException(strcat(getDllname(), ".compileFromString funtion not found"));
314 ead48a5d O'Neil Delpratt
                return nullptr;
315 72bf04c6 Norman Walsh
316
        } else {
317 00082f6f O'Neil Delpratt
        if(cppXT == nullptr) {
318
#if defined(DEBUG)
319
            std::cerr << "The Java Xslt30Processor object (i.e. cppXT) is NULL - Possible exception thrown" << std::endl;
320
#endif
321
            return nullptr;
322
        }
323 72bf04c6 Norman Walsh
                JParameters comboArrays;
324
                comboArrays = SaxonProcessor::createParameterJArray2(parameters);
325
                jobject executableObject = (jobject)(
326
                                SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cStringmID,
327
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
328
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheetStr), jitCompilation, comboArrays.stringArray, comboArrays.objectArray));
329
                if (!executableObject) {
330
                        exception = proc->checkAndCreateException(cppClass);
331 ead48a5d O'Neil Delpratt
                        return nullptr;
332 72bf04c6 Norman Walsh
                }
333 ead48a5d O'Neil Delpratt
                if (comboArrays.stringArray != nullptr) {
334 72bf04c6 Norman Walsh
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
335
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
336
                }
337
338 ead48a5d O'Neil Delpratt
                jobject obj = SaxonProcessor::sxn_environ->env->NewGlobalRef(executableObject);
339
        XsltExecutable * executable = new XsltExecutable(obj, cwdXT);
340 72bf04c6 Norman Walsh
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(executableObject);
341
                return executable;
342
        }
343
344
}
345
346
XsltExecutable * Xslt30Processor::compileFromXdmNode(XdmNode * node) {
347 ead48a5d O'Neil Delpratt
        static jmethodID cNodemID = nullptr;
348
    if(cNodemID == nullptr) {
349 72bf04c6 Norman Walsh
                        cNodemID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,"compileFromXdmNode",
350 e05bbe34 O'Neil Delpratt
                        "(Ljava/lang/String;Ljava/lang/Object;Z[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XsltExecutable;");
351 72bf04c6 Norman Walsh
        }
352
        if (!cNodemID) {
353
                std::cerr << "Error: "<< getDllname() << ".compileFromXdmNode"
354
                                << " not found\n" << std::endl;
355 ead48a5d O'Neil Delpratt
                return nullptr;
356 72bf04c6 Norman Walsh
357
        } else {
358 00082f6f O'Neil Delpratt
            if(node == nullptr) {
359
                exception = new SaxonApiException("Error in compileFromXdmNode - node argument is NULL");
360
                return nullptr;
361
            }
362
        if(cppXT == nullptr) {
363
#if defined(DEBUG)
364
            std::cerr << "The Java Xslt30Processor object (i.e. cppXT) is NULL - Possible exception thrown" << std::endl;
365
#endif
366
            return nullptr;
367
        }
368 72bf04c6 Norman Walsh
                JParameters comboArrays;
369
                comboArrays = SaxonProcessor::createParameterJArray2(parameters);
370
                jobject executableObject = (jobject)(
371
                                SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cNodemID,
372
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
373
                                                node->getUnderlyingValue(), jitCompilation, comboArrays.stringArray, comboArrays.objectArray));
374
                if (!executableObject) {
375 a69dd173 O'Neil Delpratt
                        exception = proc->checkAndCreateException(cppClass);
376 ead48a5d O'Neil Delpratt
                        return nullptr;
377 72bf04c6 Norman Walsh
                }
378 ead48a5d O'Neil Delpratt
                if (comboArrays.stringArray != nullptr) {
379 72bf04c6 Norman Walsh
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
380
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
381
                }
382
383
        XsltExecutable * executable = new XsltExecutable(SaxonProcessor::sxn_environ->env->NewGlobalRef(executableObject));
384
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(executableObject);
385
                return executable;
386
        }
387
388
}
389
390
XsltExecutable * Xslt30Processor::compileFromAssociatedFile(const char* source) {
391 ead48a5d O'Neil Delpratt
        static jmethodID cFilemID = nullptr;
392
    if(cFilemID == nullptr) {
393 72bf04c6 Norman Walsh
            cFilemID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
394
                                        "compileFromAssociatedFile",
395
                                        "(Ljava/lang/String;Ljava/lang/String;Z;[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XsltExecutable;");
396
        }
397
        if (!cFilemID) {
398
                std::cerr << "Error: "<<getDllname() << ".compileFromAssociatedFile"
399
                                << " not found\n" << std::endl;
400 ead48a5d O'Neil Delpratt
                return nullptr;
401 72bf04c6 Norman Walsh
402
        } else {
403
                
404 ead48a5d O'Neil Delpratt
                if(source == nullptr) {
405 00082f6f O'Neil Delpratt
                        exception = new SaxonApiException("Error in compileFromFile method - The Stylesheet file is NULL");
406 79d12c83 O'Neil Delpratt
                        return nullptr;
407 72bf04c6 Norman Walsh
                }
408 00082f6f O'Neil Delpratt
        if(cppXT == nullptr) {
409
#if defined(DEBUG)
410
            std::cerr << "The Java Xslt30Processor object (i.e. cppXT) is NULL - Possible exception thrown" << std::endl;
411
#endif
412
            return nullptr;
413
        }
414 72bf04c6 Norman Walsh
                JParameters comboArrays;
415
                comboArrays = SaxonProcessor::createParameterJArray2(parameters);
416
                jobject executableObject = (jobject)(
417
                                SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cFilemID,
418
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
419
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(source), jitCompilation, comboArrays.stringArray, comboArrays.objectArray));
420
                if (!executableObject) {
421 a69dd173 O'Neil Delpratt
                        exception = proc->checkAndCreateException(cppClass);
422 ead48a5d O'Neil Delpratt
                     return nullptr;
423 72bf04c6 Norman Walsh
                }
424 ead48a5d O'Neil Delpratt
                if (comboArrays.stringArray != nullptr) {
425 72bf04c6 Norman Walsh
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
426
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
427
                }
428
429
        XsltExecutable * executable = new XsltExecutable(SaxonProcessor::sxn_environ->env->NewGlobalRef(executableObject));
430
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(executableObject);
431
                return executable;
432
        }
433
434
}
435
436
437
XsltExecutable * Xslt30Processor::compileFromFile(const char* stylesheet) {
438 ead48a5d O'Neil Delpratt
        static jmethodID cFilemID = nullptr;
439
        if(cFilemID == nullptr) {
440 72bf04c6 Norman Walsh
            cFilemID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
441
                                        "compileFromFile",
442 e05bbe34 O'Neil Delpratt
                                        "(Ljava/lang/String;Ljava/lang/String;Z[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XsltExecutable;");
443 72bf04c6 Norman Walsh
        }
444 00082f6f O'Neil Delpratt
445 72bf04c6 Norman Walsh
        if (!cFilemID) {
446
                std::cerr << "Error: "<<getDllname() << ".compileFromFile"
447
                                << " not found\n" << std::endl;
448 00082f6f O'Neil Delpratt
        std::cerr<<"cp0 -testCatalog"<<std::endl;
449 ead48a5d O'Neil Delpratt
                return nullptr;
450 72bf04c6 Norman Walsh
451
        } else {
452 e05bbe34 O'Neil Delpratt
        if (stylesheet == nullptr) {
453 00082f6f O'Neil Delpratt
            exception = new SaxonApiException("Error in compileFromFile method - The Stylesheet file is nullptr");
454
            return nullptr;
455
        }
456
        if(cppXT == nullptr) {
457
#if defined(DEBUG)
458
            std::cerr << "The Java Xslt30Processor object (i.e. cppXT) is NULL - Possible exception thrown" << std::endl;
459
#endif
460
461 e05bbe34 O'Neil Delpratt
            return nullptr;
462
        }
463 00082f6f O'Neil Delpratt
464 e05bbe34 O'Neil Delpratt
        JParameters comboArrays;
465
        comboArrays = SaxonProcessor::createParameterJArray2(parameters);
466
        jobject executableObject = (jobject) (
467
                SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cFilemID,
468
                                                                   SaxonProcessor::sxn_environ->env->NewStringUTF(
469
                                                                           cwdXT.c_str()),
470
                                                                   SaxonProcessor::sxn_environ->env->NewStringUTF(
471
                                                                           stylesheet), jitCompilation,
472
                                                                   comboArrays.stringArray, comboArrays.objectArray));
473
        if (!executableObject) {
474 a69dd173 O'Neil Delpratt
            exception = proc->checkAndCreateException(cppClass);
475 e05bbe34 O'Neil Delpratt
            return nullptr;
476
477
        }
478
        if (comboArrays.stringArray != nullptr) {
479
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
480
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
481
        }
482 72bf04c6 Norman Walsh
483 ead48a5d O'Neil Delpratt
        XsltExecutable *executable;
484
        executable = new XsltExecutable(SaxonProcessor::sxn_environ->env->NewGlobalRef(executableObject), cwdXT);
485 72bf04c6 Norman Walsh
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(executableObject);
486 e05bbe34 O'Neil Delpratt
487
        return executable;
488
489 72bf04c6 Norman Walsh
        }
490
491
}
492
493
494
495
496
XdmValue * Xslt30Processor::transformFileToValue(const char* sourcefile,
497
                const char* stylesheetfile) {
498
499
        if(exceptionOccurred()) {
500
                //Possible error detected in the compile phase. Processor not in a clean state.
501
                //Require clearing exception.
502 ead48a5d O'Neil Delpratt
                return nullptr;
503 72bf04c6 Norman Walsh
        }
504
505 ead48a5d O'Neil Delpratt
        if(sourcefile == nullptr && stylesheetfile == nullptr){
506 72bf04c6 Norman Walsh
        
507 ead48a5d O'Neil Delpratt
                return nullptr;
508 72bf04c6 Norman Walsh
        }
509
510
511 ead48a5d O'Neil Delpratt
        static jmethodID mtvID = nullptr;
512
513
        if(mtvID == nullptr) {
514 72bf04c6 Norman Walsh
                        mtvID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
515
                                        "transformToValue",
516
                                        "(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;");
517
        }
518
        if (!mtvID) {
519 990eca02 O'Neil Delpratt
        std::cerr<<"Error: "<<getDllname()<<".transformtoValue function not found"<<std::endl;
520 72bf04c6 Norman Walsh
521
        } else {
522 00082f6f O'Neil Delpratt
        if(cppXT == nullptr) {
523
#if defined(DEBUG)
524
            std::cerr << "The Java Xslt30Processor object (i.e. cppXT) is NULL - Possible exception thrown" << std::endl;
525
#endif
526
            return nullptr;
527
        }
528 72bf04c6 Norman Walsh
            JParameters comboArrays;
529
                comboArrays = SaxonProcessor::createParameterJArray2(parameters);
530
531
                jobject result = (jobject)(
532
                                SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, mtvID,
533 ead48a5d O'Neil Delpratt
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()), cppXT, nullptr,
534
                                                (sourcefile != nullptr ?SaxonProcessor::sxn_environ->env->NewStringUTF(sourcefile) : nullptr),
535
                                                (stylesheetfile != nullptr ?
536 72bf04c6 Norman Walsh
                                                                SaxonProcessor::sxn_environ->env->NewStringUTF(
537
                                                                                stylesheetfile) :
538 ead48a5d O'Neil Delpratt
                                                                nullptr), comboArrays.stringArray, comboArrays.objectArray));
539
                if (comboArrays.stringArray != nullptr) {
540 72bf04c6 Norman Walsh
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
541
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
542
                }
543
                if (result) {
544
                        jclass atomicValueClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmAtomicValue");
545
                          jclass nodeClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmNode");
546
                          jclass functionItemClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmFunctionItem");
547 ead48a5d O'Neil Delpratt
                        XdmValue * value = nullptr;
548
                          XdmItem * xdmItem = nullptr;
549 72bf04c6 Norman Walsh
550
551
                                  if(SaxonProcessor::sxn_environ->env->IsInstanceOf(result, atomicValueClass)           == JNI_TRUE) {
552
                                          xdmItem = new XdmAtomicValue(SaxonProcessor::sxn_environ->env->NewGlobalRef(result));
553
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
554
                        return xdmItem;
555
556
                                  } else if(SaxonProcessor::sxn_environ->env->IsInstanceOf(result, nodeClass)           == JNI_TRUE) {
557
                                          xdmItem = new XdmNode(SaxonProcessor::sxn_environ->env->NewGlobalRef(result));
558
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
559
                        return xdmItem;
560
#if CVERSION_API_NO >= 123
561
                                  } else if (SaxonProcessor::sxn_environ->env->IsInstanceOf(result, functionItemClass)           == JNI_TRUE) {
562
                        xdmItem =  new XdmFunctionItem(SaxonProcessor::sxn_environ->env->NewGlobalRef(result));
563
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
564
                        return xdmItem;
565
#endif
566
                                  } else {
567
                                        value = new XdmValue(result, true);
568
                                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
569
                                        return value;
570
                                }
571
                                value = new XdmValue();
572
                      value->addUnderlyingValue(result);
573
574
                          SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
575
                          return value;
576
                }else {
577
        
578
                        exception = proc->checkAndCreateException(cppClass);
579
                           
580
                     }
581
        }
582 ead48a5d O'Neil Delpratt
        return nullptr;
583 72bf04c6 Norman Walsh
584
}
585
586
587
void Xslt30Processor::transformFileToFile(const char* source,
588
                const char* stylesheet, const char* outputfile) {
589
590
        if(exceptionOccurred()) {
591
                //Possible error detected in the compile phase. Processor not in a clean state.
592
                //Require clearing exception.
593
                return;        
594
        }
595 ead48a5d O'Neil Delpratt
        if(stylesheet==nullptr){
596 72bf04c6 Norman Walsh
                std::cerr<< "Error: stylesheet has not been set."<<std::endl;
597
                return;
598
        }
599 ead48a5d O'Neil Delpratt
        //
600
        static jmethodID mtfID = nullptr;
601 72bf04c6 Norman Walsh
602 ead48a5d O'Neil Delpratt
        if(mtfID == nullptr) {
603 72bf04c6 Norman Walsh
                mtfID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
604
                                        "transformToFile",
605
                                        "(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");
606
        }
607
        if (!mtfID) {
608 990eca02 O'Neil Delpratt
        std::cerr<<"Error: "<<getDllname()<<".transformToFile function not found"<<std::endl;
609 72bf04c6 Norman Walsh
610
        } else {
611 00082f6f O'Neil Delpratt
        if(cppXT == nullptr) {
612
#if defined(DEBUG)
613
            std::cerr << "The Java Xslt30Processor object (i.e. cppXT) is NULL - Possible exception thrown" << std::endl;
614
#endif
615
            return;
616
        }
617 72bf04c6 Norman Walsh
            JParameters comboArrays;
618
        comboArrays = SaxonProcessor::createParameterJArray2(parameters);
619
620
                SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, mtfID,
621 ead48a5d O'Neil Delpratt
                                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()), cppXT, nullptr,
622
                                                                (source != nullptr ? SaxonProcessor::sxn_environ->env->NewStringUTF(source) : nullptr),
623
                                                                SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheet),        (outputfile != nullptr ? SaxonProcessor::sxn_environ->env->NewStringUTF(outputfile) :nullptr),
624 72bf04c6 Norman Walsh
                                                                comboArrays.stringArray, comboArrays.objectArray);
625 ead48a5d O'Neil Delpratt
                if (comboArrays.stringArray!= nullptr) {
626 72bf04c6 Norman Walsh
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
627
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
628
                }
629
                }
630
                exception = proc->checkAndCreateException(cppClass);
631
        }
632
633
634
const char * Xslt30Processor::transformFileToString(const char* source,
635
                const char* stylesheet) {
636
637
        if(exceptionOccurred()) {
638
                //Possible error detected in the compile phase. Processor not in a clean state.
639
                //Require clearing exception.
640 ead48a5d O'Neil Delpratt
                return nullptr;
641 72bf04c6 Norman Walsh
        }
642 ead48a5d O'Neil Delpratt
        if(source == nullptr && stylesheet == nullptr){
643
                std::cerr<< "Error: nullptr file name found in transformFiletoString."<<std::endl;
644
                return nullptr;
645 72bf04c6 Norman Walsh
        }
646
647 ead48a5d O'Neil Delpratt
        static jmethodID mtsID =  nullptr;
648
649
        if(mtsID == nullptr) {
650 72bf04c6 Norman Walsh
                        mtsID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
651
                                        "transformToString",
652
                                        "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;");
653
        }
654
        if (!mtsID) {
655 990eca02 O'Neil Delpratt
        std::cerr<<"Error: "<<getDllname()<<".transformFileToString not found"<<std::endl;
656 72bf04c6 Norman Walsh
657
        } else {
658 00082f6f O'Neil Delpratt
        if(cppXT == nullptr) {
659
#if defined(DEBUG)
660
            std::cerr << "The Java Xslt30Processor object (i.e. cppXT) is NULL - Possible exception thrown" << std::endl;
661
#endif
662
            return nullptr;
663
        }
664 72bf04c6 Norman Walsh
    JParameters comboArrays;
665
    comboArrays = SaxonProcessor::createParameterJArray2(parameters);
666
667 ead48a5d O'Neil Delpratt
        jstring result = nullptr;
668 72bf04c6 Norman Walsh
        jobject obj = SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, mtsID,
669 ead48a5d O'Neil Delpratt
                                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()), cppXT, nullptr,
670
                                                (source != nullptr ? SaxonProcessor::sxn_environ->env->NewStringUTF(
671
                                                                                                source) : nullptr),
672
                                                                (stylesheet != nullptr ? SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheet) : nullptr),
673 72bf04c6 Norman Walsh
                                                                comboArrays.stringArray, comboArrays.objectArray);
674 ead48a5d O'Neil Delpratt
    if (comboArrays.stringArray!= nullptr) {
675 72bf04c6 Norman Walsh
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
676
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
677
    }
678
        if(obj) {
679
                        result = (jstring)obj;
680
        }
681
682
        if (result) {
683
                        const char * str = SaxonProcessor::sxn_environ->env->GetStringUTFChars(result,
684 ead48a5d O'Neil Delpratt
                                        nullptr);
685 72bf04c6 Norman Walsh
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(obj);
686
                        return str;
687
                } else  {
688
                        exception =proc->checkAndCreateException(cppClass);
689
                           
690
                     }
691
        }
692 ead48a5d O'Neil Delpratt
        return nullptr;
693 72bf04c6 Norman Walsh
}
694
695
696
697
const char * Xslt30Processor::getErrorMessage(){
698 ead48a5d O'Neil Delpratt
         if(exception == nullptr) {return nullptr;}
699
         return exception->getMessage();
700 72bf04c6 Norman Walsh
 }