Project

Profile

Help

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

he / latest9.9 / hec / Saxon.C.API / Xslt30Processor.cpp @ 1117bc69

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

    
13
Xslt30Processor::Xslt30Processor() {
14

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

    
18
}
19

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

    
22
        proc = p;
23

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

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

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

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

    
51
     Xslt30Processor::~Xslt30Processor(){
52
        clearProperties();
53
        clearParameters();
54
        if(selectionV != NULL) {
55
          selectionV->decrementRefCount();
56
          if(selectionV->getRefCount() == 0) {
57
                delete selectionV;
58
          }
59
        }
60
        
61
     }
62

    
63

    
64
Xslt30Processor::Xslt30Processor(const Xslt30Processor &other) {
65
        proc = other.proc;
66
        cppClass = other.cppClass;
67
        cppXT = other.cppXT;
68
        stylesheetObject = other.stylesheetObject;
69
        selectionV = other.selectionV;
70
        if(selectionV != NULL) {
71
            setInitialMatchSelection(other.selectionV);
72
        } else {
73
            selection = other.selection;
74
        }
75
    cwdXT = other.cwdXT;
76
        tunnel = other.tunnel;
77

    
78
        std::map<std::string, XdmValue*>::const_iterator paramIter = other.parameters.begin();
79
    while(paramIter != other.parameters.end())
80
    {
81

    
82
       XdmValue * valuei = paramIter->second;
83
       if(valuei == NULL) {
84
                     cerr<<"Error in Xslt30Processor copy constructor"<<endl;
85
       } else {
86
            parameters[paramIter->first] = new XdmValue(*(valuei));
87
       }
88
       paramIter++;
89
    }
90

    
91
        std::map<std::string, std::string>::const_iterator propIter = other.properties.begin();
92
        while(propIter != other.properties.end())
93
    {
94
        properties[propIter->first] = propIter->second;
95
        propIter++;
96
    }
97
        jitCompilation = other.jitCompilation;
98

    
99
}
100

    
101

    
102
Xslt30Processor * Xslt30Processor::clone() {
103
     Xslt30Processor * proc = new Xslt30Processor(*this);
104
     return proc;
105

    
106
}
107

    
108
bool Xslt30Processor::exceptionOccurred() {
109
        return proc->exceptionOccurred();
110
}
111

    
112
const char * Xslt30Processor::getErrorCode(int i) {
113
 if(proc->exception == NULL) {return NULL;}
114
 return proc->exception->getErrorCode(i);
115
 }
116

    
117

    
118
void Xslt30Processor::setParameter(const char* name, XdmValue * value) {
119
        if(value != NULL && name != NULL){
120
                value->incrementRefCount();
121
                int s = parameters.size();
122
                std::String skey = ("sparam:"+std::string(name));
123
                parameters[skey] = value;
124
                if(s == parameters.size()) {
125
            std::map<std::string, XdmValue*>::iterator it;
126
            it = parameters.find(skey);
127
            if (it != parameters.end()) {
128
                XdmValue * valuei = it->second;
129
                valuei->decrementRefCount();
130
                if(valuei != NULL && valuei->getRefCount() < 1){
131
                    delete value;
132
                }
133
                parameters.erase(skey);
134
                parameters[skey] = value;
135
            }
136
                }
137
         }
138
}
139

    
140
XdmValue* Xslt30Processor::getParameter(const char* name) {
141
        std::map<std::string, XdmValue*>::iterator it;
142
        it = parameters.find("sparam:"+std::string(name));
143
        if (it != parameters.end())
144
          return it->second;
145
            return NULL;
146
}
147

    
148
bool Xslt30Processor::removeParameter(const char* name) {
149
        return (bool)(parameters.erase("param:"+std::string(name)));
150
}
151

    
152
void Xslt30Processor::setJustInTimeCompilation(bool jit){
153
    jitCompilation = jit;
154
}
155

    
156

    
157
void Xslt30Processor::clearParameters(bool delValues) {
158
        if(delValues){
159
                       for(std::map<std::string, XdmValue*>::iterator itr = parameters.begin(); itr != parameters.end(); itr++){
160
                        
161
                        XdmValue * value = itr->second;
162
                        value->decrementRefCount();
163
#ifdef DEBUG
164
                        std::cout<<"clearParameter() - XdmValue refCount="<<value->getRefCount()<<std::endl;
165
#endif
166
                        if(value != NULL && value->getRefCount() < 1){                
167
                                delete value;
168
                        }
169
                }
170
                                
171
                SaxonProcessor::sxn_environ->env->DeleteLocalRef(selection);
172
                selection = NULL;
173
        } else {
174
for(std::map<std::string, XdmValue*>::iterator itr = parameters.begin(); itr != parameters.end(); itr++){
175
                
176
                        XdmValue * value = itr->second;
177
                        value->decrementRefCount();
178
                
179
                }
180

    
181
        selection = NULL;
182
        }
183
        parameters.clear();
184

    
185
        
186
}
187

    
188

    
189

    
190
std::map<std::string,XdmValue*>& Xslt30Processor::getParameters(){
191
        std::map<std::string,XdmValue*>& ptr = parameters;
192
        return ptr;
193
}
194

    
195

    
196
void Xslt30Processor::exceptionClear(){
197
 if(proc->exception != NULL) {
198
         delete proc->exception;
199
         proc->exception = NULL;
200
        SaxonProcessor::sxn_environ->env->ExceptionClear();
201
 }
202
  
203
 }
