Package org.apache.fop.utils.text
Class AdvancedMessageFormat
- java.lang.Object
-
- org.apache.fop.utils.text.AdvancedMessageFormat
-
public class AdvancedMessageFormat extends java.lang.ObjectFormats messages based on a template and with a set of named parameters. This is similar toMessageFormatbut 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 classAdvancedMessageFormat.CompositePartstatic interfaceAdvancedMessageFormat.FunctionImplementations of this interface do some computation based on the message parameters given to it.private static classAdvancedMessageFormat.FunctionPartstatic interfaceAdvancedMessageFormat.ObjectFormatterImplementations of this interface format certain objects to strings.static interfaceAdvancedMessageFormat.PartRepresents a message template part.static interfaceAdvancedMessageFormat.PartFactoryImplementations of this interface parse a field part and return message parts.private static classAdvancedMessageFormat.SimpleFieldPartprivate static classAdvancedMessageFormat.TextPart
-
Field Summary
Fields Modifier and Type Field Description static java.util.regex.PatternCOMMA_SEPARATOR_REGEXRegex that matches "," but not "\," (escaped comma)private static java.util.Map<java.lang.Object,AdvancedMessageFormat.Function>FUNCTIONSprivate static java.util.List<AdvancedMessageFormat.ObjectFormatter>OBJECT_FORMATTERSprivate static java.util.Map<java.lang.String,AdvancedMessageFormat.PartFactory>PART_FACTORIESprivate AdvancedMessageFormat.CompositePartrootPart
-
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.Stringformat(java.util.Map<java.lang.String,java.lang.Object> params)Formats a message with the given parameters.voidformat(java.util.Map<java.lang.String,java.lang.Object> params, java.lang.StringBuffer target)Formats a message with the given parameters.static voidformatObject(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.FunctiongetFunction(java.lang.String functionName)private AdvancedMessageFormat.PartparseField(java.lang.String field)private intparseInnerPattern(java.lang.CharSequence pattern, AdvancedMessageFormat.CompositePart parent, java.lang.StringBuffer sb, int start)private voidparsePattern(java.lang.CharSequence pattern)static java.lang.StringunescapeComma(java.lang.String string)
-
-
-
Field Detail
-
COMMA_SEPARATOR_REGEX
public 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.ObjectFormatterthat supports the object.AdvancedMessageFormat.ObjectFormatters are registered through the service provider mechanism defined by the JAR specification.- Parameters:
obj- the object to be formattedtarget- the target string buffer
-
unescapeComma
public static java.lang.String unescapeComma(java.lang.String string)
-
-