- dumpAsXMLOn(ostream) added
authorJan Kupec <jkupec@suse.cz>
Thu, 4 Sep 2008 21:16:52 +0000 (21:16 +0000)
committerJan Kupec <jkupec@suse.cz>
Thu, 4 Sep 2008 21:16:52 +0000 (21:16 +0000)
zypp/RepoInfo.cc
zypp/RepoInfo.h
zypp/ServiceInfo.cc
zypp/ServiceInfo.h
zypp/repo/RepoInfoBase.h

index db85b21..a0a01ce 100644 (file)
 #include "zypp/base/Logger.h"
 #include "zypp/base/DefaultIntegral.h"
 #include "zypp/media/MediaAccess.h"
+#include "zypp/parser/xml/XmlEscape.h"
 
 #include "zypp/RepoInfo.h"
 #include "zypp/repo/RepoInfoBaseImpl.h"
 
 using namespace std;
+using zypp::xml::escape;
 
 ///////////////////////////////////////////////////////////////////
 namespace zypp
@@ -326,6 +328,31 @@ namespace zypp
     return str;
   }
 
+  std::ostream & RepoInfo::dumpAsXMLOn( std::ostream & str) const
+  {
+    string tmpstr;
+    str
+      << "<repo"
+      << " alias=\"" << escape(alias()) << "\""
+      << " name=\"" << escape(name()) << "\""
+      << " type=\"" << type().asString() << "\""
+      << " enabled=\"" << enabled() << "\""
+      << " autorefresh=\"" << autorefresh() << "\""
+      << " gpgcheck=\"" << gpgCheck() << "\"";
+    if (!(tmpstr = gpgKeyUrl().asString()).empty())
+      str << " gpgkey=\"" << escape(tmpstr) << "\"";
+    if (!(tmpstr = mirrorListUrl().asString()).empty())
+      str << " mirrorlist=\"" << escape(tmpstr) << "\"";
+    str << ">" << endl;
+
+    for (RepoInfo::urls_const_iterator urlit = baseUrlsBegin();
+         urlit != baseUrlsEnd(); ++urlit)
+      str << "<url>" << escape(urlit->asString()) << "</url>" << endl;
+
+    str << "</repo>" << endl;
+    return str;
+  }
+
   std::ostream & operator<<( std::ostream & str, const RepoInfo & obj )
   {
     return obj.dumpOn(str);
index 36b76be..d3626f6 100644 (file)
@@ -321,6 +321,11 @@ namespace zypp
      */
     virtual std::ostream & dumpRepoOn( std::ostream & str ) const;
 
+    /**
+     * Write an XML representation of this RepoInfo object.
+     */
+    virtual std::ostream & dumpAsXMLOn( std::ostream & str) const;
+
     class Impl;
   private:
     /** Pointer to implementation */
index 2a91d41..11d5023 100644 (file)
@@ -12,6 +12,8 @@
 #include <ostream>
 #include <iostream>
 
+#include "zypp/parser/xml/XmlEscape.h"
+
 #include "zypp/RepoInfo.h"
 #include "zypp/parser/RepoindexFileReader.h"
 #include "zypp/repo/RepoInfoBaseImpl.h"
@@ -19,6 +21,7 @@
 #include "zypp/ServiceInfo.h"
 
 using namespace std;
+using zypp::xml::escape;
 
 ///////////////////////////////////////////////////////////////////////////////
 namespace zypp 
@@ -88,6 +91,18 @@ namespace zypp
     return RepoInfoBase::dumpAsIniOn(str) << "url = " << url() << endl;
   }
 
+  std::ostream & ServiceInfo::dumpAsXMLOn( std::ostream & str) const
+  {
+    return str
+      << "<service"
+      << " alias=\"" << escape(alias()) << "\""
+      << " name=\"" << escape(name()) << "\""
+      << " enabled=\"" << enabled() << "\""
+      << " autorefresh=\"" << autorefresh() << "\""
+      << " url=\"" << escape(url().asString()) << "\""
+      << "/>" << endl;
+  }
+  
   std::ostream & operator<<( std::ostream& str, const ServiceInfo &obj )
   {
     return obj.dumpAsIniOn(str);
index ce337d5..9a30b32 100644 (file)
@@ -81,6 +81,11 @@ namespace zypp
      */
     virtual std::ostream & dumpAsIniOn( std::ostream & str ) const;
 
+    /**
+     * Write an XML representation of this ServiceInfo object.
+     */
+    virtual std::ostream & dumpAsXMLOn( std::ostream & str) const;
+
     class Impl;
 
   private:
index a1ec868..d08f37f 100644 (file)
@@ -137,6 +137,11 @@ namespace zypp
        */
       virtual std::ostream & dumpAsIniOn( std::ostream & str ) const;
 
+      /**
+       * Write an XML representation of this object.
+       */
+      virtual std::ostream & dumpAsXMLOn( std::ostream & str) const = 0;
+
       class Impl;
     private:
       /** Pointer to implementation */