| 202 | } |
| 203 | |
| 204 | void RegistryTree::importFromFile(const std::string& importFilePath, |
| 205 | const std::string& parentKey) |
| 206 | { |
| 207 | std::string importKey = parentKey; |
| 208 | |
| 209 | // If an empty parentKey was passed, set it to the default import node |
| 210 | if (importKey.empty()) |
| 211 | { |
| 212 | importKey = _defaultImportNode; |
| 213 | } |
| 214 | |
| 215 | // Check if the importKey exists - if not: create it |
| 216 | std::string fullImportKey = prepareKey(importKey); |
| 217 | |
| 218 | if (!keyExists(fullImportKey)) |
| 219 | { |
| 220 | createKey(fullImportKey); |
| 221 | } |
| 222 | |
| 223 | // Lookup the mount point by using findXPath(), it must exist by now |
| 224 | xml::NodeList importNodeList = _tree.findXPath(fullImportKey); |
| 225 | |
| 226 | if (importNodeList.empty()) |
| 227 | { |
| 228 | rMessage() << "XMLRegistry: Critical: ImportNode could not be found." << std::endl; |
| 229 | return; |
| 230 | } |
| 231 | |
| 232 | rMessage() << "XMLRegistry: Importing XML file: " << importFilePath << std::endl; |
| 233 | |
| 234 | // Load the file |
| 235 | xml::Document importDoc(importFilePath); |
| 236 | |
| 237 | if (!importDoc.isValid()) |
| 238 | { |
| 239 | // Throw the XMLImportException |
| 240 | throw std::runtime_error("Unable to load file: " + importFilePath); |
| 241 | } |
| 242 | |
| 243 | // Import the document into our XML tree |
| 244 | _tree.importDocument(importDoc, importNodeList[0]); |
| 245 | } |
| 246 | |
| 247 | void RegistryTree::exportToFile(const std::string& key, const std::string& filename) |
| 248 | { |