204

    
205
   void Xslt30Processor::setcwd(const char* dir){
206
    if (dir!= NULL) {
207
        cwdXT = std::string(dir);
208
    }
209
   }
210

    
211
const char* Xslt30Processor::checkException() {
212
        /*if(proc->exception == NULL) {
213
         proc->exception = proc->checkForException(environi, cpp);
214
         }
215
         return proc->exception;*/
216
        return proc->checkException(cppXT);
217
}
218

    
219
int Xslt30Processor::exceptionCount(){
220
 if(proc->exception != NULL){
221
 return proc->exception->count();
222
 }
223
 return 0;
224
 }
225

    
226

    
227
    void Xslt30Processor::compileFromXdmNodeAndSave(XdmNode * node, const char* filename) {
228
        static jmethodID cAndSNodemID = NULL;
229

    
230
        if(cAndSNodemID == NULL) {
231
                        cAndSNodemID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
232
                                        "compileFromXdmNodeAndSave",
233
                                        "(Ljava/lang/String;Ljava/lang/Object;Ljava/lang/String;)V");
234
        }
235
        if (!cAndSNodemID) {
236
                std::cerr << "Error: "<<getDllname() << ".compileFromStringAndSave"
237
                                << " not found\n" << std::endl;
238

    
239
        } else {
240

    
241
                
242
                SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cAndSNodemID,
243
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
244
                                                node->getUnderlyingValue(), SaxonProcessor::sxn_environ->env->NewStringUTF(filename));
245
                
246
                proc->checkAndCreateException(cppClass);                
247

    
248
    }
249

    
250

    
251

    
252
}
253

    
254
    void Xslt30Processor::compileFromStringAndSave(const char* stylesheetStr, const char* filename){
255
        static jmethodID cAndSStringmID = NULL;
256
        if(cAndSStringmID == NULL) {
257
           cAndSStringmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
258
                                        "compileFromStringAndSave",
259
                                        "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
260
        }
261
        if (!cAndSStringmID) {
262
                std::cerr << "Error: "<<getDllname() << ".compileFromStringAndSave"
263
                                << " not found\n" << std::endl;
264

    
265
        } else {
266

    
267
                
268
                SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cAndSStringmID,
269
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
270
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheetStr),
271
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(filename));
272
                
273
                proc->checkAndCreateException(cppClass);                
274

    
275
    }
276
}
277

    
278

    
279

    
280
    void Xslt30Processor::compileFromFileAndSave(const char* xslFilename, const char* filename){
281
        static jmethodID cAndFStringmID =  NULL;
282

    
283
        if (cAndFStringmID == NULL) {
284
            cAndFStringmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
285
                                        "compileFromFileAndSave",
286
                                        "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
287
        }
288
        if (!cAndFStringmID) {
289
                std::cerr << "Error: "<<getDllname() << ".compileFromFileAndSave"
290
                                << " not found\n" << std::endl;
291

    
292
        } else {
293

    
294
                
295
                SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cAndFStringmID,
296
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
297
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(xslFilename),SaxonProcessor::sxn_environ->env->NewStringUTF(filename));
298
                
299
                proc->checkAndCreateException(cppClass);
300

    
301

    
302
     }
303
}
304

    
305
void Xslt30Processor::compileFromString(const char* stylesheetStr) {
306
        static jmethodID cStringmID = NULL;
307
        if (cStringmID == NULL) {
308
                        cStringmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
309
                                        "compileFromString",
310
                                        "(Ljava/lang/String;Ljava/lang/String;Z;[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XsltExecutable;");
311
        }
312
                                        
313
        if (!cStringmID) {
314
                std::cerr << "Error: "<<getDllname() << ".compileFromString"
315
                                << " not found\n" << std::endl;
316
                return NULL;
317

    
318
        } else {
319
                
320
                std::map<std::string,std::string> properties;
321

    
322
                JParameters comboArrays;
323
                comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
324
                jobject executableObject = (jobject)(
325
                                SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cStringmID,
326
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
327
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheetStr), jitCompilation, comboArrays.stringArray, comboArrays.objectArray));
328
                if (!executableObject) {
329
                        proc->checkAndCreateException(cppClass);
330
                        return NULL;
331
                }
332
                if (comboArrays.stringArray != NULL) {
333
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
334
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
335
                }
336
                SaxonProcessor::sxn_environ->env->NewGlobalRef(executableObject);
337
                return new XsltExecutable(executableObject);
338
        }
339

    
340
}
341

    
342
void Xslt30Processor::compileFromXdmNode(XdmNode * node) {
343
        static jmethodID cNodemID = NULL;
344
    if(cNodemID == NULL) {                        
345
                        cNodemID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,"compileFromXdmNode",
346
                        "(Ljava/lang/String;Ljava/lang/Object;Z;[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XsltExecutable;");
347
        }
348
        if (!cNodemID) {
349
                std::cerr << "Error: "<< getDllname() << ".compileFromXdmNode"
350
                                << " not found\n" << std::endl;
351
                return NULL;
352

    
353
        } else {
354
                JParameters comboArrays;
355
                comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
356
                jobject executableObject = (jobject)(
357
                                SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cNodemID,
358
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
359
                                                node->getUnderlyingValue(), jitCompilation, comboArrays.stringArray, comboArrays.objectArray));
360
                if (!executableObject) {
361
                        proc->checkAndCreateException(cppClass);
362
                        return NULL;
363
                }
364
                if (comboArrays.stringArray != NULL) {
365
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
366
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
367
                }
368
                SaxonProcessor::sxn_environ->env->NewGlobalRef(executableObject);
369
        return new XsltExecutable(executableObject);
370
        }
371

    
372
}
373

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

    
386
        } else {
387
                
388
                if(source == NULL) {
389
                        std::cerr << "Error in compileFromFile method - The Stylesheet file is NULL" <<std::endl;
390
                        return;
391
                }
392
                JParameters comboArrays;
393
                comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
394
                jobject executableObject = (jobject)(
395
                                SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cFilemID,
396
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
397
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(source), jitCompilation, comboArrays.stringArray, comboArrays.objectArray));
398
                if (!executableObject) {
399
                        proc->checkAndCreateException(cppClass);
400
                     return NULL;
401
                }
402
                if (comboArrays.stringArray != NULL) {
403
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
404
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
405
                }
406
                SaxonProcessor::sxn_environ->env->NewGlobalRef(executableObject);
407
                return new XsltExecutable(executableObject);
408
        }
409

    
410
}
411

    
412

    
413
void Xslt30Processor::compileFromFile(const char* stylesheet) {
414
        static jmethodID cFilemID = NULL;
415
        if(cFilemID == NULL) {
416
            cFilemID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
417
                                        "compileFromFile",
418
                                        "(Ljava/lang/String;Ljava/lang/String;Z;[Ljava/lang/String;[Ljava/lang/Object;)Lnet/sf/saxon/s9api/XsltExecutable;");
419
        }
420
        if (!cFilemID) {
421
                std::cerr << "Error: "<<getDllname() << ".compileFromFile"
422
                                << " not found\n" << std::endl;
423
                return NULL;
424

    
425
        } else {
426
                
427
                if(stylesheet == NULL) {
428
                        std::cerr << "Error in compileFromFile method - The Stylesheet file is NULL" <<std::endl;
429
                        return;
430
                }
431
                JParameters comboArrays;
432
                comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
433
                jobject excutableObject = (jobject)(
434
                                SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, cFilemID,
435
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
436
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheet), jitCompilation, comboArrays.stringArray, comboArrays.objectArray));
437
                if (!executableObject) {
438
                        proc->checkAndCreateException(cppClass);
439
                        return NULL;
440
                     
441
                }
442
                if (comboArrays.stringArray != NULL) {
443
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
444
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
445
                }
446
                SaxonProcessor::sxn_environ->env->NewGlobalRef(executableObject);
447
                return new XsltExecutable(executableObject);
448
        }
449

    
450
}
451

    
452

    
453

    
454

    
455
XdmValue * Xslt30Processor::transformFileToValue(const char* sourcefile,
456
                const char* stylesheetfile) {
457

    
458
        if(exceptionOccurred()) {
459
                //Possible error detected in the compile phase. Processor not in a clean state.
460
                //Require clearing exception.
461
                return NULL;        
462
        }
463

    
464
        if(sourcefile == NULL && stylesheetfile == NULL && !stylesheetObject){
465
        
466
                return NULL;
467
        }
468

    
469
        setProperty("resources", proc->getResourcesDirectory());
470
        static jmethodID mtvID = NULL;
471

    
472
        if(mtvID == NULL) {
473
                        mtvID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
474
                                        "transformToValue",
475
                                        "(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;");
476
        }
477
        if (!mtvID) {
478
                std::cerr << "Error: "<< getDllname() << ".transformtoValue" << " not found\n"
479
                                << std::endl;
480

    
481
        } else {
482
            JParameters comboArrays;
483
                comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
484

    
485
                jobject result = (jobject)(
486
                                SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, mtvID,
487
                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()), cppXT, NULL,
488
                                                (sourcefile != NULL ?SaxonProcessor::sxn_environ->env->NewStringUTF(sourcefile) : NULL),
489
                                                (stylesheetfile != NULL ?
490
                                                                SaxonProcessor::sxn_environ->env->NewStringUTF(
491
                                                                                stylesheetfile) :
492
                                                                NULL), comboArrays.stringArray, comboArrays.objectArray));
493
                if (comboArrays.stringArray != NULL) {
494
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
495
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
496
                }
497
                if (result) {
498
                        jclass atomicValueClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmAtomicValue");
499
                          jclass nodeClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmNode");
500
                          jclass functionItemClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmFunctionItem");
501
                        XdmValue * value = NULL;
502
                          XdmItem * xdmItem = NULL;
503

    
504

    
505
                                  if(SaxonProcessor::sxn_environ->env->IsInstanceOf(result, atomicValueClass)           == JNI_TRUE) {
506
                                          xdmItem = new XdmAtomicValue(result);
507
                        xdmItem->setProcessor(proc);
508
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
509
                        return xdmItem;
510

    
511
                                  } else if(SaxonProcessor::sxn_environ->env->IsInstanceOf(result, nodeClass)           == JNI_TRUE) {
512
                                          xdmItem = new XdmNode(result);
513
                        xdmItem->setProcessor(proc);
514
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
515
                        return xdmItem;
516

    
517
                                  } else if (SaxonProcessor::sxn_environ->env->IsInstanceOf(result, functionItemClass)           == JNI_TRUE) {
518
                        xdmItem =  new XdmFunctionItem(result);
519
                        xdmItem->setProcessor(proc);
520
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
521
                        return xdmItem;
522
                                  } else {
523
                                        value = new XdmValue(result, true);
524
                                        value->setProcessor(proc);
525
                                        for(int z=0;z<value->size();z++) {
526
                                                value->itemAt(z)->setProcessor(proc);
527
                                        }
528
                                        return value;
529
                                }
530
                                value = new XdmValue();
531
                                value->setProcessor(proc);
532
                      value->addUnderlyingValue(result);
533

    
534
                          SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
535
                          return value;
536
                }else {
537
        
538
                        proc->checkAndCreateException(cppClass);
539
                           
540
                     }
