libzypp
10.5.0
|
00001 /*---------------------------------------------------------------------\ 00002 | ____ _ __ __ ___ | 00003 | |__ / \ / / . \ . \ | 00004 | / / \ V /| _/ _/ | 00005 | / /__ | | | | | | | 00006 | /_____||_| |_| |_| | 00007 | | 00008 \---------------------------------------------------------------------*/ 00012 #include <iostream> 00013 #include "zypp/base/Logger.h" 00014 #include "zypp/base/String.h" 00015 #include "zypp/base/InputStream.h" 00016 #include "zypp/base/UserRequestException.h" 00017 00018 #include "zypp/parser/xml/Reader.h" 00019 #include "zypp/parser/ws/WebpinResultFileReader.h" 00020 #include "zypp/ws/WebpinResult.h" 00021 00022 using std::endl; 00023 using namespace zypp::xml; 00024 using namespace zypp::ws; 00025 00026 namespace zypp 00027 { 00028 namespace parser 00029 { 00030 namespace ws 00031 { 00032 00033 class WebpinResultFileReader::Impl 00034 { 00035 public: 00036 Impl( const Pathname &result_file, 00037 const ProcessWebpinResult &callback ); 00038 00042 bool consumeNode( Reader & reader_r ); 00043 private: 00044 shared_ptr<WebpinResult> _result; 00045 ProcessWebpinResult _callback; 00046 }; 00047 00048 bool WebpinResultFileReader::Impl::consumeNode(Reader & reader_r) 00049 { 00050 if ( reader_r->nodeType() == XML_READER_TYPE_ELEMENT ) 00051 { 00052 // xpath: /packages 00053 if ( reader_r->name() == "packages" ) 00054 { 00055 return true; 00056 } 00057 00058 // xpath: /packages/package (+) 00059 if ( reader_r->name() == "package" ) 00060 { _result.reset( new WebpinResult() ); } 00061 00062 // xpath: /packages/name 00063 if ( reader_r->name() == "name" ) 00064 { _result->setName(reader_r.nodeText().asString());} 00065 00066 // xpath: /packages/version 00067 if ( reader_r->name() == "version" ) 00068 { _result->setEdition(Edition(reader_r.nodeText().asString())); } 00069 00070 // xpath: /packages/summary 00071 if ( reader_r->name() == "summary" ) 00072 { _result->setSummary(reader_r.nodeText().asString()); } 00073 00074 // xpath: /packages/repoURL 00075 if ( reader_r->name() == "repoURL" ) 00076 { _result->setRepositoryUrl(Url(reader_r.nodeText().asString())); } 00077 00078 // xpath: /packages/checksum 00079 if ( reader_r->name() == "checksum" ) 00080 { _result->setChecksum(CheckSum::sha1(reader_r.nodeText().asString())); } 00081 // xpath: /packages/distro 00082 if ( reader_r->name() == "distro" ) 00083 { _result->setDistribution(reader_r.nodeText().asString());} 00084 00085 return true; 00086 } 00087 else if ( reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT ) 00088 { 00089 // xpath: /packages/package (+) 00090 if ( reader_r->name() == "package" ) 00091 { 00092 _callback(*_result); 00093 } 00094 } 00095 00096 return true; 00097 } 00098 00099 00100 WebpinResultFileReader::Impl::Impl( const Pathname &result_file, 00101 const ProcessWebpinResult &callback ) 00102 : _callback(callback) 00103 { 00104 Reader reader( result_file ); 00105 MIL << "Reading " << result_file << endl; 00106 reader.foreachNode( bind( &WebpinResultFileReader::Impl::consumeNode, this, _1 ) ); 00107 } 00108 00109 00110 WebpinResultFileReader::WebpinResultFileReader( const Pathname & result_file, 00111 const ProcessWebpinResult & callback ) 00112 : _pimpl(new WebpinResultFileReader::Impl(result_file, callback)) 00113 { 00114 } 00115 00116 WebpinResultFileReader::~WebpinResultFileReader() 00117 {} 00118 00119 std::ostream & operator<<( std::ostream & str, const WebpinResultFileReader & obj ) 00120 { 00121 return str; 00122 } 00123 00124 00125 } // namespace ws 00126 } // namespace parser 00127 } // namespace zypp 00128