User Common Formatter
Last modified by Raphaël Jakse on 2026/03/18 17:39
Content
Reference
User Common Formatter provides a factory (UserFormatterFactory) to get a user formatter:
public class UserFormatterFactory
{
public static UserFormatter create() { /*...*/ }
public static UserFormatter create(Pattern charactersToClean) { /*...*/ }
public static UserFormatter create(Map<String, String> variables, Pattern charactersToClean) { /*...*/ }
}The returned UserFormatter object allows cleaning and formating user and group names and follows this interface:
public interface UserFormatter
{
/**
* @param name the user or group name to clean
* @return the user or group name where all forbidden characters are replaced with cleanReplacement
*/
String clean(String name);
/**
* Replace placeholders in a template with the provided values.
* Placeholders are of the shape:
* - ${key} - replaced with the value of the key
* - ${key.lowerCase} - replaced with the value of the key, lowercased
* - ${key._lowerCase} - replaced with the value of the key, lowercased
* - ${key.upperCase} - replaced with the value of the key, uppercased
* - ${key._upperCase} - replaced with the value of the key, uppercased
* - ${key._clean} - replaced with the value of the key, cleaned
* - ${key.clean.lowerCase} - replaced with the value of the key, cleaned and then lowercased
* - ${key._clean._lowerCase - replaced with the value of the key, cleaned and then lowercased
* - ${key.clean.upperCase} - replaced with the value of the key, cleaned and then uppercased
* - ${key._clean._upperCase} - replaced with the value of the key, cleaned and then uppercased
* where "cleaned" means that spaces and the following characters are replaced with cleanReplacement: .:,@,^/
* @param template the string containing placeholders to replace
* @return the template string in which placeholders are replaced with values from the variables map
*/
String format(String template);
/**
* @return the pattern to match characters to replace
*/
Pattern charactersToClean();
/**
* @param charactersToClean the pattern to match characters to replace
* @return a copy of this, with the given charactersToClean
*/
UserFormatter charactersToClean(Pattern charactersToClean);
/**
* @return the available values with which to replace the placeholders
*/
Map<String, String> variables();
/**
* @param variables the available values with which to replace the placeholders
* @return a copy of this, with the given variables
*/
UserFormatter variables(Map<String, String> variables);
/**
* @return what forbidden characters are replaced with
*/
String cleanReplacement();
/**
* @param cleanReplacement what forbidden characters are replaced with
* @return a copy of this, with the given cleanReplacement
*/
UserFormatter cleanReplacement(String cleanReplacement);
}