protected String InferLangFromReferralUrl(HttpServletRequest httpRequest, String parseLangQueryParams)
    {
      // Examine the referer header that came with this request to see if we can infer the user's language.
      // If we find a query string paramater that matches the list provided, return the content of that param.
      try
      {
        String referrer = httpRequest.getHeader("referer");
        if (referrer != null && !parseLangQueryParams.isEmpty())
        {
          // These are the params we will look for
          String[] langParams = parseLangQueryParams.split(";");

          // Now parse the referrer URL
          URL referrerUrl = new URL(referrer);
          String[] params = referrerUrl.getQuery().split("&");
          for (String param : params)
          {
              int splitPos = param.indexOf("=");
              String paramName = URLDecoder.decode(param.substring(0, splitPos), "UTF-8");

              // If we find a matching lang param, return its value
              for (int i = 0; i < langParams.length; i++)
                if (paramName.equalsIgnoreCase(langParams[i]))
                {
                  String lang = URLDecoder.decode(param.substring(splitPos + 1), "UTF-8");
                  log.debug("Found language preference in referral URL: " + lang);
                  return lang;
                }
          }
        }
      }
      catch (Exception ex)
      {
        log.error("Unable to infer a lang parameter from referral URL: " + ex.getMessage());
      }

      return null;
    }