libzypp  11.13.5
WebpinResultFileReader.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #include <iostream>
13 #include "zypp/base/Logger.h"
14 #include "zypp/base/String.h"
15 #include "zypp/base/InputStream.h"
17 
18 #include "zypp/parser/xml/Reader.h"
20 #include "zypp/ws/WebpinResult.h"
21 
22 using std::endl;
23 using namespace zypp::xml;
24 using namespace zypp::ws;
25 
26 namespace zypp
27 {
28 namespace parser
29 {
30 namespace ws
31 {
32 
34 {
35 public:
36  Impl( const Pathname &result_file,
37  const ProcessWebpinResult &callback );
38 
42  bool consumeNode( Reader & reader_r );
43 private:
44  shared_ptr<WebpinResult> _result;
46 };
47 
48 bool WebpinResultFileReader::Impl::consumeNode(Reader & reader_r)
49 {
50  if ( reader_r->nodeType() == XML_READER_TYPE_ELEMENT )
51  {
52  // xpath: /packages
53  if ( reader_r->name() == "packages" )
54  {
55  return true;
56  }
57 
58  // xpath: /packages/package (+)
59  if ( reader_r->name() == "package" )
60  { _result.reset( new WebpinResult() ); }
61 
62  // xpath: /packages/name
63  if ( reader_r->name() == "name" )
64  { _result->setName(reader_r.nodeText().asString());}
65 
66  // xpath: /packages/version
67  if ( reader_r->name() == "version" )
68  { _result->setEdition(Edition(reader_r.nodeText().asString())); }
69 
70  // xpath: /packages/summary
71  if ( reader_r->name() == "summary" )
72  { _result->setSummary(reader_r.nodeText().asString()); }
73 
74  // xpath: /packages/repoURL
75  if ( reader_r->name() == "repoURL" )
76  { _result->setRepositoryUrl(Url(reader_r.nodeText().asString())); }
77 
78  // xpath: /packages/checksum
79  if ( reader_r->name() == "checksum" )
80  { _result->setChecksum(CheckSum::sha1(reader_r.nodeText().asString())); }
81  // xpath: /packages/distro
82  if ( reader_r->name() == "distro" )
83  { _result->setDistribution(reader_r.nodeText().asString());}
84 
85  return true;
86  }
87  else if ( reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT )
88  {
89  // xpath: /packages/package (+)
90  if ( reader_r->name() == "package" )
91  {
92  _callback(*_result);
93  }
94  }
95 
96  return true;
97 }
98 
99 
100 WebpinResultFileReader::Impl::Impl( const Pathname &result_file,
101  const ProcessWebpinResult &callback )
102  : _callback(callback)
103 {
104  Reader reader( result_file );
105  MIL << "Reading " << result_file << endl;
106  reader.foreachNode( bind( &WebpinResultFileReader::Impl::consumeNode, this, _1 ) );
107 }
108 
109 
111  const ProcessWebpinResult & callback )
112  : _pimpl(new WebpinResultFileReader::Impl(result_file, callback))
113 {
114 }
115 
117 {}
118 
119 std::ostream & operator<<( std::ostream & str, const WebpinResultFileReader & obj )
120 {
121  return str;
122 }
123 
124 
125 } // namespace ws
126 } // namespace parser
127 } // namespace zypp
128