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:com.eryansky.common.web.utils.WebUtils.java

/**
 * ???gzip?.// w  w w .  ja  v  a 2 s .  com
 */
public static boolean checkAccetptGzip(HttpServletRequest request) {
    // Http1.1 header
    String acceptEncoding = request.getHeader("Accept-Encoding");

    if (StringUtils.contains(acceptEncoding, "gzip")) {
        return true;
    } else {
        return false;
    }
}

From source file:net.sf.dynamicreports.test.jasper.report.JasperExpressionTest.java

@Override
public void test() {
    super.test();

    numberOfPagesTest(1);/*from   ww w  .  j  a  va 2s .co  m*/

    columnTitleCountTest(column1, 1);
    columnTitleValueTest(column1, "Column1\n\"Column1\"");

    columnTitleCountTest(column2, 1);
    columnTitleValueTest(column2, "Column2");

    columnDetailValueTest(column3, "0", "8", "3");

    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        getReportBuilder().toJrXml(bos);
        String jrxml = new String(bos.toByteArray());
        Assert.assertFalse("jrxml contains dependency to dynamicreports",
                StringUtils.contains(jrxml, "net.sf.dynamicreports"));
    } catch (DRException e) {
        Assert.fail(e.getMessage());
    }
}

From source file:com.thoughtworks.go.server.functional.helpers.CSVResponse.java

public boolean containsRow(String... rows) {
    List<String> targetRows = null;
    for (String row : this.allRows) {
        targetRows = Arrays.asList(rows);
        List<String> storedRows = Arrays.asList(row.split(","));
        if (StringUtils.contains(storedRows.toString(), targetRows.toString())) {
            return true;
        }/*from   w ww  . j a  va 2s  .c  o m*/
    }
    throw new RuntimeException("Failed to find " + targetRows + " in all allColumns " + this.allRows);

}

From source file:com.thoughtworks.go.matchers.ConsoleOutMatcherJunit5.java

public ConsoleOutMatcherJunit5 printedBuildFailed() {
    final String buildFailed = "build failed";
    if (!StringUtils.contains(actual.toLowerCase(), buildFailed)) {
        failWithMessage("Expected console to contain [<%s>] but was <%s>.", buildFailed, actual);
    }/*www  . ja  v a  2 s. c o  m*/
    return this;
}

From source file:jobhunter.controllers.PreferencesController.java

public static void addNewPortal(final String portal) {
    final String portals = getCurrent().get(PORTALS_PROPERTY, DEFAULT_PORTALS);
    if (!StringUtils.contains(portals, portal))
        setPortals(portals + ", " + portal);
}

From source file:com.thinkbiganalytics.metadata.api.SearchCriteria.java

/**
 * @return {@code true} if the value is a collection of items (i.e. used in an IN clause) {@code false} if its a single value search
 *//* w  ww.j a  v a  2  s . c  o  m*/
public boolean isValueCollection() {
    return (value != null && (value instanceof String) && StringUtils.contains((String) value, "\"")
            && StringUtils.contains((String) value, ","));
}

From source file:com.adguard.filter.rules.FilterRule.java

/**
 * Creates filter rule./*from   www  .j  a v a 2  s . c  o m*/
 * If this rule text is not valid - returns null.
 *
 * @param ruleText Rule text
 * @return Filter rule of the proper type
 */
public static FilterRule createRule(String ruleText) {

    ruleText = StringUtils.trim(ruleText);

    if (StringUtils.isBlank(ruleText) || StringUtils.length(ruleText) < MIN_RULE_LENGTH
            || StringUtils.startsWith(ruleText, COMMENT) || StringUtils.startsWith(ruleText, META_START)
            || StringUtils.contains(ruleText, MASK_OBSOLETE_SCRIPT_INJECTION)
            || StringUtils.contains(ruleText, MASK_OBSOLETE_STYLE_INJECTION)) {
        return null;
    }

    try {
        if (StringUtils.startsWith(ruleText, MASK_WHITE_LIST)) {
            return new UrlFilterRule(ruleText);
        }

        if (StringUtils.contains(ruleText, MASK_CONTENT_RULE)) {
            return new ContentFilterRule(ruleText);
        }

        if (StringUtils.contains(ruleText, MASK_CSS_RULE)
                || StringUtils.contains(ruleText, MASK_CSS_EXCEPTION_RULE)
                || StringUtils.contains(ruleText, MASK_CSS_INJECT_RULE)
                || StringUtils.contains(ruleText, MASK_CSS_INJECT_EXCEPTION_RULE)) {
            return new CssFilterRule(ruleText);
        }

        if (StringUtils.contains(ruleText, MASK_SCRIPT_RULE)) {
            return new ScriptFilterRule(ruleText);
        }

        return new UrlFilterRule(ruleText);
    } catch (Exception ex) {
        LoggerFactory.getLogger(FilterRule.class).warn("Error creating filter rule {}:\r\n{}", ruleText, ex);
        return null;
    }
}

From source file:ch.cyberduck.core.ssl.SSLExceptionMappingService.java

/**
 * close_notify(0),/*from w  ww .j a  v a2s.  co m*/
 * unexpected_message(10),
 * bad_record_mac(20),
 * decryption_failed_RESERVED(21),
 * record_overflow(22),
 * decompression_failure(30),
 * handshake_failure(40),
 * no_certificate_RESERVED(41),
 * bad_certificate(42),
 * unsupported_certificate(43),
 * certificate_revoked(44),
 * certificate_expired(45),
 * certificate_unknown(46),
 * illegal_parameter(47),
 * unknown_ca(48),
 * access_denied(49),
 * decode_error(50),
 * decrypt_error(51),
 * export_restriction_RESERVED(60),
 * protocol_version(70),
 * insufficient_security(71),
 * internal_error(80),
 * user_canceled(90),
 * no_renegotiation(100),
 * unsupported_extension(110),
 */
