00001 #include "discinfo.h" 00002 00003 namespace freedaisy { 00004 Discinfo::Discinfo() { 00005 _xmldoc = NULL; 00006 createDoc(); 00007 } 00008 00009 void Discinfo::createDoc(std::string lang) { 00010 _createDoc(); 00011 XMLNode html = createRootNode("html"); 00012 html.setAttr("xmlns", "http://www.w3.org/1999/xhtml"); 00013 00014 XMLNode head("head"); 00015 html.addChild(&head); 00016 XMLNode title("title"); 00017 head.addChild(&title); 00018 title.setContent("CD Information"); 00019 00020 XMLNode meta("meta"); 00021 meta.setAttr("http-equiv", "Content-type"); 00022 meta.setAttr("content", "text/html"); 00023 head.addChild(&meta); 00024 00025 XMLNode body("body"); 00026 html.addChild(&body); 00027 00028 setLang(lang); 00029 } 00030 00031 std::vector<Link> Discinfo::getLinks() { 00032 // Get links (XMLNodes) and add them in a vector of Link 00033 std::vector<XMLNode> nodes; 00034 std::vector<Link> links; 00035 nodes = xpathEval("//*[local-name() = 'a']"); 00036 for (std::vector<XMLNode>::iterator it = nodes.begin(); it != nodes.end() ; it++) { 00037 links.push_back(Link((*it))); 00038 } 00039 return links; 00040 } 00041 00042 void Discinfo::addLink(Link *lnk) { 00043 XMLNode node; 00044 node = xpathEval("//*[local-name() = 'body']")[0]; 00045 node.addChild(lnk); 00046 } 00047 00048 void Discinfo::delLink(Link *lnk) { 00049 std::vector<XMLNode> nodevect; 00050 nodevect = xpathEval("//*[local-name() = 'a']"); 00051 for (int i = 0; i < nodevect.size(); i++) { 00052 if ((nodevect[i].getContent() == lnk->getContent()) && 00053 (nodevect[i].getAttr("href") == lnk->getHref().getString())) { 00054 nodevect[i].unlink(); 00055 } 00056 } 00057 } 00058 00059 void Discinfo::setLang(std::string lang) { 00060 // Code shared with NCC 00061 XMLNode node; 00062 node = xpathEval("//*[local-name() = 'head']")[0]; 00063 node.setAttr("lang", lang); 00064 node.setAttr("xml:lang", lang); 00065 } 00066 00067 std::string Discinfo::getLang() { 00068 // Code shared with NCC 00069 XMLNode node; 00070 node = xpathEval("//*[local-name() = 'head']")[0]; 00071 if (node.hasAttr("lang") == 0) { 00072 return node["lang"]; 00073 } else { 00074 return "en"; 00075 } 00076 } 00077 }
1.4.6