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 == "summary") {
00081 productPtr->summary.setText(_helper.content(child), Locale(_helper.attribute(child,"lang")));
00082 }
00083 else if (name == "description") {
00084 productPtr->description.setText(_helper.content(child), Locale(_helper.attribute(child,"lang")));
00085 }
00086 else if (name == "product-flags") {
00087 parseProductFlags( productPtr, child);
00088 }
00089 else if (name == "update-urls") {
00090 parseUpdateUrls( productPtr, child);
00091 }
00092 }
00093 }
00094 return productPtr;
00095 }
00096
00097 void
00098 XMLProductParser::parseProductFlags( XMLProductData_Ptr productPtr, xmlNodePtr node)
00099 {
00100 for (xmlNodePtr child = node->children; child && child != node; child = child->next)
00101 {
00102 if (_helper.isElement(child))
00103 {
00104 string name = _helper.name(child);
00105 if (name == "product-flag")
00106 {
00107 productPtr->flags.push_back(_helper.content(child));
00108 }
00109 }
00110 }
00111 }
00112
00113 void
00114 XMLProductParser::parseUpdateUrls( XMLProductData_Ptr productPtr, xmlNodePtr node)
00115 {
00116 for (xmlNodePtr child = node->children; child && child != node; child = child->next)
00117 {
00118 if (_helper.isElement(child))
00119 {
00120 string name = _helper.name(child);
00121 if (name == "update-url")
00122 {
00123 productPtr->update_urls.push_back(_helper.content(child));
00124 }
00125 }
00126 }
00127 }
00128 }
00129 }
00130 }