Package org.apache.oro.text.regex

Examples of org.apache.oro.text.regex.MatchResult


        List<MatchResult> collectAllMatches = new ArrayList<MatchResult>();
        try {
            PatternMatcher matcher = JMeterUtils.getMatcher();
            PatternMatcherInput input = new PatternMatcherInput(textToMatch);
            while (matcher.contains(input, searchPattern)) {
                MatchResult match = matcher.getMatch();
                collectAllMatches.add(match);
            }
        } finally {
            if (name.length() > 0){
                vars.put(name + "_matchNr", Integer.toString(collectAllMatches.size())); //$NON-NLS-1$
            }
        }

        if (collectAllMatches.size() == 0) {
            return defaultValue;
        }

        if (valueIndex.equals(ALL)) {
            StringBuilder value = new StringBuilder();
            Iterator<MatchResult> it = collectAllMatches.iterator();
            boolean first = true;
            while (it.hasNext()) {
                if (!first) {
                    value.append(between);
                } else {
                    first = false;
                }
                value.append(generateResult(it.next(), name, tmplt, vars));
            }
            return value.toString();
        } else if (valueIndex.equals(RAND)) {
            MatchResult result = collectAllMatches.get(rand.nextInt(collectAllMatches.size()));
            return generateResult(result, name, tmplt, vars);
        } else {
            try {
                int index = Integer.parseInt(valueIndex) - 1;
                MatchResult result = collectAllMatches.get(index);
                return generateResult(result, name, tmplt, vars);
            } catch (NumberFormatException e) {
                float ratio = Float.parseFloat(valueIndex);
                MatchResult result = collectAllMatches
                        .get((int) (collectAllMatches.size() * ratio + .5) - 1);
                return generateResult(result, name, tmplt, vars);
            } catch (IndexOutOfBoundsException e) {
                return defaultValue;
            }
View Full Code Here


        String regularExpression = "^.$";
        Pattern pattern = JMeterUtils.getPattern(regularExpression, Perl5Compiler.READ_ONLY_MASK | Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.MULTILINE_MASK);
       
        PatternMatcherInput input = new PatternMatcherInput(stringToCheck);
        while(localMatcher.contains(input, pattern)) {
            MatchResult match = localMatcher.getMatch();
            return match.beginOffset(0);
        }
        // No divider was found
        return -1;
    }
View Full Code Here

    private String getBoundaryStringFromContentType(String requestHeaders) {
        Perl5Matcher localMatcher = JMeterUtils.getMatcher();
        String regularExpression = "^" + HTTPConstants.HEADER_CONTENT_TYPE + ": multipart/form-data; boundary=(.+)$";
        Pattern pattern = JMeterUtils.getPattern(regularExpression, Perl5Compiler.READ_ONLY_MASK | Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.MULTILINE_MASK);
        if(localMatcher.contains(requestHeaders, pattern)) {
            MatchResult match = localMatcher.getMatch();
            String matchString =  match.group(1);
            // Header may contain ;charset= , regexp extracts it so computed boundary is wrong
            int indexOf = matchString.indexOf(';');
            if(indexOf>=0) {
                return matchString.substring(0, indexOf);
            } else {
View Full Code Here

        if (!matcher.contains(subjectDN, subjectDNPattern)) {
            throw new BadCredentialsException(messages.getMessage("DaoX509AuthoritiesPopulator.noMatching",
                    new Object[] {subjectDN}, "No matching pattern was found in subjectDN: {0}"));
        }

        MatchResult match = matcher.getMatch();

        if (match.groups() != 2) { // 2 = 1 + the entire match
            throw new IllegalArgumentException("Regular expression must contain a single group ");
        }

        String userName = match.group(1);

        UserDetails user = this.userDetailsService.loadUserByUsername(userName);

        if (user == null) {
            throw new AuthenticationServiceException(
View Full Code Here

        String[]            tableNameVars      = { "tablename", "tablename", "tablename" };
        String[]            constraintNameVars = { "constraintname", "constraintname", "constraintname" };

        for (int idx = 0; (idx < 3) && matcher.contains(input, declarePattern); idx++)
        {
            MatchResult result = matcher.getMatch();

            tableNameVars[idx]      = result.group(1);
            constraintNameVars[idx] = result.group(2);
            input.setCurrentOffset(result.endOffset(2));
        }
        assertEqualsIgnoringWhitespaces(
            "SET quoted_identifier on;\n"+
            "IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'F' AND name = 'testfk')\n"+
            "     ALTER TABLE \"table3\" DROP CONSTRAINT \"testfk\";\n"+
View Full Code Here

   
            if (enteredValue != null) {
                // try to split it
                PatternMatcher matcher = new Perl5Matcher();
                if (matcher.matches(enteredValue, aggregateDefinition.getSplitPattern())) {
                    MatchResult matchResult = matcher.getMatch();
                    Iterator iterator = aggregateDefinition.getSplitMappingsIterator();
                    while (iterator.hasNext()) {
                        SplitMapping splitMapping = (SplitMapping)iterator.next();
                        String result = matchResult.group(splitMapping.getGroup());
                        // Since we know the fields are guaranteed to have a string datatype, we
                        // can set the value immediately, instead of going to the readFromRequest
                        // (which would also require us to create wrapper FormContext and Request
                        // objects)
                        ((Field)fieldsById.get(splitMapping.getFieldId())).setValue(result);
View Full Code Here

            int          month   = 1;
            int          day     = 1;

            if (matcher.matches(textRep, _datePattern))
            {
                MatchResult match     = matcher.getMatch();
                int         numGroups = match.groups();

                try
                {
                    year = Integer.parseInt(match.group(1));
                    if ((numGroups > 2) && (match.group(2) != null))
                    {
                        month = Integer.parseInt(match.group(2));
                    }
                    if ((numGroups > 3) && (match.group(3) != null))
                    {
                        day = Integer.parseInt(match.group(3));
                    }
                }
                catch (NumberFormatException ex)
                {
                    throw new ConversionException("Not a valid date : " + textRep, ex);
View Full Code Here

            int          minutes = 0;
            int          seconds = 0;

            if (matcher.matches(textRep, _timePattern))
            {
                MatchResult match     = matcher.getMatch();
                int         numGroups = match.groups();

                try
                {
                    hours = Integer.parseInt(match.group(1));
                    if ((numGroups > 2) && (match.group(2) != null))
                    {
                        minutes = Integer.parseInt(match.group(2));
                    }
                    if ((numGroups > 3) && (match.group(3) != null))
                    {
                        seconds = Integer.parseInt(match.group(3));
                    }
                }
                catch (NumberFormatException ex)
                {
                    throw new ConversionException("Not a valid time : " + textRep, ex);
View Full Code Here

  private NutchDocument resetTitle(NutchDocument doc, ParseData data, String url) {
    String contentDisposition = data.getMeta(Metadata.CONTENT_DISPOSITION);
    if (contentDisposition == null)
      return doc;

    MatchResult result;
    for (int i=0; i<patterns.length; i++) {
      if (matcher.contains(contentDisposition,patterns[i])) {
        result = matcher.getMatch();
        doc.add("title", result.group(1));
        break;
      }
    }

    return doc;
View Full Code Here

                    log.warn("Could not parse "+prevString+" "+e1);
                }
            }
            int matchCount=0;// Number of refName_n variable sets to keep
            try {
                MatchResult match;
                if (matchNumber >= 0) {// Original match behaviour
                    match = getCorrectMatch(matches, matchNumber);
                    if (match != null) {
                        vars.put(refName, generateResult(match));
                        saveGroups(vars, refName, match);
View Full Code Here

TOP

Related Classes of org.apache.oro.text.regex.MatchResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.