Class DocumentUtil

java.lang.Object
org.codelibs.fess.util.DocumentUtil

public final class DocumentUtil extends Object
Utility class for document data manipulation and type conversion. This class provides static methods for extracting typed values from document maps, URL encoding, and other document-related operations. It's designed as a final utility class with only static methods.
  • Method Details

    • getValue

      public static <T> T getValue(Map<String,Object> doc, String key, Class<T> clazz, T defaultValue)
      Gets a typed value from a document map with a default value.
      Type Parameters:
      T - the type to convert the value to
      Parameters:
      doc - the document map to extract the value from
      key - the key to look up in the document map
      clazz - the class type to convert the value to
      defaultValue - the default value to return if the key is not found or conversion fails
      Returns:
      the converted value or the default value if not found
    • getValue

      public static <T> T getValue(Map<String,Object> doc, String key, Class<T> clazz)
      Gets a typed value from a document map. Supports conversion to String, Date, Long, Integer, Double, Float, Boolean, List, and String array types. Handles both single values and arrays/lists.
      Type Parameters:
      T - the type to convert the value to
      Parameters:
      doc - the document map to extract the value from
      key - the key to look up in the document map
      clazz - the class type to convert the value to
      Returns:
      the converted value or null if not found or conversion fails
    • encodeUrl

      public static String encodeUrl(String url)
      Encodes a URL by encoding non-URL-safe characters. Uses the request's character encoding if available, otherwise defaults to UTF-8. Only encodes characters that are not considered URL-safe according to CharUtil.
      Parameters:
      url - the URL to encode
      Returns:
      the encoded URL with non-URL-safe characters properly encoded