string ofXml::toString() const { ostringstream stream; Poco::XML::DOMWriter writer; writer.setOptions(Poco::XML::XMLWriter::PRETTY_PRINT); if(document) { try { writer.writeNode( stream, getPocoDocument() ); } catch( exception & e ) { ofLogError("ofXml") << "toString(): " << e.what(); } } else if(element){ element->normalize(); writer.writeNode( stream, element ); } string tmp = stream.str(); // don't know how else to get rid of the hidden <#text></#text> nodes :/ ofStringReplace(tmp, "<#text>", ""); ofStringReplace(tmp, "</#text>", ""); return tmp; }
void XMLConfiguration::save(std::ostream& ostr) const { Poco::XML::DOMWriter writer; writer.setNewLine("\n"); writer.setOptions(Poco::XML::XMLWriter::PRETTY_PRINT); writer.writeNode(ostr, _pDocument); }
void XMLConfiguration::save(const std::string& path) const { Poco::XML::DOMWriter writer; writer.setNewLine("\n"); writer.setOptions(Poco::XML::XMLWriter::PRETTY_PRINT); writer.writeNode(path, _pDocument); }
/* Validate all of the pipelines in the given config file. * This method does some basic parsing of the config file to learn * about the various pipelines that exist in the file. */ bool ValidatePipeline::isValid(const char *a_configPath) const { bool failed = false; std::ifstream in(a_configPath); if (!in) { fprintf(stdout, "Error opening pipeline config file: %s\n", a_configPath); } else { try { Poco::XML::InputSource src(in); Poco::XML::DOMParser parser; // basic parsing Poco::AutoPtr<Poco::XML::Document> xmlDoc = parser.parse(&src); // must have at least one pipeline element Poco::AutoPtr<Poco::XML::NodeList> pipelines = xmlDoc->getElementsByTagName(TskPipelineManager::PIPELINE_ELEMENT); if (pipelines->length() == 0) { fprintf(stdout, "No pipelines found in config file.\n"); } else { // parse all pipelines in the config file for (unsigned long i = 0; i < pipelines->length(); i++) { Poco::XML::Node * pNode = pipelines->item(i); Poco::XML::Element* pElem = dynamic_cast<Poco::XML::Element*>(pNode); Poco::XML::DOMWriter writer; std::ostringstream pipelineXml; writer.writeNode(pipelineXml, pNode); std::string pipelineType = pElem->getAttribute(TskPipelineManager::PIPELINE_TYPE_ATTRIBUTE); TskPipeline * pipeline = 0; if (pipelineType == TskPipelineManager::FILE_ANALYSIS_PIPELINE_STR) pipeline = new TskFileAnalysisPipeline(); else if (pipelineType == TskPipelineManager::REPORTING_PIPELINE_STR) pipeline = new TskReportPipeline(); else { fprintf(stdout, "Unsupported pipeline type: %s\n", pipelineType.c_str()); failed = true; continue; } try { pipeline->validate(pipelineXml.str()); } catch (...) { fprintf(stdout, "Error parsing pipeline: %s\n", pElem->getAttribute(TskPipelineManager::PIPELINE_TYPE_ATTRIBUTE).c_str()); failed = true; } delete pipeline; } } } catch (Poco::XML::SAXParseException& ex) { fprintf(stderr, "Error parsing pipeline config file: %s (%s)\n", a_configPath, ex.what()); } } // If any of the pipelines failed validation we return false return failed ? false : true; }
void DebugBreakpointManager::SaveState(const Poco::Path& path) const { Poco::XML::Document* doc = new Poco::XML::Document(); Poco::XML::Element* breakpoints = doc->createElement(BREAKPOINTS_TAG); doc->appendChild(breakpoints)->release(); for (std::set<unsigned long>::const_iterator i = m_ObjectBreakpoints.begin(); i != m_ObjectBreakpoints.end(); ++i) { Poco::XML::Element* objectBreakpoint = doc->createElement(OBJECT_TAG); breakpoints->appendChild(objectBreakpoint)->release(); std::stringstream ss; ss << *i; objectBreakpoint->setAttribute(ID_ATTR, ss.str()); const Object* obj = DebugUtil::GetObject(*i); if (obj) { objectBreakpoint->setAttribute(CLASSNAME_ATTR, obj->GetClassName()); } } for (Poco::HashMap<int, const Object*>::ConstIterator i = m_SmartPointerBreakpoints.begin(); i != m_SmartPointerBreakpoints.end(); ++i) { Poco::XML::Element* spBreakpoint = doc->createElement(SMARTPOINTER_TAG); breakpoints->appendChild(spBreakpoint)->release(); std::stringstream ss; ss << i->first; spBreakpoint->setAttribute(ID_ATTR, ss.str()); const Object* obj = i->second; if (i->second) { spBreakpoint->setAttribute(CLASSNAME_ATTR, obj->GetClassName()); ss.clear(); ss << obj->GetTraceId(); spBreakpoint->setAttribute(OBJECTID_ATTR, ss.str()); } } Poco::FileOutputStream writer(path.toString()); Poco::XML::DOMWriter out; out.setOptions(3); //write declaration and pretty print out.writeNode(writer, doc); doc->release(); }
void DebugUtil::SaveState() { Poco::Path path; if (!GetPersistencePath(path)) return; path.setFileName(DEBUG_UTIL_XML); Poco::XML::Document* doc = new Poco::XML::Document(); Poco::XML::Element* debugutil = doc->createElement(DEBUGUTIL_TAG); doc->appendChild(debugutil)->release(); for (std::set<unsigned int>::const_iterator i = m_TracedObjects.begin(); i != m_TracedObjects.end(); ++i) { Poco::XML::Element* traceObject = doc->createElement(TRACEOBJECT_TAG); debugutil->appendChild(traceObject)->release(); std::stringstream ss; ss << *i; traceObject->setAttribute(ID_ATTR, ss.str()); } for (std::set<std::string>::const_iterator i = m_TracedClasses.begin(); i != m_TracedClasses.end(); ++i) { Poco::XML::Element* traceClass = doc->createElement(TRACECLASS_TAG); debugutil->appendChild(traceClass)->release(); traceClass->setAttribute(NAME_ATTR, *i); } try { Poco::FileOutputStream writer(path.toString()); Poco::XML::DOMWriter out; out.setOptions(3); //write declaration and pretty print out.writeNode(writer, doc); doc->release(); // save BreakpointManager path.setFileName(DebugBreakpointManager::BREAKPOINTS_XML); GetBreakpointManager()->SaveState(path); } catch (Poco::FileException& e) { BERRY_WARN << e.displayText(); } }
void XMLConfiguration::save(Poco::XML::DOMWriter& writer, std::ostream& ostr) const { writer.writeNode(ostr, _pDocument); }
void XMLConfiguration::save(Poco::XML::DOMWriter& writer, const std::string& path) const { writer.writeNode(path, _pDocument); }
std::string Pothos::Topology::toDotMarkup(const std::string &request) { //parse request arguments const auto result = Poco::JSON::Parser().parse(request.empty()?"{}":request); auto configObj = result.extract<Poco::JSON::Object::Ptr>(); const auto portConfig = configObj->optValue<std::string>("port", "connected"); //get a JSON dump of the topology const auto dumpResult = Poco::JSON::Parser().parse(this->dumpJSON(request)); const auto topObj = dumpResult.extract<Poco::JSON::Object::Ptr>(); const auto connsArray = topObj->getArray("connections"); const auto blocksObj = topObj->getObject("blocks"); std::vector<std::string> blockIds; blocksObj->getNames(blockIds); std::ostringstream os; os << "digraph flat_flows {" << std::endl; os << " rankdir=LR;" << std::endl; os << " node [shape=record, fontsize=10];" << std::endl; for (const auto &blockId : blockIds) { const auto blockObj = blocksObj->getObject(blockId); //form xml Poco::AutoPtr<Poco::XML::Document> xmlDoc(new Poco::XML::Document()); auto nodeTable = xmlDoc->createElement("table"); xmlDoc->appendChild(nodeTable); nodeTable->setAttribute("border", "0"); nodeTable->setAttribute("cellpadding", "0"); nodeTable->setAttribute("cellspacing", "0"); auto nodeTr = xmlDoc->createElement("tr"); nodeTable->appendChild(nodeTr); const bool enbFilter = portConfig == "connected"; const auto inputPorts = getConnectedPortInfos(topObj, blockId, enbFilter, true); const auto outputPorts = getConnectedPortInfos(topObj, blockId, enbFilter, false); if (inputPorts->size() > 0) { nodeTr->appendChild(portInfoToElem(xmlDoc, inputPorts, "in")); } { auto nodeTd = xmlDoc->createElement("td"); nodeTd->setAttribute("border", "0"); nodeTr->appendChild(nodeTd); auto table = xmlDoc->createElement("table"); nodeTd->appendChild(table); table->setAttribute("border", "0"); table->setAttribute("cellspacing", "0"); auto tr = xmlDoc->createElement("tr"); table->appendChild(tr); auto td = xmlDoc->createElement("td"); td->setAttribute("border", "1"); td->setAttribute("bgcolor", "azure"); tr->appendChild(td); auto name = blockObj->getValue<std::string>("name"); if (name.empty()) name = "Empty Name"; td->appendChild(xmlDoc->createTextNode(name)); } if (outputPorts->size() > 0) { nodeTr->appendChild(portInfoToElem(xmlDoc, outputPorts, "out")); } //dot node entry os << " "; os << std::hash<std::string>()(blockId); os << "[" << std::endl; os << " shape=none," << std::endl; os << " label=<" << std::endl; Poco::XML::DOMWriter write; write.setOptions(Poco::XML::XMLWriter::PRETTY_PRINT); write.writeNode(os, xmlDoc); os << " >" << std::endl; os << "];" << std::endl; } for (size_t c_i = 0; c_i < connsArray->size(); c_i++) { const auto conn = connsArray->getObject(c_i); os << " "; os << std::hash<std::string>()(conn->getValue<std::string>("srcId")); os << ":__out__" << conn->getValue<std::string>("srcName"); os << " -> "; os << std::hash<std::string>()(conn->getValue<std::string>("dstId")); os << ":__in__" << conn->getValue<std::string>("dstName"); os << ";" << std::endl; } os << "}" << std::endl; return os.str(); }