added parser for product data
authorJiri Srain <jsrain@suse.cz>
Mon, 28 Nov 2005 11:24:27 +0000 (11:24 +0000)
committerJiri Srain <jsrain@suse.cz>
Mon, 28 Nov 2005 11:24:27 +0000 (11:24 +0000)
zypp/parser/yum/Makefile.am
zypp/parser/yum/YUMParser.h
zypp/parser/yum/YUMParserData.cc
zypp/parser/yum/YUMParserData.h
zypp/parser/yum/YUMPatchParser.cc
zypp/parser/yum/YUMPrimaryParser.h
zypp/parser/yum/YUMProductParser.cc [new file with mode: 0644]
zypp/parser/yum/YUMProductParser.h [new file with mode: 0644]
zypp/parser/yum/schema/product.rnc
zypp/parser/yum/schema/product.rng
zypp/parser/yum/schemanames.h

index dd2d25a..d2eef82 100644 (file)
@@ -15,6 +15,7 @@ include_HEADERS = \
        YUMGroupParser.h        \
        YUMParserData.h         \
        YUMPatchParser.h        \
+       YUMProductParser.h      \
        YUMRepomdParser.h       \
        schemanames.h
 
@@ -30,7 +31,8 @@ lib@PACKAGE@_parser_yum_la_SOURCES = \
        YUMGroupParser.cc       \
        YUMPatchParser.cc       \
        YUMOtherParser.cc       \
-       YUMPrimaryParser.cc
+       YUMPrimaryParser.cc     \
+       YUMProductParser.cc
 
 
 ## ##################################################
index 097dcf1..d7c0c6f 100644 (file)
 #ifndef YUMParser_h
 #define YUMParser_h
 
-#include <zypp/parser/yum/YUMParserData.h>
-#include <zypp/parser/yum/YUMRepomdParser.h>
-#include <zypp/parser/yum/YUMPrimaryParser.h>
-#include <zypp/parser/yum/YUMGroupParser.h>
-#include <zypp/parser/yum/YUMFileListParser.h>
-#include <zypp/parser/yum/YUMOtherParser.h>
-#include <zypp/parser/yum/YUMPatchParser.h>
+#include "zypp/parser/yum/YUMParserData.h"
+#include "zypp/parser/yum/YUMRepomdParser.h"
+#include "zypp/parser/yum/YUMPrimaryParser.h"
+#include "zypp/parser/yum/YUMGroupParser.h"
+#include "zypp/parser/yum/YUMFileListParser.h"
+#include "zypp/parser/yum/YUMOtherParser.h"
+#include "zypp/parser/yum/YUMPatchParser.h"
+#include "zypp/parser/yum/YUMProductParser.h"
 
 #endif
index a07c677..0d8dd30 100644 (file)
@@ -121,6 +121,7 @@ namespace zypp {
       IMPL_PTR_TYPE(YUMFileListData);
       IMPL_PTR_TYPE(YUMOtherData);
       IMPL_PTR_TYPE(YUMPatchData);
+      IMPL_PTR_TYPE(YUMProductData);
       IMPL_PTR_TYPE(YUMPatchPackage);
       IMPL_PTR_TYPE(YUMPatchScript);
       IMPL_PTR_TYPE(YUMPatchMessage);
@@ -369,6 +370,26 @@ ostream& operator<<(ostream &out, const YUMPatchData& data)
   return out;
 }
 
+ostream& operator<<(ostream &out, const YUMProductData& data)
+{
+  out << "-------------------------------------------------" << endl
+    << "Product Data: " << endl
+    << "  type: " << data.type << endl
+    << "  vendor: " << data.vendor << endl
+    << "  name: " << data.name << endl
+    << "  display name: " << data.displayname << endl
+    << "  description: " << data.description << endl
+    << "  epoch: " << data.epoch << endl
+    << "  version: " << data.ver << endl
+    << "  release: " << data.rel << endl
+    << "  provides: " << data.provides << endl
+    << "  conflicts: " << data.conflicts << endl
+    << "  obsoletes: " << data.obsoletes << endl
+    << "  freshen: " << data.freshen << endl
+    << "  requires: " << data.requires << endl;
+  return out;
+}
+
 std::ostream& operator<<(std::ostream& out, const shared_ptr<YUMPatchAtom> data)
 {
   out << "Atom data" << endl;
index 0b6936f..265e9ec 100644 (file)
@@ -39,6 +39,7 @@ namespace zypp {
       DEFINE_PTR_TYPE( YUMFileListData );
       DEFINE_PTR_TYPE( YUMOtherData );
       DEFINE_PTR_TYPE( YUMPatchData );
+      DEFINE_PTR_TYPE( YUMProductData );
       DEFINE_PTR_TYPE( YUMPatchPackage );
       DEFINE_PTR_TYPE( YUMPatchScript );
       DEFINE_PTR_TYPE( YUMPatchMessage );
@@ -394,6 +395,18 @@ namespace zypp {
         std::list<shared_ptr<YUMPatchAtom> > atoms;
       };
 
+      class YUMProductData : public YUMObjectData {
+      public:
+       YUMProductData() {};
+       ~YUMProductData() {};
+
+       std::string type;
+       std::string vendor;
+       std::string name;
+       std::list<MultiLang> displayname;
+        std::list<MultiLang> description;
+      };
+
 
     } // namespace yum
   } // namespace parser
@@ -416,6 +429,7 @@ std::ostream& operator<<(std::ostream &out, const zypp::parser::yum::YUMGroupDat
 std::ostream& operator<<(std::ostream &out, const zypp::parser::yum::YUMFileListData& data);
 std::ostream& operator<<(std::ostream& out, const zypp::parser::yum::YUMOtherData& data);
 std::ostream& operator<<(std::ostream& out, const zypp::parser::yum::YUMPatchData& data);
+std::ostream& operator<<(std::ostream& out, const zypp::parser::yum::YUMProductData& data);
 std::ostream& operator<<(std::ostream& out, const shared_ptr<zypp::parser::yum::YUMPatchAtom> data);
 std::ostream& operator<<(std::ostream& out, const zypp::parser::yum::YUMPatchMessage& data);
 std::ostream& operator<<(std::ostream& out, const zypp::parser::yum::YUMPatchScript& data);
index d65000b..d36159d 100644 (file)
@@ -105,7 +105,7 @@ namespace zypp {
               prim.parseDependencyEntries(& patchPtr->requires, child);
             }
             else if (name == "freshen") {
-              prim.parseDependencyEntries(& patchPtr->requires, child);
+              prim.parseDependencyEntries(& patchPtr->freshen, child);
             }
             else if (name == "category") {
        patchPtr->category = _helper.content(child);
index 7ab7940..1fc74a7 100644 (file)
@@ -55,6 +55,7 @@ namespace zypp {
       private:
         // FIXME move needed method to a common class, inherit it
         friend class YUMPatchParser;
+        friend class YUMProductParser;
         virtual bool isInterested(const xmlNodePtr nodePtr);
         virtual YUMPrimaryData_Ptr process(const xmlTextReaderPtr reader);
         void parseFormatNode(YUMPrimaryData_Ptr dataPtr,
diff --git a/zypp/parser/yum/YUMProductParser.cc b/zypp/parser/yum/YUMProductParser.cc
new file mode 100644 (file)
index 0000000..a413d4b
--- /dev/null
@@ -0,0 +1,117 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+/** \file zypp/parser/yum/YUMProductParser.cc
+ *
+*/
+
+#include <istream>
+#include <string>
+#include <cassert>
+#include <libxml/xmlreader.h>
+#include <libxml/tree.h>
+#include "zypp/parser/yum/YUMProductParser.h"
+#include "zypp/parser/yum/YUMPrimaryParser.h"
+#include "zypp/parser/LibXMLHelper.h"
+#include "zypp/base/Logger.h"
+#include "zypp/parser/yum/schemanames.h"
+
+using namespace std;
+namespace zypp {
+  namespace parser {
+    namespace yum {
+
+      YUMProductParser::~YUMProductParser()
+      { }
+      
+      YUMProductParser::YUMProductParser(istream &is, const string& baseUrl)
+      : XMLNodeIterator<YUMProductData_Ptr>(is, baseUrl,PRODUCTSCHEMA)
+      {
+        fetchNext();
+      }
+      
+      YUMProductParser::YUMProductParser()
+      { }
+      
+      YUMProductParser::YUMProductParser(YUMProductData_Ptr& entry)
+      : XMLNodeIterator<YUMProductData_Ptr>(entry)
+      { }
+      
+      
+      // select for which elements process() will be called
+      bool 
+      YUMProductParser::isInterested(const xmlNodePtr nodePtr)
+      {
+        return _helper.isElement(nodePtr) && _helper.name(nodePtr) == "product";
+      }
+      
+      // do the actual processing
+      YUMProductData_Ptr
+      YUMProductParser::process(const xmlTextReaderPtr reader)
+      {
+        assert(reader);
+        YUMProductData_Ptr productPtr = new YUMProductData;
+        xmlNodePtr dataNode = xmlTextReaderExpand(reader);
+        assert(dataNode);
+        productPtr->type = _helper.attribute(dataNode,"type");
+      
+        // FIXME move the respective method to a common class, inherit it  
+        YUMPrimaryParser prim;
+      
+        for (xmlNodePtr child = dataNode->children; 
+             child && child != dataNode;
+             child = child->next) {
+          if (_helper.isElement(child)) {
+            string name = _helper.name(child);
+            if (name == "name") {
+             productPtr->name = _helper.content(child);
+            }
+            else if (name == "vendor") {
+             productPtr->vendor = _helper.content(child);
+            }
+            else if (name == "displayname") {
+              productPtr->displayname.push_back(MultiLang(
+                                      _helper.attribute(child,"lang"),
+                                       _helper.content(child)));
+            }
+            else if (name == "description") {
+              productPtr->description.push_back(MultiLang(
+                                       _helper.attribute(child,"lang"),
+                                       _helper.content(child)));
+            }
+            else if (name == "version") {
+              productPtr->epoch = _helper.attribute(child,"epoch");
+              productPtr->ver = _helper.attribute(child,"ver");
+              productPtr->rel = _helper.attribute(child,"rel");
+            }
+            else if (name == "provides") {
+              prim.parseDependencyEntries(& productPtr->provides, child);
+            }
+            else if (name == "conflicts") {
+              prim.parseDependencyEntries(& productPtr->conflicts, child);
+            }
+            else if (name == "obsoletes") {
+              prim.parseDependencyEntries(& productPtr->obsoletes, child);
+            }
+            else if (name == "requires") {
+              prim.parseDependencyEntries(& productPtr->requires, child);
+            }
+            else {
+              WAR << "YUM <data> contains the unknown element <" << name << "> "
+                << _helper.positionInfo(child) << ", skipping" << endl;
+            }
+          }
+        }
+        return productPtr;
+      } /* end process */
+      
+      
+      
+    } // namespace yum
+  } // namespace parser
+} // namespace zypp
diff --git a/zypp/parser/yum/YUMProductParser.h b/zypp/parser/yum/YUMProductParser.h
new file mode 100644 (file)
index 0000000..67e0c07
--- /dev/null
@@ -0,0 +1,64 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+/** \file zypp/parser/yum/YUMProductParser.h
+ *
+*/
+
+
+
+#ifndef YUMProductParser_h
+#define YUMProductParser_h
+
+#include "zypp/parser/yum/YUMParserData.h"
+#include "zypp/parser/XMLNodeIterator.h"
+#include "zypp/parser/LibXMLHelper.h"
+#include <list>
+
+namespace zypp {
+  namespace parser {
+    namespace yum {
+
+      /**
+      * @short Parser for YUM primary.xml files (containing package metadata)
+      * Use this class as an iterator that produces, one after one,
+      * YUMProductData_Ptr(s) for the XML package elements in the input.
+      * Here's an example:
+      *
+      * for (YUMProductParser iter(anIstream, baseUrl),
+      *      iter != YUMOtherParser.end(),     // or: iter() != 0, or ! iter.atEnd()
+      *      ++iter) {
+      *    doSomething(*iter)
+      * }
+      *
+      * The iterator owns the pointer (i.e., caller must not delete it)
+      * until the next ++ operator is called. At this time, it will be
+      * destroyed (and a new ENTRYTYPE is created.)
+      *
+      * If the input is fundamentally flawed so that it makes no sense to
+      * continue parsing, XMLNodeIterator will log it and consider the input as finished.
+      * You can query the exit status with errorStatus().
+      */
+      class YUMProductParser : public XMLNodeIterator<YUMProductData_Ptr>
+      {
+      public:
+        YUMProductParser(std::istream &is, const std::string &baseUrl);
+        YUMProductParser();
+        YUMProductParser(YUMProductData_Ptr& entry);
+        virtual ~YUMProductParser();
+    
+      private:
+        virtual bool isInterested(const xmlNodePtr nodePtr);
+        virtual YUMProductData_Ptr process(const xmlTextReaderPtr reader);
+        LibXMLHelper _helper;
+      };
+    } // namespace yum
+  } // namespace parser
+} // namespace zypp
+
+#endif
index fb90ed9..3695a7d 100644 (file)
@@ -18,24 +18,21 @@ element ns1:product {
     attribute lang { text },
     text
   }+,
-  element ns1:version {
-    attribute epoch { xsd:nonNegativeInteger },
-    attribute ver { text },
-    attribute rel { text }
-  },
   element provides {
     element entry {
       attribute name { text },
+      attribute kind { "package" | "patch" | "script" | "message" | "product"}?,
       (attribute flags { "EQ" | "LE" | "GE" },
        attribute epoch { xsd:nonNegativeInteger },
        attribute ver { text },
        attribute rel { text }?)?,
       empty
     }+
-  },
+  }?,
   element conflicts {
     element entry {
       attribute name { text },
+      attribute kind { "package" | "patch" | "script" | "message" | "product"}?,
       (attribute flags { "EQ" | "LE" | "GE" | "LT" | "GT" },
        attribute epoch { xsd:nonNegativeInteger },
        attribute ver { text },
@@ -46,6 +43,7 @@ element ns1:product {
   element obsoletes {
     element entry {
       attribute name { text },
+      attribute kind { "package" | "patch" | "script" | "message" | "product"}?,
       (attribute flags { "EQ" | "LE" | "GE" | "LT" },
        attribute epoch { xsd:nonNegativeInteger },
        attribute ver { text },
@@ -56,6 +54,7 @@ element ns1:product {
   element requires {
     element entry {
       attribute name { text },
+      attribute kind { "package" | "patch" | "script" | "message" | "product"}?,
       (attribute flags { "EQ" | "LE" | "GE" | "LT" | "GT" },
        attribute epoch { xsd:nonNegativeInteger },
        attribute ver { text },
@@ -63,5 +62,5 @@ element ns1:product {
       attribute pre { "1" | "0" }?,
       empty
     }*
-  }
+  }?
 }
index 570605a..730cffb 100644 (file)
       <text/>
     </element>
   </oneOrMore>
-  <element name="ns1:version">
-    <attribute name="epoch">
-      <data type="nonNegativeInteger"/>
-    </attribute>
-    <attribute name="ver"/>
-    <attribute name="rel"/>
-  </element>
-  <element name="provides">
-    <oneOrMore>
-      <element name="entry">
-        <attribute name="name"/>
-        <optional>
-          <attribute name="flags">
-            <choice>
-              <value>EQ</value>
-              <value>LE</value>
-              <value>GE</value>
-            </choice>
-          </attribute>
-          <attribute name="epoch">
-            <data type="nonNegativeInteger"/>
-          </attribute>
-          <attribute name="ver"/>
+  <optional>
+    <element name="provides">
+      <oneOrMore>
+        <element name="entry">
+          <attribute name="name"/>
           <optional>
-            <attribute name="rel"/>
+            <attribute name="kind">
+              <choice>
+                <value>package</value>
+                <value>patch</value>
+                <value>script</value>
+                <value>message</value>
+                <value>product</value>
+              </choice>
+            </attribute>
           </optional>
-        </optional>
-        <empty/>
-      </element>
-    </oneOrMore>
-  </element>
+          <optional>
+            <attribute name="flags">
+              <choice>
+                <value>EQ</value>
+                <value>LE</value>
+                <value>GE</value>
+              </choice>
+            </attribute>
+            <attribute name="epoch">
+              <data type="nonNegativeInteger"/>
+            </attribute>
+            <attribute name="ver"/>
+            <optional>
+              <attribute name="rel"/>
+            </optional>
+          </optional>
+          <empty/>
+        </element>
+      </oneOrMore>
+    </element>
+  </optional>
   <optional>
     <element name="conflicts">
       <oneOrMore>
       </oneOrMore>
     </element>
   </optional>
-  <element name="requires">
-    <zeroOrMore>
-      <element name="entry">
-        <attribute name="name"/>
-        <optional>
-          <attribute name="flags">
-            <choice>
-              <value>EQ</value>
-              <value>LE</value>
-              <value>GE</value>
-              <value>LT</value>
-              <value>GT</value>
-            </choice>
-          </attribute>
-          <attribute name="epoch">
-            <data type="nonNegativeInteger"/>
-          </attribute>
-          <attribute name="ver"/>
+  <optional>
+    <element name="requires">
+      <zeroOrMore>
+        <element name="entry">
+          <attribute name="name"/>
+          <optional>
+            <attribute name="flags">
+              <choice>
+                <value>EQ</value>
+                <value>LE</value>
+                <value>GE</value>
+                <value>LT</value>
+                <value>GT</value>
+              </choice>
+            </attribute>
+            <attribute name="epoch">
+              <data type="nonNegativeInteger"/>
+            </attribute>
+            <attribute name="ver"/>
+            <optional>
+              <attribute name="rel"/>
+            </optional>
+          </optional>
           <optional>
-            <attribute name="rel"/>
+            <attribute name="pre">
+              <choice>
+                <value>1</value>
+                <value>0</value>
+              </choice>
+            </attribute>
           </optional>
-        </optional>
-        <optional>
-          <attribute name="pre">
-            <choice>
-              <value>1</value>
-              <value>0</value>
-            </choice>
-          </attribute>
-        </optional>
-        <empty/>
-      </element>
-    </zeroOrMore>
-  </element>
+          <empty/>
+        </element>
+      </zeroOrMore>
+    </element>
+  </optional>
 </element>
index 1ef7944..2a50239 100644 (file)
@@ -25,6 +25,7 @@ namespace zypp {
     #define FILELISTSCHEMA (SCHEMABASE "filelists.rng")
     #define OTHERSCHEMA (SCHEMABASE "other.rng")
     #define PATCHSCHEMA (SCHEMABASE "patch.rng")
+    #define PRODUCTSCHEMA (SCHEMABASE "product.rng")
     } // namespace yum
   } // namespace parser
 } // namespace zypp