Class Sanitizers

java.lang.Object
com.sodius.oslc.core.util.Sanitizers

public class Sanitizers extends Object
Provider functions to clean up Strings.
Since:
3.5.0
  • Field Details

    • NON_PRINTABLE_CHARACTERS

      public static final Function<String,String> NON_PRINTABLE_CHARACTERS
      Removes any character from the input String that cannot be printed, such as invisible control characters and unused code points. Does not filter out whitespace characters like tabs and line feeds.

      Logs a message listing the stripped out characters, when found and TRACE level is active for this class. You may combine with withContext(Function) to provide context information for this log message.

    • NON_BREAKING_SPACES

      public static final UnaryOperator<String> NON_BREAKING_SPACES
      Replaces non-breaking spaces by regular spaces in the input String. This shall be used when non-breaking spaces are not desired, for example when storing in the application labels associated to links.

      This sanitizer does not log any message when a non-breaking space is found, as such character is not considered unexpected nor illegal.

      Since:
      4.0.0
  • Method Details

    • withContext

      public static BiFunction<String,Supplier<String>,String> withContext(Function<String,String> sanitizer)
      Converts the given sanitizer function to a BiFunction, to provide context information when logging a trace message for characters that were removed.

      The first argument of the BiFunction is the value to sanitize. The second argument is to provide context information (e.g. "description field of project Power-Training"), to indicate from where the value comes in the application. This context is used to log an accurate message, when some characters are stripped out and TRACE level is active for this class. It helps an administrator to identify the offending artifact in the application and sanitize it there directly, if desired.

      Parameters:
      sanitizer - the sanitizing function provided by the Sanitizers class
      Returns:
      a BiFunction wrapping the given function
      Throws:
      NullPointerException - if sanitizer is null
      IllegalArgumentException - if sanitizer is not a function provided by the Sanitizers class
      Since:
      3.7.0