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/base/InputStream.h"
19
#include "zypp/Pathname.h"
21
#include "zypp/parser/xml/Reader.h"
22
#include "zypp/parser/ParseException.h"
24
#include "zypp/RepoInfo.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 InputStream &is, 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(const InputStream &is,
69
const ProcessResource & callback)
73
MIL << "Reading " << is.path() << 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" )
107
// enabled or disabled is controlled by the
108
// reposToEnable/Disable list, unless the
109
// enabled attribute is set
110
info.setEnabled(false);
112
// Set some defaults that are not contained in the repo information
113
info.setAutorefresh( true );
117
s = reader_r->getAttribute("url");
119
url_s = s.asString();
121
s = reader_r->getAttribute("path");
123
path_s = s.asString();
125
if (url_s.empty() && path_s.empty())
126
throw ParseException(str::form(_("One or both of '%s' or '%s' attributes is required."), "url", "path"));
127
//! \todo FIXME this hardcodes the "/repo/" fragment - should not be if we want it to be usable by others!
128
else if (url_s.empty())
129
info.setPath(Pathname(string("/repo/") + path_s));
130
else if (path_s.empty())
131
info.setBaseUrl(Url(url_s));
133
info.setBaseUrl(Url(url_s + "/repo/" + path_s));
136
s = reader_r->getAttribute("alias");
138
throw ParseException(str::form(_("Required attribute '%s' is missing."), "alias"));
139
info.setAlias(s.asString());
142
s = reader_r->getAttribute("type");
144
info.setType(repo::RepoType(s.asString()));
147
s = reader_r->getAttribute("name");
149
info.setName(s.asString());
151
// optional targetDistro
152
s = reader_r->getAttribute("distro_target");
154
info.setTargetDistribution(s.asString());
157
s = reader_r->getAttribute("priority");
159
info.setPriority(str::strtonum<unsigned>(s.asString()));
163
s = reader_r->getAttribute("enabled");
165
info.setEnabled(str::strToTrue(s.asString()));
180
///////////////////////////////////////////////////////////////////
182
// CLASS NAME : RepoindexFileReader
184
///////////////////////////////////////////////////////////////////
186
RepoindexFileReader::RepoindexFileReader(
187
const Pathname & repoindex_file, const ProcessResource & callback)
189
_pimpl(new Impl(InputStream(repoindex_file), callback))
192
RepoindexFileReader::RepoindexFileReader(
193
const InputStream &is, const ProcessResource & callback )
194
: _pimpl(new Impl(is, callback))
197
RepoindexFileReader::~RepoindexFileReader()
204
// vim: set ts=2 sts=2 sw=2 et ai: