Package COM.activesw.api.client
Class BrokerFormat
java.lang.Object
COM.activesw.api.client.BrokerFormat
String formatting functions.
The string can reference values from an Object (currently only supports
BrokerEvent). See also BrokerEvent.toFormattedString(...).
Event fields can be referenced in the format string by a $ character
followed by the fully qualified event field name. The name is terminated
by the first space character following the $ character, or it
can be enclosed in curly braces:
$foo ${foo} $struct.sequence[3].field a${foo}b
Optionally, a format specifier can be appended to each field name
with a ':':
$foo:x ${foo:x}
The following formatting options are supported:
:s - sinqle quoting. Enclose the value in <'>, and escape single quotes in the value with a <\> :d - double quotes. Enclose the value in <">, and escape double quotes in the value with <\> :q - SQL quoting. Like :s, but escape with <'> :v - Bind variable mode. Primarly intended for use with databases, Replace the reference with a proper bind variable placeholder. Default is Oracle style, as in :v0, :v1, :v2. Can be changed to use <?> with the setFormatMode() call. :c - numeric. Use value as numeric value. If value is non-numeric, any non-numeric portions will be discarded. I.e. if the value is "123X", only "123" will be used in the result. :###x - Specify a minimum field length together with one of the options above, i.e. <:5d> will print a value of'\' can be used to escape the following character outside of variable names. To get a '$' character into the result, escape it with a '\', i.e. \\\a\$foo will be returned as \a$fooas <'AB '>.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
assemble
(BrokerEvent event, Vector tokens) Assemble a string from the tokens, replacing references with values from the event.static String
assemble
(BrokerEvent event, Vector tokens, Locale locale) Assemble a string from the tokens, replacing references with values from the event.static String
Assemble a string from the tokens, without an event reference.format()
Return formatted string, without event data.format
(BrokerEvent event) Return formatted string, usingfor resolving all event field references. static String
format
(BrokerEvent event, String format_string) Format an event using a format string.static String
format
(BrokerEvent event, String format_string, Locale locale) Format an event using a format string.format
(BrokerEvent event, Locale locale) Return formatted string, usingfor resolving all event field references. formatBindVariable
(int index, StringBuffer place_holder_name) Returns the name of the bind variable at tokenin . int
Returns the number of tokens.getTokenValue
(int t) Return the value of a token.boolean
isReferenceToken
(int t) Checks if a token is a reference to an event field.static Vector<COM.activesw.api.client.BrokerFormatToken>
Take a string, and break it up into a list of tokens.static boolean
setFormatMode
(String format_option, String mode) set the mode for a format option (see above).
-
Field Details
-
modeV
protected static char modeV
-
-
Constructor Details
-
BrokerFormat
Constructor. Parse the format string into a series of tokens- Parameters:
format_string
-
-
-
Method Details
-
getTokenCount
public int getTokenCount()Returns the number of tokens.- Returns:
- number of tokens
-
isReferenceToken
public boolean isReferenceToken(int t) Checks if a token is a reference to an event field.- Parameters:
t
- token number- Returns:
- true if token references an event field, or false if it is a fixed string
-
getTokenValue
Return the value of a token. The value is either a fixed string, or the name of an event field (see isReferenceToken()).- Parameters:
t
- token number- Returns:
- value of the token
-
format
Return formatted string, without event data. Event field values will be formatted for the US English locale.- Returns:
- formatted string
-
format
Return formatted string, usingfor resolving all event field references. Event field values will be formatted for the US English locale. - Parameters:
event
- the event for the data- Returns:
- the formatted string
- Throws:
BrokerException
-
format
Return formatted string, usingfor resolving all event field references. Event field values will be formatted for the specified locale. - Parameters:
event
- the event for the datalocale
- determines format of field value output- Returns:
- the formatted string
- Throws:
BrokerException
-
setFormatMode
set the mode for a format option (see above). These options can currently be configured: v - ':' (as in :v0, :v1) or '?' Date formatting can be affected by setting the mode to one of these: - BrokerDate -> use BrokerDate.toString() - DateFormat -> Use java.text.DateFormat to format dates Returns true if a valid mode was set. Returns false if format_option or mode are not valid values. -
format
Format an event using a format string. Equivalent toformat(event, format_string, java.util.Locale.US)
- Parameters:
event
- the event for the dataformat_string
- the format string- Returns:
- the formatted string
- Throws:
BrokerException
-
format
public static String format(BrokerEvent event, String format_string, Locale locale) throws BrokerException Format an event using a format string. Event field values will be formatted for the specified locale.- Parameters:
event
- the event for the dataformat_string
- the format stringlocale
- determines formatting of field values- Returns:
- the formatted string
- Throws:
BrokerException
-
preparse
Take a string, and break it up into a list of tokens. Deprecated - consider using new BrokerFormat(format_string) instead. Returns null if format_string is null. -
assemble
Assemble a string from the tokens, replacing references with values from the event. Field values will be formatted for the US English locale. Equivalent toassemble(event,tokens,java.util.Locale.US)
Deprecated - consider using format() method instead- Throws:
BrokerFieldNotFoundException
- If a field is referenced in the format string that is not in the event.BrokerInvalidTypeException
- If a field is not of a type supported by the string formatter.BrokerException
-
assemble
public static String assemble(BrokerEvent event, Vector tokens, Locale locale) throws BrokerException Assemble a string from the tokens, replacing references with values from the event. Field values will be formatted for the specified locale. Deprecated - consider using format() method instead- Throws:
BrokerFieldNotFoundException
- If a field is referenced in the format string that is not in the event.BrokerInvalidTypeException
- If a field is not of a type supported by the string formatter.BrokerException
-
assemble
Assemble a string from the tokens, without an event reference. Event field values will be formatted for the US English locale. Deprecated - consider using format() method instead -
formatBindVariable
Returns the name of the bind variable at tokenin . Returns null if there is no bind variable at that position, or if the index is not valid. If place_holder_name is not null, it will be set to a string that represents the place holder in the statement (i.e. ":v0" or "?").
-