version 0.1.11
[fms.git] / src / freenet / boardlistxml.cpp
diff --git a/src/freenet/boardlistxml.cpp b/src/freenet/boardlistxml.cpp
new file mode 100644 (file)
index 0000000..eb9ca8c
--- /dev/null
@@ -0,0 +1,119 @@
+#include "../../include/freenet/boardlistxml.h"\r
+\r
+#ifdef XMEM\r
+       #include <xmem.h>\r
+#endif\r
+\r
+BoardListXML::BoardListXML()\r
+{\r
+       Initialize();\r
+}\r
+\r
+void BoardListXML::AddBoard(const std::string &name, const std::string &description)\r
+{\r
+       if(name!="" && description!="")\r
+       {\r
+               m_boards.push_back(board(name,description));\r
+       }\r
+}\r
+\r
+const std::string BoardListXML::GetDescription(const long index)\r
+{\r
+       if(index>=0 && index<GetCount())\r
+       {\r
+               return m_boards[index].m_description;\r
+       }\r
+       else\r
+       {\r
+               return "";\r
+       }\r
+}\r
+\r
+const std::string BoardListXML::GetName(const long index)\r
+{\r
+       if(index>=0 && index<GetCount())\r
+       {\r
+               return m_boards[index].m_name;\r
+       }\r
+       else\r
+       {\r
+               return "";\r
+       }\r
+}\r
+\r
+std::string BoardListXML::GetXML()\r
+{\r
+       TiXmlDocument td;\r
+       TiXmlDeclaration *tdec=new TiXmlDeclaration("1.0","UTF-8","");\r
+       TiXmlElement *tid;\r
+       TiXmlPrinter tp;\r
+\r
+       td.LinkEndChild(tdec);\r
+       tid=new TiXmlElement("BoardList");\r
+       td.LinkEndChild(tid);\r
+\r
+       for(std::vector<board>::iterator i=m_boards.begin(); i!=m_boards.end(); i++)\r
+       {\r
+               TiXmlElement *tr=new TiXmlElement("Board");\r
+               tid->LinkEndChild(tr);\r
+               tr->LinkEndChild(XMLCreateCDATAElement("Name",(*i).m_name));\r
+               tr->LinkEndChild(XMLCreateCDATAElement("Description",(*i).m_description));\r
+       }\r
+\r
+       td.Accept(&tp);\r
+       return std::string(tp.CStr());\r
+}\r
+\r
+void BoardListXML::Initialize()\r
+{\r
+       m_boards.clear();\r
+}\r
+\r
+const bool BoardListXML::ParseXML(const std::string &xml)\r
+{\r
+       std::string name;\r
+       std::string description;\r
+       TiXmlDocument td;\r
+       td.Parse(xml.c_str());\r
+\r
+       if(!td.Error())\r
+       {\r
+               TiXmlText *txt;\r
+               TiXmlHandle hnd(&td);\r
+               TiXmlNode *node;\r
+\r
+               Initialize();\r
+\r
+               node=hnd.FirstChild("BoardList").FirstChild("Board").ToElement();\r
+               while(node)\r
+               {\r
+                       name="";\r
+                       description="";\r
+\r
+                       TiXmlHandle hnd2(node);\r
+                       txt=hnd2.FirstChild("Name").FirstChild().ToText();\r
+                       if(txt)\r
+                       {\r
+                               name=txt->ValueStr();\r
+                       }\r
+                       txt=hnd2.FirstChild("Description").FirstChild().ToText();\r
+                       if(txt)\r
+                       {\r
+                               description=txt->ValueStr();\r
+                       }\r
+\r
+                       if(name!="" && description!="")\r
+                       {\r
+                               m_boards.push_back(board(name,description));\r
+                       }\r
+                       \r
+                       node=node->NextSibling("Board");\r
+               }\r
+               return true;\r
+\r
+       }\r
+       else\r
+       {\r
+               return false;\r
+       }\r
+}
\ No newline at end of file