Search in sources :

Example 21 with Pattern

use of org.apache.oro.text.regex.Pattern in project ofbiz-framework by apache.

the class UrlRegexpTransform method forwardUri.

/**
 * Forward a uri according to forward pattern regular expressions. Note: this is developed for Filter usage.
 *
 * @param uri
 *            String to reverse transform
 * @return String
 */
public static boolean forwardUri(HttpServletResponse response, String uri) {
    Perl5Matcher matcher = new Perl5Matcher();
    boolean foundMatch = false;
    Integer responseCodeInt = null;
    if (SeoConfigUtil.checkUseUrlRegexp() && SeoConfigUtil.getSeoPatterns() != null && SeoConfigUtil.getForwardReplacements() != null) {
        Iterator<String> keys = SeoConfigUtil.getSeoPatterns().keySet().iterator();
        while (keys.hasNext()) {
            String key = keys.next();
            Pattern pattern = SeoConfigUtil.getSeoPatterns().get(key);
            String replacement = SeoConfigUtil.getForwardReplacements().get(key);
            if (matcher.matches(uri, pattern)) {
                for (int i = 1; i < matcher.getMatch().groups(); i++) {
                    replacement = replacement.replaceAll("\\$" + i, matcher.getMatch().group(i));
                }
                // break if found any matcher
                uri = replacement;
                responseCodeInt = SeoConfigUtil.getForwardResponseCodes().get(key);
                foundMatch = true;
                break;
            }
        }
    }
    if (foundMatch) {
        if (responseCodeInt == null) {
            response.setStatus(SeoConfigUtil.getDefaultResponseCode());
        } else {
            response.setStatus(responseCodeInt.intValue());
        }
        response.setHeader("Location", uri);
    } else {
        Debug.logInfo("Can NOT forward this url: " + uri, module);
    }
    return foundMatch;
}
Also used : Pattern(org.apache.oro.text.regex.Pattern) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher)

Example 22 with Pattern

use of org.apache.oro.text.regex.Pattern in project ofbiz-framework by apache.

the class SeoContextFilter method forwardUri.

/**
 * Forward a uri according to forward pattern regular expressions. Note: this is developed for Filter usage.
 *
 * @param uri String to reverse transform
 * @return String
 */
protected static boolean forwardUri(HttpServletResponse response, String uri) {
    Perl5Matcher matcher = new Perl5Matcher();
    boolean foundMatch = false;
    Integer responseCodeInt = null;
    if (SeoConfigUtil.checkUseUrlRegexp() && SeoConfigUtil.getSeoPatterns() != null && SeoConfigUtil.getForwardReplacements() != null) {
        Iterator<String> keys = SeoConfigUtil.getSeoPatterns().keySet().iterator();
        while (keys.hasNext()) {
            String key = keys.next();
            Pattern pattern = SeoConfigUtil.getSeoPatterns().get(key);
            String replacement = SeoConfigUtil.getForwardReplacements().get(key);
            if (matcher.matches(uri, pattern)) {
                for (int i = matcher.getMatch().groups(); i > 0; i--) {
                    replacement = replacement.replaceAll("\\$" + i, matcher.getMatch().group(i));
                }
                uri = replacement;
                responseCodeInt = SeoConfigUtil.getForwardResponseCodes().get(key);
                foundMatch = true;
            // be careful, we don't break after finding a match
            }
        }
    }
    if (foundMatch) {
        if (responseCodeInt == null) {
            response.setStatus(SeoConfigUtil.getDefaultResponseCode());
        } else {
            response.setStatus(responseCodeInt.intValue());
        }
        response.setHeader("Location", uri);
    } else {
        Debug.logInfo("Can NOT forward this url: " + uri, module);
    }
    return foundMatch;
}
Also used : Pattern(org.apache.oro.text.regex.Pattern) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher)

Example 23 with Pattern

use of org.apache.oro.text.regex.Pattern in project jmeter by apache.

the class JSONPathAssertion method isEquals.

private boolean isEquals(Object subj) {
    if (isUseRegex()) {
        String str = objectToString(subj);
        Pattern pattern = JMeterUtils.getPatternCache().getPattern(getExpectedValue());
        return JMeterUtils.getMatcher().matches(str, pattern);
    } else {
        Object expected = JSONValue.parse(getExpectedValue());
        return Objects.equals(expected, subj);
    }
}
Also used : Pattern(org.apache.oro.text.regex.Pattern) JSONObject(net.minidev.json.JSONObject)

Example 24 with Pattern

use of org.apache.oro.text.regex.Pattern in project jmeter by apache.

