00001
00002
00003
00004
00005
00006
00007
00008
00013 #include <istream>
00014 #include <string>
00015 #include "zypp/ZYppFactory.h"
00016 #include "zypp/ZYpp.h"
00017 #include "zypp/parser/xml_parser_assert.h"
00018 #include <libxml/xmlreader.h>
00019 #include <libxml/tree.h>
00020 #include "zypp/parser/yum/YUMProductParser.h"
00021 #include "zypp/parser/yum/YUMPrimaryParser.h"
00022 #include "zypp/parser/LibXMLHelper.h"
00023 #include "zypp/base/Logger.h"
00024 #include "zypp/parser/yum/schemanames.h"
00025
00026 using namespace std;
00027 namespace zypp
00028 {
00029 namespace parser
00030 {
00031 namespace yum
00032 {
00033
00034 YUMProductParser::~YUMProductParser()
00035 { }
00036
00037 YUMProductParser::YUMProductParser(std::istream &is, const std::string& baseUrl, parser::ParserProgress::Ptr progress )
00038 : XMLNodeIterator<YUMProductData_Ptr>(is, baseUrl,PRODUCTSCHEMA, progress)
00039 , _zypp_architecture( getZYpp()->architecture() )
00040 {
00041 fetchNext();
00042 }
00043
00044 YUMProductParser::YUMProductParser()
00045 : _zypp_architecture( getZYpp()->architecture() )
00046 { }
00047
00048 YUMProductParser::YUMProductParser(YUMProductData_Ptr& entry)
00049 : XMLNodeIterator<YUMProductData_Ptr>(entry)
00050 , _zypp_architecture( getZYpp()->architecture() )
00051 { }
00052
00053
00054
00055 bool
00056 YUMProductParser::isInterested(const xmlNodePtr nodePtr)
00057 {
00058 return _helper.isElement(nodePtr) && _helper.name(nodePtr) == "product";
00059 }
00060
00061
00062 YUMProductData_Ptr
00063 YUMProductParser::process(const xmlTextReaderPtr reader)
00064 {
00065 xml_assert(reader);
00066 YUMProductData_Ptr productPtr = new YUMProductData;
00067 xmlNodePtr dataNode = xmlTextReaderExpand(reader);
00068 xml_assert(dataNode);
00069 productPtr->type = _helper.attribute(dataNode,"type");
00070
00071
00072 YUMPrimaryParser prim;
00073
00074 for (xmlNodePtr child = dataNode->children;
00075 child && child != dataNode;
00076 child = child->next)
00077 {
00078 if (_helper.isElement(child))
00079 {
00080 string name = _helper.name(child);
00081 if (name == "name")
00082 {
00083 productPtr->name = _helper.content(child);
00084 }
00085 else if (name == "arch")
00086 {
00087 productPtr->arch = _helper.content(child);
00088 try
00089 {
00090 if (!Arch(productPtr->arch).compatibleWith( _zypp_architecture ))
00091 {
00092 productPtr = NULL;
00093 break;
00094 }
00095 }
00096 catch ( const Exception & excpt_r )
00097 {
00098 ZYPP_CAUGHT( excpt_r );
00099 DBG << "Skipping malformed " << productPtr->arch << endl;
00100 productPtr = NULL;
00101 break;
00102 }
00103 }
00104 else if (name == "vendor")
00105 {
00106 productPtr->vendor = _helper.content(child);
00107 }
00108 else if (name == "release-notes-url")
00109 {
00110 productPtr->releasenotesurl = _helper.content(child);
00111 }
00112 else if (name == "displayname")
00113 {
00114 productPtr->summary.setText(_helper.content(child), Locale(_helper.attribute(child,"lang")));
00115 }
00116 else if (name == "shortname")
00117 {
00118 productPtr->short_name.setText(_helper.content(child), Locale(_helper.attribute(child,"lang")));
00119 }
00120 else if (name == "description")
00121 {
00122 productPtr->description.setText(_helper.content(child), Locale(_helper.attribute(child,"lang")));
00123 }
00124 else if (name == "version")
00125 {
00126 productPtr->epoch = _helper.attribute(child,"epoch");
00127 productPtr->ver = _helper.attribute(child,"ver");
00128 productPtr->rel = _helper.attribute(child,"rel");
00129 }
00130 else if (name == "distribution-name")
00131 {
00132 productPtr->distribution_name = _helper.content(child);
00133 }
00134 else if (name == "distribution-edition")
00135 {
00136 productPtr->distribution_edition = _helper.content(child);
00137 }
00138 else if (name == "provides")
00139 {
00140 prim.parseDependencyEntries(& productPtr->provides, child);
00141 }
00142 else if (name == "conflicts")
00143 {
00144 prim.parseDependencyEntries(& productPtr->conflicts, child);
00145 }
00146 else if (name == "obsoletes")
00147 {
00148 prim.parseDependencyEntries(& productPtr->obsoletes, child);
00149 }
00150 else if (name == "prerequires")
00151 {
00152 prim.parseDependencyEntries(& productPtr->prerequires, child);
00153 }
00154 else if (name == "requires")
00155 {
00156 prim.parseDependencyEntries(& productPtr->requires, child);
00157 }
00158 else if (name == "recommends")
00159 {
00160 prim.parseDependencyEntries(& productPtr->recommends, child);
00161 }
00162 else if (name == "suggests")
00163 {
00164 prim.parseDependencyEntries(& productPtr->suggests, child);
00165 }
00166 else if (name == "supplements")
00167 {
00168 prim.parseDependencyEntries(& productPtr->supplements, child);
00169 }
00170 else if (name == "enhances")
00171 {
00172 prim.parseDependencyEntries(& productPtr->enhances, child);
00173 }
00174 else if (name == "freshens")
00175 {
00176 prim.parseDependencyEntries(& productPtr->freshens, child);
00177 }
00178 else
00179 {
00180 WAR << "YUM <data> contains the unknown element <" << name << "> "
00181 << _helper.positionInfo(child) << ", skipping" << endl;
00182 }
00183 }
00184 }
00185 return productPtr;
00186 }
00187
00188
00189
00190 }
00191 }
00192 }