comparison OrthancServer/OrthancInitialization.cpp @ 1424:fe384a9d3b51

OrthancPluginGetConfiguration
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 26 Jun 2015 15:32:45 +0200
parents 7b7d597a190c
children d710ea64f0fd
comparison
equal deleted inserted replaced
1423:7b7d597a190c 1424:fe384a9d3b51
69 69
70 static void AddFileToConfiguration(const boost::filesystem::path& path) 70 static void AddFileToConfiguration(const boost::filesystem::path& path)
71 { 71 {
72 LOG(WARNING) << "Reading the configuration from: " << path; 72 LOG(WARNING) << "Reading the configuration from: " << path;
73 73
74 std::string content; 74 Json::Value config;
75 Toolbox::ReadFile(content, path.string()); 75
76 76 {
77 Json::Value tmp; 77 std::string content;
78 Json::Reader reader; 78 Toolbox::ReadFile(content, path.string());
79 if (!reader.parse(content, tmp) || 79
80 tmp.type() != Json::objectValue) 80 Json::Value tmp;
81 { 81 Json::Reader reader;
82 LOG(ERROR) << "Bad file format for this configuration file: " << path; 82 if (!reader.parse(content, tmp) ||
83 throw OrthancException(ErrorCode_BadFileFormat); 83 tmp.type() != Json::objectValue)
84 {
85 LOG(ERROR) << "Bad file format for this configuration file: " << path;
86 throw OrthancException(ErrorCode_BadFileFormat);
87 }
88
89 Toolbox::CopyJsonWithoutComments(config, tmp);
84 } 90 }
85 91
86 if (configuration_.size() == 0) 92 if (configuration_.size() == 0)
87 { 93 {
88 configuration_ = tmp; 94 configuration_ = config;
89 } 95 }
90 else 96 else
91 { 97 {
92 Json::Value::Members members = tmp.getMemberNames(); 98 Json::Value::Members members = config.getMemberNames();
93 for (Json::Value::ArrayIndex i = 0; i < members.size(); i++) 99 for (Json::Value::ArrayIndex i = 0; i < members.size(); i++)
94 { 100 {
95 if (configuration_.isMember(members[i])) 101 if (configuration_.isMember(members[i]))
96 { 102 {
97 LOG(ERROR) << "The configuration section \"" << members[i] << "\" is defined in 2 different configuration files"; 103 LOG(ERROR) << "The configuration section \"" << members[i] << "\" is defined in 2 different configuration files";
98 throw OrthancException(ErrorCode_BadFileFormat); 104 throw OrthancException(ErrorCode_BadFileFormat);
99 } 105 }
100 else 106 else
101 { 107 {
102 configuration_[members[i]] = tmp[members[i]]; 108 configuration_[members[i]] = config[members[i]];
103 } 109 }
104 } 110 }
105 } 111 }
106 } 112 }
107 113
837 843
838 IStorageArea* Configuration::CreateStorageArea() 844 IStorageArea* Configuration::CreateStorageArea()
839 { 845 {
840 return CreateFilesystemStorage(); 846 return CreateFilesystemStorage();
841 } 847 }
848
849
850 void Configuration::FormatConfiguration(std::string& result)
851 {
852 Json::Value config;
853
854 {
855 boost::mutex::scoped_lock lock(globalMutex_);
856 config = configuration_;
857 }
858
859 Json::StyledWriter w;
860 result = w.write(config);
861 }
842 } 862 }