MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / write

Method write

src/App/Metadata.cpp:603–656  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

601}
602
603void 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
658bool Metadata::satisfies(const Meta::Dependency& dep)
659{

Callers 15

write_fileFunction · 0.45
append_fileFunction · 0.45
emit_problem_matchersFunction · 0.45
MappedName.hFile · 0.45
saveMethod · 0.45
restoreLabelReferenceMethod · 0.45
tryImportSubNameMethod · 0.45
writeStringMethod · 0.45
extractDocumentFunction · 0.45
createDocumentFunction · 0.45
TEST_FFunction · 0.45
TESTFunction · 0.45

Calls 7

unicodeFormMethod · 0.80
setAttributeMethod · 0.80
setParameterMethod · 0.45
c_strMethod · 0.45
stringMethod · 0.45
releaseMethod · 0.45
getMessageMethod · 0.45

Tested by

no test coverage detected