Search in sources :

Example 6 with NodeSelector

use of jodd.lagarto.dom.NodeSelector in project jmeter by apache.

the class JoddExtractor method extract.

/**
     * @see org.apache.jmeter.extractor.Extractor#extract(String, String, int, String, List, int, String)
     */
@Override
public int extract(String expression, String attribute, int matchNumber, String inputString, List<String> result, int found, String cacheKey) {
    NodeSelector nodeSelector;
    if (cacheKey != null) {
        nodeSelector = (NodeSelector) JMeterContextService.getContext().getSamplerContext().get(CACHE_KEY_PREFIX + cacheKey);
        if (nodeSelector == null) {
            LagartoDOMBuilder domBuilder = new LagartoDOMBuilder();
            jodd.lagarto.dom.Document doc = domBuilder.parse(inputString);
            nodeSelector = new NodeSelector(doc);
            JMeterContextService.getContext().getSamplerContext().put(CACHE_KEY_PREFIX + cacheKey, nodeSelector);
        }
    } else {
        LagartoDOMBuilder domBuilder = new LagartoDOMBuilder();
        jodd.lagarto.dom.Document doc = domBuilder.parse(inputString);
        nodeSelector = new NodeSelector(doc);
    }
    List<Node> elements = nodeSelector.select(expression);
    for (Node element : elements) {
        if (matchNumber <= 0 || found != matchNumber) {
            result.add(extractValue(attribute, element));
            found++;
        } else {
            break;
        }
    }
    return found;
}
Also used : Node(jodd.lagarto.dom.Node) NodeSelector(jodd.lagarto.dom.NodeSelector) LagartoDOMBuilder(jodd.lagarto.dom.LagartoDOMBuilder)

Aggregations

Node (jodd.lagarto.dom.Node)6 NodeSelector (jodd.lagarto.dom.NodeSelector)6 LagartoDOMBuilder (jodd.lagarto.dom.LagartoDOMBuilder)2 Test (org.junit.Test)1