public final class PatternParser
extends java.lang.Object
PatternLayout
class is delegated to the
PatternParser class.
It is this class that parses conversion patterns and creates a chained list of PatternConverters
.
Modifier and Type | Class and Description |
---|---|
private static class |
PatternParser.ParserState
The states the parser can be in while parsing the pattern.
|
Modifier and Type | Field and Description |
---|---|
private static int |
BUF_SIZE |
private Configuration |
config |
private java.util.Map<java.lang.String,java.lang.Class<PatternConverter>> |
converterRules |
private static int |
DECIMAL |
(package private) static java.lang.String |
DISABLE_ANSI |
private static char |
ESCAPE_CHAR
Escape character for format specifier.
|
private static Logger |
LOGGER |
(package private) static java.lang.String |
NO_CONSOLE_NO_ANSI |
Constructor and Description |
---|
PatternParser(Configuration config,
java.lang.String converterKey,
java.lang.Class<?> expected)
Constructor.
|
PatternParser(Configuration config,
java.lang.String converterKey,
java.lang.Class<?> expectedClass,
java.lang.Class<?> filterClass)
Constructor.
|
PatternParser(java.lang.String converterKey)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
private PatternConverter |
createConverter(java.lang.String converterId,
java.lang.StringBuilder currentLiteral,
java.util.Map<java.lang.String,java.lang.Class<PatternConverter>> rules,
java.util.List<java.lang.String> options,
boolean disableAnsi,
boolean noConsoleNoAnsi)
Creates a new PatternConverter.
|
private static int |
extractConverter(char lastChar,
java.lang.String pattern,
int start,
java.lang.StringBuilder convBuf,
java.lang.StringBuilder currentLiteral)
Extracts the converter identifier found at the given start position.
|
private static int |
extractOptions(java.lang.String pattern,
int start,
java.util.List<java.lang.String> options)
Extract options.
|
private int |
finalizeConverter(char c,
java.lang.String pattern,
int start,
java.lang.StringBuilder currentLiteral,
FormattingInfo formattingInfo,
java.util.Map<java.lang.String,java.lang.Class<PatternConverter>> rules,
java.util.List<PatternConverter> patternConverters,
java.util.List<FormattingInfo> formattingInfos,
boolean disableAnsi,
boolean noConsoleNoAnsi,
boolean convertBackslashes)
Processes a format specifier sequence.
|
java.util.List<PatternFormatter> |
parse(java.lang.String pattern) |
java.util.List<PatternFormatter> |
parse(java.lang.String pattern,
boolean alwaysWriteExceptions,
boolean noConsoleNoAnsi) |
java.util.List<PatternFormatter> |
parse(java.lang.String pattern,
boolean alwaysWriteExceptions,
boolean disableAnsi,
boolean noConsoleNoAnsi) |
void |
parse(java.lang.String pattern,
java.util.List<PatternConverter> patternConverters,
java.util.List<FormattingInfo> formattingInfos,
boolean noConsoleNoAnsi,
boolean convertBackslashes)
Parse a format specifier.
|
void |
parse(java.lang.String pattern,
java.util.List<PatternConverter> patternConverters,
java.util.List<FormattingInfo> formattingInfos,
boolean disableAnsi,
boolean noConsoleNoAnsi,
boolean convertBackslashes)
Parse a format specifier.
|
static final java.lang.String DISABLE_ANSI
static final java.lang.String NO_CONSOLE_NO_ANSI
private static final char ESCAPE_CHAR
private static final Logger LOGGER
private static final int BUF_SIZE
private static final int DECIMAL
private final Configuration config
private final java.util.Map<java.lang.String,java.lang.Class<PatternConverter>> converterRules
public PatternParser(java.lang.String converterKey)
converterKey
- The type of converters that will be used.public PatternParser(Configuration config, java.lang.String converterKey, java.lang.Class<?> expected)
config
- The current Configuration.converterKey
- The key to lookup the converters.expected
- The expected base Class of each Converter.public PatternParser(Configuration config, java.lang.String converterKey, java.lang.Class<?> expectedClass, java.lang.Class<?> filterClass)
config
- The current Configuration.converterKey
- The key to lookup the converters.expectedClass
- The expected base Class of each Converter.filterClass
- Filter the returned plugins after calling the plugin manager.public java.util.List<PatternFormatter> parse(java.lang.String pattern)
public java.util.List<PatternFormatter> parse(java.lang.String pattern, boolean alwaysWriteExceptions, boolean noConsoleNoAnsi)
public java.util.List<PatternFormatter> parse(java.lang.String pattern, boolean alwaysWriteExceptions, boolean disableAnsi, boolean noConsoleNoAnsi)
private static int extractConverter(char lastChar, java.lang.String pattern, int start, java.lang.StringBuilder convBuf, java.lang.StringBuilder currentLiteral)
After this function returns, the variable i will point to the first char after the end of the converter identifier.
If i points to a char which is not a character acceptable at the start of a unicode identifier, the value null is returned.
lastChar
- last processed character.pattern
- format string.start
- current index into pattern format.convBuf
- buffer to receive conversion specifier.currentLiteral
- literal to be output in case format specifier in unrecognized.private static int extractOptions(java.lang.String pattern, int start, java.util.List<java.lang.String> options)
pattern
- conversion pattern.start
- start of options.options
- array to receive extracted optionspublic void parse(java.lang.String pattern, java.util.List<PatternConverter> patternConverters, java.util.List<FormattingInfo> formattingInfos, boolean noConsoleNoAnsi, boolean convertBackslashes)
pattern
- pattern to parse.patternConverters
- list to receive pattern converters.formattingInfos
- list to receive field specifiers corresponding to pattern converters.noConsoleNoAnsi
- do not do not output ANSI escape codes if System.console()
convertBackslashes
- if true
, backslash characters are treated as escape characters and character
sequences like "\" followed by "t" (backslash+t) are converted to special characters like '\t' (tab).public void parse(java.lang.String pattern, java.util.List<PatternConverter> patternConverters, java.util.List<FormattingInfo> formattingInfos, boolean disableAnsi, boolean noConsoleNoAnsi, boolean convertBackslashes)
pattern
- pattern to parse.patternConverters
- list to receive pattern converters.formattingInfos
- list to receive field specifiers corresponding to pattern converters.disableAnsi
- do not output ANSI escape codesnoConsoleNoAnsi
- do not do not output ANSI escape codes if System.console()
convertBackslashes
- if true
, backslash characters are treated as escape characters and character
sequences like "\" followed by "t" (backslash+t) are converted to special characters like '\t' (tab).private PatternConverter createConverter(java.lang.String converterId, java.lang.StringBuilder currentLiteral, java.util.Map<java.lang.String,java.lang.Class<PatternConverter>> rules, java.util.List<java.lang.String> options, boolean disableAnsi, boolean noConsoleNoAnsi)
converterId
- converterId.currentLiteral
- literal to be used if converter is unrecognized or following converter if converterId contains extra
characters.rules
- map of stock pattern converters keyed by format specifier.options
- converter options.disableAnsi
- do not output ANSI escape codesnoConsoleNoAnsi
- do not do not output ANSI escape codes if System.console()
private int finalizeConverter(char c, java.lang.String pattern, int start, java.lang.StringBuilder currentLiteral, FormattingInfo formattingInfo, java.util.Map<java.lang.String,java.lang.Class<PatternConverter>> rules, java.util.List<PatternConverter> patternConverters, java.util.List<FormattingInfo> formattingInfos, boolean disableAnsi, boolean noConsoleNoAnsi, boolean convertBackslashes)
c
- initial character of format specifier.pattern
- conversion patternstart
- current position in conversion pattern.currentLiteral
- current literal.formattingInfo
- current field specifier.rules
- map of stock pattern converters keyed by format specifier.patternConverters
- list to receive parsed pattern converter.formattingInfos
- list to receive corresponding field specifier.disableAnsi
- do not output ANSI escape codesnoConsoleNoAnsi
- do not do not output ANSI escape codes if System.console()
convertBackslashes
- if true
, backslash characters are treated as escape characters and character
sequences like "\" followed by "t" (backslash+t) are converted to special characters like '\t' (tab).