Class AdvancedMessageFormat

java.lang.Object
org.docx4j.org.apache.fop.util.text.AdvancedMessageFormat

public class AdvancedMessageFormat extends Object
Formats messages based on a template and with a set of named parameters. This is similar to MessageFormat but uses named parameters and supports conditional sub-groups.

Example:

Missing field "{fieldName}"[ at location: {location}]!

  • Curly brackets ("{}") are used for fields.
  • Square brackets ("[]") are used to delimit conditional sub-groups. A sub-group is conditional when all fields inside the sub-group have a null value. In the case, everything between the brackets is skipped.
  • Constructor Details

    • AdvancedMessageFormat

      public AdvancedMessageFormat(CharSequence pattern)
      Construct a new message format.
      Parameters:
      pattern - the message format pattern.
  • Method Details

    • format

      public String format(Map<String,Object> params)
      Formats a message with the given parameters.
      Parameters:
      params - a Map of named parameters (Contents: <String, Object>)
      Returns:
      the formatted message
    • format

      public void format(Map<String,Object> params, StringBuffer target)
      Formats a message with the given parameters.
      Parameters:
      params - a Map of named parameters (Contents: <String, Object>)
      target - the target StringBuffer to write the formatted message to
    • formatObject

      public static void formatObject(Object obj, StringBuffer target)
      Formats an object to a string and writes the result to a string buffer. This method usually uses the object's toString() method unless there is an AdvancedMessageFormat.ObjectFormatter that supports the object. AdvancedMessageFormat.ObjectFormatters are registered through the service provider mechanism defined by the JAR specification.
      Parameters:
      obj - the object to be formatted
      target - the target string buffer