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/XsltProcessor.cpp
39 39
#endif
40 40
	nodeCreated = false;
41 41
    jitCompilation = false;
42
	exception = NULL;
42
	exception = nullptr;
43 43
	if(!(proc->cwd.empty()) && curr.empty()){
44 44
		cwdXT = proc->cwd;
45 45
	} else {
......
60 60
    {
61 61

  
62 62
       XdmValue * valuei = paramIter->second;
63
       if(valuei == NULL) {
63
       if(valuei == nullptr) {
64 64
    	 	//std::cerr<<"Error in XsltProcessor copy constructor"<<std::endl;
65 65
       } else {
66 66
            parameters[paramIter->first] = new XdmValue(*(valuei));
......
89 89
}
90 90

  
91 91
const char * XsltProcessor::getErrorCode() {
92
 if(exception == NULL) {
93
    return NULL;
92
 if(exception == nullptr) {
93
    return nullptr;
94 94
 }
95 95
 return exception->getErrorCode();
96 96
}
97 97

  
98 98
void XsltProcessor::setSourceFromXdmNode(XdmNode * value) {
99
    if(value != NULL){
99
    if(value != nullptr){
100 100
      value->incrementRefCount();
101 101
      parameters["node"] = value;
102 102
    }
103 103
}
104 104

  
105 105
void XsltProcessor::setSourceFromFile(const char * ifile) {
106
	if(ifile != NULL) {
106
	if(ifile != nullptr) {
107 107
		setProperty("s", ifile);
108 108
	}
109 109
}
......
113 113
}
114 114

  
115 115
void XsltProcessor::setBaseOutputURI(const char * baseURI) {
116
	if(baseURI != NULL) {
116
	if(baseURI != nullptr) {
117 117
  	    setProperty("baseoutput", baseURI);
118 118
	}
119 119
}
120 120

  
121 121
void XsltProcessor::setParameter(const char* name, XdmValue * value) {
122
	if(value != NULL && name != NULL){
122
	if(value != nullptr && name != nullptr){
123 123
		value->incrementRefCount();
124 124
		int s = parameters.size();
125 125
		std::string skey = "param:"+std::string(name);
......
130 130
            if (it != parameters.end()) {
131 131
                XdmValue * valuei = it->second;
132 132
                valuei->decrementRefCount();
133
                if(valuei != NULL && valuei->getRefCount() < 1){
133
                if(valuei != nullptr && valuei->getRefCount() < 1){
134 134
                    delete value;
135 135
                }
136 136
                parameters.erase(skey);
......
145 145
        it = parameters.find("param:"+std::string(name));
146 146
        if (it != parameters.end())
147 147
          return it->second;
148
        return NULL;
148
        return nullptr;
149 149
}
150 150

  
151 151
bool XsltProcessor::removeParameter(const char* name) {
......
157 157
}
158 158

  
159 159
void XsltProcessor::setProperty(const char* name, const char* value) {	
160
	if(name != NULL) {
160
	if(name != nullptr) {
161 161
	    int s = properties.size();
162 162
		std::string skey = std::string(name);
163
		properties.insert(std::pair<std::string, std::string>(skey, std::string((value == NULL ? "" : value))));
163
		properties.insert(std::pair<std::string, std::string>(skey, std::string((value == nullptr ? "" : value))));
164 164

  
165 165
		if(s == properties.size()) {
166 166
            std::map<std::string, std::string>::iterator it;
167 167
            it = properties.find(skey);
168 168
            if (it != properties.end()) {
169 169
                properties.erase(skey);
170
                properties[skey] = std::string((value == NULL ? "" : value));
170
                properties[skey] = std::string((value == nullptr ? "" : value));
171 171
            }
172 172
		}
173 173
	}
......
178 178
        it = properties.find(std::string(name));
179 179
        if (it != properties.end())
180 180
          return it->second.c_str();
181
	return NULL;
181
	return nullptr;
182 182
}
183 183

  
184 184
void XsltProcessor::clearParameters(bool delValues) {
......
190 190
#ifdef DEBUG
191 191
			std::cout<<"clearParameter() - XdmValue refCount="<<value->getRefCount()<<std::endl;
192 192
#endif
193
			if(value != NULL && value->getRefCount() < 1){		
193
			if(value != nullptr && value->getRefCount() < 1){
194 194
	        		delete value;
195 195
			}
196 196
        	}
......
224 224
}
225 225

  
226 226
void XsltProcessor::exceptionClear(){
227
 if(exception != NULL) {
227
 if(exception != nullptr) {
228 228
 	delete exception;
229
 	exception = NULL;
229
 	exception = nullptr;
230 230
	SaxonProcessor::sxn_environ->env->ExceptionClear();
231 231
 }
232 232
  
233 233
 }
234 234

  
235 235
   void XsltProcessor::setcwd(const char* dir){
236
    if(dir != NULL) {
236
    if(dir != nullptr) {
237 237
        cwdXT = std::string(dir);
238 238
    }
239 239
   }
240 240

  
241 241
const char* XsltProcessor::checkException() {
242
	/*if(proc->exception == NULL) {
242
	/*if(proc->exception == nullptr) {
243 243
	 proc->exception = proc->checkForException(environi, cpp);
244 244
	 }
245 245
	 return proc->exception;*/
......
398 398

  
399 399
void XsltProcessor::releaseStylesheet() {
400 400

  
401
	stylesheetObject = NULL;
401
	stylesheetObject = nullptr;
402 402
	
403 403
}
404 404

  
......
410 410
	if(exceptionOccurred()) {
411 411
		//Possible error detected in the compile phase. Processor not in a clean state.
412 412
		//Require clearing exception.
413
		return NULL;	
413
		return nullptr;
414 414
	}
415 415

  
416
	if(sourcefile == NULL && stylesheetfile == NULL && !stylesheetObject){
416
	if(sourcefile == nullptr && stylesheetfile == nullptr && !stylesheetObject){
417 417
	
418
		return NULL;
418
		return nullptr;
419 419
	}
420 420

  
421
	setProperty("resources", proc->getResourcesDirectory());
421

  
422 422
	static jmethodID mID =
423 423
			(jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
424 424
					"transformToNode",
......
428 428
				<< std::endl;
429 429

  
430 430
	} else {
431
		jobjectArray stringArray = NULL;
432
		jobjectArray objectArray = NULL;
431
		jobjectArray stringArray = nullptr;
432
		jobjectArray objectArray = nullptr;
433 433
		jclass objectClass = lookForClass(SaxonProcessor::sxn_environ->env,
434 434
				"java/lang/Object");
435 435
		jclass stringClass = lookForClass(SaxonProcessor::sxn_environ->env,
......
463 463
		jobject result = (jobject)(
464 464
				SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, mID,
465 465
						SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
466
						(sourcefile != NULL ?
466
						(sourcefile != nullptr ?
467 467
								SaxonProcessor::sxn_environ->env->NewStringUTF(sourcefile) :
468
								NULL),
469
						(stylesheetfile != NULL ?
468
								nullptr),
469
						(stylesheetfile != nullptr ?
470 470
								SaxonProcessor::sxn_environ->env->NewStringUTF(
471 471
										stylesheetfile) :
472
								NULL), stringArray, objectArray));
472
								nullptr), stringArray, objectArray));
473 473
		if (size > 0) {
474 474
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(stringArray);
475 475
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(objectArray);
......
486 486
	   		
487 487
     		}
488 488
	}
489
	return NULL;
489
	return nullptr;
490 490

  
491 491
}
492 492

  
......
499 499
		//Require clearing exception.
500 500
		return;	
501 501
	}
502
	if(source == NULL && outputfile == NULL && !stylesheetObject){
502
	if(source == nullptr && outputfile == nullptr && !stylesheetObject){
503 503
		
504 504
		return;
505 505
	}
506
	setProperty("resources", proc->getResourcesDirectory());
506

  
507 507
	jmethodID mID =
508 508
			(jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
509 509
					"transformToFile",
......
513 513
				<< std::endl;
514 514

  
515 515
	} else {
516
		jobjectArray stringArray = NULL;
517
		jobjectArray objectArray = NULL;
516
		jobjectArray stringArray = nullptr;
517
		jobjectArray objectArray = nullptr;
518 518
		jclass objectClass = lookForClass(SaxonProcessor::sxn_environ->env,
519 519
				"java/lang/Object");
520 520
		jclass stringClass = lookForClass(SaxonProcessor::sxn_environ->env,
......
547 547
				std::string s1 = typeid(iter->second).name();
548 548
				std::cerr<<"Type of itr:"<<s1<<std::endl;
549 549
				jobject xx = (iter->second)->getUnderlyingValue();
550
				if(xx == NULL) {
550
				if(xx == nullptr) {
551 551
					std::cerr<<"value failed"<<std::endl;
552 552
				} else {
553 553

  
554 554
					std::cerr<<"Type of value:"<<(typeid(xx).name())<<std::endl;
555 555
				}
556
				if((iter->second)->getUnderlyingValue() == NULL) {
557
					std::cerr<<"(iter->second)->getUnderlyingValue() is NULL"<<std::endl;
556
				if((iter->second)->getUnderlyingValue() == nullptr) {
557
					std::cerr<<"(iter->second)->getUnderlyingValue() is nullptr"<<std::endl;
558 558
				}
559 559
#endif
560 560
				SaxonProcessor::sxn_environ->env->SetObjectArrayElement(objectArray, i,
......
574 574
		}
575 575
		SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, mID,
576 576
								SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
577
								(source != NULL ?
577
								(source != nullptr ?
578 578
										SaxonProcessor::sxn_environ->env->NewStringUTF(
579 579
												source) :
580
										NULL),
581
								SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheet),NULL,
580
										nullptr),
581
								SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheet),nullptr,
582 582
								stringArray, objectArray);
583 583
		if (size > 0) {
584 584
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(stringArray);
......
592 592

  
593 593
void XsltProcessor::setupXslMessage(bool show, const char* filename) {
594 594
    if(show) {
595
        if(filename == NULL) {
595
        if(filename == nullptr) {
596 596
            setProperty("m", "on");
597 597
        } else {
598 598
            setProperty("m", filename);
......
609 609
	if(exceptionOccurred()) {
610 610
		//Possible error detected in the compile phase. Processor not in a clean state.
611 611
		//Require clearing exception.
612
		return NULL;	
612
		return nullptr;
613 613
	}
614
	if(source == NULL && stylesheet == NULL && !stylesheetObject){
614
	if(source == nullptr && stylesheet == nullptr && !stylesheetObject){
615 615
		std::cerr<< "Error: The most recent StylesheetObject failed. Please check exceptions"<<std::endl;
616
		return NULL;
616
		return nullptr;
617 617
	}
618
	setProperty("resources", proc->getResourcesDirectory());
618

  
619 619
	jmethodID mID =
620 620
			(jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(cppClass,
621 621
					"transformToString",
......
625 625
				<< std::endl;
626 626

  
627 627
	} else {
628
		jobjectArray stringArray = NULL;
629
		jobjectArray objectArray = NULL;
628
		jobjectArray stringArray = nullptr;
629
		jobjectArray objectArray = nullptr;
630 630
		jclass objectClass = lookForClass(SaxonProcessor::sxn_environ->env,
631 631
				"java/lang/Object");
632 632
		jclass stringClass = lookForClass(SaxonProcessor::sxn_environ->env,
......
660 660

  
661 661
				jobject xx = (iter->second)->getUnderlyingValue();
662 662

  
663
				if(xx == NULL) {
663
				if(xx == nullptr) {
664 664
					std::cerr<<"value failed"<<std::endl;
665 665
				} else {
666 666

  
667 667
					std::cerr<<"Type of value:"<<(typeid(xx).name())<<std::endl;
668 668
				}
669
				if((iter->second)->getUnderlyingValue() == NULL) {
670
					std::cerr<<"(iter->second)->getUnderlyingValue() is NULL"<<std::endl;
669
				if((iter->second)->getUnderlyingValue() == nullptr) {
670
					std::cerr<<"(iter->second)->getUnderlyingValue() is nullptr"<<std::endl;
671 671
				}
672 672
#endif
673 673

  
......
687 687
			}
688 688
		}
689 689

  
690
	jstring result = NULL;
690
	jstring result = nullptr;
691 691
	jobject obj =
692 692
				(
693 693
						SaxonProcessor::sxn_environ->env->CallObjectMethod(cppXT, mID,
694 694
								SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
695
								(source != NULL ?
695
								(source != nullptr ?
696 696
										SaxonProcessor::sxn_environ->env->NewStringUTF(
697 697
												source) :
698
										NULL),
698
										nullptr),
699 699
								SaxonProcessor::sxn_environ->env->NewStringUTF(stylesheet),
700 700
								stringArray, objectArray));
701 701
		if(obj) {
......
707 707
		}
708 708
		if (result) {
709 709
			const char * str = SaxonProcessor::sxn_environ->env->GetStringUTFChars(result,
710
					NULL);
710
					nullptr);
711 711
			SaxonProcessor::sxn_environ->env->DeleteLocalRef(obj);
712 712
			return str;
713 713
		} else  {
......
715 715
	   		
716 716
     		}
717 717
	}
718
	return NULL;
718
	return nullptr;
719 719
}
720 720

  
721 721

  
722 722
   const char * XsltProcessor::transformToString(){
723 723
	if(!stylesheetObject){
724 724
		std::cerr<< "Error: No styleheet found. Please compile stylsheet before calling transformToString or check exceptions"<<std::endl;
725
		return NULL;
725
		return nullptr;
726 726
	}
727
	return transformFileToString(NULL, NULL);
727
	return transformFileToString(nullptr, nullptr);
728 728
   }
729 729

  
730 730

  
731 731
    XdmValue * XsltProcessor::transformToValue(){
732 732
	if(!stylesheetObject){
733 733
		std::cerr<< "Error: No styleheet found. Please compile stylsheet before calling transformToValue or check exceptions"<<std::endl;
734
		return NULL;
734
		return nullptr;
735 735
	}
736
	return transformFileToValue(NULL, NULL);
736
	return transformFileToValue(nullptr, nullptr);
737 737
   }
738 738

  
739 739
    void XsltProcessor::transformToFile(){
......
741 741
		std::cerr<< "Error: No styleheet found. Please compile stylsheet before calling transformToFile or check exceptions"<<std::endl;
742 742
		return;
743 743
	}
744
	transformFileToFile(NULL, NULL, NULL);
744
	transformFileToFile(nullptr, nullptr, nullptr);
745 745
   }
746 746

  
747 747
const char * XsltProcessor::getErrorMessage(){
748
 	if(exception == NULL) {
749
 	    return NULL;
748
 	if(exception == nullptr) {
749
 	    return nullptr;
750 750
 	}
751 751
 	return exception->getErrorMessage();
752 752
 }

Also available in: Unified diff