Example usage for java.util.regex Pattern pattern

List of usage examples for java.util.regex Pattern pattern

Introduction

In this page you can find the example usage for java.util.regex Pattern pattern.

Prototype

String pattern

To view the source code for java.util.regex Pattern pattern.

Click Source Link

Document

The original regular-expression pattern string.

Usage

From source file:org.eclipse.osee.ote.core.test.shells.TelnetShell.java

public synchronized MatchResult waitForPattern(Pattern pattern, int millis) throws InterruptedException {
    MatchResult index = inputBuffer.waitFor(pattern, false, millis);
    if (index == null) {
        throw new InterruptedException(
                "Waiting for '" + pattern.pattern() + "' took longer then " + millis + " miliseconds.");
    }/* w w  w. ja  va 2 s.c o m*/
    return index;
}

From source file:guru.qas.martini.runtime.harness.MartiniCallable.java

protected Object[] getArguments(Step step, Method method, StepImplementation implementation) {
    Parameter[] parameters = method.getParameters();
    Object[] arguments = new Object[parameters.length];

    Map<String, String> exampleValues = null;

    Recipe recipe = martini.getRecipe();
    ScenarioDefinition definition = recipe.getScenarioDefinition();
    if (ScenarioOutline.class.isInstance(definition)) {
        exampleValues = new HashMap<>();
        ScenarioOutline outline = ScenarioOutline.class.cast(definition);

        int exampleLine = recipe.getLocation().getLine();

        List<Examples> examples = outline.getExamples();
        TableRow header = null;// ww  w .  j a v  a2  s .  c o m
        TableRow match = null;
        for (Iterator<Examples> i = examples.iterator(); null == match && i.hasNext();) {
            Examples nextExamples = i.next();
            List<TableRow> rows = nextExamples.getTableBody();
            for (Iterator<TableRow> j = rows.iterator(); null == match && j.hasNext();) {
                TableRow row = j.next();
                if (row.getLocation().getLine() == exampleLine) {
                    match = row;
                    header = nextExamples.getTableHeader();
                }
            }
        }

        checkState(null != header, "unable to locate matching Examples table");
        List<TableCell> headerCells = header.getCells();
        List<TableCell> rowCells = match.getCells();
        checkState(headerCells.size() == rowCells.size(), "Examples header to row size mismatch");
        for (int i = 0; i < headerCells.size(); i++) {
            String headerValue = headerCells.get(i).getValue();
            String rowValue = rowCells.get(i).getValue();
            exampleValues.put(headerValue, rowValue);
        }
    }

    if (parameters.length > 0) {
        String text = step.getText();
        Pattern pattern = implementation.getPattern();
        Matcher matcher = pattern.matcher(text);
        checkState(matcher.find(), "unable to locate substitution parameters for pattern %s with input %s",
                pattern.pattern(), text);

        int groupCount = matcher.groupCount();
        for (int i = 0; i < groupCount; i++) {
            String parameterAsString = matcher.group(i + 1);
            Parameter parameter = parameters[i];
            Class<?> parameterType = parameter.getType();

            Object converted;
            if (null == exampleValues) {
                converted = conversionService.convert(parameterAsString, parameterType);
            } else {
                Matcher tableMatcher = OUTLINE_PATTERN.matcher(parameterAsString);
                checkState(tableMatcher.find(), "Example table keys must be in the format <key>");
                String key = tableMatcher.group(1);
                String tableValue = exampleValues.get(key);
                converted = conversionService.convert(tableValue, parameterType);
            }

            arguments[i] = converted;
        }
    }

    return arguments;
}

From source file:org.jasig.cas.adaptors.x509.authentication.handler.support.X509CredentialsAuthenticationHandler.java

private boolean doesNameMatchPattern(final Principal principal, final Pattern pattern) {
    final boolean result = pattern.matcher(principal.getName()).matches();

    if (log.isDebugEnabled()) {
        log.debug("Pattern Match: " + result + " [" + principal.getName() + "] against [" + pattern.pattern()
                + "].");
    }//from ww w .ja  va2  s.  c o m

    return result;
}

From source file:org.kuali.kra.rules.SaveCustomAttributeRule.java

