3 #include <boost/lexical_cast.hpp> 4 #include <boost/algorithm/string.hpp> 5 #include <base-logging/Logging.hpp> 14 LOG_INFO_S <<
"XMLEnvelopeParser: starting to parse: " << storage;
16 std::string envelopeXML;
17 std::string payloadData;
20 std::string envelopeEndMarker =
"</envelope>";
21 size_t pos = storage.find(envelopeEndMarker);
22 if(pos == std::string::npos)
24 LOG_WARN_S <<
"XMLEnvelopeParser: this is not an XML envelope. Could not find </envelope>";
27 envelopeXML = storage.substr(0, pos + envelopeEndMarker.size());
29 size_t payloadPosition = pos + envelopeEndMarker.size();
30 if(payloadPosition < storage.length());
32 envelope.
setPayload(storage.substr(payloadPosition));
37 const char* parseResult = doc.Parse(envelopeXML.c_str());
39 if(parseResult != NULL)
42 LOG_WARN_S <<
"Parsing envelope XML failed for (probably the payload): " << parseResult;
44 LOG_INFO_S <<
"XMLEnvelopeParser: basic XML parsing complete.";
47 const TiXmlElement* envelopeElem = doc.FirstChildElement();
49 if(envelopeElem == NULL)
51 LOG_WARN_S <<
"Parsing error: XML main node not found.";
55 if(envelopeElem->ValueStr() !=
"envelope")
57 LOG_WARN_S <<
"Parsing error: XML main node not named 'fipa-message' but " << envelopeElem->ValueStr();
62 const TiXmlElement* pChild = envelopeElem->FirstChildElement();
66 LOG_WARN_S <<
"Parsing error: XML first params node not found.";
77 catch(std::exception& e)
79 LOG_WARN_S <<
"Parsing error base envelope: " << e.what();
84 for ( pChild = pChild->NextSiblingElement(); pChild != 0; pChild = pChild->NextSiblingElement())
90 catch(std::exception& e)
92 LOG_WARN_S <<
"Parsing error extra envelope: " << e.what();
100 const ACLBaseEnvelope XMLEnvelopeParser::parseParameters(
const TiXmlElement* paramsElem,
int paramsIndex)
const 102 if(paramsElem->ValueStr() !=
"params")
104 throw std::runtime_error(
"Parsing error: params node not named 'params' but " + paramsElem->ValueStr());
106 if(*(paramsElem->Attribute(std::string(
"index"))) != boost::lexical_cast<std::string>(paramsIndex))
108 throw std::runtime_error(
"Parsing error: params index attribute should be " +
109 boost::lexical_cast<std::string>(paramsIndex) +
" but is " + paramsElem->Attribute(
"index"));
116 const TiXmlElement * pChild;
117 for ( pChild = paramsElem->FirstChildElement(); pChild != 0; pChild = pChild->NextSiblingElement())
120 const std::string& name = pChild->ValueStr();
126 else if(name ==
"from")
129 const TiXmlElement* aid = pChild->FirstChildElement();
132 throw std::runtime_error(
"Parsing error: from has no first child");
137 else if(name ==
"comments")
139 envelope.setComments(std::string(pChild->GetText()));
141 else if(name ==
"acl-representation")
143 envelope.setACLRepresentation(std::string(pChild->GetText()));
145 else if(name ==
"payload-length")
147 envelope.setPayloadLength(boost::lexical_cast<PayloadLength>(std::string(pChild->GetText())));
149 else if(name ==
"payload-encoding")
151 envelope.setPayloadEncoding(std::string(pChild->GetText()));
153 else if(name ==
"date")
157 else if(name ==
"intended-receiver")
161 else if(name ==
"received")
165 else if(name ==
"user-defined")
171 throw std::runtime_error(
"Parsing error: unknown node: " + name);
174 envelope.setUserdefinedParameters(params);
The ACLBaseEnvelope defines the layout for an envelope with which ACLMessage data can be wrapped...
static const ReceivedObject parseReceivedObject(const TiXmlElement *receivedObjectElem)
ACLMessage envelope (also typed as fipa::acl::Letter) includes the base envelope and updated fields...
bool parseData(const std::string &storage, ACLEnvelope &envelope)
std::vector< UserdefParam > UserdefinedParameterList
void setPayload(const std::string &payload)
static const AgentIDList parseAgentIDSequence(const TiXmlElement *aidlElem)
void setBaseEnvelope(const ACLBaseEnvelope &envelope)
static const UserdefParam parseUserdefinedParameter(const TiXmlElement *paramElem)
static const AgentID parseAgentID(const TiXmlElement *aidElem)
void setTo(const AgentIDList &receivers)
void addExtraEnvelope(const ACLBaseEnvelope &envelope)
static const base::Time parseDate(const TiXmlElement *dateElem)
Foundation of Physical Intelligent Agents.