Project

Profile

Help

Revision 6304fb8b

Added by O'Neil Delpratt 5 months ago

Saxon/C bug fixes and development work

View differences:

latest10/hec/Saxon.C.API/Xslt30Processor.cpp
7 7
#include "XdmNode.h"
8 8
#include "XdmAtomicValue.h"
9 9
#include "XdmFunctionItem.h"
10
#include "XsltExecutable.h"
10 11
#ifdef DEBUG
11 12
#include <typeinfo> //used for testing only
12 13
#endif
......
38 39
#endif
39 40
	tunnel = false;
40 41
	jitCompilation = false;
41
	exception = NULL;
42
	exception = nullptr;
42 43

  
43 44
	if(!(proc->cwd.empty()) && curr.empty()){
44 45
		cwdXT = proc->cwd;
......
66 67
    {
67 68

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

  
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 78
	jitCompilation = other.jitCompilation;
84 79

  
85 80
}
86 81

  
87 82

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

  
92
}
93 84

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

  
98 89
const char * Xslt30Processor::getErrorCode() {
99
 if(exception == NULL) {return NULL;}
90
 if(exception == nullptr) {return nullptr;}
100 91
 return exception->getErrorCode();
101 92
 }
102 93

  
103 94

  
104 95
void Xslt30Processor::setParameter(const char* name, XdmValue * value) {
105
	if(value != NULL && name != NULL){
96
	if(value != nullptr && name != nullptr){
106 97
		value->incrementRefCount();
107 98
		int s = parameters.size();
108 99
		std::string skey = ("sparam:"+std::string(name));
......
113 104
            if (it != parameters.end()) {
114 105
                XdmValue * valuei = it->second;
115 106
                valuei->decrementRefCount();
116
                if(valuei != NULL && valuei->getRefCount() < 1){
107
                if(valuei != nullptr && valuei->getRefCount() < 1){
117 108
                    delete value;
118 109
                }
119 110
                parameters.erase(skey);
......
128 119
        it = parameters.find("sparam:"+std::string(name));
129 120
        if (it != parameters.end())
130 121
          return it->second;
131
	    return NULL;
122
	    return nullptr;
132 123
}
133 124

  
134 125
bool Xslt30Processor::removeParameter(const char* name) {
......
149 140
#ifdef DEBUG
150 141
			std::cout<<"clearParameter() - XdmValue refCount="<<value->getRefCount()<<std::endl;
151 142
#endif
152
			if(value != NULL && value->getRefCount() < 1){		
143
			if(value != nullptr && value->getRefCount() < 1){
153 144
	        		delete value;
154 145
			}
155 146
        	}
......
177 168

  
178 169

  
179 170
void Xslt30Processor::exceptionClear(){
180
 if(exception != NULL) {
171
 if(exception != nullptr) {
181 172
 	delete exception;
182
 	exception = NULL;
173
 	exception = nullptr;
183 174
	SaxonProcessor::sxn_environ->env->ExceptionClear();
184 175
 }
185 176
  
186 177
 }
187 178

  
188 179
   void Xslt30Processor::setcwd(const char* dir){
189
    if (dir!= NULL) {
180
    if (dir!= nullptr) {
190 181
        cwdXT = std::string(dir);
191 182
    }
192 183
   }
193 184

  
194 185
const char* Xslt30Processor::checkException() {
195
	/*if(proc->exception == NULL) {
186
	/*if(proc->exception == nullptr) {
196 187
	 proc->exception = proc->checkForException(environi, cpp);
197 188
	 }
198 189
	 return proc->exception;*/
......
202 193

  
203 194

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

  
207
	if(cAndSNodemID == NULL) {
198
	if(cAndSNodemID == nullptr) {
208 199
			cAndSNodemID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
209 200
					"compileFromXdmNodeAndSave",
210 201
					"(Ljava/lang/String;Ljava/lang/Object;Ljava/lang/String;)V");
......
229 220
}
230 221

  
231 222
    void Xslt30Processor::compileFromStringAndSave(const char* stylesheetStr, const char* filename){
232
	static jmethodID cAndSStringmID = NULL;
233
	if(cAndSStringmID == NULL) {
223
	static jmethodID cAndSStringmID = nullptr;
224
	if(cAndSStringmID == nullptr) {
234 225
	   cAndSStringmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
235 226
					"compileFromStringAndSave",
236 227
					"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
......
255 246

  
256 247

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

  
260
	if (cAndFStringmID == NULL) {
251
	if (cAndFStringmID == nullptr) {
261 252
	    cAndFStringmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
262 253
					"compileFromFileAndSave",
263 254
					"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
......
280 271
}
281 272

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

  
295 286
	} else {
296 287

  
......
302 293
						SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheetStr), jitCompilation, comboArrays.stringArray, comboArrays.objectArray));
303 294
		if (!executableObject) {
304 295
			exception = proc->checkAndCreateException(cppClass);
305
			return NULL;
296
			return nullptr;
306 297
		}
307
		if (comboArrays.stringArray != NULL) {
298
		if (comboArrays.stringArray != nullptr) {
308 299
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
309 300
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
310 301
		}
311 302

  
312
        XsltExecutable * executable = new XsltExecutable(SaxonProcessor::sxn_environ->env->NewGlobalRef(executableObject));
303
		jobject obj = SaxonProcessor::sxn_environ->env->NewGlobalRef(executableObject);
304
        XsltExecutable * executable = new XsltExecutable(obj, cwdXT);
313 305
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(executableObject);
314 306
		return executable;
315 307
	}
......
317 309
}
318 310

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

  
330 322
	} else {
331 323
		JParameters comboArrays;
......
336 328
						node->getUnderlyingValue(), jitCompilation, comboArrays.stringArray, comboArrays.objectArray));
337 329
		if (!executableObject) {
338 330
			proc->checkAndCreateException(cppClass);
339
			return NULL;
331
			return nullptr;
340 332
		}
341
		if (comboArrays.stringArray != NULL) {
333
		if (comboArrays.stringArray != nullptr) {
342 334
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
343 335
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
344 336
		}
......
351 343
}
352 344

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

  
365 357
	} else {
366 358
		
367
		if(source == NULL) {
368
			std::cerr << "Error in compileFromFile method - The Stylesheet file is NULL" <<std::endl;
359
		if(source == nullptr) {
360
			std::cerr << "Error in compileFromFile method - The Stylesheet file is nullptr" <<std::endl;
369 361
			return;
370 362
		}
371 363
		JParameters comboArrays;
......
376 368
						SaxonProcessor::sxn_environ->env->NewStringUTF(source), jitCompilation, comboArrays.stringArray, comboArrays.objectArray));
377 369
		if (!executableObject) {
378 370
			proc->checkAndCreateException(cppClass);
379
     		return NULL;
371
     		return nullptr;
380 372
		}
381
		if (comboArrays.stringArray != NULL) {
373
		if (comboArrays.stringArray != nullptr) {
382 374
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
383 375
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
384 376
		}
......
392 384

  
393 385

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

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

  
428
        XsltExecutable * executable = new XsltExecutable(SaxonProcessor::sxn_environ->env->NewGlobalRef(executableObject));
420
        XsltExecutable *executable;
421
        executable = new XsltExecutable(SaxonProcessor::sxn_environ->env->NewGlobalRef(executableObject), cwdXT);
429 422
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(executableObject);
430 423
		return executable;
431 424
	}
......
441 434
	if(exceptionOccurred()) {
442 435
		//Possible error detected in the compile phase. Processor not in a clean state.
443 436
		//Require clearing exception.
444
		return NULL;	
437
		return nullptr;
445 438
	}
446 439

  
447
	if(sourcefile == NULL && stylesheetfile == NULL){
440
	if(sourcefile == nullptr && stylesheetfile == nullptr){
448 441
	
449
		return NULL;
442
		return nullptr;
450 443
	}
451 444

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

  
455
	if(mtvID == NULL) {
446
	static jmethodID mtvID = nullptr;
447

  
448
	if(mtvID == nullptr) {
456 449
			mtvID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
457 450
					"transformToValue",
458 451
					"(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;");
......
467 460

  
468 461
		jobject result = (jobject)(
469 462
				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 ?
463
						SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()), cppXT, nullptr,
464
						(sourcefile != nullptr ?SaxonProcessor::sxn_environ->env->NewStringUTF(sourcefile) : nullptr),
465
						(stylesheetfile != nullptr ?
473 466
								SaxonProcessor::sxn_environ->env->NewStringUTF(
474 467
										stylesheetfile) :
475
								NULL), comboArrays.stringArray, comboArrays.objectArray));
476
		if (comboArrays.stringArray != NULL) {
468
								nullptr), comboArrays.stringArray, comboArrays.objectArray));
469
		if (comboArrays.stringArray != nullptr) {
477 470
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
478 471
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
479 472
		}
......
481 474
			jclass atomicValueClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmAtomicValue");
482 475
          		jclass nodeClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmNode");
483 476
          		jclass functionItemClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmFunctionItem");
484
			XdmValue * value = NULL;
485
          		XdmItem * xdmItem = NULL;
477
			XdmValue * value = nullptr;
478
          		XdmItem * xdmItem = nullptr;
486 479

  
487 480

  
488 481
          			if(SaxonProcessor::sxn_environ->env->IsInstanceOf(result, atomicValueClass)           == JNI_TRUE) {
......
524 517
	   		
525 518
     		}
526 519
	}
527
	return NULL;
520
	return nullptr;
528 521

  
529 522
}
530 523

  
......
537 530
		//Require clearing exception.
538 531
		return;	
539 532
	}
