1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/parser/yum/PatchesFileReader.cc
10 * Implementation of patches.xml file reader.
12 #include "zypp/base/String.h"
13 #include "zypp/base/Logger.h"
15 #include "zypp/Date.h"
16 #include "zypp/CheckSum.h"
17 #include "zypp/OnMediaLocation.h"
19 #include "zypp/parser/xml/Reader.h"
20 #include "zypp/parser/yum/PatchesFileReader.h"
24 using namespace zypp::xml;
46 ///////////////////////////////////////////////////////////////////////
48 // CLASS NAME : PatchesFileReader::Impl
50 class PatchesFileReader::Impl : private base::NonCopyable
56 Impl(const Pathname &patches_file, const ProcessResource & callback);
59 * Callback provided to the XML parser. Don't use it.
61 bool consumeNode( Reader & reader_r );
64 OnMediaLocation _location;
67 ProcessResource _callback;
69 std::string _checksum_type;
72 ///////////////////////////////////////////////////////////////////////
75 PatchesFileReader::Impl::Impl(const Pathname & patches_file,
76 const ProcessResource & callback)
77 : _tag(tag_NONE), _callback(callback)
79 Reader reader( patches_file );
80 MIL << "Reading " << patches_file << endl;
81 reader.foreachNode(bind( &PatchesFileReader::Impl::consumeNode, this, _1 ));
84 // --------------------------------------------------------------------------
86 bool PatchesFileReader::Impl::consumeNode( Reader & reader_r )
88 //MIL << reader_r->name() << endl;
89 std::string data_type;
90 if ( reader_r->nodeType() == XML_READER_TYPE_ELEMENT )
92 if ( reader_r->name() == "patches" )
97 if ( reader_r->name() == "patch" )
100 _id = reader_r->getAttribute("id").asString();
103 if ( reader_r->name() == "location" )
106 _location.filename( reader_r->getAttribute("href").asString() );
109 if ( reader_r->name() == "checksum" )
112 string checksum_type = reader_r->getAttribute("type").asString() ;
113 string checksum_vaue = reader_r.nodeText().asString();
114 _location.checksum( CheckSum( checksum_type, checksum_vaue ) );
117 if ( reader_r->name() == "timestamp" )
123 else if ( reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT )
125 //MIL << "end element" << endl;
126 if ( reader_r->name() == "patch" )
127 _callback( _location, _id );
134 ///////////////////////////////////////////////////////////////////
136 // CLASS NAME : PatchesFileReader
138 ///////////////////////////////////////////////////////////////////
140 PatchesFileReader::PatchesFileReader(const Pathname & patches_file,
141 const ProcessResource & callback)
142 : _pimpl(new Impl(patches_file, callback))
145 PatchesFileReader::~PatchesFileReader()
153 // vim: set ts=2 sts=2 sw=2 et ai: