PatchesFileReader.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/OnMediaLocation.h"
00018 
00019 #include "zypp/parser/xml/Reader.h"
00020 #include "zypp/parser/yum/PatchesFileReader.h"
00021 
00022 
00023 using namespace std;
00024 using namespace zypp::xml;
00025 
00026 namespace zypp
00027 {
00028   namespace parser
00029   {
00030     namespace yum
00031     {
00032 
00033 
00034   enum Tag
00035   {
00036     tag_NONE,
00037     tag_Patches,
00038     tag_Patch,
00039     tag_Location,
00040     tag_CheckSum,
00041     tag_Timestamp,
00042     tag_OpenCheckSum
00043   };
00044 
00045 
00047   //
00048   //  CLASS NAME : PatchesFileReader::Impl
00049   //
00050   class PatchesFileReader::Impl : private base::NonCopyable
00051   {
00052   public:
00056     Impl(const Pathname &patches_file, const ProcessResource & callback);
00057 
00061     bool consumeNode( Reader & reader_r );
00062 
00063   private:
00064     OnMediaLocation _location;
00065     Tag _tag;
00066     std::string _id;
00067     ProcessResource _callback;
00068     CheckSum _checksum;
00069     std::string _checksum_type;
00070     Date _timestamp;
00071   };
00073 
00074 
00075   PatchesFileReader::Impl::Impl(const Pathname & patches_file,
00076                                 const ProcessResource & callback)
00077     : _tag(tag_NONE), _callback(callback)
00078   {
00079     Reader reader( patches_file );
00080     MIL << "Reading " << patches_file << endl;
00081     reader.foreachNode(bind( &PatchesFileReader::Impl::consumeNode, this, _1 ));
00082   }
00083 
00084   // --------------------------------------------------------------------------
00085 
00086   bool PatchesFileReader::Impl::consumeNode( Reader & reader_r )
00087   {
00088     //MIL << reader_r->name() << endl;
00089     std::string data_type;
00090     if ( reader_r->nodeType() == XML_READER_TYPE_ELEMENT )
00091     {
00092       if ( reader_r->name() == "patches" )
00093       {
00094         _tag = tag_Patches;
00095         return true;
00096       }
00097       if ( reader_r->name() == "patch" )
00098       {
00099         _tag = tag_Patch;
00100         _id = reader_r->getAttribute("id").asString();
00101         return true;
00102       }
00103       if ( reader_r->name() == "location" )
00104       {
00105         _tag = tag_Location;
00106         _location.setLocation( reader_r->getAttribute("href").asString(), 1 );
00107         return true;
00108       }
00109       if ( reader_r->name() == "checksum" )
00110       {
00111         _tag = tag_CheckSum;
00112         string checksum_type = reader_r->getAttribute("type").asString() ;
00113         string checksum_vaue = reader_r.nodeText().asString();
00114         _location.setChecksum( CheckSum( checksum_type, checksum_vaue ) );
00115         return true;
00116       }
00117       if ( reader_r->name() == "timestamp" )
00118       {
00119         // ignore it
00120         return true;
00121       }
00122     }
00123     else if ( reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT )
00124     {
00125       //MIL << "end element" << endl;
00126       if ( reader_r->name() == "patch" )
00127         _callback( _location, _id );
00128       return true;
00129     }
00130     return true;
00131   }
00132 
00133 
00135   //
00136   //  CLASS NAME : PatchesFileReader
00137   //
00139 
00140   PatchesFileReader::PatchesFileReader(const Pathname & patches_file,
00141                                        const ProcessResource & callback)
00142     : _pimpl(new Impl(patches_file, callback))
00143   {}
00144 
00145   PatchesFileReader::~PatchesFileReader()
00146   {}
00147 
00148 
00149     } // ns yum
00150   } // ns parser
00151 } // ns zypp
00152 
00153 // 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