1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/parser/yum/RepoindexFileReader.cc
10 * Implementation of repoindex.xml file reader.
14 #include "zypp/base/String.h"
15 #include "zypp/base/Logger.h"
17 #include "zypp/Pathname.h"
18 #include "zypp/parser/xml/Reader.h"
20 #include "zypp/parser/RepoindexFileReader.h"
22 #undef ZYPP_BASE_LOGGER_LOGGROUP
23 #define ZYPP_BASE_LOGGER_LOGGROUP "parser"
26 using namespace zypp::xml;
34 ///////////////////////////////////////////////////////////////////////
36 // CLASS NAME : RepoindexFileReader::Impl
38 class RepoindexFileReader::Impl : private base::NonCopyable
44 * \see RepoindexFileReader::RepoindexFileReader(Pathname,ProcessResource)
46 Impl(const Pathname &repoindex_file, const ProcessResource & callback);
49 * Callback provided to the XML parser.
51 bool consumeNode( Reader & reader_r );
55 /** Function for processing collected data. Passed-in through constructor. */
56 ProcessResource _callback;
58 ///////////////////////////////////////////////////////////////////////
60 RepoindexFileReader::Impl::Impl(
61 const Pathname &repoindex_file, const ProcessResource & callback)
64 Reader reader( repoindex_file );
65 MIL << "Reading " << repoindex_file << endl;
66 reader.foreachNode( bind( &RepoindexFileReader::Impl::consumeNode, this, _1 ) );
69 // --------------------------------------------------------------------------
72 * xpath and multiplicity of processed nodes are included in the code
75 * // xpath: <xpath> (?|*|+)
77 * if multiplicity is ommited, then the node has multiplicity 'one'.
80 // --------------------------------------------------------------------------
82 bool RepoindexFileReader::Impl::consumeNode( Reader & reader_r )
84 if ( reader_r->nodeType() == XML_READER_TYPE_ELEMENT )
87 if ( reader_r->name() == "repoindex" )
92 // xpath: /repoindex/data (+)
93 if ( reader_r->name() == "repo" )
96 info.setPath(Pathname(string("/repo/")+reader_r->getAttribute("path").asString()));
97 info.setAlias(reader_r->getAttribute("alias").asString());
98 info.setType(repo::RepoType::RPMMD_e); //TODO hardwired rpmmd???
99 XmlString s = reader_r->getAttribute("name");
100 if (s.get()) //name setted so also set it
101 info.setName(s.asString());
112 ///////////////////////////////////////////////////////////////////
114 // CLASS NAME : RepoindexFileReader
116 ///////////////////////////////////////////////////////////////////
118 RepoindexFileReader::RepoindexFileReader(
119 const Pathname & repoindex_file, const ProcessResource & callback)
121 _pimpl(new Impl(repoindex_file, callback))
124 RepoindexFileReader::~RepoindexFileReader()
131 // vim: set ts=2 sts=2 sw=2 et ai: