Search in sources :

Example 11 with PatternMatcher

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);
}
Also used : Perl5Compiler(org.apache.oro.text.regex.Perl5Compiler) Pattern(org.apache.oro.text.regex.Pattern) PatternCompiler(org.apache.oro.text.regex.PatternCompiler) StringProperty(org.apache.jmeter.testelement.property.StringProperty) StringSubstitution(org.apache.oro.text.regex.StringSubstitution) MalformedPatternException(org.apache.oro.text.regex.MalformedPatternException) PatternMatcher(org.apache.oro.text.regex.PatternMatcher)

Example 12 with PatternMatcher

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;
}
Also used : Perl5Compiler(org.apache.oro.text.regex.Perl5Compiler) Pattern(org.apache.oro.text.regex.Pattern) PatternCompiler(org.apache.oro.text.regex.PatternCompiler) MalformedURLException(java.net.MalformedURLException) ArrayList(java.util.ArrayList) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) MatchResult(org.apache.oro.text.regex.MatchResult) MalformedURLException(java.net.MalformedURLException) PatternMatcherInput(org.apache.oro.text.regex.PatternMatcherInput) PatternMatcher(org.apache.oro.text.regex.PatternMatcher)

Example 13 with PatternMatcher

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);
    }
}
Also used : Map(java.util.Map) PatternMatcher(org.apache.oro.text.regex.PatternMatcher) Test(org.junit.Test)

Example 14 with PatternMatcher

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;
}
Also used : ApdexThresholdsInfo(org.apache.jmeter.report.processor.ApdexThresholdsInfo) ApdexSummaryConsumer(org.apache.jmeter.report.processor.ApdexSummaryConsumer) Map(java.util.Map) PatternMatcher(org.apache.oro.text.regex.PatternMatcher)

Example 15 with PatternMatcher

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;
}
Also used : Pattern(org.apache.oro.text.regex.Pattern) Perl5Substitution(org.apache.oro.text.regex.Perl5Substitution) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) PatternMatcher(org.apache.oro.text.regex.PatternMatcher)

Aggregations

PatternMatcher (org.apache.oro.text.regex.PatternMatcher)17 Perl5Matcher (org.apache.oro.text.regex.Perl5Matcher)11 Pattern (org.apache.oro.text.regex.Pattern)9 ArrayList (java.util.ArrayList)7 PatternCompiler (org.apache.oro.text.regex.PatternCompiler)7 Perl5Compiler (org.apache.oro.text.regex.Perl5Compiler)7 MalformedPatternException (org.apache.oro.text.regex.MalformedPatternException)5 MatchResult (org.apache.oro.text.regex.MatchResult)5 PatternMatcherInput (org.apache.oro.text.regex.PatternMatcherInput)5 MalformedURLException (java.net.MalformedURLException)2 Map (java.util.Map)2 Perl5Substitution (org.apache.oro.text.regex.Perl5Substitution)2 BaseOtterTest (com.alibaba.otter.shared.common.BaseOtterTest)1 ConfigException (com.alibaba.otter.shared.common.model.config.ConfigException)1 ModeValue (com.alibaba.otter.shared.common.model.config.data.DataMedia.ModeValue)1 URL (java.net.URL)1 LinkedList (java.util.LinkedList)1 CompoundVariable (org.apache.jmeter.engine.util.CompoundVariable)1 ApdexSummaryConsumer (org.apache.jmeter.report.processor.ApdexSummaryConsumer)1 ApdexThresholdsInfo (org.apache.jmeter.report.processor.ApdexThresholdsInfo)1