00001
00002
00003
00004
00005
00006
00007
00008
00015 #include <zypp/parser/yum/YUMOtherParser.h>
00016 #include <istream>
00017 #include <string>
00018 #include "zypp/parser/xml_parser_assert.h"
00019 #include <libxml/xmlstring.h>
00020 #include <libxml/xmlreader.h>
00021 #include <libxml/tree.h>
00022 #include <zypp/parser/LibXMLHelper.h>
00023 #include <zypp/base/Logger.h>
00024 #include <zypp/parser/yum/schemanames.h>
00025 #include <zypp/ZYppFactory.h>
00026
00027 using namespace std;
00028 namespace zypp {
00029 namespace parser {
00030 namespace yum {
00031
00032
00033 YUMOtherParser::YUMOtherParser(istream &is, const string& baseUrl)
00034 : XMLNodeIterator<YUMOtherData_Ptr>(is, baseUrl,OTHERSCHEMA)
00035 , _zypp_architecture( getZYpp()->architecture() )
00036 {
00037 fetchNext();
00038 }
00039
00040 YUMOtherParser::YUMOtherParser()
00041 : _zypp_architecture( getZYpp()->architecture() )
00042 { }
00043
00044 YUMOtherParser::YUMOtherParser(YUMOtherData_Ptr& entry)
00045 : XMLNodeIterator<YUMOtherData_Ptr>(entry)
00046 , _zypp_architecture( getZYpp()->architecture() )
00047 { }
00048
00049
00050
00051 YUMOtherParser::~YUMOtherParser()
00052 {
00053 }
00054
00055
00056
00057
00058
00059 bool
00060 YUMOtherParser::isInterested(const xmlNodePtr nodePtr)
00061 {
00062 bool result = (_helper.isElement(nodePtr)
00063 && _helper.name(nodePtr) == "package");
00064 return result;
00065 }
00066
00067
00068
00069 YUMOtherData_Ptr
00070 YUMOtherParser::process(const xmlTextReaderPtr reader)
00071 {
00072 xml_assert(reader);
00073 YUMOtherData_Ptr dataPtr = new YUMOtherData;
00074 xmlNodePtr dataNode = xmlTextReaderExpand(reader);
00075 xml_assert(dataNode);
00076
00077 dataPtr->pkgId = _helper.attribute(dataNode,"pkgid");
00078 dataPtr->name = _helper.attribute(dataNode,"name");
00079 dataPtr->arch = _helper.attribute(dataNode,"arch");
00080
00081 try {
00082 if (!Arch(dataPtr->arch).compatibleWith( _zypp_architecture )) {
00083 return NULL;
00084 }
00085 }
00086 catch( const Exception & excpt_r ) {
00087 ZYPP_CAUGHT( excpt_r );
00088 DBG << "Skipping malformed " << dataPtr->arch << endl;
00089 return NULL;
00090 }
00091
00092 for (xmlNodePtr child = dataNode->children;
00093 child != 0;
00094 child = child->next) {
00095 if (_helper.isElement(child)) {
00096 string name = _helper.name(child);
00097 if (name == "version") {
00098 dataPtr->epoch = _helper.attribute(child,"epoch");
00099 dataPtr->ver = _helper.attribute(child,"ver");
00100 dataPtr->rel = _helper.attribute(child,"rel");
00101 }
00102 else if (name == "changelog") {
00103 #if 0
00104 dataPtr->changelog.push_back
00105 (ChangelogEntry(_helper.attribute(child,"author"),
00106 _helper.attribute(child,"date"),
00107 _helper.content(child)));
00108 #endif
00109 }
00110 else {
00111 WAR << "YUM <otherdata> contains the unknown element <" << name << "> "
00112 << _helper.positionInfo(child) << ", skipping" << endl;
00113 }
00114 }
00115 }
00116 return dataPtr;
00117 }
00118
00119 }
00120 }
00121 }