Example #1
0
  /**
   * Tests if the provided string is a valid extension key string.
   *
   * <p>A field is not valid if it contains a whitespace character
   *
   * @param extensionKeyStr the extension key string to test
   * @return if the extension key string contains a whitespace character
   */
  public static Boolean isValidExtensionKey(final String extensionKeyStr) {
    final Boolean isValid;

    if (extensionKeyStr == null) {
      StringUtils.LOG.warn("Tried to detect if a null string was a valid extension key string");

      isValid = false;
    } else if (StringUtils.INVALID_EXTENSION_KEY_PATTERN.matcher(extensionKeyStr).find()) {
      isValid = false;
    } else {
      isValid = true;
    }

    StringUtils.LOG.debug(
        "The extension key \"{}\" is {}valid", extensionKeyStr, isValid ? "" : "not ");

    return isValid;
  }
Example #2
0
  /**
   * Every key in a CEF extension map must escape the ='s character
   *
   * <p>Null strings return null for now.
   *
   * @param keyStr the text of the extension value that requires escaping
   * @return the escaped version of the extension value string
   * @throws InvalidExtensionKey if the key is invalid
   */
  public static String escapeExtensionKey(final String keyStr) throws InvalidExtensionKey {
    if (keyStr == null) {
      StringUtils.LOG.warn("Tried to escape a null CEF extension key");

      return null;
    }

    if (StringUtils.INVALID_EXTENSION_KEY_PATTERN.matcher(keyStr).find()) {
      StringUtils.LOG.error("The field string contained an invalid character");

      throw new InvalidExtensionKey(
          "The field string " + keyStr + " contained an invalid character");
    }

    final String escapedStr =
        StringUtils.ESCAPE_EXTENSION_KEY_PATTERN.matcher(keyStr).replaceAll("\\\\=");

    StringUtils.LOG.debug("The CEF extension key \"{}\" was escaped to \"{}\"", keyStr, escapedStr);

    return escapedStr;
  }