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

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

Introduction

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

Prototype

public static boolean contains(final CharSequence seq, final CharSequence searchSeq) 

Source Link

Document

Checks if CharSequence contains a search CharSequence, handling null .

Usage

From source file:org.alfresco.po.share.search.FacetedSearchPage.java

/**
 * Gets the current url hash./* ww  w. j  a  v a  2  s. c  o  m*/
 *
 * @return the url hash
 */
public String getUrlHash() {
    String url = this.driver.getCurrentUrl();

    // Empty url or no #
    if (StringUtils.isEmpty(url) || !StringUtils.contains(url, "#")) {
        return null;
    }

    return StringUtils.substringAfter(url, "#");
}

From source file:org.alfresco.po.share.util.PageUtils.java

/**
 * Is a WebElement usable?/*w w w  .j av  a 2s  . co  m*/
 *
 * @param element the WebElement
 * @return boolean
 */
public static boolean usableElement(WebElement element) {
    if (element != null && element.isDisplayed() && element.isEnabled()
            && !StringUtils.contains(element.getAttribute("class"), "dijitDisabled")
            && !StringUtils.contains(element.getAttribute("aria-disabled"), "true")) {
        return true;
    }
    return false;
}

From source file:org.apache.archiva.web.test.tools.WebdriverUtility.java

public static WebDriver newWebDriver(String seleniumBrowser, String seleniumHost, int seleniumPort,
        boolean seleniumRemote) {
    log.info("WebDriver {}, {}, {}, {}", seleniumBrowser, seleniumHost, seleniumPort, seleniumRemote);
    if (seleniumRemote && StringUtils.isEmpty(seleniumHost)) {
        throw new IllegalArgumentException("seleniumHost must be set, when seleniumRemote=true");
    }// w  w  w  . j av  a2  s. co  m
    try {

        if (StringUtils.contains(seleniumBrowser, "chrome")) {
            ChromeOptions options = new ChromeOptions();
            options.addArguments("start-maximized");
            if (seleniumRemote) {
                DesiredCapabilities capabilities = DesiredCapabilities.chrome();
                capabilities.setCapability(ChromeOptions.CAPABILITY, options);
                return new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"),
                        capabilities);
            } else {
                return new ChromeDriver(options);
            }
        }

        if (StringUtils.contains(seleniumBrowser, "safari")) {
            if (seleniumRemote) {
                return new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"),
                        DesiredCapabilities.safari());
            } else {
                return new SafariDriver();
            }
        }

        if (StringUtils.contains(seleniumBrowser, "iexplore")) {
            if (seleniumRemote) {
                return new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"),
                        DesiredCapabilities.internetExplorer());
            } else {
                new InternetExplorerDriver();
            }
        }

        if (StringUtils.contains(seleniumBrowser, "firefox")) {
            if (seleniumRemote) {
                return new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"),
                        DesiredCapabilities.firefox());
            } else {
                return new FirefoxDriver();
            }
        }

        DesiredCapabilities capabilities = DesiredCapabilities.htmlUnit();
        capabilities.setJavascriptEnabled(true);
        capabilities.setVersion("firefox-52");
        WebDriver driver;
        if (seleniumRemote) {
            driver = new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"),
                    capabilities);
        } else {
            driver = new HtmlUnitDriver(capabilities) {
                @Override
                protected WebClient modifyWebClient(WebClient client) {
                    client.getOptions().setThrowExceptionOnFailingStatusCode(false);
                    client.getOptions().setThrowExceptionOnScriptError(false);
                    client.getOptions().setCssEnabled(true);
                    return client;
                }
            };

        }
        return driver;

    } catch (MalformedURLException e) {
        throw new RuntimeException("Initializion of remote driver failed");
    }

}

From source file:org.apache.archiva.web.test.WebDriverBrowseTest.java

@Override
public WebDriver getDefaultDriver() {
    String seleniumBrowser = System.getProperty("selenium.browser");

    if (StringUtils.contains(seleniumBrowser, "chrome")) {
        return new ChromeDriver();
    }//from  w  w w.  j a v a2  s .c o  m

    if (StringUtils.contains(seleniumBrowser, "safari")) {
        return new SafariDriver();
    }

    if (StringUtils.contains(seleniumBrowser, "iexplore")) {
        return new InternetExplorerDriver();
    }

    return new FirefoxDriver();

}

From source file:org.apache.drill.exec.planner.sql.SqlConverter.java

public SqlNode validate(final SqlNode parsedNode) {
    try {//from w  w w. j  av a 2 s .  com
        SqlNode validatedNode = validator.validate(parsedNode);
        return validatedNode;
    } catch (RuntimeException e) {
        final Throwable rootCause = ExceptionUtils.getRootCause(e);
        if (rootCause instanceof SqlValidatorException
                && StringUtils.contains(rootCause.getMessage(), "No match found for function signature")) {
            throw new FunctionNotFoundException(rootCause.getMessage(), e);
        }
        UserException.Builder builder = UserException.validationError(e).addContext("SQL Query", sql);
        if (isInnerQuery) {
            builder.message("Failure validating a view your query is dependent upon.");
        }
        throw builder.build(logger);
    }
}

From source file:org.apache.fineract.infrastructure.dataexport.helper.DataExportUtils.java

