Project

Profile

Help

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

he / latest9.9 / hec / Saxon.C.API / Xslt30Processor.cpp @ 5401a5ae

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
#ifdef DEBUG
11
#include <typeinfo> //used for testing only
12
#endif
13

    
14
Xslt30Processor::Xslt30Processor() {
15

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

    
19
}
20

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

    
23
        proc = p;
24

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

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

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

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

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

    
56

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

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

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

    
77
        std::map<std::string, std::string>::const_iterator propIter = other.properties.begin();
78
        while(propIter != other.properties.end())
79
    {
80
        properties[propIter->first] = propIter->second;
81
        propIter++;
82
    }
83
        jitCompilation = other.jitCompilation;
84

    
85
}
86

    
87

    
88
Xslt30Processor * Xslt30Processor::clone() {
89
     Xslt30Processor * proc = new Xslt30Processor(*this);
90
     return proc;
91

    
92
}
93

    
94
bool Xslt30Processor::exceptionOccurred() {
95
        return proc->exceptionOccurred();
96
}
97

    
98
const char * Xslt30Processor::getErrorCode() {
99
 if(exception == NULL) {return NULL;}
100
 return exception->getErrorCode();
101
 }
102

    
103

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

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

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

    
138
void Xslt30Processor::setJustInTimeCompilation(bool jit){
139
    jitCompilation = jit;
140
}
141

    
142

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

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

    
165
        }
166
        parameters.clear();
167

    
168
        
169
}
170

    
171

    
172

    
173
std::map<std::string,XdmValue*>& Xslt30Processor::getParameters(){
174
        std::map<std::string,XdmValue*>& ptr = parameters;
175
        return ptr;
176
}
177

    
178

    
179
void Xslt30Processor::exceptionClear(){
180
 if(exception != NULL) {
181
         delete exception;
182
         exception = NULL;
183
        SaxonProcessor::sxn_environ->env->ExceptionClear();
184
 }
185
  
186
 }
187

    
188
   void Xslt30Processor::setcwd(const char* dir){
189
    if (dir!= NULL) {
190
        cwdXT = std::string(dir);
191
    }
192
   }
193

    
194
const char* Xslt30Processor::checkException() {
195
        /*if(proc->exception == NULL) {
196
         proc->exception = proc->checkForException(environi, cpp);
197
         }
198
         return proc->exception;*/
199
        return proc->checkException(cppXT);
200
}
201

    
202

    
203

    
204
void Xslt30Processor::compileFromXdmNodeAndSave(XdmNode * node, const char* filename) {
205
        static jmethodID cAndSNodemID = NULL;
206

    
207
        if(cAndSNodemID == NULL) {
208
                        cAndSNodemID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
209
                                        "compileFromXdmNodeAndSave",
210
                                        "(Ljava/lang/String;Ljava/lang/Object;Ljava/lang/String;)V");
211
        }
212
        if (!cAndSNodemID) {
213
                std::cerr << "Error: "<<getDllname() << ".compileFromStringAndSave"
214
                                << " not found\n" << std::endl;
215

    
216
        } else {
217

    
218
                
219
                SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cAndSNodemID,
220
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
221
                                                node->getUnderlyingValue(), SaxonProcessor::sxn_environ->env->NewStringUTF(filename));
222
                
223
                exception = proc->checkAndCreateException(cppClass);
224

    
225
    }
226

    
227

    
228

    
229
}
230

    
231
    void Xslt30Processor::compileFromStringAndSave(const char* stylesheetStr, const char* filename){
232
        static jmethodID cAndSStringmID = NULL;
233
        if(cAndSStringmID == NULL) {
234
           cAndSStringmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
235
                                        "compileFromStringAndSave",
236
                                        "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
237
        }
238
        if (!cAndSStringmID) {
239
                std::cerr << "Error: "<<getDllname() << ".compileFromStringAndSave"
240
                                << " not found\n" << std::endl;
241

    
242
        } else {
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 =  NULL;
259

    
260
        if (cAndFStringmID == NULL) {
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
                std::cerr << "Error: "<<getDllname() << ".compileFromFileAndSave"
267
                                << " not found\n" << std::endl;
268

    
269
        } else {
270

    
271
                
272
                SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cAndFStringmID,
273
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
274
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(xslFilename),SaxonProcessor::sxn_environ->env->NewStringUTF(filename));
275

    
276
                exception = proc->checkAndCreateException(cppClass);
277

    
278

    
279
     }
280
}
281

    
282
XsltExecutable * Xslt30Processor::compileFromString(const char* stylesheetStr) {
283
        static jmethodID cStringmID = NULL;
284
        if (cStringmID == NULL) {
285
                        cStringmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
286
                                        "compileFromString",
287
                                        "(Ljava/lang/String;Ljava/lang/String;Z;[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XsltExecutable;");
288
        }
