<commit_before>#include "WMS.h"
#include "WMSException.h"
#include "WMSGetMap.h"

#include "TemplateFactory.h"

#include <macgyver/String.h>

#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/algorithm/string/erase.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/foreach.hpp>

#include <spine/Exception.h>
#include <spine/Convenience.h>

namespace SmartMet
{
namespace Plugin
{
namespace WMS
{
namespace
{
struct CaseInsensitiveComparator : std::binary_function<std::string, std::string, bool>
{
  char asciilower(char ch) const
  {
    char ret = ch;
    if (ch >= 'A' && ch <= 'Z')
      ret = static_cast<char>(ch + ('a' - 'A'));
    return ret;
  }

  bool operator()(const std::string& first, const std::string& second) const
  {
    std::size_t n = std::min(first.size(), second.size());
    for (std::size_t i = 0; i < n; i++)
    {
      char ch1 = asciilower(first[i]);
      char ch2 = asciilower(second[i]);
      if (ch1 != ch2)
        return false;
    }

    return (first.size() == second.size());
  }
};

std::string demimetype(const std::string& theMimeType)
{
  if (theMimeType == "image/png")
    return "png";
  if (theMimeType == "application/pdf")
    return "pdf";
  if (theMimeType == "application/postscript")
    return "ps";
  if (theMimeType == "image/svg+xml")
    return "svg";

  throw SmartMet::Spine::Exception(BCP, "Unknown mime type requested: '" + theMimeType + "'");
}

void check_getmap_request_options(const SmartMet::Spine::HTTP::Request& theHTTPRequest)
{
  try
  {
    // check that all mandatory options has been defined
    std::string missing_options;

    if (!theHTTPRequest.getParameter("VERSION"))
    {
      SmartMet::Spine::Exception exception(BCP, "Version not defined");
      exception.addParameter(WMS_EXCEPTION_CODE, WMS_VOID_EXCEPTION_CODE);
      throw exception;
    }

    if (!theHTTPRequest.getParameter("LAYERS"))
    {
      SmartMet::Spine::Exception exception(BCP,
                                           "At least one layer must be defined in GetMap request");
      exception.addParameter(WMS_EXCEPTION_CODE, WMS_LAYER_NOT_DEFINED);
      throw exception;
    }

    if (!theHTTPRequest.getParameter("STYLES"))
    {
      SmartMet::Spine::Exception exception(BCP,
                                           "STYLE-option must be defined, even if it is empty");
      exception.addParameter(WMS_EXCEPTION_CODE, WMS_STYLE_NOT_DEFINED);
      throw exception;
    }

    if (!theHTTPRequest.getParameter("CRS"))
    {
      SmartMet::Spine::Exception exception(BCP, "CRS-option has not been defined");
      exception.addParameter(WMS_EXCEPTION_CODE, WMS_VOID_EXCEPTION_CODE);
      throw exception;
    }

    if (!theHTTPRequest.getParameter("BBOX"))
    {
      SmartMet::Spine::Exception exception(BCP, "BBOX-option has not been defined");
      exception.addParameter(WMS_EXCEPTION_CODE, WMS_MISSING_DIMENSION_VALUE);
      throw exception;
    }

    if (!theHTTPRequest.getParameter("WIDTH"))
    {
      SmartMet::Spine::Exception exception(BCP, "WIDTH-option has not been defined");<commit_msg>StyleNotDefined exception text changed to use STYLES instead of STYLE.<commit_after>#include "WMS.h"
#include "WMSException.h"
#include "WMSGetMap.h"

#include "TemplateFactory.h"

#include <macgyver/String.h>

#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/algorithm/string/erase.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/foreach.hpp>

#include <spine/Exception.h>
#include <spine/Convenience.h>

namespace SmartMet
{
namespace Plugin
{
namespace WMS
{
namespace
{
struct CaseInsensitiveComparator : std::binary_function<std::string, std::string, bool>
{
  char asciilower(char ch) const
  {
    char ret = ch;
    if (ch >= 'A' && ch <= 'Z')
      ret = static_cast<char>(ch + ('a' - 'A'));
    return ret;
  }

  bool operator()(const std::string& first, const std::string& second) const
  {
    std::size_t n = std::min(first.size(), second.size());
    for (std::size_t i = 0; i < n; i++)
    {
      char ch1 = asciilower(first[i]);
      char ch2 = asciilower(second[i]);
      if (ch1 != ch2)
        return false;
    }

    return (first.size() == second.size());
  }
};

std::string demimetype(const std::string& theMimeType)
{
  if (theMimeType == "image/png")
    return "png";
  if (theMimeType == "application/pdf")
    return "pdf";
  if (theMimeType == "application/postscript")
    return "ps";
  if (theMimeType == "image/svg+xml")
    return "svg";

  throw SmartMet::Spine::Exception(BCP, "Unknown mime type requested: '" + theMimeType + "'");
}

void check_getmap_request_options(const SmartMet::Spine::HTTP::Request& theHTTPRequest)
{
  try
  {
    // check that all mandatory options has been defined
    std::string missing_options;

    if (!theHTTPRequest.getParameter("VERSION"))
    {
      SmartMet::Spine::Exception exception(BCP, "Version not defined");
      exception.addParameter(WMS_EXCEPTION_CODE, WMS_VOID_EXCEPTION_CODE);
      throw exception;
    }

    if (!theHTTPRequest.getParameter("LAYERS"))
    {
      SmartMet::Spine::Exception exception(BCP,
                                           "At least one layer must be defined in GetMap request");
      exception.addParameter(WMS_EXCEPTION_CODE, WMS_LAYER_NOT_DEFINED);
      throw exception;
    }

    if (!theHTTPRequest.getParameter("STYLES"))
    {
      SmartMet::Spine::Exception exception(BCP,
                                           "STYLES-option must be defined, even if it is empty");
      exception.addParameter(WMS_EXCEPTION_CODE, WMS_STYLE_NOT_DEFINED);
      throw exception;
    }

    if (!theHTTPRequest.getParameter("CRS"))
    {
      SmartMet::Spine::Exception exception(BCP, "CRS-option has not been defined");
      exception.addParameter(WMS_EXCEPTION_CODE, WMS_VOID_EXCEPTION_CODE);
      throw exception;
    }

    if (!theHTTPRequest.getParameter("BBOX"))
    {
      SmartMet::Spine::Exception exception(BCP, "BBOX-option has not been defined");
      exception.addParameter(WMS_EXCEPTION_CODE, WMS_MISSING_DIMENSION_VALUE);
      throw exception;
    }

    if (!theHTTPRequest.getParameter("WIDTH"))
    {
      SmartMet::Spine::Exception exception(BCP, "WIDTH-option has not been defined");
{'fraction_non_alphanumeric': 0.13311788242536166, 'fraction_numerical': 0.0015389350569405972, 'mean_word_length': 3.573539760731879, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6160312', 'n_tokens_mistral': 2141, 'n_tokens_neox': 2096, 'n_words': 444}