XMLProductParser.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/parser/xml_parser_assert.h"
00016 #include <libxml/xmlreader.h>
00017 #include <libxml/tree.h>
00018 #include "zypp/parser/xmlstore/XMLProductParser.h"
00019 #include "zypp/parser/xmlstore/XMLResObjectParser.h"
00020 #include "zypp/parser/LibXMLHelper.h"
00021 #include "zypp/base/Logger.h"
00022 #include "zypp/parser/xmlstore/schemanames.h"
00023 
00024 using namespace std;
00025 namespace zypp {
00026   namespace parser {
00027     namespace xmlstore {
00028 
00029       XMLProductParser::~XMLProductParser()
00030       { }
00031 
00032       XMLProductParser::XMLProductParser(std::istream &is, const std::string& baseUrl)
00033         : XMLNodeIterator<XMLProductData_Ptr>(is, baseUrl ,PRODUCTSCHEMA)
00034       {
00035         fetchNext();
00036       }
00037 
00038       XMLProductParser::XMLProductParser()
00039       { }
00040 
00041       XMLProductParser::XMLProductParser(XMLProductData_Ptr& entry)
00042       : XMLNodeIterator<XMLProductData_Ptr>(entry)
00043       { }
00044 
00045 
00046       // select for which elements process() will be called
00047       bool
00048       XMLProductParser::isInterested(const xmlNodePtr nodePtr)
00049       {
00050         return _helper.isElement(nodePtr) && _helper.name(nodePtr) == "product";
00051       }
00052 
00053       // do the actual processing
00054       XMLProductData_Ptr
00055       XMLProductParser::process(const xmlTextReaderPtr reader)
00056       {
00057         xml_assert(reader);
00058         XMLProductData_Ptr productPtr = new XMLProductData;
00059         xmlNodePtr dataNode = xmlTextReaderExpand(reader);
00060         xml_assert(dataNode);
00061         productPtr->type = _helper.attribute(dataNode,"type");
00062         productPtr->parser_version = _helper.attribute(dataNode, "version");
00063 
00064         parseResObjectCommonData( productPtr, dataNode);
00065         parseDependencies( productPtr, dataNode);
00066 
00067         for (xmlNodePtr child = dataNode->children; child && child != dataNode; child = child->next)
00068         {
00069           if (_helper.isElement(child))
00070           {
00071             string name = _helper.name(child);
00072             if (name == "vendor")
00073             {
00074               productPtr->vendor = _helper.content(child);
00075             }
00076             else if (name == "release-notes-url") {
00077               productPtr->releasenotesurl = _helper.content(child);
00078             }
00079             else if (name == "distribution-name") {
00080               productPtr->dist_name = _helper.content(child);
00081             }
00082             else if (name == "distribution-edition") {
00083               productPtr->dist_version = _helper.content(child);
00084             }
00085             else if (name == "shortname") {
00086               productPtr->short_name.setText(_helper.content(child), Locale(_helper.attribute(child,"lang")));
00087             }
00088             else if (name == "product-flags") {
00089               parseProductFlags( productPtr, child);
00090             }
00091             else if (name == "update-urls")
00092             {
00093               parseList<string>( "update-url", productPtr->update_urls, child);
00094             }
00095             else if (name == "extra-urls")
00096             {
00097               parseList<string>( "extra-url", productPtr->extra_urls, child);
00098             }
00099             else if (name == "optional-urls")
00100             {
00101               parseList<string>( "optional-url", productPtr->optional_urls, child);
00102             }
00103 
00104           }
00105         }
00106         return productPtr;
00107       } /* end process */
00108 
00109       void
00110       XMLProductParser::parseProductFlags( XMLProductData_Ptr productPtr, xmlNodePtr node)
00111       {
00112         for (xmlNodePtr child = node->children; child && child != node; child = child->next)
00113         {
00114           if (_helper.isElement(child))
00115           {
00116             string name = _helper.name(child);
00117             if (name == "product-flag")
00118             {
00119               productPtr->flags.push_back(_helper.content(child));
00120             }
00121           }
00122         }
00123       }
00124 
00125       template <class T>
00126       void XMLProductParser::parseList( const std::string &tagname, std::list<T> &list, xmlNodePtr node)
00127       {
00128         for (xmlNodePtr child = node->children; child && child != node; child = child->next)
00129         {
00130           if (_helper.isElement(child))
00131           {
00132             string name = _helper.name(child);
00133             if (name == tagname)
00134             {
00135               list.push_back(_helper.content(child));
00136             }
00137           }
00138         }
00139       }
00140 
00141     } // namespace yum
00142   } // namespace parser
00143 } // namespace zypp

Generated on Tue Sep 25 19:23:03 2007 for libzypp by  doxygen 1.5.3