1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/parser/yum/PatchesFileReader.cc
10 * Implementation of patches.xml file reader.
14 #include "zypp/base/String.h"
15 #include "zypp/base/Logger.h"
17 #include "zypp/Date.h"
18 #include "zypp/CheckSum.h"
19 #include "zypp/OnMediaLocation.h"
21 #include "zypp/parser/xml/Reader.h"
22 #include "zypp/parser/yum/PatchesFileReader.h"
26 using namespace zypp::xml;
48 ///////////////////////////////////////////////////////////////////////
50 // CLASS NAME : PatchesFileReader::Impl
52 class PatchesFileReader::Impl : private base::NonCopyable
58 Impl(const Pathname &patches_file, const ProcessResource & callback);
61 * Callback provided to the XML parser. Don't use it.
63 bool consumeNode( Reader & reader_r );
66 OnMediaLocation _location;
69 ProcessResource _callback;
71 std::string _checksum_type;
74 ///////////////////////////////////////////////////////////////////////
77 PatchesFileReader::Impl::Impl(const Pathname & patches_file,
78 const ProcessResource & callback)
79 : _tag(tag_NONE), _callback(callback)
81 Reader reader( patches_file );
82 MIL << "Reading " << patches_file << endl;
83 reader.foreachNode(bind( &PatchesFileReader::Impl::consumeNode, this, _1 ));
86 // --------------------------------------------------------------------------
88 bool PatchesFileReader::Impl::consumeNode( Reader & reader_r )
90 //MIL << reader_r->name() << endl;
91 std::string data_type;
92 if ( reader_r->nodeType() == XML_READER_TYPE_ELEMENT )
94 if ( reader_r->name() == "patches" )
99 if ( reader_r->name() == "patch" )
102 _id = reader_r->getAttribute("id").asString();
105 if ( reader_r->name() == "location" )
108 _location.setLocation( reader_r->getAttribute("href").asString(), 1 );
111 if ( reader_r->name() == "checksum" )
114 string checksum_type = reader_r->getAttribute("type").asString() ;
115 string checksum_vaue = reader_r.nodeText().asString();
116 _location.setChecksum( CheckSum( checksum_type, checksum_vaue ) );
119 if ( reader_r->name() == "timestamp" )
125 else if ( reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT )
127 //MIL << "end element" << endl;
128 if ( reader_r->name() == "patch" )
129 _callback( _location, _id );
136 ///////////////////////////////////////////////////////////////////
138 // CLASS NAME : PatchesFileReader
140 ///////////////////////////////////////////////////////////////////
142 PatchesFileReader::PatchesFileReader(const Pathname & patches_file,
143 const ProcessResource & callback)
144 : _pimpl(new Impl(patches_file, callback))
147 PatchesFileReader::~PatchesFileReader()
155 // vim: set ts=2 sts=2 sw=2 et ai: