|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface SnippetSelector
SnippetSelector
defines an interface that may be implemented and registered via service loading
to add new snippet selection mechanisms.
package my.package;
public class MySnippetSelector implements SnippetSelector {
public String[] getExpressionPrefixes() {
return new String[] {"my:"};
}
public boolean canSelectSnippetsWith(String expression, URL contentUrl, Map macroParameters) {
return expression.toLowerCase().startsWith("my:");
}
public Iterator<Integer> selectSnippets(String expression, URL contentUrl, LineNumberReader content,
Map<String, Object> macroParameters) throws IOException {
List<Integer> output = new LinkedList<Integer>();
for (String line = content.readLine(); line != null; line = content.readLine()) {
if (... EXPRESSION MATCHES LINE ...) output.add(content.getLineNumber());
}
return output.iterator();
}
}
Register the implementation using service loading:
META-INF/services/
org.tinyjee.maven.dim.spi.SnippetSelector
my.package.MySnippetSelector
Field Summary | |
---|---|
static String |
CASE_SENSITIVE
Is an optional boolean parameter that toggles whether snippet selection is case sensitive. |
static String |
EXPAND_SNIPPETS
Is a boolean parameters that may be used by snippet selectors to expand the included content to additional regions if matching an element that has belongings in other locations of the same file. |
static Iterable<SnippetSelector> |
SELECTORS
Is an iterable over all selectors within the classpath. |
Method Summary | |
---|---|
boolean |
canSelectSnippetsWith(String expression,
URL contentUrl,
Map<String,Object> macroParameters)
Returns true if the expression is supported by this snippet selector. |
String[] |
getExpressionPrefixes()
Returns all prefixes that are explicitly supported by this snippet selector. |
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. |
Field Detail |
---|
static final String CASE_SENSITIVE
static final String EXPAND_SNIPPETS
static final Iterable<SnippetSelector> SELECTORS
Method Detail |
---|
String[] getExpressionPrefixes()
boolean canSelectSnippetsWith(String expression, URL contentUrl, Map<String,Object> macroParameters)
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).macroParameters
- the parameters used with the macro call.
Iterator<Integer> selectSnippets(String expression, URL contentUrl, LineNumberReader content, Map<String,Object> macroParameters) throws IOException
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.
IOException
- In case of reading the URL failed.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |