YUMProductParser.cc

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00013 #include <istream>
00014 #include <string>
00015 #include "zypp/ZYppFactory.h"
00016 #include "zypp/ZYpp.h"
00017 #include "zypp/parser/xml_parser_assert.h"
00018 #include <libxml/xmlreader.h>
00019 #include <libxml/tree.h>
00020 #include "zypp/parser/yum/YUMProductParser.h"
00021 #include "zypp/parser/yum/YUMPrimaryParser.h"
00022 #include "zypp/parser/LibXMLHelper.h"
00023 #include "zypp/base/Logger.h"
00024 #include "zypp/parser/yum/schemanames.h"
00025 
00026 using namespace std;
00027 namespace zypp
00028 {
00029 namespace parser
00030 {
00031 namespace yum
00032 {
00033 
00034 YUMProductParser::~YUMProductParser()
00035 { }
00036 
00037 YUMProductParser::YUMProductParser(std::istream &is, const std::string& baseUrl, parser::ParserProgress::Ptr progress )
00038     : XMLNodeIterator<YUMProductData_Ptr>(is, baseUrl,PRODUCTSCHEMA, progress)
00039       , _zypp_architecture( getZYpp()->architecture() )
00040 {
00041   fetchNext();
00042 }
00043 
00044 YUMProductParser::YUMProductParser()
00045   : _zypp_architecture( getZYpp()->architecture() )
00046 { }
00047 
00048 YUMProductParser::YUMProductParser(YUMProductData_Ptr& entry)
00049     : XMLNodeIterator<YUMProductData_Ptr>(entry)
00050       , _zypp_architecture( getZYpp()->architecture() )
00051 { }
00052 
00053 
00054 // select for which elements process() will be called
00055 bool
00056 YUMProductParser::isInterested(const xmlNodePtr nodePtr)
00057 {
00058   return _helper.isElement(nodePtr) && _helper.name(nodePtr) == "product";
00059 }
00060 
00061 // do the actual processing
00062 YUMProductData_Ptr
00063 YUMProductParser::process(const xmlTextReaderPtr reader)
00064 {
00065   xml_assert(reader);
00066   YUMProductData_Ptr productPtr = new YUMProductData;
00067   xmlNodePtr dataNode = xmlTextReaderExpand(reader);
00068   xml_assert(dataNode);
00069   productPtr->type = _helper.attribute(dataNode,"type");
00070 
00071   // FIXME move the respective method to a common class, inherit it
00072   YUMPrimaryParser prim;
00073 
00074   for (xmlNodePtr child = dataNode->children;
00075        child && child != dataNode;
00076        child = child->next)
00077   {
00078     if (_helper.isElement(child))
00079     {
00080       string name = _helper.name(child);
00081       if (name == "name")
00082       {
00083         productPtr->name = _helper.content(child);
00084       }
00085       else if (name == "arch")
00086       {
00087         productPtr->arch = _helper.content(child);
00088         try
00089         {
00090           if (!Arch(productPtr->arch).compatibleWith( _zypp_architecture ))
00091           {
00092             productPtr = NULL;                  // skip <package>, incompatible architecture
00093             ERR << "Skipping incompatible architecture product. " << endl;
00094             break;
00095           }
00096         }
00097         catch ( const Exception & excpt_r )
00098         {
00099           ZYPP_CAUGHT( excpt_r );
00100           DBG << "Skipping malformed " << productPtr->arch << endl;
00101           productPtr = NULL;
00102           break;
00103         }
00104       }
00105       else if (name == "vendor")
00106       {
00107         productPtr->vendor = _helper.content(child);
00108       }
00109       else if (name == "release-notes-url")
00110       {
00111         productPtr->releasenotesurl = _helper.content(child);
00112       }
00113       else if (name == "displayname")
00114       {
00115         productPtr->summary.setText(_helper.content(child), Locale(_helper.attribute(child,"lang")));
00116       }
00117       else if (name == "shortname")
00118       {
00119         productPtr->short_name.setText(_helper.content(child), Locale(_helper.attribute(child,"lang")));
00120       }
00121       else if (name == "description")
00122       {
00123         productPtr->description.setText(_helper.content(child), Locale(_helper.attribute(child,"lang")));
00124       }
00125       else if (name == "version")
00126       {
00127         productPtr->epoch = _helper.attribute(child,"epoch");
00128         productPtr->ver = _helper.attribute(child,"ver");
00129         productPtr->rel = _helper.attribute(child,"rel");
00130       }
00131       else if (name == "distribution-name")
00132       {
00133         productPtr->distribution_name = _helper.content(child);
00134       }
00135       else if (name == "distribution-edition")
00136       {
00137         productPtr->distribution_edition = _helper.content(child);
00138       }
00139       else if (name == "provides")
00140       {
00141         prim.parseDependencyEntries(& productPtr->provides, child);
00142       }
00143       else if (name == "conflicts")
00144       {
00145         prim.parseDependencyEntries(& productPtr->conflicts, child);
00146       }
00147       else if (name == "obsoletes")
00148       {
00149         prim.parseDependencyEntries(& productPtr->obsoletes, child);
00150       }
00151       else if (name == "prerequires")
00152       {
00153         prim.parseDependencyEntries(& productPtr->prerequires, child);
00154       }
00155       else if (name == "requires")
00156       {
00157         prim.parseDependencyEntries(& productPtr->requires, child);
00158       }
00159       else if (name == "recommends")
00160       {
00161         prim.parseDependencyEntries(& productPtr->recommends, child);
00162       }
00163       else if (name == "suggests")
00164       {
00165         prim.parseDependencyEntries(& productPtr->suggests, child);
00166       }
00167       else if (name == "supplements")
00168       {
00169         prim.parseDependencyEntries(& productPtr->supplements, child);
00170       }
00171       else if (name == "enhances")
00172       {
00173         prim.parseDependencyEntries(& productPtr->enhances, child);
00174       }
00175       else if (name == "freshens")
00176       {
00177         prim.parseDependencyEntries(& productPtr->freshens, child);
00178       }
00179       else
00180       {
00181         WAR << "YUM <data> contains the unknown element <" << name << "> "
00182         << _helper.positionInfo(child) << ", skipping" << endl;
00183       }
00184     }
00185   }
00186   return productPtr;
00187 } /* end process */
00188 
00189 
00190 
00191 } // namespace yum
00192 } // namespace parser
00193 } // namespace zypp

Generated on Thu Apr 24 02:24:50 2008 for zypp by  doxygen 1.4.6