Example usage for org.apache.commons.lang3 StringUtils containsIgnoreCase

List of usage examples for org.apache.commons.lang3 StringUtils containsIgnoreCase

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils containsIgnoreCase.

Prototype

public static boolean containsIgnoreCase(final CharSequence str, final CharSequence searchStr) 

Source Link

Document

Checks if CharSequence contains a search CharSequence irrespective of case, handling null .

Usage

From source file:org.asqatasun.rules.elementselector.CaptchaElementSelector.java

@Override
public void selectElements(SSPHandler sspHandler, ElementHandler<Element> selectionHandler) {
    if (!StringUtils.containsIgnoreCase(sspHandler.getSSP().getDOM(), CAPTCHA_KEY)) {
        return;//from w w w . jav a 2 s . c  o  m
    }
    if (elementSelector != null) {
        elementSelector.selectElements(sspHandler, selectionHandler);
    } else if (imageHandler != null) {
        selectionHandler.addAll(imageHandler.get());
    }
    extractCaptchaElements(selectionHandler);
}

From source file:org.asqatasun.rules.elementselector.CaptchaElementSelector.java

/**
 *
 * @param element//from   ww  w .  j  av a2  s  . c om
 * @return wheter either one attribute of the current element, either its
 * text, either one attribute of one of its parent or the text of one of
 * its parents contains the "captcha" keyword
 */
private boolean parseAttributeToExtractCaptcha(Element element) {
    if (element.nodeName().equalsIgnoreCase(HTML_ELEMENT)
            || element.nodeName().equalsIgnoreCase(BODY_ELEMENT)) {
        return false;
    }
    if (StringUtils.containsIgnoreCase(element.ownText(), CAPTCHA_KEY)) {
        return true;
    } else {
        for (Attribute attr : element.attributes()) {
            if (StringUtils.containsIgnoreCase(attr.getValue(), CAPTCHA_KEY)) {
                return true;
            }
        }
    }
    return false;
}

From source file:org.asqatasun.rules.test.AbstractRuleImplementationTestCase.java

/**
 * Default implementation of setConsolidate. May be overridden only in 
 * special cases//from  w ww. j  a va 2s .  c om
 */
protected void setConsolidate() {
    for (String webResourceKey : webResourceMap.keySet()) {
        if (StringUtils.containsIgnoreCase(webResourceKey, "Passed")) {
            assertEquals(TestSolution.PASSED, consolidate(webResourceKey).getValue());
        } else if (StringUtils.containsIgnoreCase(webResourceKey, "Failed")) {
            assertEquals(TestSolution.FAILED, consolidate(webResourceKey).getValue());
        } else if (StringUtils.containsIgnoreCase(webResourceKey, "NMI")) {
            assertEquals(TestSolution.NEED_MORE_INFO, consolidate(webResourceKey).getValue());
        } else if (StringUtils.containsIgnoreCase(webResourceKey, "NA")) {
            assertEquals(TestSolution.NOT_APPLICABLE, consolidate(webResourceKey).getValue());
        }
    }
}

From source file:org.asqatasun.webapp.validator.PageAuditSetUpFormValidator.java

/**
 * Check whether the Urls filled-in by the user are correct.
 * 1- They have to be all on the same domain. 
 * 2- When the contract has on option of type DOMAIN, they have to match 
 * to the value of the option/* w w w  .jav  a2 s .  co  m*/
 * 
 * @param pageAuditSetUpCommand
 * @param errors 
 */
private void validateUrl(AuditSetUpCommand pageAuditSetUpCommand, Errors errors) {

    boolean onContractUrl = false;

    String contractUrl = getContractDataService()
            .getUrlFromContractOption(getContractDataService().read(pageAuditSetUpCommand.getContractId()));

    boolean emptyUrl = true;
    String domainOfFirstUrlEncountered = "";
    Set<Integer> urlWithProblemIndexSet = new HashSet();
    Set<Integer> urlWithFilePrefixSet = new HashSet();

    // We parse all the URL filled-in by the user and extract the ones that
    // don't match with the domain of the first encountered URL.
    int index = 0;
    for (String url : pageAuditSetUpCommand.getUrlList()) {
        if (url != null && !url.isEmpty()) {

            emptyUrl = false;

            // first we sanitize the url and extract the domain
            url = url.trim();

            if (hasUrlFilePrefix(url)) {
                urlWithFilePrefixSet.add(index);
            } else {
                url = extractDomainFromUrl(url);

                // we store the url if it's the first one.
                if (domainOfFirstUrlEncountered.isEmpty()) {
                    domainOfFirstUrlEncountered = url;

                    // if the domain of this url is different from the one of the 
                    // first encountered domain, we store its index.
                } else if (!url.equalsIgnoreCase(domainOfFirstUrlEncountered)) {
                    urlWithProblemIndexSet.add(index);
                }
                if (!onContractUrl
                        && (StringUtils.containsIgnoreCase(contractUrl, url) || contractUrl.isEmpty())) {
                    onContractUrl = true;
                }
            }
        }
        index++;
    }

    if (emptyUrl) { // if no URL is filled-in
        LOGGER.debug("emptyUrl");
        errors.rejectValue(GENERAL_ERROR_MSG_KEY, MANDATORY_FIELD_MSG_BUNDLE_KEY);
    } else if (!urlWithFilePrefixSet.isEmpty()) { // if some URLs are not on the right domain
        LOGGER.debug("fileAuditNotAllowed");
        errors.rejectValue(GENERAL_ERROR_MSG_KEY, FILE_NOT_ALLOWED_HERE_MSG_BUNDLE_KEY);
        for (Integer urlIndex : urlWithFilePrefixSet) {
            errors.rejectValue(ID_INPUT_PREFIX + "[" + urlIndex + "]", FILE_NOT_ALLOWED_HERE_MSG_BUNDLE_KEY);
        }
    } else if (!onContractUrl) { // if the URL is not allowed (not on the contract for authenticated users)
        LOGGER.debug("notOnContract");
        errors.rejectValue(GENERAL_ERROR_MSG_KEY, NOT_ON_CONTRACT_MSG_BUNDLE_KEY);
    } else if (!urlWithProblemIndexSet.isEmpty()) { // if some URLs are not on the right domain
        LOGGER.debug("notOnSameDomain");
        errors.rejectValue(GENERAL_ERROR_MSG_KEY, URL_ON_DIFFERENT_DOMAIN_MSG_BUNDLE_KEY);
        for (Integer urlIndex : urlWithProblemIndexSet) {
            String[] arg = { domainOfFirstUrlEncountered };
            errors.rejectValue(ID_INPUT_PREFIX + "[" + urlIndex + "]", NOT_ON_SAME_DOMAIN_MSG_BUNDLE_KEY, arg,
                    "{0}");
        }
    }
}

From source file:org.bitbucket.mlopatkin.android.logviewer.search.IgnoreCaseSearcher.java

@Override
public boolean isStringMatched(String s) {
    return StringUtils.containsIgnoreCase(s, textToSearch);
}

From source file:org.codelabor.system.security.validator.xss.internal.constraintvalidators.NonSafeHtmlStringListValidator.java

public boolean isValid(List<String> list, ConstraintValidatorContext context) {
    if (CollectionUtils.isNotEmpty(list)) {
        for (String value : list) {
            if (StringUtils.isNotBlank(value)) {
                for (String blacklistPattern : blacklist) {
                    logger.debug("value: {}, blacklistPattern: {}", value, blacklistPattern);
                    if (StringUtils.containsIgnoreCase(value, blacklistPattern)) {
                        return false;
                    }//from   w  w w .j  a  v  a  2  s. c o m
                }
            }
        }
    }
    return true;
}

From source file:org.codelabor.system.security.validator.xss.internal.constraintvalidators.NonSafeHtmlValidator.java

public boolean isValid(CharSequence value, ConstraintValidatorContext context) {
    if (StringUtils.isNotBlank(value)) {
        for (String blacklistPattern : blacklist) {
            logger.debug("value: {}, blacklistPattern: {}", value, blacklistPattern);
            if (StringUtils.containsIgnoreCase(value, blacklistPattern)) {
                return false;
            }/*from w  w  w  .j ava2  s.  co  m*/
        }
    }
    return true;
}

From source file:org.cybercat.automation.components.PageElement.java

/**
 * Intention of this method is to initialize PageElement object based on
 * partial locator (that returns list of similar WebElements) and text
 * contained in the WebElement//from  w w  w  .j  a  v  a2  s.co m
 * 
 * @param browser
 * @param text
 * @throws PageObjectException
 */
public void initWebElement(final Browser browser, final String text) throws PageObjectException {
    if (state.equals(ElementState.CREATED)) {
        try {
            processor.initWebElementByCriteria(browser, new AbstractCriteria<List<WebElement>>(path) {

                @Override
                public ExpectedCondition<List<WebElement>> getExpectedCondition(String path) {
                    return ExpectedConditions.presenceOfAllElementsLocatedBy(processor.getByElement(path));
                }

                @Override
                public boolean onSuccess(List<WebElement> elements, String path) {
                    for (WebElement thisElement : elements) {
                        String innerText = (String) browser.executeScript("return arguments[0].textContent",
                                thisElement);
                        System.out.println(thisElement.toString() + " +++ " + innerText + " +++ " + text);
                        if (StringUtils.containsIgnoreCase(innerText, text)) {
                            actualPath = path;
                            element = thisElement;
                            browser.highlightElement(element);
                            setState(ElementState.INITIALIZED);
                            return true;
                        }
                    }
                    return false;
                }
            });
        } catch (Exception e) {
            log.error("element \"" + name + "\" is not found ");
            throw new PageObjectException("element \"" + name + "\" is not found by text: \"" + text + "\"", e);
        }
        if (element == null)
            throw new PageObjectException("element \"" + name + "\" is not found. By Path:" + getActualPath());
        if (!waitPresent())
            throw new PageObjectException("\"" + getName() + "\" element is not visible by path "
                    + getActualPath() + "  and text: " + text);
    }

}

From source file:org.cybercat.automation.components.SelectorBox.java

public void selectFromSelectorBoxContains(String value, boolean checkSelected) throws PageObjectException {
    Select selectBox = new Select(getElement());
    try {//  w w w.  ja va 2s.  c  o  m
        List<String> elementsText = getOptionsText();

        for (String elementText : elementsText) {

            if (StringUtils.containsIgnoreCase(elementText, value)) {
                if (checkSelected) {
                    String selected = getFirstSelectedValue();
                    if (StringUtils.equalsIgnoreCase(selected, value)) {
                        LOG.info("Selected option equals to value to select: " + value);
                        return;
                    }
                }
                selectBox.selectByIndex(elementsText.lastIndexOf(elementText));

                LOG.info("Component name:" + super.getName() + "  selected value:" + elementText);

                return;
            }
        }
    } catch (Exception e) {
        throw new PageObjectException("Component name:" + super.getName() + "  by path:" + super.getPath()[0],
                e);
    }
}

From source file:org.cybercat.automation.components.SelectorBox.java

public void selectByOptionValue(String optionValue) {
    List<WebElement> options = new Select(getElement()).getOptions();
    for (WebElement option : options) {
        if (StringUtils.containsIgnoreCase(option.getAttribute("value"), optionValue)) {
            option.click();/* w ww. ja  va 2  s .  co m*/
            LOG.info("Selected value: " + option.getAttribute("value"));
            break;
        }
    }

}