/**
 * Validates the format/length of custom attribute.
 * @param customAttribute The custom attribute to validate
 * @param errorKey The error key on the interface
 * @return/*from w w  w .j av  a2s. c  o  m*/
 */
private boolean validateAttributeFormat(CustomAttribute customAttribute,
        CustomAttributeDataType customAttributeDataType, String errorKey) {
    boolean isValid = true;

    Integer maxLength = customAttribute.getDataLength();
    String attributeValue = customAttribute.getValue();
    if ((maxLength != null) && (maxLength.intValue() < attributeValue.length())) {
        reportError(errorKey, RiceKeyConstants.ERROR_MAX_LENGTH, customAttribute.getLabel(),
                maxLength.toString());
        isValid = false;
    }

    final ValidationPattern validationPattern = VALIDATION_CLASSES
            .get(customAttributeDataType.getDescription());

    // if there is no data type matched, then set error ?
    Pattern validationExpression = validationPattern.getRegexPattern();

    String validFormat = getValidFormat(customAttributeDataType.getDescription());

    if (validationExpression != null && !ALL_REGEX.equals(validationExpression.pattern())) {
        if (customAttributeDataType.getDescription().equalsIgnoreCase(DATE)) {
            if (!attributeValue.matches(DATE_REGEX)) {
                reportError(errorKey, RiceKeyConstants.ERROR_INVALID_FORMAT, customAttribute.getLabel(),
                        attributeValue, validFormat);
                isValid = false;
            }
        } else if (!validationExpression.matcher(attributeValue).matches()) {
            reportError(errorKey, KeyConstants.ERROR_INVALID_FORMAT_WITH_FORMAT, customAttribute.getLabel(),
                    attributeValue, validFormat);
            isValid = false;
        }
    }

    if (isValid && customAttributeDataType.getDescription().equals("Date")) {
        if (!StringUtils.isEmpty(attributeValue)) {
            try {
                DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT);
                dateFormat.setLenient(false);
                dateFormat.parse(attributeValue);
            } catch (ParseException e) {
                reportError(errorKey, KeyConstants.ERROR_DATE, attributeValue, customAttribute.getLabel());
                isValid = false;
            }
        }
    }
    // validate BO data against the database contents 
    String lookupClass = customAttribute.getLookupClass();
    if (lookupClass != null && lookupClass.equals("org.kuali.kra.bo.KcPerson")) {
        if (customAttribute.getDataTypeCode().equals("1")
                && customAttribute.getLookupReturn().equals("userName")) {
            validFormat = getValidFormat(customAttributeDataType.getDescription());
            KcPersonService kps = getKcPersonService();
            KcPerson customPerson = kps.getKcPersonByUserName(customAttribute.getValue());
            if (customPerson == null) {
                GlobalVariables.getErrorMap().putError(errorKey, RiceKeyConstants.ERROR_EXISTENCE,
                        customAttribute.getLabel(), attributeValue, validFormat);
                return false;
            } else {
                return true;
            }
        } else {
            // can only validate for userName, if fullName, etc is used then a lookup
            // is assumed that a lookup is being used, in which case validation 
            // is not necessary
            return true;
        }
    } else if (lookupClass != null && lookupClass.equals("org.kuali.kra.bo.ArgValueLookup")) {
        ArgValueLookupValuesFinder finder = new ArgValueLookupValuesFinder();
        finder.setArgName(customAttribute.getLookupReturn());
        List<KeyLabelPair> kv = finder.getKeyValues();
        Iterator<KeyLabelPair> i = kv.iterator();
        while (i.hasNext()) {
            KeyLabelPair element = (KeyLabelPair) i.next();
            String label = element.getLabel().toLowerCase();
            if (label.equals(attributeValue.toLowerCase())) {
                return true;
            }
        }
        validFormat = getValidFormat(customAttributeDataType.getDescription());
        GlobalVariables.getErrorMap().putError(errorKey, RiceKeyConstants.ERROR_EXISTENCE,
                customAttribute.getLabel(), attributeValue, validFormat);
        return false;
    } else if (lookupClass != null) {
        Class boClass = null;
        try {
            boClass = Class.forName(lookupClass);
        } catch (ClassNotFoundException cnfE) {
            /* Do nothing, checked on input */ }

        if (isInvalid(boClass, keyValue(customAttribute.getLookupReturn(), customAttribute.getValue()))) {
            validFormat = getValidFormat(customAttributeDataType.getDescription());
            GlobalVariables.getErrorMap().putError(errorKey, RiceKeyConstants.ERROR_EXISTENCE,
                    customAttribute.getLabel(), attributeValue, validFormat);
            return false;
        }
    }

    return isValid;
}

