use of org.apache.oro.text.regex.PatternMatcher in project jmeter by apache.
the class ReplaceFunctionsWithStrings method transformValue.
@Override
public JMeterProperty transformValue(JMeterProperty prop) throws InvalidVariableException {
PatternMatcher pm = JMeterUtils.getMatcher();
PatternCompiler compiler = new Perl5Compiler();
String input = prop.getStringValue();
if (input == null) {
return prop;
}
for (Entry<String, String> entry : getVariables().entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
if (regexMatch) {
try {
Pattern pattern = compiler.compile(constructPattern(value));
input = Util.substitute(pm, pattern, new StringSubstitution(FUNCTION_REF_PREFIX + key + FUNCTION_REF_SUFFIX), input, Util.SUBSTITUTE_ALL);
} catch (MalformedPatternException e) {
log.warn("Malformed pattern: {}", value);
}
} else {
input = StringUtilities.substitute(input, value, FUNCTION_REF_PREFIX + key + FUNCTION_REF_SUFFIX);
}
}
return new StringProperty(prop.getName(), input);
}
use of org.apache.oro.text.regex.PatternMatcher in project nutch by apache.
the class OutlinkExtractor method getOutlinks.
/**
* Extracts <code>Outlink</code> from given plain text and adds anchor to the
* extracted <code>Outlink</code>s
*
* @param plainText
* the plain text from wich URLs should be extracted.
* @param anchor
* the anchor of the url
*
* @return Array of <code>Outlink</code>s within found in plainText
*/
public static Outlink[] getOutlinks(final String plainText, String anchor, Configuration conf) {
long start = System.currentTimeMillis();
final List<Outlink> outlinks = new ArrayList<>();
try {
final PatternCompiler cp = new Perl5Compiler();
final Pattern pattern = cp.compile(URL_PATTERN, Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.READ_ONLY_MASK | Perl5Compiler.MULTILINE_MASK);
final PatternMatcher matcher = new Perl5Matcher();
final PatternMatcherInput input = new PatternMatcherInput(plainText);
MatchResult result;
String url;
// loop the matches
while (matcher.contains(input, pattern)) {
// do not unnecessarily hit this limit.)
if (System.currentTimeMillis() - start >= 60000L) {
if (LOG.isWarnEnabled()) {
LOG.warn("Time limit exceeded for getOutLinks");
}
break;
}
result = matcher.getMatch();
url = result.group(0);
try {
outlinks.add(new Outlink(url, anchor));
} catch (MalformedURLException mue) {
LOG.warn("Invalid url: '" + url + "', skipping.");
}
}
} catch (Exception ex) {
// on
if (LOG.isErrorEnabled()) {
LOG.error("getOutlinks", ex);
}
}
final Outlink[] retval;
// create array of the Outlinks
if (outlinks != null && outlinks.size() > 0) {
retval = outlinks.toArray(new Outlink[0]);
} else {
retval = new Outlink[0];
}
return retval;
}
use of org.apache.oro.text.regex.PatternMatcher in project jmeter by apache.
the class ApdexPerTransactionTest method testSampleNameMatching.
@Test
public void testSampleNameMatching() {
/* matching pairs :
* sample(\d+) sample2
* sample(\d+) sample12
* scenar01-12 scenar01-12
* samples12 samples12
* */
String[] sampleNames = { "sample2", "sample12", "scenar01-12", "samples12" };
Map<String, Long[]> apdex = ReportGeneratorConfiguration.getApdexPerTransactionParts(apdexString);
for (String sampleName : sampleNames) {
boolean hasMatched = false;
for (Map.Entry<String, Long[]> entry : apdex.entrySet()) {
org.apache.oro.text.regex.Pattern regex = JMeterUtils.getPatternCache().getPattern(entry.getKey());
PatternMatcher matcher = JMeterUtils.getMatcher();
if (matcher.matches(sampleName, regex)) {
hasMatched = true;
}
}
assertTrue(hasMatched);
}
}
use of org.apache.oro.text.regex.PatternMatcher in project jmeter by apache.
the class ReportGenerator method createApdexSummaryConsumer.
private ApdexSummaryConsumer createApdexSummaryConsumer() {
ApdexSummaryConsumer apdexSummaryConsumer = new ApdexSummaryConsumer();
apdexSummaryConsumer.setName(APDEX_SUMMARY_CONSUMER_NAME);
apdexSummaryConsumer.setHasOverallResult(true);
apdexSummaryConsumer.setThresholdSelector(sampleName -> {
ApdexThresholdsInfo info = new ApdexThresholdsInfo();
info.setSatisfiedThreshold(configuration.getApdexSatisfiedThreshold());
info.setToleratedThreshold(configuration.getApdexToleratedThreshold());
for (Map.Entry<String, Long[]> entry : configuration.getApdexPerTransaction().entrySet()) {
org.apache.oro.text.regex.Pattern regex = JMeterUtils.getPatternCache().getPattern(entry.getKey());
PatternMatcher matcher = JMeterUtils.getMatcher();
if (matcher.matches(sampleName, regex)) {
Long satisfied = entry.getValue()[0];
Long tolerated = entry.getValue()[1];
if (log.isDebugEnabled()) {
log.debug("Found match for sampleName:{}, Regex:{}, satisfied value:{}, tolerated value:{}", entry.getKey(), satisfied, tolerated);
}
info.setSatisfiedThreshold(satisfied);
info.setToleratedThreshold(tolerated);
break;
}
}
return info;
});
return apdexSummaryConsumer;
}
use of org.apache.oro.text.regex.PatternMatcher in project tdi-studio-se by Talend.
the class AbstractMapComponent method hasOrRenameEntry.
/**
*
* ggu Comment method "hasOrRenameEntry".
*
*/
protected boolean hasOrRenameEntry(IExternalMapEntry entry, String oldName, String newName, boolean renameAction) {
if (entry == null || oldName == null || newName == null && renameAction) {
throw new NullPointerException();
}
if (entry.getExpression() != null) {
Pattern pattern = getRenamePattern(oldName);
if (pattern != null) {
PatternMatcher matcher = new Perl5Matcher();
((Perl5Matcher) matcher).setMultiline(true);
if (renameAction) {
Perl5Substitution substitution = getRenameSubstitution(newName);
String expression = renameDataIntoExpression(pattern, matcher, substitution, entry.getExpression());
entry.setExpression(expression);
} else {
if (hasDataIntoExpression(pattern, matcher, entry.getExpression())) {
return true;
}
}
}
}
return false;
}
Aggregations