org.x4juli.formatter.pattern
Class PatternParser

java.lang.Object
  extended byorg.x4juli.global.components.AbstractComponent
      extended byorg.x4juli.formatter.pattern.PatternParser
All Implemented Interfaces:
Component

public final class PatternParser
extends AbstractComponent

Most of the work of the PatternFormatter class is delegated to the PatternParser class.

It is this class that parses conversion patterns and creates a chained list of PatternConverters.

Logging API as a whole was originally done for Apache log4j. Juli is a port of main parts of that to complete the Java Logging APIs. All credits for initial idea, design, implementation, documentation belong to the log4j crew. This file was originally published by James P. Cakalic, Ceki Gülcü, Anders Kristensen, Paul Smith, Curt Arnold. Please use exclusively the appropriate mailing lists for questions, remarks and contribution.

Since:
0.5
Author:
Boris Unckel

Nested Class Summary
private static class PatternParser.ReadOnlyMap
          The class wraps another Map but throws exceptions on any attempt to modify the map.
 
Field Summary
private static int CONVERTER_STATE
          In converter name state.
private static int DOT_STATE
          Dot state.
private static char ESCAPE_CHAR
          Escape character for format specifier.
private static java.util.Map FILENAME_PATTERN_RULES
          Standard format specifiers for rolling file appenders.
private static PatternParser INSTANCE
           
private static int LITERAL_STATE
          Literal state.
private static int MAX_STATE
          Max state.
private static int MIN_STATE
          Min state.
private static java.util.Map PATTERN_LAYOUT_RULES
          Standard format specifiers for PatternLayout.
 
Fields inherited from class org.x4juli.global.components.AbstractComponent
manager, repository
 
Constructor Summary
private PatternParser()
          Private constructor.
 
Method Summary
private static PatternConverter createConverter(java.lang.String converterId, java.lang.StringBuffer currentLiteral, java.util.Map converterRegistry, java.util.Map rules, java.util.List options)
          Creates a new PatternConverter.
private  PatternConverter doCcreateConverter(java.lang.String converterId, java.lang.StringBuffer currentLiteral, java.util.Map converterRegistry, java.util.Map rules, java.util.List options)
          Creates a new PatternConverter.
private  int doFinalizeConverter(char c, java.lang.String pattern, int j, java.lang.StringBuffer currentLiteral, FormattingInfo formattingInfo, java.util.Map converterRegistry, java.util.Map rules, java.util.List patternConverters, java.util.List formattingInfos)
          Processes a format specifier sequence.
private  void doParse(java.lang.String pattern, java.util.List patternConverters, java.util.List formattingInfos, java.util.Map converterRegistry, java.util.Map rules)
          Parse a format specifier.
private  int extractConverter(char lastChar, java.lang.String pattern, int j, java.lang.StringBuffer convBuf, java.lang.StringBuffer currentLiteral)
          Extract the converter identifier found at position i.
private static int extractOptions(java.lang.String pattern, int j, java.util.List options)
          Extract options.
private static int finalizeConverter(char c, java.lang.String pattern, int i, java.lang.StringBuffer currentLiteral, FormattingInfo formattingInfo, java.util.Map converterRegistry, java.util.Map rules, java.util.List patternConverters, java.util.List formattingInfos)
          Processes a format specifier sequence.
static java.util.Map getFileNamePatternRules()
          Get standard format specifiers for rolling file appender file specification.
 MessageProperties getMessageProperties()
          Specifiy Properties for the component. Default Implementation returns null.
static java.util.Map getPatternLayoutRules()
          Get standard format specifiers for PatternLayout.
static void parse(java.lang.String pattern, java.util.List patternConverters, java.util.List formattingInfos, java.util.Map converterRegistry, java.util.Map rules)
          Parse a format specifier.
 
Methods inherited from class org.x4juli.global.components.AbstractComponent
getLogger, getLoggerRepository, getNonFloodingLogger, getProperty, getProperty, getProperty, getProperty, resetErrorCount, setObjectStore
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ESCAPE_CHAR

private static final char ESCAPE_CHAR
Escape character for format specifier.

See Also:
Constant Field Values

LITERAL_STATE

private static final int LITERAL_STATE
Literal state.

See Also:
Constant Field Values

CONVERTER_STATE

private static final int CONVERTER_STATE
In converter name state.

See Also:
Constant Field Values

DOT_STATE

private static final int DOT_STATE
Dot state.

See Also:
Constant Field Values

MIN_STATE

private static final int MIN_STATE
Min state.

See Also:
Constant Field Values

MAX_STATE

private static final int MAX_STATE
Max state.

See Also:
Constant Field Values

PATTERN_LAYOUT_RULES

private static final java.util.Map PATTERN_LAYOUT_RULES
Standard format specifiers for PatternLayout.


FILENAME_PATTERN_RULES

private static final java.util.Map FILENAME_PATTERN_RULES
Standard format specifiers for rolling file appenders.


INSTANCE

private static final PatternParser INSTANCE
Constructor Detail

PatternParser

private PatternParser()
Private constructor.

Method Detail

getPatternLayoutRules

public static java.util.Map getPatternLayoutRules()
Get standard format specifiers for PatternLayout.

