Class FessFunctions

java.lang.Object
org.codelibs.fess.taglib.FessFunctions

public class FessFunctions extends Object
Utility class providing static functions for Fess JSP/JSTL expressions and tag libraries. This class contains various helper methods for formatting, parsing, and manipulating data in Fess web templates, including date formatting, localization, file operations, and query parameter handling.
Since:
1.0
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Private constructor to prevent instantiation of this utility class.
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    base64(String value)
    Encodes a string to URL-safe Base64 format.
    static Date
    date(Long value)
    Converts a Long timestamp to a Date object.
    static String
    Escapes a string so it can be safely embedded inside a JavaScript string literal.
    static String
    Generates hidden HTML form fields for facet filtering.
    static String
    Generates URL query parameters for facet filtering.
    Retrieves the list of facet query view objects for display.
    static boolean
    Checks if a file exists at the specified path within the servlet context.
    static String
    formatCode(String prefix, String style, String mimetype, String input)
    Formats code content with syntax highlighting and line numbers.
    static String
    Formats a LocalDateTime object to ISO datetime string format.
    static String
    Formats a ZonedDateTime object using the specified format pattern.
    static String
    Formats a Date object to ISO datetime string format in UTC timezone.
    static String
    formatDuration(long durationMillis)
    Formats a duration in milliseconds to a human-readable string.
    static String
    formatFileSize(long value)
    Formats a file size in bytes to a human-readable string with appropriate units.
    static String
    formatNumber(long value, String pattern)
    Formats a number using the specified pattern and user's locale.
    static String
    Generates hidden HTML form fields for geographic filtering.
    static String
    Generates URL query parameters for geographic filtering.
    static String
    getMessage(String key, String defaultValue)
    Retrieves a localized message for the given key.
    static boolean
    Checks if the current user has the specified action role or administrative privileges.
    static String
    html(boolean isOpen)
    Generates an HTML opening or closing tag with appropriate language attribute.
    static String
    join(Object input)
    Joins array or list elements into a single space-separated string.
    static String
    label(String value)
    Retrieves the localized label value for the given key from the current request's label map.
    static Boolean
    Checks if a label with the specified key exists in the current request's label map.
    static String
    Masks email addresses in the input string for privacy protection.
    static String
    Generates URL query parameters for pagination, excluding the specified query parameter.
    static Date
    Parses a date string using the default date format.
    static Date
    parseDate(String value, String format)
    Parses a date string using the specified format.
    static String
    replace(Object input, String regex, String replacement)
    Replaces all occurrences of a regular expression pattern in the input string.
    static String
    sdh(String input)
    Encodes a string for similar document hash processing.
    static String
    url(String input)
    Generates a complete URL with context path and cache-busting timestamp.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • FessFunctions

      protected FessFunctions()
      Private constructor to prevent instantiation of this utility class. This class is intended to be used only through its static methods.
  • Method Details

    • html

      public static String html(boolean isOpen)
      Generates an HTML opening or closing tag with appropriate language attribute.
      Parameters:
      isOpen - true to generate opening HTML tag, false for closing tag
      Returns:
      HTML opening tag with language attribute or closing tag
    • labelExists

      public static Boolean labelExists(String value)
      Checks if a label with the specified key exists in the current request's label map.
      Parameters:
      value - the label key to check
      Returns:
      true if the label exists, false otherwise
    • label

      public static String label(String value)
      Retrieves the localized label value for the given key from the current request's label map.
      Parameters:
      value - the label key to retrieve
      Returns:
      the localized label value, or the key itself if not found
    • date

      public static Date date(Long value)
      Converts a Long timestamp to a Date object.
      Parameters:
      value - the timestamp in milliseconds
      Returns:
      Date object representing the timestamp, or null if value is null
    • parseDate

      public static Date parseDate(String value)
      Parses a date string using the default date format.
      Parameters:
      value - the date string to parse
      Returns:
      parsed Date object, or null if parsing fails
    • parseDate

      public static Date parseDate(String value, String format)
      Parses a date string using the specified format.
      Parameters:
      value - the date string to parse
      format - the date format pattern or "pdf_date" for PDF date format
      Returns:
      parsed Date object, or null if parsing fails
    • formatDate

      public static String formatDate(Date date)
      Formats a Date object to ISO datetime string format in UTC timezone.
      Parameters:
      date - the date to format
      Returns:
      formatted date string, or empty string if date is null
    • formatDate

      public static String formatDate(LocalDateTime date)
      Formats a LocalDateTime object to ISO datetime string format.
      Parameters:
      date - the LocalDateTime to format
      Returns:
      formatted date string, or empty string if date is null
    • formatDate

      public static String formatDate(ZonedDateTime date, String format)
      Formats a ZonedDateTime object using the specified format pattern.
      Parameters:
      date - the ZonedDateTime to format
      format - the date format pattern
      Returns:
      formatted date string, or empty string if date is null
    • formatDuration

      public static String formatDuration(long durationMillis)
      Formats a duration in milliseconds to a human-readable string.
      Parameters:
      durationMillis - the duration in milliseconds
      Returns:
      formatted duration string (e.g., "2 days 14:30:25.123" or "14:30:25.123")
    • formatNumber

      public static String formatNumber(long value, String pattern)
      Formats a number using the specified pattern and user's locale.
      Parameters:
      value - the number to format
      pattern - the number format pattern
      Returns:
      formatted number string
    • formatFileSize

      public static String formatFileSize(long value)
      Formats a file size in bytes to a human-readable string with appropriate units.
      Parameters:
      value - the file size in bytes
      Returns:
      formatted file size string (e.g., "1.5M", "2.3G", "512K")
    • pagingQuery

      public static String pagingQuery(String query)
      Generates URL query parameters for pagination, excluding the specified query parameter.
      Parameters:
      query - the query parameter to exclude from paging
      Returns:
      URL-encoded query string for pagination
    • facetQuery

      public static String facetQuery()
      Generates URL query parameters for facet filtering.
      Returns:
      URL-encoded query string containing facet parameters
    • geoQuery

      public static String geoQuery()
      Generates URL query parameters for geographic filtering.
      Returns:
      URL-encoded query string containing geographic parameters
    • facetForm

      public static String facetForm()
      Generates hidden HTML form fields for facet filtering.
      Returns:
      HTML string containing hidden input fields for facet parameters
    • geoForm

      public static String geoForm()
      Generates hidden HTML form fields for geographic filtering.
      Returns:
      HTML string containing hidden input fields for geographic parameters
    • facetQueryViewList

      public static List<FacetQueryView> facetQueryViewList()
      Retrieves the list of facet query view objects for display.
      Returns:
      list of FacetQueryView objects
    • base64

      public static String base64(String value)
      Encodes a string to URL-safe Base64 format.
      Parameters:
      value - the string to encode
      Returns:
      Base64 encoded string, or empty string if value is null
    • fileExists

      public static boolean fileExists(String path)
      Checks if a file exists at the specified path within the servlet context.
      Parameters:
      path - the file path relative to the servlet context
      Returns:
      true if the file exists, false otherwise
    • url

      public static String url(String input)
      Generates a complete URL with context path and cache-busting timestamp.
      Parameters:
      input - the relative URL path starting with '/'
      Returns:
      complete URL with context path and optional timestamp parameter
      Throws:
      IllegalArgumentException - if input is null or doesn't start with '/'
    • sdh

      public static String sdh(String input)
      Encodes a string for similar document hash processing.
      Parameters:
      input - the string to encode
      Returns:
      encoded string, or the original input if blank
    • join

      public static String join(Object input)
      Joins array or list elements into a single space-separated string.
      Parameters:
      input - the input object (String[], List, or String)
      Returns:
      joined string with elements separated by spaces, or empty string if invalid input
    • escapeJs

      public static String escapeJs(String input)
      Escapes a string so it can be safely embedded inside a JavaScript string literal. Single quotes, double quotes, backslashes, and control characters are escaped.
      Parameters:
      input - the input string to escape
      Returns:
      JavaScript-safe escaped string, or empty string if input is null
    • replace

      public static String replace(Object input, String regex, String replacement)
      Replaces all occurrences of a regular expression pattern in the input string.
      Parameters:
      input - the input object to process
      regex - the regular expression pattern to match
      replacement - the replacement string
      Returns:
      string with all matches replaced, or empty string if input is null
    • formatCode

      public static String formatCode(String prefix, String style, String mimetype, String input)
      Formats code content with syntax highlighting and line numbers.
      Parameters:
      prefix - the line number prefix pattern
      style - the CSS class name for styling
      mimetype - the MIME type of the content (currently unused)
      input - the code content to format
      Returns:
      HTML formatted code with line numbers and styling
    • getMessage

      public static String getMessage(String key, String defaultValue)
      Retrieves a localized message for the given key.
      Parameters:
      key - the message key
      defaultValue - the default value to return if message not found
      Returns:
      localized message or default value
    • hasActionRole

      public static boolean hasActionRole(String role)
      Checks if the current user has the specified action role or administrative privileges.
      Parameters:
      role - the role to check (supports both view and edit variants)
      Returns:
      true if the user has the role or admin privileges, false otherwise
    • maskEmail

      public static String maskEmail(String value)
      Masks email addresses in the input string for privacy protection.
      Parameters:
      value - the string that may contain email addresses
      Returns:
      string with email addresses replaced by masked pattern