1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/parser/RepoindexFileReader.cc
10 * Implementation of repoindex.xml file reader.
14 #include "zypp/base/String.h"
15 #include "zypp/base/Logger.h"
16 #include "zypp/base/Gettext.h"
17 #include "zypp/Pathname.h"
19 #include "zypp/parser/xml/Reader.h"
20 #include "zypp/parser/ParseException.h"
22 #include "zypp/RepoInfo.h"
23 #include "zypp/Target.h"
24 #include "zypp/ZYppFactory.h"
26 #include "zypp/parser/RepoindexFileReader.h"
29 #undef ZYPP_BASE_LOGGER_LOGGROUP
30 #define ZYPP_BASE_LOGGER_LOGGROUP "parser"
33 using namespace zypp::xml;
41 ///////////////////////////////////////////////////////////////////////
43 // CLASS NAME : RepoindexFileReader::Impl
45 class RepoindexFileReader::Impl : private base::NonCopyable
51 * \see RepoindexFileReader::RepoindexFileReader(Pathname,ProcessResource)
53 Impl(const Pathname &repoindex_file, const ProcessResource & callback);
56 * Callback provided to the XML parser.
58 bool consumeNode( Reader & reader_r );
62 /** Function for processing collected data. Passed-in through constructor. */
63 ProcessResource _callback;
64 string _target_distro;
66 ///////////////////////////////////////////////////////////////////////
68 RepoindexFileReader::Impl::Impl(
69 const Pathname &repoindex_file, const ProcessResource & callback)
72 Reader reader( repoindex_file );
73 MIL << "Reading " << repoindex_file << endl;
74 reader.foreachNode( bind( &RepoindexFileReader::Impl::consumeNode, this, _1 ) );
77 // --------------------------------------------------------------------------
80 * xpath and multiplicity of processed nodes are included in the code
83 * // xpath: <xpath> (?|*|+)
85 * if multiplicity is ommited, then the node has multiplicity 'one'.
88 // --------------------------------------------------------------------------
90 bool RepoindexFileReader::Impl::consumeNode( Reader & reader_r )
92 if ( reader_r->nodeType() == XML_READER_TYPE_ELEMENT )
95 if ( reader_r->name() == "repoindex" )
100 // xpath: /repoindex/data (+)
101 if ( reader_r->name() == "repo" )
109 s = reader_r->getAttribute("url");
111 url_s = s.asString();
113 s = reader_r->getAttribute("path");
115 path_s = s.asString();
117 if (url_s.empty() && path_s.empty())
118 throw ParseException(str::form(_("One or both of '%s' or '%s' attributes is required."), "url", "path"));
119 //! \todo FIXME this hardcodes the "/repo/" fragment - should not be if we want it to be usable by others!
120 else if (url_s.empty())
121 info.setPath(Pathname(string("/repo/") + path_s));
122 else if (path_s.empty())
123 info.setBaseUrl(Url(url_s));
125 info.setBaseUrl(Url(url_s + "/repo/" + path_s));
128 info.setAlias(reader_r->getAttribute("alias").asString());
131 s = reader_r->getAttribute("type");
133 info.setType(repo::RepoType(s.asString()));
136 s = reader_r->getAttribute("name");
138 info.setName(s.asString());
140 // optional targetDistro
141 s = reader_r->getAttribute("distro_target");
143 info.setTargetDistribution(s.asString());
157 ///////////////////////////////////////////////////////////////////
159 // CLASS NAME : RepoindexFileReader
161 ///////////////////////////////////////////////////////////////////
163 RepoindexFileReader::RepoindexFileReader(
164 const Pathname & repoindex_file, const ProcessResource & callback)
166 _pimpl(new Impl(repoindex_file, callback))
169 RepoindexFileReader::~RepoindexFileReader()
176 // vim: set ts=2 sts=2 sw=2 et ai: