org.tinyjee.maven.dim.sources
Class XPathSnippetSelector
java.lang.Object
org.tinyjee.maven.dim.sources.AbstractSnippetSelector
org.tinyjee.maven.dim.sources.XPathSnippetSelector
- All Implemented Interfaces:
- SnippetSelector
public class XPathSnippetSelector
- extends AbstractSnippetSelector
Implements a XPath expression based snippet selector supporting XML and
JSON formatted input, using the expression prefix "XP:".
Well formed content required: This snippet selector requires well formed XML or JSON input. Anything else will cause failures.
Example Expressions:
xp:/html/head/title
xp://title
- '
xp:/default:html/default:head
' (with namespace awareness enabled the prefix for the default XML-NS is 'default')
Notes:
- XPath support for JSON is enabled if the source content's file extension is
"
.json
" or "source-content-type=json
" is set. See json document builder
for details how json translates to XML.
- XML namespace awareness can be turned on by setting "
namespace-aware=true
" (does not exist in JSON).
- Author:
- Juergen_Kellerer, 2011-10-14
NAMESPACE_AWARE
public static final String NAMESPACE_AWARE
- See Also:
- Constant Field Values
XPathSnippetSelector
public XPathSnippetSelector()
XPathSnippetSelector
protected XPathSnippetSelector(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.