| 25 | } |
| 26 | |
| 27 | std::string mitk::PropertyListSerializer::Serialize() |
| 28 | { |
| 29 | m_FailedProperties = PropertyList::New(); |
| 30 | |
| 31 | if (m_PropertyList.IsNull() || m_PropertyList->IsEmpty()) |
| 32 | { |
| 33 | MITK_ERROR << "Not serializing nullptr or empty PropertyList"; |
| 34 | return ""; |
| 35 | } |
| 36 | |
| 37 | // tmpname |
| 38 | static unsigned long count = 1; |
| 39 | unsigned long n = count++; |
| 40 | std::ostringstream name; |
| 41 | for (int i = 0; i < 6; ++i) |
| 42 | { |
| 43 | name << char('a' + (n % 26)); |
| 44 | n /= 26; |
| 45 | } |
| 46 | std::string filename; |
| 47 | filename.append(name.str()); |
| 48 | |
| 49 | std::string fullname(m_WorkingDirectory); |
| 50 | fullname += "/"; |
| 51 | fullname += filename; |
| 52 | fullname = itksys::SystemTools::ConvertToOutputPath(fullname.c_str()); |
| 53 | |
| 54 | // Trim quotes |
| 55 | std::string::size_type length = fullname.length(); |
| 56 | |
| 57 | if (length >= 2 && fullname[0] == '"' && fullname[length - 1] == '"') |
| 58 | fullname = fullname.substr(1, length - 2); |
| 59 | |
| 60 | tinyxml2::XMLDocument document; |
| 61 | document.InsertEndChild(document.NewDeclaration()); |
| 62 | |
| 63 | auto *version = document.NewElement("Version"); |
| 64 | version->SetAttribute("Writer", __FILE__); |
| 65 | version->SetAttribute("Revision", "$Revision: 17055 $"); |
| 66 | version->SetAttribute("FileVersion", 1); |
| 67 | document.InsertEndChild(version); |
| 68 | |
| 69 | // add XML contents |
| 70 | const PropertyList::PropertyMap *propmap = m_PropertyList->GetMap(); |
| 71 | for (auto iter = propmap->begin(); iter != propmap->end(); ++iter) |
| 72 | { |
| 73 | std::string key = iter->first; |
| 74 | const BaseProperty *property = iter->second; |
| 75 | auto *element = SerializeOneProperty(document, key, property); |
| 76 | if (element) |
| 77 | { |
| 78 | document.InsertEndChild(element); |
| 79 | // TODO test serializer for error |
| 80 | } |
| 81 | else |
| 82 | { |
| 83 | m_FailedProperties->ReplaceProperty(key, const_cast<BaseProperty *>(property)); |
| 84 | } |
no test coverage detected