| 132 | } |
| 133 | |
| 134 | void Metadata::loadFromInputSource(const InputSource& source) |
| 135 | { |
| 136 | // Any exception thrown by the XML code propagates out and prevents object creation |
| 137 | XMLPlatformUtils::Initialize(); |
| 138 | |
| 139 | _parser = std::make_shared<XercesDOMParser>(); |
| 140 | _parser->setValidationScheme(XercesDOMParser::Val_Never); |
| 141 | _parser->setDoNamespaces(true); |
| 142 | |
| 143 | auto errHandler = std::make_unique<MetadataInternal::XMLErrorHandler>(); |
| 144 | _parser->setErrorHandler(errHandler.get()); |
| 145 | |
| 146 | _parser->parse(source); |
| 147 | |
| 148 | auto doc = _parser->getDocument(); |
| 149 | _dom = doc->getDocumentElement(); |
| 150 | |
| 151 | auto rootTagName = StrXUTF8(_dom->getTagName()).str; |
| 152 | if (rootTagName != "package") { |
| 153 | throw Base::XMLBaseException( |
| 154 | "Malformed package.xml document: Root <package> group not found"); |
| 155 | } |
| 156 | auto formatVersion = XMLString::parseInt(_dom->getAttribute(XUTF8StrLiteral("format").unicodeForm())); |
| 157 | switch (formatVersion) { |
| 158 | case 1: |
| 159 | parseVersion1(_dom); |
| 160 | break; |
| 161 | default: |
| 162 | throw Base::XMLBaseException( |
| 163 | "package.xml format version is not supported by this version of FreeCAD"); |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | Metadata::~Metadata() = default; |
| 168 |
nothing calls this directly
no test coverage detected