the class CSVSaveService method getSampleSaveConfiguration.

/**
 * Parse a CSV header line
 *
 * @param headerLine
 *            from CSV file
 * @param filename
 *            name of file (for log message only)
 * @return config corresponding to the header items found or null if not a
 *         header line
 */
public static SampleSaveConfiguration getSampleSaveConfiguration(String headerLine, String filename) {
    // Try
    String[] parts = splitHeader(headerLine, _saveConfig.getDelimiter());
    // default
    // delimiter
    String delim = null;
    if (parts == null) {
        Perl5Matcher matcher = JMeterUtils.getMatcher();
        PatternMatcherInput input = new PatternMatcherInput(headerLine);
        Pattern pattern = JMeterUtils.getPatternCache().getPattern(// $NON-NLS-1$
        "\\w+((\\W)\\w+)?(\\2\\w+)*(\\2\"\\w+\")*", // last entries may be quoted strings
        Perl5Compiler.READ_ONLY_MASK);
        if (matcher.matches(input, pattern)) {
            delim = matcher.getMatch().group(2);
            // now validate the
            parts = splitHeader(headerLine, delim);
        // result
        }
    }
    if (parts == null) {
        // failed to recognise the header
        return null;
    }
    // We know the column names all exist, so create the config
    SampleSaveConfiguration saveConfig = new SampleSaveConfiguration(false);
    int varCount = 0;
    for (String label : parts) {
        if (isVariableName(label)) {
            varCount++;
        } else {
            Functor set = headerLabelMethods.get(label);
            set.invoke(saveConfig, new Boolean[] { Boolean.TRUE });
        }
    }
    if (delim != null) {
        if (log.isWarnEnabled()) {
            log.warn("Default delimiter '{}' did not work; using alternate '{}' for reading {}", _saveConfig.getDelimiter(), delim, filename);
        }
        saveConfig.setDelimiter(delim);
    }
    saveConfig.setVarCount(varCount);
    return saveConfig;
}
Also used : Pattern(org.apache.oro.text.regex.Pattern) SampleSaveConfiguration(org.apache.jmeter.samplers.SampleSaveConfiguration) PatternMatcherInput(org.apache.oro.text.regex.PatternMatcherInput) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) Functor(org.apache.jorphan.reflect.Functor)

Example 25 with Pattern

use of org.apache.oro.text.regex.Pattern in project jmeter by apache.

the class HtmlParsingUtils method extractStyleURLs.

public static void extractStyleURLs(final URL baseUrl, final URLCollection urls, String styleTagStr) {
    Perl5Matcher matcher = JMeterUtils.getMatcher();
    Pattern pattern = JMeterUtils.getPatternCache().getPattern(// $NON-NLS-1$
    "URL\\(\\s*('|\")(.*)('|\")\\s*\\)", Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.SINGLELINE_MASK | Perl5Compiler.READ_ONLY_MASK);
    PatternMatcherInput input;
    input = new PatternMatcherInput(styleTagStr);
    while (matcher.contains(input, pattern)) {
        MatchResult match = matcher.getMatch();
        // The value is in the second group
        String styleUrl = match.group(2);
        urls.addURL(styleUrl, baseUrl);
    }
}
Also used : Pattern(org.apache.oro.text.regex.Pattern) PatternMatcherInput(org.apache.oro.text.regex.PatternMatcherInput) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) MatchResult(org.apache.oro.text.regex.MatchResult)

Aggregations

Pattern (org.apache.oro.text.regex.Pattern)70 Perl5Matcher (org.apache.oro.text.regex.Perl5Matcher)48 MalformedPatternException (org.apache.oro.text.regex.MalformedPatternException)27 Perl5Compiler (org.apache.oro.text.regex.Perl5Compiler)24 MatchResult (org.apache.oro.text.regex.MatchResult)17 PatternMatcherInput (org.apache.oro.text.regex.PatternMatcherInput)14 ArrayList (java.util.ArrayList)12 PatternMatcher (org.apache.oro.text.regex.PatternMatcher)9 PatternCompiler (org.apache.oro.text.regex.PatternCompiler)7 IOException (java.io.IOException)6 MalformedCachePatternException (org.apache.oro.text.MalformedCachePatternException)6 MalformedURLException (java.net.MalformedURLException)4 BufferedReader (java.io.BufferedReader)3 FileInputStream (java.io.FileInputStream)3 InputStreamReader (java.io.InputStreamReader)3 Perl5Substitution (org.apache.oro.text.regex.Perl5Substitution)3 EOFException (java.io.EOFException)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2