Package org.apache.fop.util.text
Class AdvancedMessageFormat
- java.lang.Object
-
- org.apache.fop.util.text.AdvancedMessageFormat
-
public class AdvancedMessageFormat extends java.lang.Object
Formats messages based on a template and with a set of named parameters. This is similar toMessageFormat
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 Classes Modifier and Type Class Description private static class
AdvancedMessageFormat.CompositePart
static interface
AdvancedMessageFormat.Function
Implementations of this interface do some computation based on the message parameters given to it.private static class
AdvancedMessageFormat.FunctionPart
static interface
AdvancedMessageFormat.ObjectFormatter
Implementations of this interface format certain objects to strings.static interface
AdvancedMessageFormat.Part
Represents a message template part.static interface
AdvancedMessageFormat.PartFactory
Implementations of this interface parse a field part and return message parts.private static class
AdvancedMessageFormat.SimpleFieldPart
private static class
AdvancedMessageFormat.TextPart
-
Field Summary
Fields Modifier and Type Field Description (package private) static java.util.regex.Pattern
COMMA_SEPARATOR_REGEX
Regex that matches "," but not "\," (escaped comma)private static java.util.Map<java.lang.Object,AdvancedMessageFormat.Function>
FUNCTIONS
private static java.util.List<AdvancedMessageFormat.ObjectFormatter>
OBJECT_FORMATTERS
private static java.util.Map<java.lang.String,AdvancedMessageFormat.PartFactory>
PART_FACTORIES
private AdvancedMessageFormat.CompositePart
rootPart
-
Constructor Summary
Constructors Constructor Description AdvancedMessageFormat(java.lang.CharSequence pattern)
Construct a new message format.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
format(java.util.Map<java.lang.String,java.lang.Object> params)
Formats a message with the given parameters.void
format(java.util.Map<java.lang.String,java.lang.Object> params, java.lang.StringBuffer target)
Formats a message with the given parameters.static void
formatObject(java.lang.Object obj, java.lang.StringBuffer target)
Formats an object to a string and writes the result to a string buffer.private static AdvancedMessageFormat.Function
getFunction(java.lang.String functionName)
private AdvancedMessageFormat.Part
parseField(java.lang.String field)
private int
parseInnerPattern(java.lang.CharSequence pattern, AdvancedMessageFormat.CompositePart parent, java.lang.StringBuffer sb, int start)
private void
parsePattern(java.lang.CharSequence pattern)
(package private) static java.lang.String
unescapeComma(java.lang.String string)
-
-
-
Field Detail
-
COMMA_SEPARATOR_REGEX
static final java.util.regex.Pattern COMMA_SEPARATOR_REGEX
Regex that matches "," but not "\," (escaped comma)
-
PART_FACTORIES
private static final java.util.Map<java.lang.String,AdvancedMessageFormat.PartFactory> PART_FACTORIES
-
OBJECT_FORMATTERS
private static final java.util.List<AdvancedMessageFormat.ObjectFormatter> OBJECT_FORMATTERS
-
FUNCTIONS
private static final java.util.Map<java.lang.Object,AdvancedMessageFormat.Function> FUNCTIONS
-
rootPart
private AdvancedMessageFormat.CompositePart rootPart
-
-
Method Detail
-
parsePattern
private void parsePattern(java.lang.CharSequence pattern)
-
parseInnerPattern
private int parseInnerPattern(java.lang.CharSequence pattern, AdvancedMessageFormat.CompositePart parent, java.lang.StringBuffer sb, int start)
-
parseField
private AdvancedMessageFormat.Part parseField(java.lang.String field)
-
getFunction
private static AdvancedMessageFormat.Function getFunction(java.lang.String functionName)
-
format
public java.lang.String format(java.util.Map<java.lang.String,java.lang.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(java.util.Map<java.lang.String,java.lang.Object> params, java.lang.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(java.lang.Object obj, java.lang.StringBuffer target)
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
static java.lang.String unescapeComma(java.lang.String string)
-
-