]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: XMLFormatter may print XML tags lowercased and underscored now.
authorRadoslaw Zarzynski <rzarzynski@mirantis.com>
Thu, 22 Oct 2015 16:56:14 +0000 (18:56 +0200)
committerRadoslaw Zarzynski <rzarzynski@mirantis.com>
Tue, 8 Dec 2015 16:57:23 +0000 (17:57 +0100)
Signed-off-by: Radoslaw Zarzynski <rzarzynski@mirantis.com>
src/common/Formatter.cc
src/common/Formatter.h

index 9b5b20303e85c34534c62eaa9c508cca230a9ed5..f5ce058a2f74f81eea6497e7a88e22a173deccf2 100644 (file)
@@ -21,6 +21,7 @@
 #include "common/escape.h"
 #include "include/buffer.h"
 
+#include <algorithm>
 #include <iostream>
 #include <sstream>
 #include <stdarg.h>
@@ -32,6 +33,9 @@
 #include <boost/format.hpp>
 
 
+static char tolower_underscore(const char b) {
+  return ' ' == b ? '_' : std::tolower(b);
+}
 
 // -----------------------
 namespace ceph {
@@ -317,8 +321,9 @@ void JSONFormatter::write_raw_data(const char *data)
 const char *XMLFormatter::XML_1_DTD =
   "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
 
-XMLFormatter::XMLFormatter(bool pretty)
-: m_pretty(pretty)
+XMLFormatter::XMLFormatter(bool pretty, bool lowercased_underscored)
+: m_pretty(pretty),
+  m_lowercased_underscored(lowercased_underscored)
 {
   reset();
 }
@@ -379,6 +384,10 @@ void XMLFormatter::close_section()
   finish_pending_string();
 
   std::string section = m_sections.back();
+  if (m_lowercased_underscored) {
+    std::transform(section.begin(), section.end(), section.begin(),
+          tolower_underscore);
+  }
   m_sections.pop_back();
   print_spaces();
   m_ss << "</" << section << ">";
@@ -389,6 +398,9 @@ void XMLFormatter::close_section()
 void XMLFormatter::dump_unsigned(const char *name, uint64_t u)
 {
   std::string e(name);
+  if (m_lowercased_underscored) {
+    std::transform(e.begin(), e.end(), e.begin(), tolower_underscore);
+  }
   print_spaces();
   m_ss << "<" << e << ">" << u << "</" << e << ">";
   if (m_pretty)
@@ -398,6 +410,9 @@ void XMLFormatter::dump_unsigned(const char *name, uint64_t u)
 void XMLFormatter::dump_int(const char *name, int64_t u)
 {
   std::string e(name);
+  if (m_lowercased_underscored) {
+    std::transform(e.begin(), e.end(), e.begin(), tolower_underscore);
+  }
   print_spaces();
   m_ss << "<" << e << ">" << u << "</" << e << ">";
   if (m_pretty)
@@ -407,6 +422,9 @@ void XMLFormatter::dump_int(const char *name, int64_t u)
 void XMLFormatter::dump_float(const char *name, double d)
 {
   std::string e(name);
+  if (m_lowercased_underscored) {
+    std::transform(e.begin(), e.end(), e.begin(), tolower_underscore);
+  }
   print_spaces();
   m_ss << "<" << e << ">" << d << "</" << e << ">";
   if (m_pretty)
@@ -416,6 +434,9 @@ void XMLFormatter::dump_float(const char *name, double d)
 void XMLFormatter::dump_string(const char *name, const std::string& s)
 {
   std::string e(name);
+  if (m_lowercased_underscored) {
+    std::transform(e.begin(), e.end(), e.begin(), tolower_underscore);
+  }
   print_spaces();
   m_ss << "<" << e << ">" << escape_xml_str(s.c_str()) << "</" << e << ">";
   if (m_pretty)
@@ -425,6 +446,9 @@ void XMLFormatter::dump_string(const char *name, const std::string& s)
 void XMLFormatter::dump_string_with_attrs(const char *name, const std::string& s, const FormatterAttrs& attrs)
 {
   std::string e(name);
+  if (m_lowercased_underscored) {
+    std::transform(e.begin(), e.end(), e.begin(), tolower_underscore);
+  }
   std::string attrs_str;
   get_attrs_str(&attrs, attrs_str);
   print_spaces();
@@ -447,6 +471,9 @@ void XMLFormatter::dump_format_va(const char* name, const char *ns, bool quoted,
   vsnprintf(buf, LARGE_SIZE, fmt, ap);
 
   std::string e(name);
+  if (m_lowercased_underscored) {
+    std::transform(e.begin(), e.end(), e.begin(), tolower_underscore);
+  }
   print_spaces();
   if (ns) {
     m_ss << "<" << e << " xmlns=\"" << ns << "\">" << buf << "</" << e << ">";
@@ -490,10 +517,15 @@ void XMLFormatter::open_section_in_ns(const char *name, const char *ns, const Fo
     get_attrs_str(attrs, attrs_str);
   }
 
+  std::string e(name);
+  if (m_lowercased_underscored) {
+    std::transform(e.begin(), e.end(), e.begin(), tolower_underscore);
+  }
+
   if (ns) {
-    m_ss << "<" << name << attrs_str << " xmlns=\"" << ns << "\">";
+    m_ss << "<" << e << attrs_str << " xmlns=\"" << ns << "\">";
   } else {
-    m_ss << "<" << name << attrs_str << ">";
+    m_ss << "<" << e << attrs_str << ">";
   }
   if (m_pretty)
     m_ss << "\n";
index 3c145c8912b2c9d3e675b1ff2a1ef87e7b54ce26..3784bdb4cfcd30e5c377416160a90bef3d4ea8ed 100644 (file)
@@ -128,7 +128,7 @@ namespace ceph {
   class XMLFormatter : public Formatter {
   public:
     static const char *XML_1_DTD;
-    XMLFormatter(bool pretty = false);
+    XMLFormatter(bool pretty = false, bool lowercased_underscored = false);
 
     void flush(std::ostream& os);
     void reset();
@@ -160,6 +160,7 @@ namespace ceph {
     std::stringstream m_ss, m_pending_string;
     std::deque<std::string> m_sections;
     bool m_pretty;
+    bool m_lowercased_underscored;
     std::string m_pending_string_name;
   };