Mercurial > hg > orthanc
comparison Core/WebServiceParameters.cpp @ 3444:6fe42a335a80
WebServiceParameters::GetBooleanUserProperty()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 24 Jun 2019 17:15:03 +0200 |
parents | 595bfee4391a |
children | 94f4a18a79cc |
comparison
equal
deleted
inserted
replaced
3443:0371b65d5f76 | 3444:6fe42a335a80 |
---|---|
287 for (Json::Value::Members::const_iterator it = members.begin(); | 287 for (Json::Value::Members::const_iterator it = members.begin(); |
288 it != members.end(); ++it) | 288 it != members.end(); ++it) |
289 { | 289 { |
290 if (!IsReservedKey(*it)) | 290 if (!IsReservedKey(*it)) |
291 { | 291 { |
292 if (peer[*it].type() != Json::stringValue) | 292 switch (peer[*it].type()) |
293 { | 293 { |
294 throw OrthancException(ErrorCode_BadFileFormat); | 294 case Json::stringValue: |
295 } | 295 userProperties_[*it] = peer[*it].asString(); |
296 else | 296 break; |
297 { | 297 |
298 userProperties_[*it] = peer[*it].asString(); | 298 case Json::booleanValue: |
299 userProperties_[*it] = peer[*it].asBool() ? "1" : "0"; | |
300 break; | |
301 | |
302 case Json::intValue: | |
303 userProperties_[*it] = boost::lexical_cast<std::string>(peer[*it].asInt()); | |
304 break; | |
305 | |
306 default: | |
307 throw OrthancException(ErrorCode_BadFileFormat); | |
299 } | 308 } |
300 } | 309 } |
301 } | 310 } |
302 } | 311 } |
303 | 312 |
399 else | 408 else |
400 { | 409 { |
401 value = found->second; | 410 value = found->second; |
402 return true; | 411 return true; |
403 } | 412 } |
413 } | |
414 | |
415 | |
416 bool WebServiceParameters::GetBooleanUserProperty(const std::string& key, | |
417 bool defaultValue) const | |
418 { | |
419 Dictionary::const_iterator found = userProperties_.find(key); | |
420 | |
421 if (found == userProperties_.end()) | |
422 { | |
423 return defaultValue; | |
424 } | |
425 else if (found->second == "0" || | |
426 found->second == "false") | |
427 { | |
428 return false; | |
429 } | |
430 else if (found->second == "1" || | |
431 found->second == "true") | |
432 { | |
433 return true; | |
434 } | |
435 else | |
436 { | |
437 throw OrthancException(ErrorCode_BadFileFormat, "Bad value for a Boolean user property in the parameters " | |
438 "of a Web service: Property \"" + key + "\" equals: " + found->second); | |
439 } | |
404 } | 440 } |
405 | 441 |
406 | 442 |
407 bool WebServiceParameters::IsAdvancedFormatNeeded() const | 443 bool WebServiceParameters::IsAdvancedFormatNeeded() const |
408 { | 444 { |