From source file:org.omegat.util.FileUtilTest.java

public void testCompileFileMask() {
    Pattern r = FileUtil.compileFileMask("Ab1-&*/**");
    assertEquals("(?:|.*/)Ab1\\-\\&[^/]*(?:|/.*)", r.pattern());
}

From source file:org.kuali.kra.institutionalproposal.customdata.InstitutionalProposalCustomDataRuleImpl.java

/**
 * // w ww .jav  a  2  s .co m
 * This method is to validate the format/length of custom attribute
 * @param customAttribute
 * @param errorKey
 * @return
 */
private boolean validateAttributeFormat(CustomAttribute customAttribute, String errorKey) {

    CustomAttributeDataType customAttributeDataType = customAttribute.getCustomAttributeDataType();
    String attributeValue = customAttribute.getValue();
    if (customAttributeDataType == null && customAttribute.getDataTypeCode() != null) {
        customAttributeDataType = getCustomAttributeService()
                .getCustomAttributeDataType(customAttribute.getDataTypeCode());
    }
    if (customAttributeDataType != null) {
        Integer maxLength = customAttribute.getDataLength();
        if ((maxLength != null) && (maxLength.intValue() < attributeValue.length())) {
            GlobalVariables.getErrorMap().putError(errorKey, RiceKeyConstants.ERROR_MAX_LENGTH,
                    customAttribute.getLabel(), maxLength.toString());
            return false;
        }

        ValidationPattern validationPattern = null;
        try {
            validationPattern = (ValidationPattern) Class
                    .forName(validationClasses.get(customAttributeDataType.getDescription())).newInstance();
            if (customAttributeDataType.getDescription().equalsIgnoreCase(STRING)) {
                ((org.kuali.rice.kns.datadictionary.validation.charlevel.AnyCharacterValidationPattern) validationPattern)
                        .setAllowWhitespace(true);
            }
        } catch (Exception e) {
            //do nothing
        }
        String validFormat = getValidFormat(customAttributeDataType.getDescription());
        if (customAttributeDataType.getDescription().equalsIgnoreCase(STRING)
                || customAttributeDataType.getDescription().equalsIgnoreCase(NUMBER)) {
            Pattern validationExpression = validationPattern.getRegexPattern();
            //String validFormat = getValidFormat(customAttributeDataType.getDescription());

            if (validationExpression != null && !validationExpression.pattern().equals(DOT_STAR)) {
                if (!validationExpression.matcher(attributeValue).matches()) {
                    GlobalVariables.getErrorMap().putError(errorKey, RiceKeyConstants.ERROR_INVALID_FORMAT,
                            customAttribute.getLabel(), attributeValue, validFormat);
                    return false;
                }
            }
        } else if (customAttributeDataType.getDescription().equalsIgnoreCase(DATE)) {
            if (!attributeValue.matches(DATE_REGEX)) {
                GlobalVariables.getErrorMap().putError(errorKey, RiceKeyConstants.ERROR_INVALID_FORMAT,
                        customAttribute.getLabel(), attributeValue, validFormat);
                return false;
            }
        }
        //            Pattern validationExpression = validationPattern.getRegexPattern();
        //            String validFormat = getValidFormat(customAttributeDataType.getDescription());
        //            if (validationExpression != null && !validationExpression.pattern().equals(DOT_STAR)) {
        //                if (!validationExpression.matcher(attributeValue).matches()) {
        //                    GlobalVariables.getErrorMap().putError(errorKey, RiceKeyConstants.ERROR_INVALID_FORMAT, 
        //                                                                customAttribute.getLabel(), attributeValue, validFormat);
        //                    return false;
        //                }
        //            }
        // validate BO data against the database contents 
        String lookupClass = customAttribute.getLookupClass();
        if (lookupClass != null && lookupClass.equals("org.kuali.kra.bo.KcPerson")) {
            if (customAttribute.getDataTypeCode().equals("1")
                    && customAttribute.getLookupReturn().equals("userName")) {
                validFormat = getValidFormat(customAttributeDataType.getDescription());
                KcPersonService kps = getKcPersonService();
                KcPerson customPerson = kps.getKcPersonByUserName(customAttribute.getValue());
                if (customPerson == null) {
                    GlobalVariables.getErrorMap().putError(errorKey, RiceKeyConstants.ERROR_EXISTENCE,
                            customAttribute.getLabel(), attributeValue, validFormat);
                    return false;
                } else {
                    return true;
                }
            } else {
                // can only validate for userName, if fullName, etc is used then a lookup
                // is assumed that a lookup is being used, in which case validation 
                // is not necessary
                return true;
            }
        } else if (lookupClass != null && lookupClass.equals("org.kuali.kra.bo.ArgValueLookup")) {
            ArgValueLookupValuesFinder finder = new ArgValueLookupValuesFinder();
            finder.setArgName(customAttribute.getLookupReturn());
            List<KeyLabelPair> kv = finder.getKeyValues();
            Iterator<KeyLabelPair> i = kv.iterator();
            while (i.hasNext()) {
                KeyLabelPair element = (KeyLabelPair) i.next();
                String label = element.getLabel().toLowerCase();
                if (label.equals(attributeValue.toLowerCase())) {
                    return true;
                }
            }
            validFormat = getValidFormat(customAttributeDataType.getDescription());
            GlobalVariables.getErrorMap().putError(errorKey, RiceKeyConstants.ERROR_EXISTENCE,
                    customAttribute.getLabel(), attributeValue, validFormat);
            return false;
        } else if (lookupClass != null) {
            Class boClass = null;
            try {
                boClass = Class.forName(lookupClass);
            } catch (ClassNotFoundException cnfE) {
                /* Do nothing, checked on input */ }

            if (isInvalid(boClass, keyValue(customAttribute.getLookupReturn(), customAttribute.getValue()))) {
                validFormat = getValidFormat(customAttributeDataType.getDescription());
                GlobalVariables.getErrorMap().putError(errorKey, RiceKeyConstants.ERROR_EXISTENCE,
                        customAttribute.getLabel(), attributeValue, validFormat);
                return false;
            }
        }
    }
    return true;
}

From source file:org.kuali.kra.subaward.customdata.SubAwardCustomDataRuleImpl.java

/**
 * //from w  w w .j av  a2 s  . co  m
 * This method is to validate the format/length of custom attribute
 * @param customAttribute
 * @param errorKey
 * @return
 */
@SuppressWarnings("unchecked")
private boolean validateAttributeFormat(CustomAttribute customAttribute, String errorKey) {

    CustomAttributeDataType customAttributeDataType = customAttribute.getCustomAttributeDataType();
    String attributeValue = customAttribute.getValue();
    if (customAttributeDataType == null && customAttribute.getDataTypeCode() != null) {
        customAttributeDataType = getCustomAttributeService()
                .getCustomAttributeDataType(customAttribute.getDataTypeCode());
    }
    if (customAttributeDataType != null) {
        Integer maxLength = customAttribute.getDataLength();
        if ((maxLength != null) && (maxLength.intValue() < attributeValue.length())) {
            GlobalVariables.getErrorMap().putError(errorKey, RiceKeyConstants.ERROR_MAX_LENGTH,
                    customAttribute.getLabel(), maxLength.toString());
            return false;
        }

        ValidationPattern validationPattern = null;
        try {
            validationPattern = (ValidationPattern) Class
                    .forName(validationClasses.get(customAttributeDataType.getDescription())).newInstance();
            if (customAttributeDataType.getDescription().equalsIgnoreCase(STRING)) {
                ((org.kuali.rice.kns.datadictionary.validation.charlevel.AnyCharacterValidationPattern) validationPattern)
                        .setAllowWhitespace(true);
            }
        } catch (Exception e) {
            //do nothing
        }
        String validFormat = getValidFormat(customAttributeDataType.getDescription());
        if (customAttributeDataType.getDescription().equalsIgnoreCase(STRING)
                || customAttributeDataType.getDescription().equalsIgnoreCase(NUMBER)) {
            Pattern validationExpression = validationPattern.getRegexPattern();
            //String validFormat = getValidFormat(customAttributeDataType.getDescription());

            if (validationExpression != null && !validationExpression.pattern().equals(DOT_STAR)) {
                if (!validationExpression.matcher(attributeValue).matches()) {
                    GlobalVariables.getErrorMap().putError(errorKey, RiceKeyConstants.ERROR_INVALID_FORMAT,
                            customAttribute.getLabel(), attributeValue, validFormat);
                    return false;
                }
            }
        } else if (customAttributeDataType.getDescription().equalsIgnoreCase(DATE)) {
            if (!attributeValue.matches(DATE_REGEX)) {
                GlobalVariables.getErrorMap().putError(errorKey, RiceKeyConstants.ERROR_INVALID_FORMAT,
                        customAttribute.getLabel(), attributeValue, validFormat);
                return false;
            }
        }

        String lookupClass = customAttribute.getLookupClass();
        if (lookupClass != null && lookupClass.equals("org.kuali.kra.bo.KcPerson")) {
            if (customAttribute.getDataTypeCode().equals("1")
                    && customAttribute.getLookupReturn().equals("userName")) {
                validFormat = getValidFormat(customAttributeDataType.getDescription());
                KcPersonService kps = getKcPersonService();
                KcPerson customPerson = kps.getKcPersonByUserName(customAttribute.getValue());
                if (customPerson == null) {
                    GlobalVariables.getErrorMap().putError(errorKey, RiceKeyConstants.ERROR_EXISTENCE,
                            customAttribute.getLabel(), attributeValue, validFormat);
                    return false;
                } else {
                    return true;
                }
            } else {
                return true;
            }
        } else if (lookupClass != null && lookupClass.equals("org.kuali.kra.bo.ArgValueLookup")) {
            ArgValueLookupValuesFinder finder = new ArgValueLookupValuesFinder();
            finder.setArgName(customAttribute.getLookupReturn());
            List<KeyLabelPair> kv = finder.getKeyValues();
            Iterator<KeyLabelPair> i = kv.iterator();
            while (i.hasNext()) {
                KeyLabelPair element = (KeyLabelPair) i.next();
                String label = element.getLabel().toLowerCase();
                if (label.equals(attributeValue.toLowerCase())) {
                    return true;
                }
            }
            validFormat = getValidFormat(customAttributeDataType.getDescription());
            GlobalVariables.getErrorMap().putError(errorKey, RiceKeyConstants.ERROR_EXISTENCE,
                    customAttribute.getLabel(), attributeValue, validFormat);
            return false;
        } else if (lookupClass != null && lookupClass.equals("org.kuali.kra.bo.ArgValueLookup")) {
            ArgValueLookupValuesFinder finder = new ArgValueLookupValuesFinder();
            finder.setArgName(customAttribute.getLookupReturn());
            List<KeyLabelPair> kv = finder.getKeyValues();
            Iterator<KeyLabelPair> i = kv.iterator();
            while (i.hasNext()) {
                KeyLabelPair element = (KeyLabelPair) i.next();
                String label = element.getLabel().toLowerCase();
                if (label.equals(attributeValue.toLowerCase())) {
                    return true;
                }
            }
            validFormat = getValidFormat(customAttributeDataType.getDescription());
            GlobalVariables.getErrorMap().putError(errorKey, RiceKeyConstants.ERROR_EXISTENCE,
                    customAttribute.getLabel(), attributeValue, validFormat);
            return false;
        } else if (lookupClass != null) {
            Class boClass = null;
            try {
                boClass = Class.forName(lookupClass);
            } catch (ClassNotFoundException cnfE) {
                /* Do nothing, checked on input */ }

            if (isInvalid(boClass, keyValue(customAttribute.getLookupReturn(), customAttribute.getValue()))) {
                validFormat = getValidFormat(customAttributeDataType.getDescription());
                GlobalVariables.getErrorMap().putError(errorKey, RiceKeyConstants.ERROR_EXISTENCE,
                        customAttribute.getLabel(), attributeValue, validFormat);
                return false;
            }
        }
    }
    return true;
}