541
        }
542
        return NULL;
543

    
544
}
545

    
546

    
547
void Xslt30Processor::transformFileToFile(const char* source,
548
                const char* stylesheet, const char* outputfile) {
549

    
550
        if(exceptionOccurred()) {
551
                //Possible error detected in the compile phase. Processor not in a clean state.
552
                //Require clearing exception.
553
                return;        
554
        }
555
        if(!stylesheetObject && stylesheet==NULL){
556
                std::cerr<< "Error: stylesheet has not been set or created using the compile methods."<<std::endl;
557
                return;
558
        }
559
        setProperty("resources", proc->getResourcesDirectory());
560
        static jmethodID mtfID = NULL;
561

    
562
        if(mtfID == NULL) {
563
                mtfID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
564
                                        "transformToFile",
565
                                        "(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");
566
        }
567
        if (!mtfID) {
568
                std::cerr << "Error: "<<getDllname() << "transformToFile" << " not found\n"
569
                                << std::endl;
570

    
571
        } else {
572
            JParameters comboArrays;
573
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
574

    
575
                SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, mtfID,
576
                                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()), cppXT, NULL,
577
                                                                (source != NULL ? SaxonProcessor::sxn_environ->env->NewStringUTF(source) : NULL),
578
                                                                SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheet),        (outputfile != NULL ? SaxonProcessor::sxn_environ->env->NewStringUTF(outputfile) :NULL),
579
                                                                comboArrays.stringArray, comboArrays.objectArray);
580
                if (comboArrays.stringArray!= NULL) {
581
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
582
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
583
                }
584
                }
585
                proc->checkAndCreateException(cppClass);
586
        }
587

    
588

    
589
const char * Xslt30Processor::transformFileToString(const char* source,
590
                const char* stylesheet) {
591

    
592
        if(exceptionOccurred()) {
593
                //Possible error detected in the compile phase. Processor not in a clean state.
594
                //Require clearing exception.
595
                return NULL;        
596
        }
597
        if(source == NULL && stylesheet == NULL && !stylesheetObject){
598
                std::cerr<< "Error: No stylesheet found. Please compile stylesheet before calling transformFileToString or check exceptions"<<std::endl;
599
                return NULL;
600
        }
601
        setProperty("resources", proc->getResourcesDirectory());
602
        static jmethodID mtsID =  NULL;
603

    
604
        if(mtsID == NULL) {
605
                        mtsID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
606
                                        "transformToString",
607
                                        "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;");
608
        }
609
        if (!mtsID) {
610
                std::cerr << "Error: "<<getDllname() << "transformFileToString" << " not found\n"
611
                                << std::endl;
612

    
613
        } else {
614
    JParameters comboArrays;
615
    comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
616

    
617
        jstring result = NULL;
618
        jobject obj = SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, mtsID,
619
                                                                SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()), cppXT, NULL,
620
                                                (source != NULL ? SaxonProcessor::sxn_environ->env->NewStringUTF(
621
                                                                                                source) : NULL),
622
                                                                (stylesheet != NULL ? SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheet) : NULL),
623
                                                                comboArrays.stringArray, comboArrays.objectArray);
624
    if (comboArrays.stringArray!= NULL) {
625
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
626
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
627
    }
628
        if(obj) {
629
                        result = (jstring)obj;
630
        }
631

    
632
        if (result) {
633
                        const char * str = SaxonProcessor::sxn_environ->env->GetStringUTFChars(result,
634
                                        NULL);
635
                        SaxonProcessor::sxn_environ->env->DeleteLocalRef(obj);
636
                        return str;
637
                } else  {
638
                        proc->checkAndCreateException(cppClass);  
639
                           
640
                     }
641
        }
642
        return NULL;
643
}
644

    
645

    
646

    
647
const char * Xslt30Processor::getErrorMessage(int i ){
648
         if(proc->exception == NULL) {return NULL;}
649
         return proc->exception->getErrorMessage(i);
650
 }
651

    
(32-32/50)