00001
00002
00003
00004
00005
00006
00007
00008
00013 #include <zypp/parser/xmlstore/XMLResObjectParser.h>
00014 #include <istream>
00015 #include <string>
00016 #include "zypp/parser/xml_parser_assert.h"
00017 #include <libxml/xmlstring.h>
00018 #include <libxml/xmlreader.h>
00019 #include <libxml/tree.h>
00020 #include <zypp/parser/LibXMLHelper.h>
00021 #include <zypp/base/Logger.h>
00022 #include <zypp/base/String.h>
00023 #include <zypp/parser/yum/schemanames.h>
00024
00025 using namespace std;
00026 namespace zypp
00027 {
00028 namespace parser
00029 {
00030 namespace xmlstore
00031 {
00032
00033
00034 XMLResObjectParser::XMLResObjectParser()
00035 { }
00036
00037 XMLResObjectParser::~XMLResObjectParser()
00038 {
00039 }
00040
00041
00042 void
00043 XMLResObjectParser::parseResObjectCommonData( XMLResObjectData_Ptr dataPtr, xmlNodePtr node)
00044 {
00045 xml_assert(node);
00046
00047 for (xmlNodePtr child = node->children; child != 0; child = child ->next)
00048 {
00049 if (_helper.isElement(child))
00050 {
00051 string name = _helper.name(child);
00052
00053 if (name == "name") {
00054 dataPtr->name = _helper.content(child);
00055 }
00056 else if (name == "arch") {
00057 dataPtr->arch = _helper.content(child);
00058 }
00059 else if (name == "version") {
00060 dataPtr->epoch = _helper.attribute(child,"epoch");
00061 dataPtr->ver = _helper.attribute(child,"ver");
00062 dataPtr->rel = _helper.attribute(child,"rel");
00063 }
00064 else if (name == "summary") {
00065 dataPtr->summary.setText(_helper.content(child), Locale(_helper.attribute(child,"lang")));
00066 }
00067 else if (name == "description") {
00068 dataPtr->description.setText(_helper.content(child), Locale(_helper.attribute(child,"lang")));
00069 }
00070 else if (name == "install-notify") {
00071 dataPtr->install_notify.setText(_helper.content(child), Locale(_helper.attribute(child,"lang")));
00072 }
00073 else if (name == "delete-notify") {
00074 dataPtr->delete_notify.setText(_helper.content(child), Locale(_helper.attribute(child,"lang")));
00075 }
00076 else if (name == "license-to-confirm") {
00077 dataPtr->license_to_confirm.setText(_helper.content(child), Locale(_helper.attribute(child,"lang")));
00078 }
00079 else if (name == "vendor") {
00080 dataPtr->vendor = _helper.content(child);
00081 }
00082 else if (name == "size") {
00083 dataPtr->size = str::strtonum<int>(_helper.content(child));
00084 }
00085 else if (name == "archive-size") {
00086 dataPtr->archive_size = str::strtonum<int>(_helper.content(child));
00087 }
00088 else if (name == "install-only") {
00089 dataPtr->install_only = (_helper.content(child) == "true") ? true : false;
00090 }
00091 else if (name == "build-time") {
00092 dataPtr->build_time = str::strtonum<int>(_helper.content(child));
00093 }
00094 else if (name == "install-time") {
00095 dataPtr->install_time = str::strtonum<int>(_helper.content(child));
00096 }
00097 }
00098 }
00099 }
00100
00101 void
00102 XMLResObjectParser::parseDependencies( XMLResObjectData_Ptr dataPtr, xmlNodePtr node)
00103 {
00104 xml_assert(node);
00105
00106 for (xmlNodePtr child = node->children; child != 0; child = child ->next)
00107 {
00108 if (_helper.isElement(child))
00109 {
00110 string name = _helper.name(child);
00111 if (name == "provides") {
00112 parseDependencyEntries(& dataPtr->provides, child);
00113 }
00114 else if (name == "conflicts") {
00115 parseDependencyEntries(& dataPtr->conflicts, child);
00116 }
00117 else if (name == "obsoletes") {
00118 parseDependencyEntries(& dataPtr->obsoletes, child);
00119 }
00120 else if (name == "prerequires") {
00121 parseDependencyEntries(& dataPtr->prerequires, child);
00122 }
00123 else if (name == "requires") {
00124 parseDependencyEntries(& dataPtr->requires, child);
00125 }
00126 else if (name == "recommends") {
00127 parseDependencyEntries(& dataPtr->recommends, child);
00128 }
00129 else if (name == "suggests") {
00130 parseDependencyEntries(& dataPtr->suggests, child);
00131 }
00132 else if (name == "supplements") {
00133 parseDependencyEntries(& dataPtr->supplements, child);
00134 }
00135 else if (name == "enhances") {
00136 parseDependencyEntries(& dataPtr->enhances, child);
00137 }
00138 else if (name == "freshens") {
00139 parseDependencyEntries(& dataPtr->freshens, child);
00140 }
00141 }
00142 }
00143
00144 }
00145
00146 void
00147 XMLResObjectParser::parseDependencyEntries(list<XMLDependency> *depList,
00148 xmlNodePtr depNode)
00149 {
00150 xml_assert(depNode);
00151
00152 for (xmlNodePtr child = depNode->children; child != 0; child = child ->next)
00153 {
00154 if (_helper.isElement(child))
00155 {
00156 string name = _helper.name(child);
00157
00158 if ( name == "capability" )
00159 {
00160 depList->push_back
00161 (XMLDependency(_helper.attribute(child,"kind"),
00162 _helper.content(child)));
00163 }
00164 else
00165 {
00166 WAR << "XML dependency contains the unknown element <" << name << "> "
00167 << _helper.positionInfo(child) << ", skipping" << endl;
00168 }
00169 }
00170 }
00171 }
00172
00173 }
00174 }
00175 }