Mercurial > hg > orthanc
changeset 2968:e361df74639f
added few plugin helpers
author | am@osimis.io |
---|---|
date | Wed, 05 Dec 2018 16:30:28 +0100 |
parents | 146eaed9b02c |
children | 2c16c29b287d 62b07b30e3db 9b734c3e1095 |
files | Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Plugins/Samples/Common/OrthancPluginCppWrapper.h |
diffstat | 2 files changed, 89 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Wed Dec 05 16:30:11 2018 +0100 +++ b/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Wed Dec 05 16:30:28 2018 +0100 @@ -1113,6 +1113,32 @@ #endif /* HAS_ORTHANC_PLUGIN_FIND_MATCHER == 1 */ + void AnswerJson(const Json::Value& value, + OrthancPluginRestOutput* output + ) + { + Json::StyledWriter writer; + std::string bodyString = writer.write(value); + + OrthancPluginAnswerBuffer(GetGlobalContext(), output, bodyString.c_str(), bodyString.size(), "application/json"); + } + + bool RestApiGetString(std::string& result, + const std::string& uri, + bool applyPlugins) + { + MemoryBuffer answer; + if (!answer.RestApiGet(uri, applyPlugins)) + { + return false; + } + else + { + answer.ToString(result); + return true; + } + } + bool RestApiGet(Json::Value& result, const std::string& uri, @@ -1311,6 +1337,58 @@ } } + const char* GetMimeType(const std::string& path) + { + size_t dot = path.find_last_of('.'); + + std::string extension = (dot == std::string::npos) ? "" : path.substr(dot); + std::transform(extension.begin(), extension.end(), extension.begin(), tolower); + + if (extension == ".html") + { + return "text/html"; + } + else if (extension == ".css") + { + return "text/css"; + } + else if (extension == ".js") + { + return "application/javascript"; + } + else if (extension == ".gif") + { + return "image/gif"; + } + else if (extension == ".svg") + { + return "image/svg+xml"; + } + else if (extension == ".json") + { + return "application/json"; + } + else if (extension == ".xml") + { + return "application/xml"; + } + else if (extension == ".wasm") + { + return "application/wasm"; + } + else if (extension == ".png") + { + return "image/png"; + } + else if (extension == ".jpg" || extension == ".jpeg") + { + return "image/jpeg"; + } + else + { + return "application/octet-stream"; + } + }
--- a/Plugins/Samples/Common/OrthancPluginCppWrapper.h Wed Dec 05 16:30:11 2018 +0100 +++ b/Plugins/Samples/Common/OrthancPluginCppWrapper.h Wed Dec 05 16:30:28 2018 +0100 @@ -419,6 +419,10 @@ const std::string& uri, bool applyPlugins); + bool RestApiGetString(std::string& result, + const std::string& uri, + bool applyPlugins); + bool RestApiPost(Json::Value& result, const std::string& uri, const char* body, @@ -466,6 +470,13 @@ const std::string& username, const std::string& password); + void AnswerJson(const Json::Value& value, + OrthancPluginRestOutput* output + ); + + const char* GetMimeType(const std::string& path); + + void LogError(const std::string& message); void LogWarning(const std::string& message);