Package org.codehaus.plexus.util
Class LineOrientedInterpolatingReader
- java.lang.Object
-
- java.io.Reader
-
- java.io.FilterReader
-
- org.codehaus.plexus.util.LineOrientedInterpolatingReader
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,java.lang.Readable
public class LineOrientedInterpolatingReader extends java.io.FilterReader
A FilterReader which interpolates keyword values into a character stream. Keywords are recognized when enclosed between starting and ending delimiter strings. The keywords themselves, and their values, are fetched from a Map supplied to the constructor.When a possible keyword token is recognized (by detecting the starting and ending token delimiters):
- if the enclosed string is found in the keyword Map, the delimiters and the keyword are effectively replaced by the keyword's value;
- if the enclosed string is found in the keyword Map, but its value has zero length, then the token (delimiters and keyword) is effectively removed from the character stream;
- if the enclosed string is not found in the keyword Map, then no substitution is made; the token text is passed through unaltered.
A token in the incoming character stream may be escaped by prepending an "escape sequence" which is specified to the constructor. An escaped token is passed through as written, with the escape sequence removed. This allows things which would look like tokens to be read literally rather than interpolated.
- See Also:
InterpolationFilterReader
-
-
Field Summary
Fields Modifier and Type Field Description private static char
CARRIAGE_RETURN_CHAR
private java.util.Map<java.lang.String,java.lang.Object>
context
static java.lang.String
DEFAULT_END_DELIM
static java.lang.String
DEFAULT_ESCAPE_SEQ
static java.lang.String
DEFAULT_START_DELIM
private java.lang.String
endDelim
private java.lang.String
escapeSeq
private java.lang.String
line
private int
lineIdx
private int
minExpressionSize
private static char
NEWLINE_CHAR
private java.io.PushbackReader
pushbackReader
private Reflector
reflector
private java.lang.String
startDelim
-
Constructor Summary
Constructors Constructor Description LineOrientedInterpolatingReader(java.io.Reader reader, java.util.Map<java.lang.String,?> context)
Filters a Reader using the default escape sequence "\" and token delimiters "${", "}".LineOrientedInterpolatingReader(java.io.Reader reader, java.util.Map<java.lang.String,?> context, java.lang.String startDelim, java.lang.String endDelim)
Filters a Reader using the default escape sequence "\".LineOrientedInterpolatingReader(java.io.Reader reader, java.util.Map<java.lang.String,?> context, java.lang.String startDelim, java.lang.String endDelim, java.lang.String escapeSeq)
Construct an interpolating Reader, specifying token delimiters and the escape sequence.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.util.Map<java.lang.String,java.lang.Object>
evaluateExpressions(java.util.Set<java.lang.String> expressions)
private java.lang.String
findAndReplaceUnlessEscaped(java.lang.String rawLine, java.lang.String search, java.lang.String replace)
private int
findDelimiter(java.lang.String rawLine, java.lang.String delimiter, int lastPos)
private java.util.Set<java.lang.String>
parseForExpressions(java.lang.String rawLine)
int
read()
int
read(char[] cbuf, int off, int len)
private void
readAndInterpolateLine()
private java.lang.String
readLine()
private java.lang.String
replaceWithInterpolatedValues(java.lang.String rawLine, java.util.Map<java.lang.String,java.lang.Object> evaluatedExpressions)
long
skip(long n)
-
-
-
Field Detail
-
DEFAULT_START_DELIM
public static final java.lang.String DEFAULT_START_DELIM
- See Also:
- Constant Field Values
-
DEFAULT_END_DELIM
public static final java.lang.String DEFAULT_END_DELIM
- See Also:
- Constant Field Values
-
DEFAULT_ESCAPE_SEQ
public static final java.lang.String DEFAULT_ESCAPE_SEQ
- See Also:
- Constant Field Values
-
CARRIAGE_RETURN_CHAR
private static final char CARRIAGE_RETURN_CHAR
- See Also:
- Constant Field Values
-
NEWLINE_CHAR
private static final char NEWLINE_CHAR
- See Also:
- Constant Field Values
-
pushbackReader
private final java.io.PushbackReader pushbackReader
-
context
private final java.util.Map<java.lang.String,java.lang.Object> context
-
startDelim
private final java.lang.String startDelim
-
endDelim
private final java.lang.String endDelim
-
escapeSeq
private final java.lang.String escapeSeq
-
minExpressionSize
private final int minExpressionSize
-
reflector
private final Reflector reflector
-
lineIdx
private int lineIdx
-
line
private java.lang.String line
-
-
Constructor Detail
-
LineOrientedInterpolatingReader
public LineOrientedInterpolatingReader(java.io.Reader reader, java.util.Map<java.lang.String,?> context, java.lang.String startDelim, java.lang.String endDelim, java.lang.String escapeSeq)
Construct an interpolating Reader, specifying token delimiters and the escape sequence.- Parameters:
reader
- the Reader to be filtered.context
- keyword/value pairs for interpolation.startDelim
- character sequence which (possibly) begins a token.endDelim
- character sequence which ends a token.escapeSeq
- escape sequence
-
LineOrientedInterpolatingReader
public LineOrientedInterpolatingReader(java.io.Reader reader, java.util.Map<java.lang.String,?> context, java.lang.String startDelim, java.lang.String endDelim)
Filters a Reader using the default escape sequence "\".- Parameters:
reader
- the Reader to be filtered.context
- keyword/value pairs for interpolation.startDelim
- the character sequence which (possibly) begins a token.endDelim
- the character sequence which ends a token.
-
LineOrientedInterpolatingReader
public LineOrientedInterpolatingReader(java.io.Reader reader, java.util.Map<java.lang.String,?> context)
Filters a Reader using the default escape sequence "\" and token delimiters "${", "}".- Parameters:
reader
- the Reader to be filtered.context
- keyword/value pairs for interpolation.
-
-
Method Detail
-
read
public int read() throws java.io.IOException
- Overrides:
read
in classjava.io.FilterReader
- Throws:
java.io.IOException
-
read
public int read(char[] cbuf, int off, int len) throws java.io.IOException
- Overrides:
read
in classjava.io.FilterReader
- Throws:
java.io.IOException
-
skip
public long skip(long n) throws java.io.IOException
- Overrides:
skip
in classjava.io.FilterReader
- Throws:
java.io.IOException
-
readAndInterpolateLine
private void readAndInterpolateLine() throws java.io.IOException
- Throws:
java.io.IOException
-
readLine
private java.lang.String readLine() throws java.io.IOException
- Throws:
java.io.IOException
-
replaceWithInterpolatedValues
private java.lang.String replaceWithInterpolatedValues(java.lang.String rawLine, java.util.Map<java.lang.String,java.lang.Object> evaluatedExpressions)
-
evaluateExpressions
private java.util.Map<java.lang.String,java.lang.Object> evaluateExpressions(java.util.Set<java.lang.String> expressions)
-
parseForExpressions
private java.util.Set<java.lang.String> parseForExpressions(java.lang.String rawLine)
-
findDelimiter
private int findDelimiter(java.lang.String rawLine, java.lang.String delimiter, int lastPos)
-
findAndReplaceUnlessEscaped
private java.lang.String findAndReplaceUnlessEscaped(java.lang.String rawLine, java.lang.String search, java.lang.String replace)
-
-