@Override
public BackgroundException map(final SSLException failure) {
    final StringBuilder buffer = new StringBuilder();
    for (Throwable cause : ExceptionUtils.getThrowableList(failure)) {
        if (cause instanceof SocketException) {
            // Map Connection has been shutdown: javax.net.ssl.SSLException: java.net.SocketException: Broken pipe
            return new DefaultSocketExceptionMappingService().map((SocketException) cause);
        }
    }
    final String message = failure.getMessage();
    for (Alert alert : Alert.values()) {
        if (StringUtils.contains(message, alert.name())) {
            this.append(buffer, alert.getDescription());
            break;
        }
    }
    if (failure instanceof SSLHandshakeException) {
        if (ExceptionUtils.getRootCause(failure) instanceof CertificateException) {
            log.warn(String.format("Ignore certificate failure %s and drop connection", failure.getMessage()));
            // Server certificate not accepted
            return new ConnectionCanceledException(failure);
        }
        return new SSLNegotiateException(buffer.toString(), failure);
    }
    if (ExceptionUtils.getRootCause(failure) instanceof GeneralSecurityException) {
        this.append(buffer, ExceptionUtils.getRootCause(failure).getMessage());
        return new InteroperabilityException(buffer.toString(), failure);
    }
    this.append(buffer, message);
    return new InteroperabilityException(buffer.toString(), failure);
}

From source file:com.utdallas.s3lab.smvhunter.monkey.DeviceOfflineMonitor.java

@Override
public void run() {

    int count = 0;
    while (true) {
        try {//  w w w  .  j  a  va  2s .c  om
            if (stop) {
                //free all the threads
                UIEnumerator.execCommand("killall emulator-arm");
                return;
            }

            try {
                //run every 30 secs
                Thread.sleep(1000 * 30);
            } catch (InterruptedException ex) {
                logger.error("sleep interrupted", ex);
                if (stop) {
                    //free all the threads
                    UIEnumerator.execCommand("killall emulator-arm");
                    return;
                }
            }

            ////////////////////// adb status check
            //check adb status
            count++;
            if (count % 5 == 0) {
                String out = UIEnumerator.execSpecial(MonkeyMe.adbLocation + " devices");
                //restart the adb daemon when it does not respond
                //don't know why it happens but after 5-6 hours adb
                //daemon stops responding
                if (!StringUtils.contains(out, "emulator-")) {
                    UIEnumerator.execSpecial("killall adb");
                    UIEnumerator.execSpecial(MonkeyMe.adbLocation + " start-server");
                }
            }
            //kill adb process if the count increases above 100
            String adbCount = UIEnumerator.execSpecial("ps aux | grep adb");
            if (adbCount.split("\\n").length > 100) {
                logger.info("number of adb process exceeded 100. Restarting adb");
                UIEnumerator.execSpecial("killall adb");
                UIEnumerator.execCommand(MonkeyMe.adbLocation + " start-server");
            }

            ///////////////// adb status check end

            //check for offline devices
            String offlineDevices = UIEnumerator.execSpecial(LIST_OFFLINE);
            //for each device find the pid and process
            for (String device : offlineDevices.split("\\n")) {
                if (StringUtils.isEmpty(device)) {
                    continue;
                }
                logger.error(String.format("%s found offline. processing ", device));
                if (NumberUtils.isNumber(device)) {
                    //find the pid of the emulator
                    String cmd = String.format(PID_OF_OFFLINE_DEVICE, device);
                    String offlinePid = UIEnumerator.execSpecial(cmd);

                    //now find the emulator name
                    final String emulatorName = UIEnumerator
                            .execSpecial(String.format(EMULATOR_NAME, offlinePid));

                    //kill the emulator and start another one
                    UIEnumerator.execSpecial(String.format(KILL_EMULATOR, offlinePid));
                    //wait for a sec
                    Thread.sleep(2000);

                    logger.info(String.format("killed %s. now starting again", emulatorName));
                    //start the emulator in a new thread
                    exec.execute(new Runnable() {
                        @Override
                        public void run() {
                            try {
                                //start it again
                                String out = UIEnumerator
                                        .execSpecial(String.format(START_EMULATOR, emulatorName));
                                logger.info(String.format("%s started with message ", out));
                            } catch (Exception e) {
                                logger.error(e);
                            }

                        }
                    });

                }
            }
        } catch (Exception e) {
            logger.error(e);
        }
    }
}

From source file:de.vandermeer.skb.datatool.backend.BackendLatexAcrLog.java

/**
 * Loads and processes the the LaTeX, creates list of found acronyms.
 * @throws IOException if there is a problem with the file read
 *///from w w w . ja  v a 2s  .c o  m
public void loadLatexLog() throws IOException {
    Validate.validState(this.file != null);
    BufferedReader br = new BufferedReader(new FileReader(this.file));
    String line;
    while ((line = br.readLine()) != null) {
        if (StringUtils.contains(line, "Package acronym ")) {
            if (StringUtils.contains(line, "Info: ")) {
                String acro = StringUtils.substringAfter(line, "acro:");
                acro = StringUtils.substringBefore(acro, "'");
                this.acronymsLog.add(acro);
                this.acronymsUsed++;
            } else if (StringUtils.contains(line, "Warning: ")) {
                String acro = StringUtils.substringAfter(line, "`");
                acro = StringUtils.substringBefore(acro, "'");
                this.acronymsLog.add(acro);
                this.acronymsUsed++;
            } else {
                System.err.println("##########");
            }
        }
    }
    br.close();
}