540
	if(stylesheet==NULL){
533
	if(stylesheet==nullptr){
541 534
		std::cerr<< "Error: stylesheet has not been set."<<std::endl;
542 535
		return;
543 536
	}
544
	//setProperty("resources", proc->getResourcesDirectory());
545
	static jmethodID mtfID = NULL;
537
	//
538
	static jmethodID mtfID = nullptr;
546 539

  
547
	if(mtfID == NULL) {
540
	if(mtfID == nullptr) {
548 541
		mtfID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
549 542
					"transformToFile",
550 543
					"(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");
......
558 551
        comboArrays = SaxonProcessor::createParameterJArray2(parameters);
559 552

  
560 553
		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),
554
								SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()), cppXT, nullptr,
555
								(source != nullptr ? SaxonProcessor::sxn_environ->env->NewStringUTF(source) : nullptr),
556
								SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheet),	(outputfile != nullptr ? SaxonProcessor::sxn_environ->env->NewStringUTF(outputfile) :nullptr),
564 557
								comboArrays.stringArray, comboArrays.objectArray);
565
		if (comboArrays.stringArray!= NULL) {
558
		if (comboArrays.stringArray!= nullptr) {
566 559
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
567 560
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
568 561
		}
......
577 570
	if(exceptionOccurred()) {
578 571
		//Possible error detected in the compile phase. Processor not in a clean state.
579 572
		//Require clearing exception.
580
		return NULL;	
573
		return nullptr;
581 574
	}
582
	if(source == NULL && stylesheet == NULL){
583
		std::cerr<< "Error: NULL file name found in transformFiletoString."<<std::endl;
584
		return NULL;
575
	if(source == nullptr && stylesheet == nullptr){
576
		std::cerr<< "Error: nullptr file name found in transformFiletoString."<<std::endl;
577
		return nullptr;
585 578
	}
586
	setProperty("resources", proc->getResourcesDirectory());
587
	static jmethodID mtsID =  NULL;
588 579

  
589
	if(mtsID == NULL) {
580
	static jmethodID mtsID =  nullptr;
581

  
582
	if(mtsID == nullptr) {
590 583
			mtsID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
591 584
					"transformToString",
592 585
					"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;");
......
599 592
    JParameters comboArrays;
600 593
    comboArrays = SaxonProcessor::createParameterJArray2(parameters);
601 594

  
602
	jstring result = NULL;
595
	jstring result = nullptr;
603 596
	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),
597
								SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()), cppXT, nullptr,
598
						(source != nullptr ? SaxonProcessor::sxn_environ->env->NewStringUTF(
599
												source) : nullptr),
600
								(stylesheet != nullptr ? SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheet) : nullptr),
608 601
								comboArrays.stringArray, comboArrays.objectArray);
609
    if (comboArrays.stringArray!= NULL) {
602
    if (comboArrays.stringArray!= nullptr) {
610 603
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.stringArray);
611 604
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
612 605
    }
......
616 609

  
617 610
	if (result) {
618 611
			const char * str = SaxonProcessor::sxn_environ->env->GetStringUTFChars(result,
619
					NULL);
612
					nullptr);
620 613
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(obj);
621 614
			return str;
622 615
		} else  {
......
624 617
	   		
625 618
     		}
626 619
	}
627
	return NULL;
620
	return nullptr;
628 621
}
629 622

  
630 623

  
631 624

  
632 625
const char * Xslt30Processor::getErrorMessage(){
633
 	if(exception == NULL) {return NULL;}
634
 	return exception->getErrorMessage();
626
 	if(exception == nullptr) {return nullptr;}
627
 	return exception->getMessage();
635 628
 }
636 629

  

Also available in: Unified diff