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 {
00026 namespace parser
00027 {
00028 namespace yum
00029 {
00030 
00031 YUMGroupParser::YUMGroupParser()
00032 { }
00033 
00034 YUMGroupParser::YUMGroupParser(YUMGroupData_Ptr& entry)
00035     : XMLNodeIterator<YUMGroupData_Ptr>(entry)
00036 { }
00037 
00038 
00039 YUMGroupParser::~YUMGroupParser()
00040 { }
00041 
00042 
00043 // select for which elements process() will be called
00044 bool
00045 YUMGroupParser::isInterested(const xmlNodePtr nodePtr)
00046 {
00047   return _helper.isElement(nodePtr) && _helper.name(nodePtr) == "group";
00048 }
00049 
00050 // do the actual processing
00051 YUMGroupData_Ptr
00052 YUMGroupParser::process(const xmlTextReaderPtr reader)
00053 {
00054   xml_assert(reader);
00055   YUMGroupData_Ptr dataPtr = new YUMGroupData;
00056   xmlNodePtr dataNode = xmlTextReaderExpand(reader);
00057   xml_assert(dataNode);
00058 
00059   for (xmlNodePtr child = dataNode->children;
00060        child && child != dataNode;
00061        child = child->next)
00062   {
00063     if (_helper.isElement(child))
00064     {
00065       string name = _helper.name(child);
00066       if (name == "groupid")
00067       {
00068         dataPtr->groupId = _helper.content(child);
00069       }
00070       else if (name == "name")
00071       {
00072         dataPtr->name.setText(_helper.content(child), Locale(_helper.attribute(child,"lang")));
00073       }
00074       else if (name == "default")
00075       {
00076         dataPtr->default_ = _helper.content(child);
00077       }
00078       else if (name == "uservisible")
00079       {
00080         dataPtr->userVisible = _helper.content(child);
00081       }
00082       else if (name == "description")
00083       {
00084         dataPtr->description.setText(_helper.content(child), Locale(_helper.attribute(child,"lang")));
00085         ERR << "description has " << dataPtr->description.locales().size() << std::endl;
00086       }
00087       else if (name == "grouplist")
00088       {
00089         parseGrouplist(dataPtr, child);
00090       }
00091       else if (name == "packagelist")
00092       {
00093         parsePackageList(dataPtr, child);
00094       }
00095       else
00096       {
00097         WAR << "YUM <group> contains the unknown element <" << name << "> "
00098         << _helper.positionInfo(child) << ", skipping" << endl;
00099       }
00100     }
00101   }
00102   return dataPtr;
00103 } /* end process */
00104 
00105 void YUMGroupParser::parseGrouplist(YUMGroupData_Ptr dataPtr,
00106                                     xmlNodePtr node)
00107 {
00108   xml_assert(dataPtr);
00109   xml_assert(node);
00110 
00111   for (xmlNodePtr child = node->children;
00112        child != 0;
00113        child = child ->next)
00114   {
00115     if (_helper.isElement(child))
00116     {
00117       string name = _helper.name(child);
00118       if (name == "metapkg" || name == "groupreq")
00119       {
00120         dataPtr->grouplist.push_back
00121         (MetaPkg(_helper.attribute(child,"type"),
00122                  _helper.content(child)));
00123       }
00124       else
00125       {
00126         WAR << "YUM <grouplist> contains the unknown element <" << name << "> "
00127         << _helper.positionInfo(child) << ", skipping" << endl;
00128       }
00129     }
00130   }
00131 }
00132 
00133 
00134 void YUMGroupParser::parsePackageList(YUMGroupData_Ptr dataPtr,
00135                                       xmlNodePtr node)
00136 {
00137   xml_assert(dataPtr);
00138   xml_assert(node);
00139 
00140   for (xmlNodePtr child = node->children;
00141        child != 0;
00142        child = child ->next)
00143   {
00144     if (_helper.isElement(child))
00145     {
00146       string name = _helper.name(child);
00147       if (name == "packagereq")
00148       {
00149         dataPtr->packageList.push_back
00150         (PackageReq(_helper.attribute(child,"type"),
00151                     _helper.attribute(child,"epoch"),
00152                     _helper.attribute(child,"ver"),
00153                     _helper.attribute(child,"rel"),
00154                     _helper.content(child)));
00155       }
00156       else
00157       {
00158         WAR << "YUM <packagelist> contains the unknown element <" << name << "> "
00159         << _helper.positionInfo(child) << ", skipping" << endl;
00160       }
00161     }
00162   }
00163 }
00164 
00165 
00166 
00167 YUMGroupParser::YUMGroupParser(std::istream &is, const std::string &baseUrl, parser::ParserProgress::Ptr progress )
00168     : XMLNodeIterator<YUMGroupData_Ptr>(is, baseUrl,GROUPSCHEMA, progress)
00169 {
00170   fetchNext();
00171 }
00172 
00173 } // namespace yum
00174 } // namespace parser
00175 } // namespace zypp

Generated on Tue Nov 28 16:49:30 2006 for zypp by  doxygen 1.5.0