/**
 * Searches for the CodeValueData object mapped to key similar to specified column value
 * //from w  ww. ja  v  a  2  s .co  m
 * @param codeValueMap
 * @param columnName
 * @param columnValue
 * @param mysqlDataType
 * @return AbstractMap.SimpleEntry object
 */
public static AbstractMap.SimpleEntry<String, MysqlDataType> replaceCodeValueIdWithValue(
        final HashMap<Long, CodeValueData> codeValueMap, final String columnName, String columnValue,
        MysqlDataType mysqlDataType) {
    if (columnName != null && StringUtils.isNotBlank(columnValue)) {
        if (StringUtils.endsWith(columnName, "_cv_id") || StringUtils.contains(columnName, "_cd_")) {
            Long codeValueId = null;

            try {
                codeValueId = Long.valueOf(columnValue);

            } catch (Exception e) {
            }

            CodeValueData codeValueData = codeValueMap.get(codeValueId);

            if (codeValueData != null) {
                columnValue = codeValueData.getName();

                // change the data type from integer to string
                mysqlDataType = MysqlDataType.VARCHAR;
            }
        } else if (StringUtils.contains(columnName, "_cb_")) {
            final String[] csvToArray = StringUtils.split(columnValue, ",");

            if (csvToArray != null) {
                final String[] cleanCsvToArray = new String[csvToArray.length];

                for (int i = 0; i < csvToArray.length; i++) {
                    Long codeValueId = null;

                    try {
                        codeValueId = Long.valueOf(csvToArray[i]);

                    } catch (Exception e) {
                    }

                    CodeValueData codeValueData = codeValueMap.get(codeValueId);

                    cleanCsvToArray[i] = null;

                    if (codeValueData != null) {
                        cleanCsvToArray[i] = codeValueData.getName();
                    }
                }

                columnValue = StringUtils.join(cleanCsvToArray, ", ");
            }
        }
    }

    return new AbstractMap.SimpleEntry<String, MysqlDataType>(columnValue, mysqlDataType);
}

From source file:org.apache.hadoop.gateway.websockets.GatewayWebsocketHandler.java

/**
 * This method looks at the context path and returns the backend websocket
 * url. If websocket url is found it is used as is, or we default to
 * ws://{host}:{port} which might or might not be right.
 * /* w ww .  j av  a  2s.c o  m*/
 * @param  The context path
 * @return Websocket backend url
 */
private synchronized String getMatchedBackendURL(final String path) {

    final ServiceRegistry serviceRegistryService = services
            .getService(GatewayServices.SERVICE_REGISTRY_SERVICE);

    final ServiceDefinitionRegistry serviceDefinitionService = services
            .getService(GatewayServices.SERVICE_DEFINITION_REGISTRY);

    /* Filter out the /cluster/topology to get the context we want */
    String[] pathInfo = path.split(REGEX_SPLIT_CONTEXT);

    final ServiceDefEntry entry = serviceDefinitionService.getMatchingService(pathInfo[1]);

    if (entry == null) {
        throw new RuntimeException(String.format("Cannot find service for the given path: %s", path));
    }

    final File servicesDir = new File(config.getGatewayServicesDir());

    final Set<ServiceDefinition> serviceDefs = ServiceDefinitionsLoader.getServiceDefinitions(servicesDir);

    /* URL used to connect to websocket backend */
    String backendURL = urlFromServiceDefinition(serviceDefs, serviceRegistryService, entry, path);

    try {

        /* if we do not find websocket URL we default to HTTP */
        if (!StringUtils.contains(backendURL, WEBSOCKET_PROTOCOL_STRING)) {
            URL serviceUrl = new URL(backendURL);

            final StringBuffer backend = new StringBuffer();
            /* Use http host:port if ws url not configured */
            final String protocol = (serviceUrl.getProtocol() == "ws" || serviceUrl.getProtocol() == "wss")
                    ? serviceUrl.getProtocol()
                    : "ws";
            backend.append(protocol).append("://");
            backend.append(serviceUrl.getHost()).append(":");
            backend.append(serviceUrl.getPort()).append("/");
            ;
            backend.append(serviceUrl.getPath());

            backendURL = backend.toString();
        }

    } catch (MalformedURLException e) {
        LOG.badUrlError(e);
        throw new RuntimeException(e.toString());
    }

    return backendURL;
}

From source file:org.apache.marmotta.platform.core.services.importer.ImportServiceImpl.java

private Importer getImporterInstance(String type) throws MarmottaImportException {
    if (StringUtils.contains(type, ';')) {
        type = type.split(";")[0];
    }//w w w. j  a v a2s  .  co  m
    if (!importerMap.containsKey(type)) {
        throw new MarmottaImportException("no importer defined for type " + type);
    }
    return importerMap.get(type);
}

From source file:org.apache.sling.contextaware.config.impl.ConfigurationBuilderImpl.java

/**
 * Check the name.//from  w  ww  .  ja  v  a 2s  . com
 * A name must not be null and relative.
 * @param name The name
 * @return {@code true} if it is valid
 */
private boolean isNameValid(final String name) {
    return !StringUtils.isBlank(name) && !StringUtils.startsWith(name, "/")
            && !StringUtils.contains(name, "../");
}

From source file:org.apache.sling.nosql.generic.simple.provider.SimpleNoSqlAdapter.java

public boolean validPath(String path) {
    return !(StringUtils.contains(path, "/invalid/") || StringUtils.endsWith(path, "/invalid"));
}