| 601 | } |
| 602 | |
| 603 | void Metadata::write(const fs::path& file) const |
| 604 | { |
| 605 | DOMImplementation* impl = |
| 606 | DOMImplementationRegistry::getDOMImplementation(XUTF8StrLiteral("Core LS").unicodeForm()); |
| 607 | |
| 608 | DOMDocument* doc = impl->createDocument(nullptr, XUTF8StrLiteral("package").unicodeForm(), nullptr); |
| 609 | DOMElement* root = doc->getDocumentElement(); |
| 610 | root->setAttribute(XUTF8StrLiteral("format").unicodeForm(), XUTF8StrLiteral("1").unicodeForm()); |
| 611 | root->setAttribute(XUTF8StrLiteral("xmlns").unicodeForm(), |
| 612 | XUTF8StrLiteral("https://wiki.freecad.org/Package_Metadata").unicodeForm()); |
| 613 | |
| 614 | appendToElement(root); |
| 615 | |
| 616 | DOMLSSerializer* theSerializer = ((DOMImplementationLS*)impl)->createLSSerializer(); |
| 617 | DOMConfiguration* config = theSerializer->getDomConfig(); |
| 618 | if (config->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true)) { |
| 619 | config->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true); |
| 620 | } |
| 621 | |
| 622 | // set feature if the serializer supports the feature/mode |
| 623 | if (config->canSetParameter(XMLUni::fgDOMWRTSplitCdataSections, true)) { |
| 624 | config->setParameter(XMLUni::fgDOMWRTSplitCdataSections, true); |
| 625 | } |
| 626 | |
| 627 | if (config->canSetParameter(XMLUni::fgDOMWRTDiscardDefaultContent, true)) { |
| 628 | config->setParameter(XMLUni::fgDOMWRTDiscardDefaultContent, true); |
| 629 | } |
| 630 | |
| 631 | try { |
| 632 | XMLFormatTarget* myFormTarget = new LocalFileFormatTarget(file.string().c_str()); |
| 633 | DOMLSOutput* theOutput = ((DOMImplementationLS*)impl)->createLSOutput(); |
| 634 | |
| 635 | theOutput->setByteStream(myFormTarget); |
| 636 | theSerializer->write(doc, theOutput); |
| 637 | |
| 638 | theOutput->release(); |
| 639 | theSerializer->release(); |
| 640 | delete myFormTarget; |
| 641 | } |
| 642 | catch (const XMLException& toCatch) { |
| 643 | char* message = XMLString::transcode(toCatch.getMessage()); |
| 644 | std::string what = message; |
| 645 | XMLString::release(&message); |
| 646 | throw Base::XMLBaseException(what); |
| 647 | } |
| 648 | catch (const DOMException& toCatch) { |
| 649 | char* message = XMLString::transcode(toCatch.getMessage()); |
| 650 | std::string what = message; |
| 651 | XMLString::release(&message); |
| 652 | throw Base::XMLBaseException(what); |
| 653 | } |
| 654 | |
| 655 | doc->release(); |
| 656 | } |
| 657 | |
| 658 | bool Metadata::satisfies(const Meta::Dependency& dep) |
| 659 | { |
no test coverage detected