src/discinfo.cpp

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

Generated on Sun Jun 25 23:35:45 2006 for libdaisy by  doxygen 1.4.6