Package org.apache.fop.util.text
Class AdvancedMessageFormat
java.lang.Object
org.apache.fop.util.text.AdvancedMessageFormat
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
static interface
Implementations of this interface do some computation based on the message parameters given to it.private static class
static interface
Implementations of this interface format certain objects to strings.static interface
Represents a message template part.static interface
Implementations of this interface parse a field part and return message parts.private static class
private static class
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final Pattern
Regex that matches "," but not "\," (escaped comma)private static final Map<Object,
AdvancedMessageFormat.Function> private static final List<AdvancedMessageFormat.ObjectFormatter>
private static final Map<String,
AdvancedMessageFormat.PartFactory> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionFormats a message with the given parameters.void
format
(Map<String, Object> params, StringBuffer target) Formats a message with the given parameters.static void
formatObject
(Object obj, StringBuffer target) Formats an object to a string and writes the result to a string buffer.private static AdvancedMessageFormat.Function
getFunction
(String functionName) private AdvancedMessageFormat.Part
parseField
(String field) private int
parseInnerPattern
(CharSequence pattern, AdvancedMessageFormat.CompositePart parent, StringBuffer sb, int start) private void
parsePattern
(CharSequence pattern) (package private) static String
unescapeComma
(String string)
-
Field Details
-
COMMA_SEPARATOR_REGEX
Regex that matches "," but not "\," (escaped comma) -
PART_FACTORIES
-
OBJECT_FORMATTERS
-
FUNCTIONS
-
rootPart
-
-
Constructor Details
-
AdvancedMessageFormat
Construct a new message format.- Parameters:
pattern
- the message format pattern.
-
-
Method Details
-
parsePattern
-
parseInnerPattern
private int parseInnerPattern(CharSequence pattern, AdvancedMessageFormat.CompositePart parent, StringBuffer sb, int start) -
parseField
-
getFunction
-
format
Formats a message with the given parameters.- Parameters:
params
- a Map of named parameters (Contents: <String, Object>)- Returns:
- the formatted message
-
format
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
Formats an object to a string and writes the result to a string buffer. This method usually uses the object'stoString()
method unless there is anAdvancedMessageFormat.ObjectFormatter
that supports the object.AdvancedMessageFormat.ObjectFormatter
s are registered through the service provider mechanism defined by the JAR specification.- Parameters:
obj
- the object to be formattedtarget
- the target string buffer
-
unescapeComma
-