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"
24 #include "zypp/parser/RepoindexFileReader.h"
27 #undef ZYPP_BASE_LOGGER_LOGGROUP
28 #define ZYPP_BASE_LOGGER_LOGGROUP "parser"
31 using namespace zypp::xml;
39 ///////////////////////////////////////////////////////////////////////
41 // CLASS NAME : RepoindexFileReader::Impl
43 class RepoindexFileReader::Impl : private base::NonCopyable
49 * \see RepoindexFileReader::RepoindexFileReader(Pathname,ProcessResource)
51 Impl(const Pathname &repoindex_file, const ProcessResource & callback);
54 * Callback provided to the XML parser.
56 bool consumeNode( Reader & reader_r );
60 /** Function for processing collected data. Passed-in through constructor. */
61 ProcessResource _callback;
62 string _target_distro;
64 ///////////////////////////////////////////////////////////////////////
66 RepoindexFileReader::Impl::Impl(
67 const Pathname &repoindex_file, const ProcessResource & callback)
70 Reader reader( repoindex_file );
71 MIL << "Reading " << repoindex_file << endl;
72 reader.foreachNode( bind( &RepoindexFileReader::Impl::consumeNode, this, _1 ) );
75 // --------------------------------------------------------------------------
78 * xpath and multiplicity of processed nodes are included in the code
81 * // xpath: <xpath> (?|*|+)
83 * if multiplicity is ommited, then the node has multiplicity 'one'.
86 // --------------------------------------------------------------------------
88 bool RepoindexFileReader::Impl::consumeNode( Reader & reader_r )
90 if ( reader_r->nodeType() == XML_READER_TYPE_ELEMENT )
93 if ( reader_r->name() == "repoindex" )
98 // xpath: /repoindex/data (+)
99 if ( reader_r->name() == "repo" )
107 s = reader_r->getAttribute("url");
109 url_s = s.asString();
111 s = reader_r->getAttribute("path");
113 path_s = s.asString();
115 if (url_s.empty() && path_s.empty())
116 throw ParseException(str::form(_("One or both of '%s' or '%s' attributes is required."), "url", "path"));
117 //! \todo FIXME this hardcodes the "/repo/" fragment - should not be if we want it to be usable by others!
118 else if (url_s.empty())
119 info.setPath(Pathname(string("/repo/") + path_s));
120 else if (path_s.empty())
121 info.setBaseUrl(Url(url_s));
123 info.setBaseUrl(Url(url_s + "/repo/" + path_s));
126 s = reader_r->getAttribute("alias");
128 throw ParseException(str::form(_("Required attribute '%s' is missing."), "alias"));
129 info.setAlias(s.asString());
132 s = reader_r->getAttribute("type");
134 info.setType(repo::RepoType(s.asString()));
137 s = reader_r->getAttribute("name");
139 info.setName(s.asString());
141 // optional targetDistro
142 s = reader_r->getAttribute("distro_target");
144 info.setTargetDistribution(s.asString());
148 // Set some defaults that are not contained in the repo information
149 info.setAutorefresh( true );
150 // enabled or disabled is controlled by the
151 // reposToEnable/Disable list
152 info.setEnabled(false);
164 ///////////////////////////////////////////////////////////////////
166 // CLASS NAME : RepoindexFileReader
168 ///////////////////////////////////////////////////////////////////
170 RepoindexFileReader::RepoindexFileReader(
171 const Pathname & repoindex_file, const ProcessResource & callback)
173 _pimpl(new Impl(repoindex_file, callback))
176 RepoindexFileReader::~RepoindexFileReader()
183 // vim: set ts=2 sts=2 sw=2 et ai: