1 #include "../../include/freenet/boardlistxml.h"
\r
7 BoardListXML::BoardListXML()
\r
12 void BoardListXML::AddBoard(const std::string &name, const std::string &description)
\r
14 if(name!="" && description!="")
\r
16 std::string lowername=name;
\r
17 StringFunctions::LowerCase(lowername,lowername);
\r
18 if(lowername.size()>40)
\r
20 lowername.erase(40);
\r
22 m_boards.push_back(board(lowername,description));
\r
26 const std::string BoardListXML::GetDescription(const long index)
\r
28 if(index>=0 && index<GetCount())
\r
30 return m_boards[index].m_description;
\r
38 const std::string BoardListXML::GetName(const long index)
\r
40 if(index>=0 && index<GetCount())
\r
42 return m_boards[index].m_name;
\r
50 std::string BoardListXML::GetXML()
\r
52 Poco::AutoPtr<Poco::XML::Document> doc=new Poco::XML::Document;
\r
54 //TiXmlDeclaration *tdec=new TiXmlDeclaration("1.0","UTF-8","");
\r
55 Poco::XML::Element *root=doc->createElement("BoardList");
\r
56 //TiXmlElement *tid;
\r
59 doc->appendChild(root);
\r
60 //td.LinkEndChild(tdec);
\r
61 //tid=new TiXmlElement("BoardList");
\r
62 //td.LinkEndChild(tid);
\r
64 for(std::vector<board>::iterator i=m_boards.begin(); i!=m_boards.end(); i++)
\r
66 std::string boardname=(*i).m_name;
\r
67 StringFunctions::LowerCase(boardname,boardname);
\r
68 Poco::XML::Element *tr=doc->createElement("Board");
\r
69 //TiXmlElement *tr=new TiXmlElement("Board");
\r
70 root->appendChild(tr);
\r
71 //tid->LinkEndChild(tr);
\r
72 tr->appendChild(XMLCreateCDATAElement(doc,"Name",boardname));
\r
73 //tr->LinkEndChild(XMLCreateCDATAElement("Name",boardname));
\r
74 tr->appendChild(XMLCreateCDATAElement(doc,"Description",(*i).m_description));
\r
75 //tr->LinkEndChild(XMLCreateCDATAElement("Description",(*i).m_description));
\r
79 //return std::string(tp.CStr());
\r
80 return GenerateXML(doc);
\r
83 void BoardListXML::Initialize()
\r
88 const bool BoardListXML::ParseXML(const std::string &xml)
\r
91 Poco::XML::DOMParser dp;
\r
97 Poco::AutoPtr<Poco::XML::Document> doc=dp.parseString(FixCDATA(xml));
\r
98 Poco::XML::Element *root=XMLGetFirstChild(doc,"BoardList");
\r
99 Poco::XML::Element *boardel=NULL;
\r
101 boardel=XMLGetFirstChild(root,"Board");
\r
104 std::string name="";
\r
105 std::string description="";
\r
107 Poco::XML::Element *txt=XMLGetFirstChild(boardel,"Name");
\r
108 if(txt && txt->firstChild())
\r
110 name=SanitizeSingleString(txt->firstChild()->getNodeValue());
\r
111 StringFunctions::LowerCase(name,name);
\r
117 txt=XMLGetFirstChild(boardel,"Description");
\r
118 if(txt && txt->firstChild())
\r
120 description=SanitizeSingleString(txt->firstChild()->getNodeValue());
\r
123 if(name!="" && description!="")
\r
125 m_boards.push_back(board(name,description));
\r
128 boardel=XMLGetNextSibling(boardel,"Board");
\r
142 std::string description;
\r
144 td.Parse(xml.c_str());
\r
149 TiXmlHandle hnd(&td);
\r
154 node=hnd.FirstChild("BoardList").FirstChild("Board").ToElement();
\r
160 TiXmlHandle hnd2(node);
\r
161 txt=hnd2.FirstChild("Name").FirstChild().ToText();
\r
164 name=txt->ValueStr();
\r
165 StringFunctions::LowerCase(name,name);
\r
171 txt=hnd2.FirstChild("Description").FirstChild().ToText();
\r
174 description=txt->ValueStr();
\r
177 if(name!="" && description!="")
\r
179 m_boards.push_back(board(name,description));
\r
182 node=node->NextSibling("Board");
\r