From source file:com.hmsinc.epicenter.classifier.regex.RegexClassifier.java

/**
 * @param entry//from www .j a  v  a 2 s.c o  m
 * @param cc
 * @return
 */
private boolean matchPattern(final Entry entry, final String cc) {
    final Pattern p = getPatternForEntry(entry);
    final boolean ret = p.matcher(cc).matches();
    logger.trace("Match pattern {} for {}: {}", new Object[] { p.pattern(), cc, ret });
    return ret;
}

From source file:org.kuali.kra.award.customdata.AwardCustomDataRuleImpl.java

/**
 * //from w  ww  .j ava 2 s .c o  m
 * This method is to validate the format/length of custom attribute
 * @param customAttribute
 * @param errorKey
 * @return
 */
@SuppressWarnings("unchecked")
private boolean validateAttributeFormat(CustomAttribute customAttribute, String errorKey) {

    CustomAttributeDataType customAttributeDataType = customAttribute.getCustomAttributeDataType();
    String attributeValue = customAttribute.getValue();
    if (customAttributeDataType == null && customAttribute.getDataTypeCode() != null) {
        customAttributeDataType = getCustomAttributeService()
                .getCustomAttributeDataType(customAttribute.getDataTypeCode());
    }
    if (customAttributeDataType != null) {
        Integer maxLength = customAttribute.getDataLength();
        if ((maxLength != null) && (maxLength.intValue() < attributeValue.length())) {
            GlobalVariables.getErrorMap().putError(errorKey, RiceKeyConstants.ERROR_MAX_LENGTH,
                    customAttribute.getLabel(), maxLength.toString());
            return false;
        }

        ValidationPattern validationPattern = null;
        try {
            validationPattern = (ValidationPattern) Class
                    .forName(validationClasses.get(customAttributeDataType.getDescription())).newInstance();
            if (customAttributeDataType.getDescription().equalsIgnoreCase(STRING)) {
                ((org.kuali.rice.kns.datadictionary.validation.charlevel.AnyCharacterValidationPattern) validationPattern)
                        .setAllowWhitespace(true);
            }
        } catch (Exception e) {
            //do nothing
        }
        String validFormat = getValidFormat(customAttributeDataType.getDescription());
        if (customAttributeDataType.getDescription().equalsIgnoreCase(STRING)
                || customAttributeDataType.getDescription().equalsIgnoreCase(NUMBER)) {
            Pattern validationExpression = validationPattern.getRegexPattern();
            //String validFormat = getValidFormat(customAttributeDataType.getDescription());

            if (validationExpression != null && !validationExpression.pattern().equals(DOT_STAR)) {
                if (!validationExpression.matcher(attributeValue).matches()) {
                    GlobalVariables.getErrorMap().putError(errorKey, RiceKeyConstants.ERROR_INVALID_FORMAT,
                            customAttribute.getLabel(), attributeValue, validFormat);
                    return false;
                }
            }
        } else if (customAttributeDataType.getDescription().equalsIgnoreCase(DATE)) {
            if (!attributeValue.matches(DATE_REGEX)) {
                GlobalVariables.getErrorMap().putError(errorKey, RiceKeyConstants.ERROR_INVALID_FORMAT,
                        customAttribute.getLabel(), attributeValue, validFormat);
                return false;
            }
        }

        // validate BO data against the database contents 
        String lookupClass = customAttribute.getLookupClass();
        if (lookupClass != null && lookupClass.equals("org.kuali.kra.bo.KcPerson")) {
            if (customAttribute.getDataTypeCode().equals("1")
                    && customAttribute.getLookupReturn().equals("userName")) {
                validFormat = getValidFormat(customAttributeDataType.getDescription());
                KcPersonService kps = getKcPersonService();
                KcPerson customPerson = kps.getKcPersonByUserName(customAttribute.getValue());
                if (customPerson == null) {
                    GlobalVariables.getErrorMap().putError(errorKey, RiceKeyConstants.ERROR_EXISTENCE,
                            customAttribute.getLabel(), attributeValue, validFormat);
                    return false;
                } else {
                    return true;
                }
            } else {
                // can only validate for userName, if fullName, etc is used then a lookup
                // is assumed that a lookup is being used, in which case validation 
                // is not necessary
                return true;
            }
        } else if (lookupClass != null && lookupClass.equals("org.kuali.kra.bo.ArgValueLookup")) {
            ArgValueLookupValuesFinder finder = new ArgValueLookupValuesFinder();
            finder.setArgName(customAttribute.getLookupReturn());
            List<KeyLabelPair> kv = finder.getKeyValues();
            Iterator<KeyLabelPair> i = kv.iterator();
            while (i.hasNext()) {
                KeyLabelPair element = (KeyLabelPair) i.next();
                String label = element.getLabel().toLowerCase();
                if (label.equals(attributeValue.toLowerCase())) {
                    return true;
                }
            }
            validFormat = getValidFormat(customAttributeDataType.getDescription());
            GlobalVariables.getErrorMap().putError(errorKey, RiceKeyConstants.ERROR_EXISTENCE,
                    customAttribute.getLabel(), attributeValue, validFormat);
            return false;
        } else if (lookupClass != null && lookupClass.equals("org.kuali.kra.bo.ArgValueLookup")) {
            ArgValueLookupValuesFinder finder = new ArgValueLookupValuesFinder();
            finder.setArgName(customAttribute.getLookupReturn());
            List<KeyLabelPair> kv = finder.getKeyValues();
            Iterator<KeyLabelPair> i = kv.iterator();
            while (i.hasNext()) {
                KeyLabelPair element = (KeyLabelPair) i.next();
                String label = element.getLabel().toLowerCase();
                if (label.equals(attributeValue.toLowerCase())) {
                    return true;
                }
            }
            validFormat = getValidFormat(customAttributeDataType.getDescription());
            GlobalVariables.getErrorMap().putError(errorKey, RiceKeyConstants.ERROR_EXISTENCE,
                    customAttribute.getLabel(), attributeValue, validFormat);
            return false;
        } else if (lookupClass != null) {
            Class boClass = null;
            try {
                boClass = Class.forName(lookupClass);
            } catch (ClassNotFoundException cnfE) {
                /* Do nothing, checked on input */ }

            if (isInvalid(boClass, keyValue(customAttribute.getLookupReturn(), customAttribute.getValue()))) {
                validFormat = getValidFormat(customAttributeDataType.getDescription());
                GlobalVariables.getErrorMap().putError(errorKey, RiceKeyConstants.ERROR_EXISTENCE,
                        customAttribute.getLabel(), attributeValue, validFormat);
                return false;
            }
        }
    }
    return true;
}

From source file:com.versatus.jwebshield.UrlPatternMatcher.java

/**
 * Match a URL against a pattern./*from ww  w  .  j  ava2s.c o  m*/
 * 
 * @param url
 *            String
 * @param pattern
 *            String
 * @return boolean
 * @throws Exception
 */
public boolean matches(String url, String pattern) throws Exception {

    boolean result = false;

    logger.debug("matches: input - url=" + url + " | pattern=" + pattern);

    if (pattern == null || url == null) {
        throw new Exception("Input parameter(s) are blank!");
    }

    Pattern p;
    if (pattern.contains("*")) {
        p = Pattern.compile(pattern.replace("*", "").replace("/", "\\/") + "$");

    } else if (pattern.equalsIgnoreCase("/")) {
        p = Pattern.compile(pattern.replace("/", "\\/"));
    } else {
        p = Pattern.compile(pattern.replace(".", "\\.").replace("/", "\\/") + "$");
    }

    Matcher matcher = p.matcher(url);

    logger.debug("matches: Original pattern=" + pattern + " | regex=" + p.pattern());

    while (matcher.find()) {
        result = true;
        logger.debug("matches: group=" + matcher.group());
    }
    logger.debug("Matching " + pattern + " against " + url + " | result=" + result);

    return result;

}