RepomdFileReader.cc

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #include "zypp/base/String.h"
00013 #include "zypp/base/Logger.h"
00014 
00015 #include "zypp/Date.h"
00016 #include "zypp/CheckSum.h"
00017 #include "zypp/parser/xml/Reader.h"
00018 
00019 #include "zypp/parser/yum/RepomdFileReader.h"
00020 
00021 #undef ZYPP_BASE_LOGGER_LOGGROUP
00022 #define ZYPP_BASE_LOGGER_LOGGROUP "parser::yum"
00023 
00024 using namespace std;
00025 using namespace zypp::xml;
00026 using zypp::repo::yum::ResourceType;
00027 
00028 namespace zypp
00029 {
00030   namespace parser
00031   {
00032     namespace yum
00033     {
00034 
00035 
00037   //
00038   //  CLASS NAME : RepomdFileReader::Impl
00039   //
00040   class RepomdFileReader::Impl : private base::NonCopyable
00041   {
00042   public:
00043 
00048     enum Tag
00049     {
00050       tag_NONE,
00051       tag_Repomd,
00052       tag_Data,
00053       tag_Location,
00054       tag_CheckSum,
00055       tag_Timestamp,
00056       tag_OpenCheckSum
00057     };
00058 
00059   public:
00065     Impl(const Pathname &repomd_file, const ProcessResource & callback);
00066 
00070     bool consumeNode( Reader & reader_r );
00071 
00072 
00073   private:
00075     OnMediaLocation _location;
00076 
00078     Tag _tag;
00079 
00081     repo::yum::ResourceType _type;
00082 
00084     ProcessResource _callback;
00085 
00087     CheckSum _checksum;
00088 
00090     std::string _checksum_type;
00091 
00093     Date _timestamp;
00094   };
00096 
00097   RepomdFileReader::Impl::Impl(
00098       const Pathname &repomd_file, const ProcessResource & callback)
00099     :
00100       _tag(tag_NONE), _type(ResourceType::NONE_e), _callback(callback)
00101   {
00102     Reader reader( repomd_file );
00103     MIL << "Reading " << repomd_file << endl;
00104     reader.foreachNode( bind( &RepomdFileReader::Impl::consumeNode, this, _1 ) );
00105   }
00106 
00107   // --------------------------------------------------------------------------
00108 
00109   /*
00110    * xpath and multiplicity of processed nodes are included in the code
00111    * for convenience:
00112    *
00113    * // xpath: <xpath> (?|*|+)
00114    *
00115    * if multiplicity is ommited, then the node has multiplicity 'one'.
00116    */
00117 
00118   // --------------------------------------------------------------------------
00119 
00120   bool RepomdFileReader::Impl::consumeNode( Reader & reader_r )
00121   {
00122     if ( reader_r->nodeType() == XML_READER_TYPE_ELEMENT )
00123     {
00124       // xpath: /repomd
00125       if ( reader_r->name() == "repomd" )
00126       {
00127         _tag = tag_Repomd;
00128         return true;
00129       }
00130 
00131       // xpath: /repomd/data (+)
00132       if ( reader_r->name() == "data" )
00133       {
00134         _tag = tag_Data;
00135         _type = ResourceType(reader_r->getAttribute("type").asString());
00136         return true;
00137       }
00138 
00139       // xpath: /repomd/location
00140       if ( reader_r->name() == "location" )
00141       {
00142         _tag = tag_Location;
00143         _location.setLocation( reader_r->getAttribute("href").asString(), 1 );
00144         // ignoring attribute xml:base
00145         return true;
00146       }
00147 
00148       // xpath: /repomd/checksum
00149       if ( reader_r->name() == "checksum" )
00150       {
00151         _tag = tag_CheckSum;
00152         string checksum_type = reader_r->getAttribute("type").asString() ;
00153         string checksum_vaue = reader_r.nodeText().asString();
00154         _location.setChecksum( CheckSum( checksum_type, checksum_vaue ) );
00155         return true;
00156       }
00157 
00158       // xpath: /repomd/timestamp
00159       if ( reader_r->name() == "timestamp" )
00160       {
00161         // ignore it
00162         return true;
00163       }
00164 
00166     }
00167 
00168     else if ( reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT )
00169     {
00170       // xpath: /repomd/data
00171       if ( reader_r->name() == "data" )
00172       {
00173         if (_callback)
00174           _callback( _location, _type );
00175 
00176         return true;
00177       }
00178     }
00179 
00180     return true;
00181   }
00182 
00183 
00185   //
00186   //  CLASS NAME : RepomdFileReader
00187   //
00189 
00190   RepomdFileReader::RepomdFileReader(
00191       const Pathname & repomd_file, const ProcessResource & callback)
00192     :
00193       _pimpl(new Impl(repomd_file, callback))
00194   {}
00195 
00196   RepomdFileReader::~RepomdFileReader()
00197   {}
00198 
00199 
00200     } // ns yum
00201   } // ns parser
00202 } // ns zypp
00203 
00204 // vim: set ts=2 sts=2 sw=2 et ai:

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