org.tinyjee.maven.dim.sources
Class RegularExpressionSnippetSelector

java.lang.Object
  extended by org.tinyjee.maven.dim.sources.AbstractSnippetSelector
      extended by org.tinyjee.maven.dim.sources.AbstractStreamingSnippetSelector
          extended by org.tinyjee.maven.dim.sources.RegularExpressionSnippetSelector
All Implemented Interfaces:
SnippetSelector

public class RegularExpressionSnippetSelector
extends AbstractStreamingSnippetSelector

Implements a simple regular expression based snippet selector using the expression prefix "RE:".

Expression samples:

By default this selector works case-sensitive, unless "case-sensitive=false" is specified with the macro call or the case in-sensitive flag "(?i)" is set in the regular expression (as used in the second example).

Author:
Juergen_Kellerer, 2011-10-14

Nested Class Summary
 
Nested classes/interfaces inherited from class org.tinyjee.maven.dim.sources.AbstractStreamingSnippetSelector
AbstractStreamingSnippetSelector.AbstractStreamIterator<E>
 
Field Summary
 
Fields inherited from class org.tinyjee.maven.dim.sources.AbstractSnippetSelector
expressionPrefix
 
Fields inherited from interface org.tinyjee.maven.dim.spi.SnippetSelector
CASE_SENSITIVE, EXPAND_SNIPPETS, SELECTORS
 
Constructor Summary
  RegularExpressionSnippetSelector()
          Constructs a new regular expression based snippet selector.
protected RegularExpressionSnippetSelector(String expressionPrefix)
           
 
Method Summary
protected  Pattern compile(String expression, boolean caseSensitive)
           
 Iterator<Integer> selectSnippets(String expression, URL contentUrl, LineNumberReader content, Map<String,Object> macroParameters)
          Selects snippets in the given content and returns an iterator over selected line numbers.
 
Methods inherited from class org.tinyjee.maven.dim.sources.AbstractSnippetSelector
assertExpressionIsValid, canSelectSnippetsWith, getExpressionPrefixes, stripPrefix, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RegularExpressionSnippetSelector

public RegularExpressionSnippetSelector()
Constructs a new regular expression based snippet selector.


RegularExpressionSnippetSelector

protected RegularExpressionSnippetSelector(String expressionPrefix)
Method Detail

compile

protected Pattern compile(String expression,
                          boolean caseSensitive)

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.