1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/parser/yum/OtherFileReader.cc
10 * Implementation of other.xml.gz file reader.
12 #include "zypp/base/Logger.h"
13 #include "zypp/parser/xml/Reader.h"
14 #include "zypp/data/ResolvableData.h"
15 #include "zypp/Changelog.h"
16 #include "zypp/base/UserRequestException.h"
18 #include "zypp/parser/yum/OtherFileReader.h"
19 #include "zypp/parser/yum/FileReaderBaseImpl.h"
21 #undef ZYPP_BASE_LOGGER_LOGGROUP
22 #define ZYPP_BASE_LOGGER_LOGGROUP "parser::yum"
25 using namespace zypp::xml;
35 ///////////////////////////////////////////////////////////////////////
37 // CLASS NAME : OtherFileReader::Impl
39 class OtherFileReader::Impl : public BaseImpl
43 const Pathname & other_file,
44 const ProcessPackage & callback,
45 const ProgressData::ReceiverFnc & progress);
50 * Callback provided to the XML parser.
52 bool consumeNode(xml::Reader & reader_r);
55 * Creates a new \ref data::Resolvable_Ptr, swaps its contents with
56 * \ref _resolvable and returns it. Used to hand-out the data object to its consumer
57 * (a \ref ProcessPackage function) after it has been read.
59 data::Resolvable_Ptr handoutResolvable();
64 * Pointer to the \ref zypp::data::Resolvable object for storing the NVRA
67 zypp::data::Resolvable_Ptr _resolvable;
70 * Changelog of \ref _resolvable.
75 * Callback for processing package metadata passed in through constructor.
77 ProcessPackage _callback;
80 * Progress reporting object.
84 ///////////////////////////////////////////////////////////////////////
86 OtherFileReader::Impl::Impl(
87 const Pathname & other_file,
88 const ProcessPackage & callback,
89 const ProgressData::ReceiverFnc & progress)
93 _ticks.sendTo(progress);
94 _ticks.name("other.xml.gz");
96 Reader reader(other_file);
97 MIL << "Reading " << other_file << endl;
98 reader.foreachNode(bind(&OtherFileReader::Impl::consumeNode, this, _1));
101 // --------------------------------------------------------------------------
104 * xpath and multiplicity of processed nodes are included in the code
107 * // xpath: <xpath> (?|*|+)
109 * if multiplicity is ommited, then the node has multiplicity 'one'.
112 // --------------------------------------------------------------------------
114 bool OtherFileReader::Impl::consumeNode(Reader & reader_r)
116 if (reader_r->nodeType() == XML_READER_TYPE_ELEMENT)
119 if (reader_r->name() == "otherdata")
121 unsigned total_packages;
122 zypp::str::strtonum(reader_r->getAttribute("packages").asString(), total_packages);
123 _ticks.range(total_packages);
128 // xpath: /otherdata/package (+)
129 if (reader_r->name() == "package")
131 _resolvable = new data::Resolvable;
134 _resolvable->name = reader_r->getAttribute("name").asString();
135 _resolvable->arch = Arch( reader_r->getAttribute("arch").asString() );
140 // xpath: /otherdata/package/version
141 if (reader_r->name() == "version")
143 editionStringFromAttrs( reader_r, _resolvable->edition );
147 // xpath: /otherdata/package/changelog (*)
148 if (reader_r->name() == "changelog")
150 ChangelogEntry entry(
151 Date(reader_r->getAttribute("date").asString()),
152 reader_r->getAttribute("author").asString(),
153 reader_r.nodeText().asString());
154 _changelog.push_back(entry);
159 else if (reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT)
161 // xpath: /otherdata/package
162 if (reader_r->name() == "package")
164 if (_callback && !_changelog.empty())
165 _callback(handoutResolvable(), _changelog);
168 ZYPP_THROW(AbortRequestException());
174 if (reader_r->name() == "otherdata")
184 // --------------------------------------------------------------------------
186 data::Resolvable_Ptr OtherFileReader::Impl::handoutResolvable()
188 data::Resolvable_Ptr ret;
189 ret.swap(_resolvable);
194 ///////////////////////////////////////////////////////////////////
196 // CLASS NAME : OtherFileReader
198 ///////////////////////////////////////////////////////////////////
200 OtherFileReader::OtherFileReader(
201 const Pathname & other_file,
202 const ProcessPackage & callback,
203 const ProgressData::ReceiverFnc & progress)
205 _pimpl(new Impl(other_file, callback, progress))
208 OtherFileReader::~OtherFileReader()
216 // vim: set ts=2 sts=2 sw=2 et ai: