org.tinyjee.maven.dim.sources
Class LineRangeSnippetSelector
java.lang.Object
org.tinyjee.maven.dim.sources.AbstractSnippetSelector
org.tinyjee.maven.dim.sources.LineRangeSnippetSelector
- All Implemented Interfaces:
- SnippetSelector
public class LineRangeSnippetSelector
- extends AbstractSnippetSelector
Implements a selector based on a line range definition to select snippets using the expression prefix "lines:".
The primary purpose of this selector is to cut-off content that should not be in the output (e.g. using !lines:100+
).
Example expressions:
- '
lines:50-100
' (from 50 to 100)
- '
lines:50+
' (from 50 to EOF)
- '
lines:50-
' (from 1 to 50)
- '
lines:1,3,10-12,1000+
' (selects 1, 3, 10, 11, 12 and 1000 to EOF)
- Author:
- Juergen_Kellerer, 2011-10-16
LineRangeSnippetSelector
public LineRangeSnippetSelector()
LineRangeSnippetSelector
protected LineRangeSnippetSelector(String expressionPrefix)
selectSnippets
public Iterator<Integer> selectSnippets(String expression,
URL contentUrl,
LineNumberReader content,
Map<String,Object> macroParameters)
throws IOException
- Description copied from interface:
SnippetSelector
- Selects snippets in the given content and returns an iterator over selected line numbers.
Note: The caller reads the returned iterator fully before closing the content stream.
This way snippet selectors can truly implement streaming selection (in difference to the provided example).
- Parameters:
expression
- a single snippet expression.contentUrl
- the resolved URL of the content to include (might be 'null' if the source does not provide a Url).content
- a reader providing the content. Implementations must read content from this reader as the Url
may point to an outdated static source that does not reflect the content to include.macroParameters
- the parameters used with the macro call.
- Returns:
- an iterator containing all selected line numbers.
- Throws:
IOException
- In case of reading the URL failed.
countTotalLines
protected int countTotalLines(LineNumberReader content)
throws IOException
- Throws:
IOException