289
                                        
290
        if (!cStringmID) {
291
                std::cerr << "Error: "<<getDllname() << ".compileFromString"
292
                                << " not found\n" << std::endl;
293
                return NULL;
294

    
295
        } else {
296

    
297
                JParameters comboArrays;
298
                comboArrays = SaxonProcessor::createParameterJArray2(parameters);
299
                jobject executableObject = (jobject)(
300
                                SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cStringmID,
301
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
302
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheetStr), jitCompilation, comboArrays.stringArray, comboArrays.objectArray));
303
                if (!executableObject) {
304
                        exception = proc->checkAndCreateException(cppClass);
305
                        return NULL;
306
                }
307
                if (comboArrays.stringArray != NULL) {
308
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
309
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
310
                }
311

    
312
        XsltExecutable * executable = new XsltExecutable(SaxonProcessor::sxn_environ->env->NewGlobalRef(executableObject));
313
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(executableObject);
314
                return executable;
315
        }
316

    
317
}
318

    
319
XsltExecutable * Xslt30Processor::compileFromXdmNode(XdmNode * node) {
320
        static jmethodID cNodemID = NULL;
321
    if(cNodemID == NULL) {                        
322
                        cNodemID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,"compileFromXdmNode",
323
                        "(Ljava/lang/String;Ljava/lang/Object;Z;[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XsltExecutable;");
324
        }
325
        if (!cNodemID) {
326
                std::cerr << "Error: "<< getDllname() << ".compileFromXdmNode"
327
                                << " not found\n" << std::endl;
328
                return NULL;
329

    
330
        } else {
331
                JParameters comboArrays;
332
                comboArrays = SaxonProcessor::createParameterJArray2(parameters);
333
                jobject executableObject = (jobject)(
334
                                SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cNodemID,
335
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
336
                                                node->getUnderlyingValue(), jitCompilation, comboArrays.stringArray, comboArrays.objectArray));
337
                if (!executableObject) {
338
                        proc->checkAndCreateException(cppClass);
339
                        return NULL;
340
                }
341
                if (comboArrays.stringArray != NULL) {
342
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
343
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
344
                }
345

    
346
        XsltExecutable * executable = new XsltExecutable(SaxonProcessor::sxn_environ->env->NewGlobalRef(executableObject));
347
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(executableObject);
348
                return executable;
349
        }
350

    
351
}
352

    
353
XsltExecutable * Xslt30Processor::compileFromAssociatedFile(const char* source) {
354
        static jmethodID cFilemID = NULL;
355
    if(cFilemID == NULL) {        
356
            cFilemID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
357
                                        "compileFromAssociatedFile",
358
                                        "(Ljava/lang/String;Ljava/lang/String;Z;[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XsltExecutable;");
359
        }
360
        if (!cFilemID) {
361
                std::cerr << "Error: "<<getDllname() << ".compileFromAssociatedFile"
362
                                << " not found\n" << std::endl;
363
                return NULL;
364

    
365
        } else {
366
                
367
                if(source == NULL) {
368
                        std::cerr << "Error in compileFromFile method - The Stylesheet file is NULL" <<std::endl;
369
                        return;
370
                }
371
                JParameters comboArrays;
372
                comboArrays = SaxonProcessor::createParameterJArray2(parameters);
373
                jobject executableObject = (jobject)(
374
                                SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cFilemID,
375
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
376
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(source), jitCompilation, comboArrays.stringArray, comboArrays.objectArray));
377
                if (!executableObject) {
378
                        proc->checkAndCreateException(cppClass);
379
                     return NULL;
380
                }
381
                if (comboArrays.stringArray != NULL) {
382
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
383
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
384
                }
385

    
386
        XsltExecutable * executable = new XsltExecutable(SaxonProcessor::sxn_environ->env->NewGlobalRef(executableObject));
387
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(executableObject);
388
                return executable;
389
        }
390

    
391
}
392

    
393

    
394
XsltExecutable * Xslt30Processor::compileFromFile(const char* stylesheet) {
395
        static jmethodID cFilemID = NULL;
396
        if(cFilemID == NULL) {
397
            cFilemID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
398
                                        "compileFromFile",
399
                                        "(Ljava/lang/String;Ljava/lang/String;Z;[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XsltExecutable;");
400
        }
401
        if (!cFilemID) {
402
                std::cerr << "Error: "<<getDllname() << ".compileFromFile"
403
                                << " not found\n" << std::endl;
404
                return NULL;
405

    
406
        } else {
407
                
408
                if(stylesheet == NULL) {
409
                        std::cerr << "Error in compileFromFile method - The Stylesheet file is NULL" <<std::endl;
410
                        return;
411
                }
412
                JParameters comboArrays;
413
                comboArrays = SaxonProcessor::createParameterJArray2(parameters);
414
                jobject executableObject = (jobject)(
415
                                SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cFilemID,
416
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
417
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheet), jitCompilation, comboArrays.stringArray, comboArrays.objectArray));
418
                if (!executableObject) {
419
                        proc->checkAndCreateException(cppClass);
420
                        return NULL;
421
                     
422
                }
423
                if (comboArrays.stringArray != NULL) {
424
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
425
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
426
                }
427

    
428
        XsltExecutable * executable = new XsltExecutable(SaxonProcessor::sxn_environ->env->NewGlobalRef(executableObject));
429
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(executableObject);
430
                return executable;
431
        }
432

    
433
}
434

    
435

    
436

    
437

    
438
XdmValue * Xslt30Processor::transformFileToValue(const char* sourcefile,
439
                const char* stylesheetfile) {
440

    
441
        if(exceptionOccurred()) {
442
                //Possible error detected in the compile phase. Processor not in a clean state.
443
                //Require clearing exception.
444
                return NULL;        
445
        }
446

    
447
        if(sourcefile == NULL && stylesheetfile == NULL){
448
        
449
                return NULL;
450
        }
451

    
452
        setProperty("resources", proc->getResourcesDirectory());
453
        static jmethodID mtvID = NULL;
454

    
455
        if(mtvID == NULL) {
456
                        mtvID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
457
                                        "transformToValue",
458
                                        "(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;");
459
        }
460
        if (!mtvID) {
461
                std::cerr << "Error: "<< getDllname() << ".transformtoValue" << " not found\n"
462
                                << std::endl;
463

    
464
        } else {
465
            JParameters comboArrays;
466
                comboArrays = SaxonProcessor::createParameterJArray2(parameters);
467

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

    
487

    
488
                                  if(SaxonProcessor::sxn_environ->env->IsInstanceOf(result, atomicValueClass)           == JNI_TRUE) {
489
                                          xdmItem = new XdmAtomicValue(SaxonProcessor::sxn_environ->env->NewGlobalRef(result));
490
                        xdmItem->setProcessor(proc);
491
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
492
                        return xdmItem;
493

    
494
                                  } else if(SaxonProcessor::sxn_environ->env->IsInstanceOf(result, nodeClass)           == JNI_TRUE) {
495
                                          xdmItem = new XdmNode(SaxonProcessor::sxn_environ->env->NewGlobalRef(result));
496
                        xdmItem->setProcessor(proc);
497
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
498
                        return xdmItem;
499
#if CVERSION_API_NO >= 123
500
                                  } else if (SaxonProcessor::sxn_environ->env->IsInstanceOf(result, functionItemClass)           == JNI_TRUE) {
501
                        xdmItem =  new XdmFunctionItem(SaxonProcessor::sxn_environ->env->NewGlobalRef(result));
502
                        xdmItem->setProcessor(proc);
503
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
504
                        return xdmItem;
505
#endif
506
                                  } else {
507
                                        value = new XdmValue(result, true);
508
                                        value->setProcessor(proc);
509
                                        for(int z=0;z<value->size();z++) {
510
                                                value->itemAt(z)->setProcessor(proc);
511
                                        }
512
                                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
513
                                        return value;
514
                                }
515
                                value = new XdmValue();
516
                                value->setProcessor(proc);
517
                      value->addUnderlyingValue(result);
518

    
519
                          SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
520
                          return value;
521
                }else {
522
        
523
                        exception = proc->checkAndCreateException(cppClass);
524
                           
525
                     }
