Пример #1
0
void HTTPWatchdogService::sendPID(EvHttpRequestContext* pCtx, PIDType pid)
{
    stringstream ss;
    ss << pid;
    XMLDocumentWrapper xmlDoc;    
    xmlDoc.appendNode(XMLDocumentWrapper::NODE_ELEMENT, "pid", ss.str());
    
    ostringstream oss;
    xmlDoc.print(oss);
    pCtx->getOutBuffer()->addData(oss.str().c_str(), oss.str().length());
}
Пример #2
0
void HTTPWatchdogService::sendProcessInfo(EvHttpRequestContext* pCtx,
        const ProcessInfoPtr& pProcInfo)
{
    XMLDocumentWrapper xmlDoc;
    XMLNodeWrapperPtr pProcNode = xmlDoc.appendNode(
            XMLDocumentWrapper::NODE_ELEMENT, "process");
    procInfoToXML(pProcNode, pProcInfo);
    stringstream ss;
    xmlDoc.print(ss);
    pCtx->getOutBuffer()->addData(ss.str().c_str(), ss.str().length());
}
Пример #3
0
void XMLConfigurator::save(const string& sCfgFile)
{
    m_sPath = sCfgFile;
    XMLDocumentWrapper xmlDoc;
    XMLNodeWrapperPtr pRoot = xmlDoc.appendNode(
            XMLDocumentWrapper::NODE_ELEMENT, CONFIGURE_TAG_NAME);
    save(xmlDoc, pRoot, getMap());

    //TODO: UTF-8 encoding
    xmlDoc.addDeclarationNode("UTF-8");
    xmlDoc.printToFile(m_sPath);
}
void XMLDocumentWrapperTestCase::testPrint()
{
    XMLDocumentWrapper xmlDoc;
    xmlDoc.addDeclarationNode("UTF-8");

    xmlDoc.appendNode(XMLDocumentWrapper::NODE_ELEMENT, "root");
    XMLNodeWrapperPtr pRoot = xmlDoc.firstNode();
    pRoot->appendNode(XMLDocumentWrapper::NODE_ELEMENT, "global", "testvalue");
    pRoot->appendAttribute("id", "testid");
        
    ostringstream ss;
    xmlDoc.print(ss);

    string sExpect = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
                     "<root id=\"testid\">\n"
                     "\t<global>testvalue</global>\n"
                     "</root>\n\n";
    CPPUNIT_ASSERT_EQUAL(sExpect, ss.str());
}
Пример #5
0
void XMLConfigurator::save(const string& sCfgFile, FileSystemPtr& pFileSys)
{
    XMLDocumentWrapper xmlDoc;
    XMLNodeWrapperPtr pRoot = xmlDoc.appendNode(
            XMLDocumentWrapper::NODE_ELEMENT, CONFIGURE_TAG_NAME);
    Iterator it = iterator();
    while (it.hasNext())
    {
        Configurator::KeyValuePair kv = it.next();

        if (kv.second.getType() == typeid(Configurator::ConfMap))
        {
            XMLNodeWrapperPtr pNode = xmlDoc.allocateNode(
                    XMLDocumentWrapper::NODE_ELEMENT, kv.first.c_str());
            save(xmlDoc, pNode, AnyCast<Configurator::ConfMap>(kv.second));
            pRoot->appendNode(pNode);
        }
        else 
        {
            string str = AnyCast<string>(kv.second);
            XMLNodeWrapperPtr pNode = xmlDoc.allocateNode(
                    XMLDocumentWrapper::NODE_ELEMENT, kv.first.c_str(), str);
            pRoot->appendNode(pNode);
        }
    }

    OutputStreamPtr pOutStream = pFileSys->createFile(sCfgFile);
    if (pOutStream.isNull())
    {
        FIRTEX_THROW(FileIOException, "Save configure [%s] FAILED ",
                     sCfgFile.c_str());
    }
    string str;
    xmlDoc.addDeclarationNode("UTF-8");
    xmlDoc.print(str);
    pOutStream->write((const void*)str.c_str(), str.length());
}
void XMLDocumentWrapperTestCase::testClearAndReuse()
{
    XMLDocumentWrapper xmlDoc;

    string sExpect = "<result>\n"
                     "\t<hits number_hits=\"1\">\n"
                     "\t\t<hit>hit_value1</hit>\n"
                     "\t</hits>\n"
                     "\t<hits number_hits=\"2\">\n"
                     "\t\t<hit>hit_value2</hit>\n"
                     "\t</hits>\n"
                     "</result>\n\n";
                 
    for (size_t i = 0; i < 2; ++i)
    {
        XMLNodeWrapperPtr pRootNode = xmlDoc.appendNode(
                XMLDocumentWrapper::NODE_ELEMENT, "result");

        XMLNodeWrapperPtr pHitsNode = pRootNode->appendNode(
            XMLDocumentWrapper::NODE_ELEMENT, "hits");
        pHitsNode->appendAttribute("number_hits", "1");
        pHitsNode->appendNode(XMLDocumentWrapper::NODE_ELEMENT,
                              "hit", "hit_value1");
        
        pHitsNode = pRootNode->appendNode(
                XMLDocumentWrapper::NODE_ELEMENT, "hits");
        pHitsNode->appendAttribute("number_hits", "2");
        pHitsNode->appendNode(XMLDocumentWrapper::NODE_ELEMENT,
                              "hit", "hit_value2");

        ostringstream ss;
        xmlDoc.print(ss);
        CPPUNIT_ASSERT_EQUAL(sExpect, ss.str());

        xmlDoc.clear();
    }
}