PatternMatcher matcher = (PatternMatcher) localMatcher.get();
String responseText = new String(previousResult.getResponseData());
PatternMatcherInput input = new PatternMatcherInput(responseText);
while (matcher.contains(input, searchPattern))
{
MatchResult match = matcher.getMatch();
collectAllMatches.add(match);
}
}
catch (NumberFormatException e)
{
log.error("", e);
return defaultValue;
}
catch (Exception e)
{
return defaultValue;
}
finally
{
vars.put(name+"_matchNr", ""+collectAllMatches.size());
}
if (collectAllMatches.size() == 0)
{
return defaultValue;
}
if (valueIndex.equals(ALL))
{
StringBuffer value = new StringBuffer();
Iterator it = collectAllMatches.iterator();
boolean first = true;
while (it.hasNext())
{
if (!first)
{
value.append(between);
}
else
{
first = false;
}
value.append(generateResult((MatchResult) it.next(),name, tmplt, vars));
}
return value.toString();
}
else if (valueIndex.equals(RAND))
{
MatchResult result =
(MatchResult) collectAllMatches.get(
rand.nextInt(collectAllMatches.size()));
return generateResult(result,name, tmplt, vars);
}
else
{
try
{
int index = Integer.parseInt(valueIndex) - 1;
MatchResult result = (MatchResult) collectAllMatches.get(index);
return generateResult(result,name, tmplt, vars);
}
catch (NumberFormatException e)
{
float ratio = Float.parseFloat(valueIndex);
MatchResult result =
(MatchResult) collectAllMatches.get(
(int) (collectAllMatches.size() * ratio + .5) - 1);
return generateResult(result,name, tmplt, vars);
}
catch (IndexOutOfBoundsException e)