changeset 292:0222a9afa866 refactoring

reorganization
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 08 Jun 2019 17:47:01 +0200
parents 05b4f440a961
children 7e3989d2ea5a
files Plugin/Configuration.cpp Plugin/Configuration.h Plugin/QidoRs.cpp Plugin/StowRs.cpp Plugin/StowRs.h
diffstat 5 files changed, 65 insertions(+), 64 deletions(-) [+]
line wrap: on
line diff
--- a/Plugin/Configuration.cpp	Sat Jun 08 17:42:49 2019 +0200
+++ b/Plugin/Configuration.cpp	Sat Jun 08 17:47:01 2019 +0200
@@ -536,5 +536,61 @@
     {
       return defaultEncoding_;
     }
+
+
+    static bool IsXmlExpected(const std::string& acceptHeader)
+    {
+      std::string accept;
+      Orthanc::Toolbox::ToLowerCase(accept, acceptHeader);
+  
+      if (accept == "application/dicom+json" ||
+          accept == "application/json" ||
+          accept == "*/*")
+      {
+        return false;
+      }
+      else if (accept == "application/dicom+xml" ||
+               accept == "application/xml" ||
+               accept == "text/xml")
+      {
+        return true;
+      }
+      else
+      {
+        OrthancPlugins::LogError("Unsupported return MIME type: " + accept +
+                                 ", will return DICOM+JSON");
+        return false;
+      }
+    }
+
+
+    bool IsXmlExpected(const std::map<std::string, std::string>& headers)
+    {
+      std::map<std::string, std::string>::const_iterator found = headers.find("accept");
+
+      if (found == headers.end())
+      {
+        return false;   // By default, return DICOM+JSON
+      }
+      else
+      {
+        return IsXmlExpected(found->second);
+      }
+    }
+
+
+    bool IsXmlExpected(const OrthancPluginHttpRequest* request)
+    {
+      std::string accept;
+
+      if (OrthancPlugins::LookupHttpHeader(accept, request, "accept"))
+      {
+        return IsXmlExpected(accept);
+      }
+      else
+      {
+        return false;   // By default, return DICOM+JSON
+      }
+    }
   }
 }
--- a/Plugin/Configuration.h	Sat Jun 08 17:42:49 2019 +0200
+++ b/Plugin/Configuration.h	Sat Jun 08 17:47:01 2019 +0200
@@ -101,5 +101,10 @@
                            const std::string& sopInstanceUid);
 
     Orthanc::Encoding GetDefaultEncoding();
+
+    bool IsXmlExpected(const std::map<std::string, std::string>& headers);
+
+    // TODO => REMOVE
+    bool IsXmlExpected(const OrthancPluginHttpRequest* request);
   }
 }
--- a/Plugin/QidoRs.cpp	Sat Jun 08 17:42:49 2019 +0200
+++ b/Plugin/QidoRs.cpp	Sat Jun 08 17:47:01 2019 +0200
@@ -494,7 +494,8 @@
   
   std::string wadoBase = OrthancPlugins::Configuration::GetBaseUrl(request);
 
-  OrthancPlugins::DicomWebFormatter::HttpWriter writer(output, IsXmlExpected(request));
+  OrthancPlugins::DicomWebFormatter::HttpWriter writer(
+    output, OrthancPlugins::Configuration::IsXmlExpected(request));
 
   // Fix of issue #13
   for (ResourcesAndInstances::const_iterator
--- a/Plugin/StowRs.cpp	Sat Jun 08 17:42:49 2019 +0200
+++ b/Plugin/StowRs.cpp	Sat Jun 08 17:47:01 2019 +0200
@@ -28,63 +28,6 @@
 #include <Plugins/Samples/Common/OrthancPluginCppWrapper.h>
 
 
-static bool IsXmlExpected(const std::string& acceptHeader)
-{
-  std::string accept;
-  Orthanc::Toolbox::ToLowerCase(accept, acceptHeader);
-  
-  if (accept == "application/dicom+json" ||
-      accept == "application/json" ||
-      accept == "*/*")
-  {
-    return false;
-  }
-  else if (accept == "application/dicom+xml" ||
-           accept == "application/xml" ||
-           accept == "text/xml")
-  {
-    return true;
-  }
-  else
-  {
-    OrthancPlugins::LogError("Unsupported return MIME type: " + accept +
-                             ", will return DICOM+JSON");
-    return false;
-  }
-}
-
-
-bool IsXmlExpected(const std::map<std::string, std::string>& headers)
-{
-  std::map<std::string, std::string>::const_iterator found = headers.find("accept");
-
-  if (found == headers.end())
-  {
-    return false;   // By default, return DICOM+JSON
-  }
-  else
-  {
-    return IsXmlExpected(found->second);
-  }
-}
-
-
-  // TODO => REMOVE
-bool IsXmlExpected(const OrthancPluginHttpRequest* request)
-{
-  std::string accept;
-
-  if (OrthancPlugins::LookupHttpHeader(accept, request, "accept"))
-  {
-    return IsXmlExpected(accept);
-  }
-  else
-  {
-    return false;   // By default, return DICOM+JSON
-  }
-}
-
-
 void StowCallback(OrthancPluginRestOutput* output,
                   const char* url,
                   const OrthancPluginHttpRequest* request)
@@ -259,7 +202,7 @@
   result[OrthancPlugins::DICOM_TAG_FAILED_SOP_SEQUENCE.Format()] = failed;
   result[OrthancPlugins::DICOM_TAG_REFERENCED_SOP_SEQUENCE.Format()] = success;
 
-  const bool isXml = IsXmlExpected(request);
+  const bool isXml = OrthancPlugins::Configuration::IsXmlExpected(request);
   std::string answer;
   
   {
@@ -465,6 +408,6 @@
                                       "The STOW-RS plugin currently only supports \"application/dicom\" subtype");
     }
 
-    return new Handler(context, IsXmlExpected(headers), wadoBase, expectedStudy);
+    return new Handler(context, Configuration::IsXmlExpected(headers), wadoBase, expectedStudy);
   }
 }
--- a/Plugin/StowRs.h	Sat Jun 08 17:42:49 2019 +0200
+++ b/Plugin/StowRs.h	Sat Jun 08 17:47:01 2019 +0200
@@ -26,10 +26,6 @@
 #include <Plugins/Samples/Common/OrthancPluginCppWrapper.h>
 
 
-bool IsXmlExpected(const std::map<std::string, std::string>& headers);
-
-bool IsXmlExpected(const OrthancPluginHttpRequest* request);
-
 void StowCallback(OrthancPluginRestOutput* output,
                   const char* url,
                   const OrthancPluginHttpRequest* request);