526
        }
527
        return NULL;
528

    
529
}
530

    
531

    
532
void Xslt30Processor::transformFileToFile(const char* source,
533
                const char* stylesheet, const char* outputfile) {
534

    
535
        if(exceptionOccurred()) {
536
                //Possible error detected in the compile phase. Processor not in a clean state.
537
                //Require clearing exception.
538
                return;        
539
        }
540
        if(stylesheet==NULL){
541
                std::cerr<< "Error: stylesheet has not been set."<<std::endl;
542
                return;
543
        }
544
        //setProperty("resources", proc->getResourcesDirectory());
545
        static jmethodID mtfID = NULL;
546

    
547
        if(mtfID == NULL) {
548
                mtfID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
549
                                        "transformToFile",
550
                                        "(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");
551
        }
552
        if (!mtfID) {
553
                std::cerr << "Error: "<<getDllname() << "transformToFile" << " not found\n"
554
                                << std::endl;
555

    
556
        } else {
557
            JParameters comboArrays;
558
        comboArrays = SaxonProcessor::createParameterJArray2(parameters);
559

    
560
                SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, mtfID,
561
                                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()), cppXT, NULL,
562
                                                                (source != NULL ? SaxonProcessor::sxn_environ->env->NewStringUTF(source) : NULL),
563
                                                                SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheet),        (outputfile != NULL ? SaxonProcessor::sxn_environ->env->NewStringUTF(outputfile) :NULL),
564
                                                                comboArrays.stringArray, comboArrays.objectArray);
565
                if (comboArrays.stringArray!= NULL) {
566
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
567
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
568
                }
569
                }
570
                exception = proc->checkAndCreateException(cppClass);
571
        }
572

    
573

    
574
const char * Xslt30Processor::transformFileToString(const char* source,
575
                const char* stylesheet) {
576

    
577
        if(exceptionOccurred()) {
578
                //Possible error detected in the compile phase. Processor not in a clean state.
579
                //Require clearing exception.
580
                return NULL;        
581
        }
582
        if(source == NULL && stylesheet == NULL){
583
                std::cerr<< "Error: NULL file name found in transformFiletoString."<<std::endl;
584
                return NULL;
585
        }
586
        setProperty("resources", proc->getResourcesDirectory());
587
        static jmethodID mtsID =  NULL;
588

    
589
        if(mtsID == NULL) {
590
                        mtsID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
591
                                        "transformToString",
592
                                        "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;");
593
        }
594
        if (!mtsID) {
595
                std::cerr << "Error: "<<getDllname() << "transformFileToString" << " not found\n"
596
                                << std::endl;
597

    
598
        } else {
599
    JParameters comboArrays;
600
    comboArrays = SaxonProcessor::createParameterJArray2(parameters);
601

    
602
        jstring result = NULL;
603
        jobject obj = SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, mtsID,
604
                                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()), cppXT, NULL,
605
                                                (source != NULL ? SaxonProcessor::sxn_environ->env->NewStringUTF(
606
                                                                                                source) : NULL),
607
                                                                (stylesheet != NULL ? SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheet) : NULL),
608
                                                                comboArrays.stringArray, comboArrays.objectArray);
609
    if (comboArrays.stringArray!= NULL) {
610
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
611
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
612
    }
613
        if(obj) {
614
                        result = (jstring)obj;
615
        }
616

    
617
        if (result) {
618
                        const char * str = SaxonProcessor::sxn_environ->env->GetStringUTFChars(result,
619
                                        NULL);
620
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(obj);
621
                        return str;
622
                } else  {
623
                        exception =proc->checkAndCreateException(cppClass);
624
                           
625
                     }
626
        }
627
        return NULL;
628
}
629

    
630

    
631

    
632
const char * Xslt30Processor::getErrorMessage(){
633
         if(exception == NULL) {return NULL;}
634
         return exception->getErrorMessage();
635
 }
636

    
(34-34/52)