122 lines
3.1 KiB
C++
122 lines
3.1 KiB
C++
#include "xml/XMLDocument.hpp"
|
|
#include "se/Response.hpp"
|
|
#include "se/ResponseExtension.hpp"
|
|
#include "se/LPE/LPCrtRespExtension.hpp"
|
|
|
|
/*
|
|
* Have to use static funcion instead of static variable
|
|
* since there is not guarantee about the construct/destruct
|
|
* order of a static instance of any types
|
|
*/
|
|
const std::string LPCrtRespExtension::KVLIST_EXPR()
|
|
{
|
|
return EXTENSION_EXPR() + "/launch:claims";
|
|
}
|
|
|
|
LPCrtRespExtension::LPCrtRespExtension() :
|
|
initialised(false),
|
|
kvLists()
|
|
{
|
|
}
|
|
|
|
void LPCrtRespExtension::fromXML(XMLDocument *xmlDoc)
|
|
{
|
|
int kvListCount = xmlDoc->getNodeCount("count(" + KVLIST_EXPR() + ")");
|
|
|
|
if (kvListCount == 0)
|
|
{
|
|
initialised = false;
|
|
}
|
|
else
|
|
{
|
|
for (int i = 1; i <= kvListCount; i++)
|
|
{
|
|
const std::string currentKVListXPath =
|
|
ReceiveSE::replaceIndex(KVLIST_EXPR() + "[IDX]", i);
|
|
const std::string kvListName =
|
|
xmlDoc->getNodeValue(currentKVListXPath + "/@name");
|
|
|
|
kvLists[kvListName] = createKVList(xmlDoc, currentKVListXPath);
|
|
}
|
|
|
|
initialised = true;
|
|
}
|
|
}
|
|
|
|
const std::set<std::string> LPCrtRespExtension::getLists() const
|
|
{
|
|
std::set<std::string> kvListNames;
|
|
|
|
ExtensionList::const_iterator extensionListIterator;
|
|
|
|
for (extensionListIterator = kvLists.begin();
|
|
extensionListIterator != kvLists.end();
|
|
extensionListIterator++)
|
|
{
|
|
kvListNames.insert(extensionListIterator->first);
|
|
}
|
|
|
|
return kvListNames;
|
|
}
|
|
|
|
const std::set<std::string> LPCrtRespExtension::getListItems(
|
|
const std::string &listName) const
|
|
{
|
|
std::set<std::string> itemNames;
|
|
ExtensionList::const_iterator extensionListIterator = kvLists.find(listName);
|
|
|
|
if (extensionListIterator != kvLists.end())
|
|
{
|
|
KeyValueList::const_iterator keyValueListIterator;
|
|
|
|
for (keyValueListIterator = extensionListIterator->second.begin();
|
|
keyValueListIterator != extensionListIterator->second.end();
|
|
keyValueListIterator++)
|
|
{
|
|
itemNames.insert(keyValueListIterator->first);
|
|
}
|
|
}
|
|
|
|
return itemNames;
|
|
}
|
|
|
|
const std::string LPCrtRespExtension::getItem(
|
|
const std::string &listName,
|
|
const std::string &key) const
|
|
{
|
|
std::string itemValue;
|
|
ExtensionList::const_iterator extensionListIterator = kvLists.find(listName);
|
|
|
|
if (extensionListIterator != kvLists.end())
|
|
{
|
|
KeyValueList::const_iterator keyValueListIterator =
|
|
extensionListIterator->second.find(key);
|
|
|
|
if (keyValueListIterator != extensionListIterator->second.end())
|
|
{
|
|
itemValue = keyValueListIterator->second;
|
|
}
|
|
}
|
|
|
|
return itemValue;
|
|
}
|
|
|
|
const KeyValueList LPCrtRespExtension::createKVList(
|
|
XMLDocument *xmlDoc,
|
|
const std::string &kvListXPath)
|
|
{
|
|
int kvItemCount = xmlDoc->getNodeCount("count(" + kvListXPath + "/kv:item)");
|
|
|
|
KeyValueList kvList;
|
|
|
|
for (int i = 1; i <= kvItemCount; i++)
|
|
{
|
|
std::string itemXPath = ReceiveSE::replaceIndex(kvListXPath + "/kv:item[IDX]", i);
|
|
std::string key = xmlDoc->getNodeValue(itemXPath + "/@key");
|
|
std::string value = xmlDoc->getNodeValue(itemXPath);
|
|
kvList[key] = value;
|
|
}
|
|
|
|
return kvList;
|
|
}
|