1 #include "../../include/freenet/messagelistxml.h"
\r
7 MessageListXML::MessageListXML()
\r
12 void MessageListXML::AddMessage(const std::string &date, const long index, const std::vector<std::string> &boards)
\r
14 m_messages.push_back(message(date,index,boards));
\r
17 void MessageListXML::AddExternalMessage(const std::string &identity, const std::string &date, const long index, const std::vector<std::string> &boards)
\r
19 m_externalmessages.push_back(externalmessage("Keyed",identity,date,index,boards));
\r
22 void MessageListXML::AddExternalMessage(const std::string &messagekey, const std::string &date, const std::vector<std::string> &boards)
\r
24 m_externalmessages.push_back(externalmessage("Anonymous",messagekey,date,boards));
\r
27 std::vector<std::string> MessageListXML::GetBoards(const long index)
\r
29 if(index>=0 && index<m_messages.size())
\r
31 return m_messages[index].m_boards;
\r
35 return std::vector<std::string>();
\r
39 std::string MessageListXML::GetDate(const long index)
\r
41 if(index>=0 && index<m_messages.size())
\r
43 return m_messages[index].m_date;
\r
51 std::vector<std::string> MessageListXML::GetExternalBoards(const long index)
\r
53 if(index>=0 && index<m_externalmessages.size())
\r
55 return m_externalmessages[index].m_boards;
\r
59 return std::vector<std::string>();
\r
63 std::string MessageListXML::GetExternalDate(const long index)
\r
65 if(index>=0 && index<m_externalmessages.size())
\r
67 return m_externalmessages[index].m_date;
\r
75 std::string MessageListXML::GetExternalIdentity(const long index)
\r
77 if(index>=0 && index<m_externalmessages.size())
\r
79 return m_externalmessages[index].m_identity;
\r
87 const long MessageListXML::GetExternalIndex(const long index)
\r
89 if(index>=0 && index<m_externalmessages.size())
\r
91 return m_externalmessages[index].m_index;
\r
99 std::string MessageListXML::GetExternalMessageKey(const long index)
\r
101 if(index>=0 && index<m_externalmessages.size())
\r
103 return m_externalmessages[index].m_messagekey;
\r
111 std::string MessageListXML::GetExternalType(const long index)
\r
113 if(index>=0 && index<m_externalmessages.size())
\r
115 return m_externalmessages[index].m_type;
\r
123 const long MessageListXML::GetIndex(const long index)
\r
125 if(index>=0 && index<m_messages.size())
\r
127 return m_messages[index].m_index;
\r
135 std::string MessageListXML::GetXML()
\r
137 Poco::AutoPtr<Poco::XML::Document> doc=new Poco::XML::Document;
\r
138 //TiXmlDocument td;
\r
139 //TiXmlDeclaration *tdec=new TiXmlDeclaration("1.0","UTF-8","");
\r
140 Poco::XML::Element *root=doc->createElement("MessageList");
\r
141 //TiXmlElement *tid;
\r
144 doc->appendChild(root);
\r
145 //td.LinkEndChild(tdec);
\r
146 //tid=new TiXmlElement("MessageList");
\r
147 //td.LinkEndChild(tid);
\r
149 for(std::vector<message>::iterator i=m_messages.begin(); i!=m_messages.end(); i++)
\r
151 Poco::XML::Element *tr=doc->createElement("Message");
\r
152 //TiXmlElement *tr=new TiXmlElement("Message");
\r
153 root->appendChild(tr);
\r
154 //tid->LinkEndChild(tr);
\r
155 tr->appendChild(XMLCreateTextElement(doc,"Date",(*i).m_date));
\r
156 //tr->LinkEndChild(XMLCreateTextElement("Date",(*i).m_date));
\r
157 tr->appendChild(XMLCreateTextElement(doc,"Index",(*i).m_index));
\r
158 //tr->LinkEndChild(XMLCreateTextElement("Index",(*i).m_index));
\r
159 Poco::XML::Element *boards=doc->createElement("Boards");
\r
160 //TiXmlElement *brds=new TiXmlElement("Boards");
\r
161 tr->appendChild(boards);
\r
162 //tr->LinkEndChild(brds);
\r
163 for(std::vector<std::string>::iterator j=(*i).m_boards.begin(); j!=(*i).m_boards.end(); j++)
\r
165 boards->appendChild(XMLCreateCDATAElement(doc,"Board",(*j)));
\r
166 //brds->LinkEndChild(XMLCreateCDATAElement("Board",(*j)));
\r
170 for(std::vector<externalmessage>::iterator i=m_externalmessages.begin(); i!=m_externalmessages.end(); i++)
\r
172 Poco::XML::Element *tr=doc->createElement("ExternalMessage");
\r
173 //TiXmlElement *tr=new TiXmlElement("ExternalMessage");
\r
174 root->appendChild(tr);
\r
175 //tid->LinkEndChild(tr);
\r
176 tr->appendChild(XMLCreateTextElement(doc,"Type",(*i).m_type));
\r
177 //tr->LinkEndChild(XMLCreateTextElement("Type",(*i).m_type));
\r
178 if((*i).m_type=="Keyed")
\r
180 tr->appendChild(XMLCreateCDATAElement(doc,"Identity",(*i).m_identity));
\r
181 //tr->LinkEndChild(XMLCreateCDATAElement("Identity",(*i).m_identity));
\r
182 tr->appendChild(XMLCreateTextElement(doc,"Index",(*i).m_index));
\r
183 //tr->LinkEndChild(XMLCreateTextElement("Index",(*i).m_index));
\r
187 tr->appendChild(XMLCreateCDATAElement(doc,"MessageKey",(*i).m_messagekey));
\r
188 //tr->LinkEndChild(XMLCreateCDATAElement("MessageKey",(*i).m_messagekey));
\r
190 tr->appendChild(XMLCreateTextElement(doc,"Date",(*i).m_date));
\r
191 //tr->LinkEndChild(XMLCreateTextElement("Date",(*i).m_date));
\r
192 Poco::XML::Element *boards=doc->createElement("Boards");
\r
193 //TiXmlElement *brds=new TiXmlElement("Boards");
\r
194 tr->appendChild(boards);
\r
195 //tr->LinkEndChild(brds);
\r
196 for(std::vector<std::string>::iterator j=(*i).m_boards.begin(); j!=(*i).m_boards.end(); j++)
\r
198 boards->appendChild(XMLCreateCDATAElement(doc,"Board",(*j)));
\r
199 //brds->LinkEndChild(XMLCreateCDATAElement("Board",(*j)));
\r
204 //return std::string(tp.CStr());
\r
205 return GenerateXML(doc);
\r
208 void MessageListXML::Initialize()
\r
210 m_messages.clear();
\r
211 m_externalmessages.clear();
\r
214 const bool MessageListXML::ParseXML(const std::string &xml)
\r
218 Poco::XML::DOMParser dp;
\r
224 Poco::AutoPtr<Poco::XML::Document> doc=dp.parseString(FixCDATA(xml));
\r
225 Poco::XML::Element *root=XMLGetFirstChild(doc,"MessageList");
\r
227 Poco::XML::Element *node=XMLGetFirstChild(root,"Message");
\r
230 std::string date="";
\r
232 std::vector<std::string> boards;
\r
234 Poco::XML::Element *node2=XMLGetFirstChild(node,"Date");
\r
235 if(node2 && node2->firstChild())
\r
237 date=SanitizeSingleString(node2->firstChild()->getNodeValue());
\r
239 node2=XMLGetFirstChild(node,"Index");
\r
240 if(node2 && node2->firstChild())
\r
242 std::string indexstr=SanitizeSingleString(node2->firstChild()->getNodeValue());
\r
243 StringFunctions::Convert(indexstr,index);
\r
245 node2=XMLGetFirstChild(node,"Boards");
\r
248 Poco::XML::Element *node3=XMLGetFirstChild(node2,"Board");
\r
251 if(node3 && node3->firstChild())
\r
253 std::string boardname=SanitizeSingleString(node3->firstChild()->getNodeValue());
\r
254 StringFunctions::LowerCase(boardname,boardname);
\r
255 if(boardname.size()>40)
\r
257 boardname.erase(40);
\r
259 boards.push_back(boardname);
\r
261 node3=XMLGetNextSibling(node3,"Board");
\r
265 m_messages.push_back(message(date,index,boards));
\r
267 node=XMLGetNextSibling(node,"Message");
\r
270 node=XMLGetFirstChild(root,"ExternalMessage");
\r
273 std::string type="";
\r
274 std::string identity="";
\r
275 std::string date="";
\r
277 std::vector<std::string> boards;
\r
279 Poco::XML::Element *node2=XMLGetFirstChild(node,"Type");
\r
280 if(node2 && node2->firstChild())
\r
282 type=SanitizeSingleString(node2->firstChild()->getNodeValue());
\r
287 node2=XMLGetFirstChild(node,"Identity");
\r
288 if(node2 && node2->firstChild())
\r
290 identity=SanitizeSingleString(node2->firstChild()->getNodeValue());
\r
292 node2=XMLGetFirstChild(node,"Date");
\r
293 if(node2 && node2->firstChild())
\r
295 date=SanitizeSingleString(node2->firstChild()->getNodeValue());
\r
297 node2=XMLGetFirstChild(node,"Index");
\r
298 if(node2 && node2->firstChild())
\r
300 std::string indexstr=SanitizeSingleString(node2->firstChild()->getNodeValue());
\r
301 StringFunctions::Convert(indexstr,index);
\r
303 node2=XMLGetFirstChild(node,"Boards");
\r
306 Poco::XML::Element *node3=XMLGetFirstChild(node2,"Board");
\r
309 if(node3 && node3->firstChild())
\r
311 std::string boardname=SanitizeSingleString(node3->firstChild()->getNodeValue());
\r
312 StringFunctions::LowerCase(boardname,boardname);
\r
313 if(boardname.size()>40)
\r
315 boardname.erase(40);
\r
317 boards.push_back(boardname);
\r
319 node3=XMLGetNextSibling(node3,"Board");
\r
322 m_externalmessages.push_back(externalmessage("Keyed",identity,date,index,boards));
\r
325 node=XMLGetNextSibling(node,"ExternalMessage");
\r
337 td.Parse(xml.c_str());
\r
341 std::string tempstr;
\r
344 std::vector<std::string> boards;
\r
346 TiXmlHandle hnd(&td);
\r
352 node=hnd.FirstChild("MessageList").FirstChild("Message").ToNode();
\r
359 TiXmlHandle hnd2(node);
\r
360 txt=hnd2.FirstChild("Date").FirstChild().ToText();
\r
363 date=SanitizeSingleString(txt->ValueStr());
\r
365 txt=hnd2.FirstChild("Index").FirstChild().ToText();
\r
368 tempstr=SanitizeSingleString(txt->ValueStr());
\r
369 StringFunctions::Convert(tempstr,index);
\r
371 node2=hnd2.FirstChild("Boards").FirstChild("Board").ToNode();
\r
374 if(node2->FirstChild())
\r
376 std::string boardname=SanitizeSingleString(node2->FirstChild()->ValueStr());
\r
377 StringFunctions::LowerCase(boardname,boardname);
\r
378 boards.push_back(boardname);
\r
380 node2=node2->NextSibling("Board");
\r
383 m_messages.push_back(message(date,index,boards));
\r
385 node=node->NextSibling("Message");
\r
388 node=hnd.FirstChild("MessageList").FirstChild("ExternalMessage").ToNode();
\r
391 std::string type="";
\r
392 std::string identity="";
\r
397 TiXmlHandle hnd2(node);
\r
398 txt=hnd2.FirstChild("Type").FirstChild().ToText();
\r
401 type=SanitizeSingleString(txt->ValueStr());
\r
406 txt=hnd2.FirstChild("Identity").FirstChild().ToText();
\r
409 identity=SanitizeSingleString(txt->ValueStr());
\r
411 txt=hnd2.FirstChild("Date").FirstChild().ToText();
\r
414 date=SanitizeSingleString(txt->ValueStr());
\r
416 txt=hnd2.FirstChild("Index").FirstChild().ToText();
\r
419 tempstr=SanitizeSingleString(txt->ValueStr());
\r
420 StringFunctions::Convert(tempstr,index);
\r
422 node2=hnd2.FirstChild("Boards").FirstChild("Board").ToNode();
\r
425 if(node2->FirstChild())
\r
427 std::string boardname=SanitizeSingleString(node2->FirstChild()->ValueStr());
\r
428 StringFunctions::LowerCase(boardname,boardname);
\r
429 boards.push_back(boardname);
\r
431 node2=node2->NextSibling("Board");
\r
433 m_externalmessages.push_back(externalmessage("Keyed",identity,date,index,boards));
\r
436 node=node->NextSibling("ExternalMessage");
\r