Class StorageUtils

java.lang.Object
org.exoplatform.social.core.storage.impl.StorageUtils

public class StorageUtils extends Object
  • Field Details

  • Constructor Details

    • StorageUtils

      public StorageUtils()
  • Method Details

    • subList

      public static <T> List<T> subList(List<T> list, int startIndex, int toIndex)
      Gets sub list from the provided list with start and end index.
      Parameters:
      list - the identity list
      startIndex - start index to get
      toIndex - end index to get
      Returns:
      sub list of the provided list
    • toRFC3339Date

      public static String toRFC3339Date(Date dateTime)
    • parseRFC3339Date

      public static Date parseRFC3339Date(String dateString)
    • normalizeSearchText

      public static String normalizeSearchText(String text)
      Prepares a searched text for an analyzed Elasticsearch query (a match query): the Latin combining diacritics are removed, as the index analyzers' asciifolding does, because the ngram fields' search analyzer (space display name, category name) folds nothing. The text is decomposed (NFD) to find them and recomposed (NFC) afterwards, so that a Hangul syllable or a kana with a sound mark, which NFD also decomposes, is searched as typed. Nothing else is changed: the field's search analyzer splits the text into the tokens the index holds, and a text with no token matches nothing.
      Parameters:
      text - searched text, as typed
      Returns:
      the text to search, trimmed; null when the text is null
    • escapeJsonValue

      public static String escapeJsonValue(String value)
      Escapes a value written between the quotes of a JSON string of a query built as text, so that a quote, a backslash or a control character in the value reaches Elasticsearch as that character.
      Parameters:
      value - value to write
      Returns:
      the escaped value, null when the value is null
    • escapeSearchText

      public static String escapeSearchText(String text)
      Escapes a searched text for the JSON string of an analyzed query: normalizeSearchText(String) then escapeJsonValue(String).
      Parameters:
      text - searched text, as typed
      Returns:
      the text to write between the quotes of the query JSON string
    • fillQueryTemplate

      public static String fillQueryTemplate(String template, Map<String,String> values)
      Fills a query template in one pass: each @name@ placeholder of the template is replaced by its value, and a placeholder's name found inside a value, such as a searched @limit@, is written as is. A placeholder the values do not name is replaced by an empty string.
      Parameters:
      template - query template holding @name@ placeholders
      values - value of each placeholder, by name without the @
      Returns:
      the filled query