38 #include <Ice/Properties.h>
40 #include <boost/regex.hpp>
48 using namespace Data_Structure;
49 using namespace Parser;
57 std::string configPath = app->getConfigPath();
59 std::string cachePath = ArmarXDataPath::GetCachePath();
61 if (!std::filesystem::exists(std::filesystem::path(configPath)))
63 std::ofstream out(configPath);
71 cfgProperties->load(configPath);
74 std::filesystem::path xmlPath = std::filesystem::path(cachePath) / std::filesystem::path(
"ComponentFiles") / std::filesystem::path(app->getPackageName() +
"." + app->getName() +
".xml");
75 if (!std::filesystem::exists(xmlPath))
77 ARMARX_INFO_S <<
"Could not find cached XML file at " << xmlPath;
79 result->setProperties(cfgProperties);
85 Ice::PropertyDict dict = cfgProperties->getPropertiesForPrefix(
"");
86 for (
auto const& property : dict)
89 if (!app->isDefaultProperty(property.first))
91 xmlProperties->defineOptionalProperty(property.first, property.second,
"No Description");
92 xmlProperties->getProperties()->setProperty(property.first, property.second);
93 app->setIsDefaultProperty(property.first,
false);
100 if (property.second.compare(
"<set value!>") &&
101 property.second.compare(
"::_NOT_SET_::"))
103 app->setDefaultPropertyEnabled(property.first,
true);
104 xmlProperties->getProperties()->setProperty(property.first, property.second);
111 return xmlProperties;
124 container->setProperties(properties);
129 auto contents = RapidXmlReader::ReadFileContents(path);
131 const boost::regex e(
"<!-- ([a-zA-Z0-9_]+) properties -->");
132 boost::match_results<std::string::const_iterator> what;
134 bool found = boost::regex_search(contents, what, e);
138 app->setConfigDomain(what[1]);
144 ARMARX_INFO <<
"App `" << app->getName() <<
"` not found.";
148 reader = RapidXmlReader::FromXmlString(contents);
153 ARMARX_INFO_S <<
"It is most likely that the file has no valid XML formatting" << std::endl;
157 for (
RapidXmlReaderNode property_node = reader->getRoot(
"property"); property_node.
is_valid(); property_node = property_node.next_sibling())
159 const std::string propertyName = property_node.attribute_value(
"name");
160 const std::string description = property_node.first_node(
"description").value();
165 Ice::StringSeq valueStrings;
171 valueStrings.push_back(current_value.
value());
175 if (!valueStrings.empty())
181 std::string defaultValue =
"";
183 bool required =
false;
185 while (current_attribute.
is_valid())
188 if (current_attribute.
name().compare(
"attribute") != 0)
192 else if (current_attribute.
attribute_value(
"name").find(
"Default") != std::string::npos)
194 defaultValue = current_attribute.
value();
196 else if (current_attribute.
attribute_value(
"name").find(
"CaseSensitivity") != std::string::npos)
199 else if (current_attribute.
attribute_value(
"name").find(
"Required") != std::string::npos)
201 if (current_attribute.
value().compare(
"yes") == 0)
213 for (
auto&
v : valueStrings)
217 container->getProperties()->setProperty(propertyName,
"::_NOT_SET_::");
223 for (
auto&
v : valueStrings)
227 container->getProperties()->setProperty(propertyName, defaultValue);
234 app->setIsDefaultProperty(propertyName,
true);
235 app->setDefaultPropertyEnabled(propertyName,
false);
246 if (!appInstance->isConfigWritable())
255 std::string resultStr;
262 Ice::PropertyDict dict = props->getProperties()->getPropertiesForPrefix(
"");
265 for (
auto const& property : dict)
267 if (appInstance->isDefaultProperty(property.first) && !appInstance->isDefaultPropertyEnabled(property.first))
269 disableProperty(resultStr, property.first);
274 size_t begin = resultStr.rfind(
"# Ice.Config:");
275 size_t end = resultStr.rfind(
"Ice.Config = <set value!>");
277 if (end == std::string::npos)
279 (end = resultStr.rfind(
"Ice.Config = \"\"")) != std::string::npos ? end += 15 : end = std::string::npos;
285 if (begin != std::string::npos && end != std::string::npos)
287 resultStr.erase(begin, end - begin);
290 std::ofstream cfgFile;
291 cfgFile.open(appInstance->getConfigPath(), std::ofstream::out | std::ofstream::trunc);
295 ARMARX_WARNING_S <<
"Failed to write to Cfg file at " << appInstance->getConfigPath();
299 cfgFile << resultStr;
304 std::string IceParser::getCacheDir()
306 std::string cachePath = ArmarXDataPath::GetCachePath();
307 return (std::filesystem::path(cachePath) / std::filesystem::path(
"ComponentFiles")).string();
310 void IceParser::disableProperty(std::string& result,
const std::string propertyName)
313 if (result.find_last_of(propertyName) != std::string::npos)
315 size_t it1 = result.rfind(propertyName +
" = ");
316 std::string commentedName =
"# " + propertyName +
" = ";
317 size_t it2 = result.find(commentedName, it1);
319 if (it1 != std::string::npos && it2 == std::string::npos)
321 result.insert(it1,
"# ");
326 void IceParser::clearXmlCacheDir()
328 std::filesystem::remove_all(std::filesystem::path(getCacheDir()));