use of org.apache.oro.text.PatternCacheLRU in project jmeter by apache.
the class HtmlParsingUtils method isAnchorMatched.
/**
* Check if anchor matches by checking against:
* - protocol
* - domain
* - path
* - parameter names
*
* @param newLink target to match
* @param config pattern to match against
*
* @return true if target URL matches pattern URL
*/
public static boolean isAnchorMatched(HTTPSamplerBase newLink, HTTPSamplerBase config) {
String query = null;
try {
query = URLDecoder.decode(newLink.getQueryString(), StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {
// UTF-8 unsupported? You must be joking!
log.error("UTF-8 encoding not supported!");
throw new Error("Should not happen: " + e.toString(), e);
}
final Arguments arguments = config.getArguments();
final Perl5Matcher matcher = JMeterUtils.getMatcher();
final PatternCacheLRU patternCache = JMeterUtils.getPatternCache();
if (!isEqualOrMatches(newLink.getProtocol(), config.getProtocol(), matcher, patternCache)) {
return false;
}
final String domain = config.getDomain();
if (domain != null && domain.length() > 0) {
if (!isEqualOrMatches(newLink.getDomain(), domain, matcher, patternCache)) {
return false;
}
}
final String path = config.getPath();
if (!newLink.getPath().equals(path) && !matcher.matches(newLink.getPath(), // $NON-NLS-1$
patternCache.getPattern(// $NON-NLS-1$
"[/]*" + path, Perl5Compiler.READ_ONLY_MASK))) {
return false;
}
for (JMeterProperty argument : arguments) {
Argument item = (Argument) argument.getObjectValue();
final String name = item.getName();
if (!query.contains(name + "=")) {
// $NON-NLS-1$
if (!(matcher.contains(query, patternCache.getPattern(name, Perl5Compiler.READ_ONLY_MASK)))) {
return false;
}
}
}
return true;
}
use of org.apache.oro.text.PatternCacheLRU in project jmeter by apache.
the class HtmlParsingUtils method isArgumentMatched.
/**
* Arguments match if the input name matches the corresponding pattern name
* and the input value matches the pattern value, where the matching is done
* first using String equals, and then Regular Expression matching if the equals test fails.
*
* @param arg - input Argument
* @param patternArg - pattern to match against
* @return true if both name and value match
*/
public static boolean isArgumentMatched(Argument arg, Argument patternArg) {
final Perl5Matcher matcher = JMeterUtils.getMatcher();
final PatternCacheLRU patternCache = JMeterUtils.getPatternCache();
return isEqualOrMatches(arg.getName(), patternArg.getName(), matcher, patternCache) && isEqualOrMatches(arg.getValue(), patternArg.getValue(), matcher, patternCache);
}
use of org.apache.oro.text.PatternCacheLRU in project jmeter by apache.
the class RenderAsRegexp method process.
private String process(String textToParse) {
Perl5Matcher matcher = new Perl5Matcher();
PatternMatcherInput input = new PatternMatcherInput(textToParse);
PatternCacheLRU pcLRU = new PatternCacheLRU();
Pattern pattern;
try {
pattern = pcLRU.getPattern(regexpField.getText(), Perl5Compiler.READ_ONLY_MASK);
} catch (MalformedCachePatternException e) {
return e.toString();
}
List<MatchResult> matches = new LinkedList<>();
while (matcher.contains(input, pattern)) {
matches.add(matcher.getMatch());
}
// Construct a multi-line string with all matches
StringBuilder sb = new StringBuilder();
final int size = matches.size();
sb.append("Match count: ").append(size).append("\n");
for (int j = 0; j < size; j++) {
MatchResult mr = matches.get(j);
final int groups = mr.groups();
for (int i = 0; i < groups; i++) {
sb.append("Match[").append(j + 1).append("][").append(i).append("]=").append(mr.group(i)).append("\n");
}
}
return sb.toString();
}
Aggregations