Returns:
read-only map of format converter classes keyed by format specifier strings.

getFileNamePatternRules

public static java.util.Map getFileNamePatternRules()
Get standard format specifiers for rolling file appender file specification.

Returns:
read-only map of format converter classes keyed by format specifier strings.

parse

public static void parse(java.lang.String pattern,
                         java.util.List patternConverters,
                         java.util.List formattingInfos,
                         java.util.Map converterRegistry,
                         java.util.Map rules)
Parse a format specifier.

Parameters:
pattern - pattern to parse.
patternConverters - list to receive pattern converters.
formattingInfos - list to receive field specifiers corresponding to pattern converters.
converterRegistry - map of user-supported pattern converters keyed by format specifier, may be null.
rules - map of stock pattern converters keyed by format specifier.

doParse

private void doParse(java.lang.String pattern,
                     java.util.List patternConverters,
                     java.util.List formattingInfos,
                     java.util.Map converterRegistry,
                     java.util.Map rules)
Parse a format specifier.

Parameters:
pattern - pattern to parse.
patternConverters - list to receive pattern converters.
formattingInfos - list to receive field specifiers corresponding to pattern converters.
converterRegistry - map of user-supported pattern converters keyed by format specifier, may be null.
rules - map of stock pattern converters keyed by format specifier.

getMessageProperties

public MessageProperties getMessageProperties()
Specifiy Properties for the component. Default Implementation returns null.

Specified by:
getMessageProperties in interface Component
Overrides:
getMessageProperties in class AbstractComponent
Since:

createConverter

private static PatternConverter createConverter(java.lang.String converterId,
                                                java.lang.StringBuffer currentLiteral,
                                                java.util.Map converterRegistry,
                                                java.util.Map rules,
                                                java.util.List options)
Creates a new PatternConverter.

Parameters:
converterId - converterId.
currentLiteral - literal to be used if converter is unrecognized or following converter if converterId contains extra characters.
converterRegistry - map of user-supported pattern converters keyed by format specifier, may be null.
rules - map of stock pattern converters keyed by format specifier.
options - converter options.
Returns:
converter or null.

doCcreateConverter

private PatternConverter doCcreateConverter(java.lang.String converterId,
                                            java.lang.StringBuffer currentLiteral,
                                            java.util.Map converterRegistry,
                                            java.util.Map rules,
                                            java.util.List options)
Creates a new PatternConverter.

Parameters:
converterId - converterId.
currentLiteral - literal to be used if converter is unrecognized or following converter if converterId contains extra characters.
converterRegistry - map of user-supported pattern converters keyed by format specifier, may be null.
rules - map of stock pattern converters keyed by format specifier.
options - converter options.
Returns:
converter or null.

extractConverter

private int extractConverter(char lastChar,
                             java.lang.String pattern,
                             int j,
                             java.lang.StringBuffer convBuf,
                             java.lang.StringBuffer currentLiteral)
Extract the converter identifier found at position i. 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.

Parameters:
lastChar - last processed character.
pattern - format string.
j - current index into pattern format.
convBuf - buffer to receive conversion specifier.
currentLiteral - literal to be output in case format specifier in unrecognized.
Returns:
position in pattern after converter.
Since:
0.5

extractOptions

private static int extractOptions(java.lang.String pattern,
                                  int j,
                                  java.util.List options)
Extract options.

Parameters:
pattern - conversion pattern.
j - start of options.
options - array to receive extracted options
Returns:
position in pattern after options.
Since:
0.5

finalizeConverter

private static int finalizeConverter(char c,
                                     java.lang.String pattern,
                                     int i,
                                     java.lang.StringBuffer currentLiteral,
                                     FormattingInfo formattingInfo,
                                     java.util.Map converterRegistry,
                                     java.util.Map rules,
                                     java.util.List patternConverters,
                                     java.util.List formattingInfos)
Processes a format specifier sequence.

Parameters:
c - initial character of format specifier.
pattern - conversion pattern
i - current position in conversion pattern.
currentLiteral - current literal.
formattingInfo - current field specifier.
converterRegistry - map of user-provided pattern converters keyed by format specifier, may be null.
rules - map of stock pattern converters keyed by format specifier.
patternConverters - list to receive parsed pattern converter.
formattingInfos - list to receive corresponding field specifier.
Returns:
position after format specifier sequence.

doFinalizeConverter

private int doFinalizeConverter(char c,
                                java.lang.String pattern,
                                int j,
                                java.lang.StringBuffer currentLiteral,
                                FormattingInfo formattingInfo,
                                java.util.Map converterRegistry,
                                java.util.Map rules,
                                java.util.List patternConverters,
                                java.util.List formattingInfos)
Processes a format specifier sequence.

Parameters:
c - initial character of format specifier.
pattern - conversion pattern
j - current position in conversion pattern.
currentLiteral - current literal.
formattingInfo - current field specifier.
converterRegistry - map of user-provided pattern converters keyed by format specifier, may be null.
rules - map of stock pattern converters keyed by format specifier.
patternConverters - list to receive parsed pattern converter.
formattingInfos - list to receive corresponding field specifier.
Returns:
position after format specifier sequence.


${license_html}