YUMGroupParser.cc

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00013 #include <zypp/parser/yum/YUMGroupParser.h>
00014 #include <zypp/parser/LibXMLHelper.h>
00015 #include <istream>
00016 #include <string>
00017 #include "zypp/parser/xml_parser_assert.h"
00018 #include <libxml/xmlreader.h>
00019 #include <libxml/tree.h>
00020 #include <zypp/base/Logger.h>
00021 #include <zypp/parser/yum/schemanames.h>
00022 
00023 using namespace std;
00024 namespace zypp {
00025   namespace parser {
00026     namespace yum {
00027 
00028       YUMGroupParser::YUMGroupParser()
00029       { }
00030       
00031       YUMGroupParser::YUMGroupParser(YUMGroupData_Ptr& entry)
00032       : XMLNodeIterator<YUMGroupData_Ptr>(entry)
00033       { }
00034       
00035       
00036       YUMGroupParser::~YUMGroupParser()
00037       { }
00038       
00039       
00040       // select for which elements process() will be called
00041       bool 
00042       YUMGroupParser::isInterested(const xmlNodePtr nodePtr)
00043       {
00044         return _helper.isElement(nodePtr) && _helper.name(nodePtr) == "group";
00045       }
00046       
00047       // do the actual processing
00048       YUMGroupData_Ptr
00049       YUMGroupParser::process(const xmlTextReaderPtr reader)
00050       {
00051         xml_assert(reader);
00052         YUMGroupData_Ptr dataPtr = new YUMGroupData;
00053         xmlNodePtr dataNode = xmlTextReaderExpand(reader);
00054         xml_assert(dataNode);
00055         
00056         for (xmlNodePtr child = dataNode->children;
00057              child && child != dataNode;
00058              child = child->next) {
00059                if (_helper.isElement(child)) {
00060                  string name = _helper.name(child);
00061                  if (name == "groupid") {
00062                    dataPtr->groupId = _helper.content(child);
00063                  }
00064                  else if (name == "name") {
00065                    dataPtr->name.setText(_helper.content(child), Locale(_helper.attribute(child,"lang")));
00066                  }
00067                  else if (name == "default") {
00068                    dataPtr->default_ = _helper.content(child);
00069                  }
00070                  else if (name == "uservisible") {
00071                    dataPtr->userVisible = _helper.content(child);
00072                  }
00073                  else if (name == "description") {
00074                    dataPtr->description.setText(_helper.content(child), Locale(_helper.attribute(child,"lang")));
00075                    ERR << "description has " << dataPtr->description.locales().size() << std::endl;
00076                  }
00077                  else if (name == "grouplist") {
00078                    parseGrouplist(dataPtr, child);
00079                  }
00080                  else if (name == "packagelist") {
00081                    parsePackageList(dataPtr, child);
00082                  }
00083                  else {
00084                    WAR << "YUM <group> contains the unknown element <" << name << "> "
00085                      << _helper.positionInfo(child) << ", skipping" << endl;
00086                  }
00087                }
00088              }
00089         return dataPtr;
00090       } /* end process */
00091       
00092       void YUMGroupParser::parseGrouplist(YUMGroupData_Ptr dataPtr,
00093                                                 xmlNodePtr node)
00094       {
00095         xml_assert(dataPtr);
00096         xml_assert(node);
00097         
00098         for (xmlNodePtr child = node->children;
00099              child != 0;
00100              child = child ->next) {
00101                if (_helper.isElement(child)) {
00102                  string name = _helper.name(child);
00103                  if (name == "metapkg" || name == "groupreq") {
00104                    dataPtr->grouplist.push_back
00105                      (MetaPkg(_helper.attribute(child,"type"),
00106                               _helper.content(child)));
00107                  }
00108                  else {
00109                    WAR << "YUM <grouplist> contains the unknown element <" << name << "> "
00110                      << _helper.positionInfo(child) << ", skipping" << endl;
00111                  }
00112                }
00113              }
00114       }
00115       
00116       
00117       void YUMGroupParser::parsePackageList(YUMGroupData_Ptr dataPtr,
00118                                                   xmlNodePtr node)
00119       {
00120         xml_assert(dataPtr);
00121         xml_assert(node);
00122         
00123         for (xmlNodePtr child = node->children;
00124              child != 0;
00125              child = child ->next) {
00126                if (_helper.isElement(child)) {
00127                  string name = _helper.name(child);
00128                  if (name == "packagereq") {
00129                  dataPtr->packageList.push_back
00130                    (PackageReq(_helper.attribute(child,"type"),
00131                                _helper.attribute(child,"epoch"),
00132                                _helper.attribute(child,"ver"),
00133                                _helper.attribute(child,"rel"),
00134                                _helper.content(child)));
00135                  }
00136                  else {
00137                    WAR << "YUM <packagelist> contains the unknown element <" << name << "> "
00138                      << _helper.positionInfo(child) << ", skipping" << endl;
00139                  }
00140                }
00141              }
00142       }
00143       
00144       
00145       
00146       YUMGroupParser::YUMGroupParser(istream &is, const string &baseUrl)
00147       : XMLNodeIterator<YUMGroupData_Ptr>(is, baseUrl,GROUPSCHEMA)
00148       { 
00149         fetchNext();
00150       }
00151       
00152     } // namespace yum
00153   } // namespace parser
00154 } // namespace zypp

Generated on Thu Jul 6 00:07:21 2006 for zypp by  doxygen 1.4.6