00001
00002
00003
00004
00005
00006
00007
00008
00013 #include <istream>
00014 #include <string>
00015 #include "zypp/parser/xml_parser_assert.h"
00016 #include <libxml/xmlreader.h>
00017 #include <libxml/tree.h>
00018 #include "zypp/parser/xmlstore/XMLProductParser.h"
00019 #include "zypp/parser/xmlstore/XMLResObjectParser.h"
00020 #include "zypp/parser/LibXMLHelper.h"
00021 #include "zypp/base/Logger.h"
00022 #include "zypp/parser/xmlstore/schemanames.h"
00023
00024 using namespace std;
00025 namespace zypp {
00026 namespace parser {
00027 namespace xmlstore {
00028
00029 XMLProductParser::~XMLProductParser()
00030 { }
00031
00032 XMLProductParser::XMLProductParser(istream &is, const string& baseUrl)
00033 : XMLNodeIterator<XMLProductData_Ptr>(is, baseUrl ,PRODUCTSCHEMA)
00034 {
00035 fetchNext();
00036 }
00037
00038 XMLProductParser::XMLProductParser()
00039 { }
00040
00041 XMLProductParser::XMLProductParser(XMLProductData_Ptr& entry)
00042 : XMLNodeIterator<XMLProductData_Ptr>(entry)
00043 { }
00044
00045
00046
00047 bool
00048 XMLProductParser::isInterested(const xmlNodePtr nodePtr)
00049 {
00050 return _helper.isElement(nodePtr) && _helper.name(nodePtr) == "product";
00051 }
00052
00053
00054 XMLProductData_Ptr
00055 XMLProductParser::process(const xmlTextReaderPtr reader)
00056 {
00057 xml_assert(reader);
00058 XMLProductData_Ptr productPtr = new XMLProductData;
00059 xmlNodePtr dataNode = xmlTextReaderExpand(reader);
00060 xml_assert(dataNode);
00061 productPtr->type = _helper.attribute(dataNode,"type");
00062
00063 parseResObjectCommonData( productPtr, dataNode);
00064 parseDependencies( productPtr, dataNode);
00065
00066 for (xmlNodePtr child = dataNode->children; child && child != dataNode; child = child->next)
00067 {
00068 if (_helper.isElement(child))
00069 {
00070 string name = _helper.name(child);
00071 if (name == "vendor") {
00072 productPtr->vendor = _helper.content(child);
00073 }
00074 else if (name == "release-notes-url") {
00075 productPtr->releasenotesurl = _helper.content(child);
00076 }
00077 else if (name == "shortname") {
00078 productPtr->short_name.setText(_helper.content(child), Locale(_helper.attribute(child,"lang")));
00079 }
00080 else if (name == "product-flags") {
00081 parseProductFlags( productPtr, child);
00082 }
00083 else if (name == "update-urls") {
00084 parseUpdateUrls( productPtr, child);
00085 }
00086 }
00087 }
00088 return productPtr;
00089 }
00090
00091 void
00092 XMLProductParser::parseProductFlags( XMLProductData_Ptr productPtr, xmlNodePtr node)
00093 {
00094 for (xmlNodePtr child = node->children; child && child != node; child = child->next)
00095 {
00096 if (_helper.isElement(child))
00097 {
00098 string name = _helper.name(child);
00099 if (name == "product-flag")
00100 {
00101 productPtr->flags.push_back(_helper.content(child));
00102 }
00103 }
00104 }
00105 }
00106
00107 void
00108 XMLProductParser::parseUpdateUrls( XMLProductData_Ptr productPtr, xmlNodePtr node)
00109 {
00110 for (xmlNodePtr child = node->children; child && child != node; child = child->next)
00111 {
00112 if (_helper.isElement(child))
00113 {
00114 string name = _helper.name(child);
00115 if (name == "update-url")
00116 {
00117 productPtr->update_urls.push_back(_helper.content(child));
00118 }
00119 }
00120 }
00121 }
00122 }
00123 }
00124 }