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

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

Introduction

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

Prototype

public static boolean containsIgnoreCase(String str, String searchStr) 

Source Link

Document

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

Usage

From source file:org.caleydo.core.internal.cmd.ZoomHandler.java

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    String action = event.getParameter("action");
    final boolean reset = StringUtils.equalsIgnoreCase(action, "reset");
    final boolean increaseZoomFactor = StringUtils.containsIgnoreCase(action, "in");

    final IPreferenceStore prefs = MyPreferences.prefs();
    int current = prefs.getInt(MyPreferences.VIEW_ZOOM_FACTOR);

    int next;// www. j ava 2  s. c  om
    if (reset)
        next = prefs.getDefaultInt(MyPreferences.VIEW_ZOOM_FACTOR);
    else if (increaseZoomFactor)
        next = current + CHANGE;
    else
        next = Math.max(10, current - CHANGE);

    MyPreferences.prefs().setValue(MyPreferences.VIEW_ZOOM_FACTOR, next);

    return null;
}

From source file:org.caleydo.view.bicluster.elem.ClusterElement.java

@ListenTo
private void onSearchClusterEvent(SearchClusterEvent event) {
    if (event.isClear()) {
        targetOpacityfactor = highOpacityFactor;
    } else if (StringUtils.containsIgnoreCase(getLabel(), event.getText())) {
        targetOpacityfactor = highOpacityFactor;
        log.debug(getLabel() + " matches " + event.getText());
    } else {/*w  w  w. j  a  v  a 2  s .  co  m*/
        targetOpacityfactor = lowOpacityFactor;
        log.debug(getLabel() + " not matches " + event.getText());
    }
    repaintChildren();
}

From source file:org.carewebframework.vista.ui.vitals.DisplayController.java

private void chartData() {
    Date dateHigh = null;/*from   w w w .  j  a  v  a 2  s . c o  m*/
    Date dateLow = null;
    int row = selectedRow;
    boolean useAge = chkAge.isVisible() && chkAge.isChecked();
    chart.clear();
    int colcount = hdrVitals.getChildren().size() - 1;

    if (row < 0 || row >= lstVitals.getItemCount() || colcount < 0) {
        return;
    }

    boolean hasData = false;
    String testname = getValue(0, row);
    String testid = (String) getObject(0, row);
    boolean isBP = StringUtils.containsIgnoreCase(testname, "pressure");
    chart.getYAxis().title.text = (String) getObject(colcount, row);
    chart.getXAxis().title.text = useAge ? "age (months)" : null;
    chart.getXAxis().type = useAge ? "linear" : "datetime";

    for (int col = 1; col < colcount; col++) {
        Listheader hdr = (Listheader) hdrVitals.getChildren().get(col);
        FMDate date = (FMDate) hdr.getValue();

        if (date != null) {
            double xVal = useAge ? dateToAge(date) : date.getTime();
            String vals[] = StrUtil.split(getValue(col, row), ";");
            boolean newData = false;

            for (String val : vals) {
                if (isBP) {
                    String pcs[] = StrUtil.split(val, "/");

                    if (pcs.length > 0) {
                        newData |= plotData(xVal, pcs[0], "Systolic", testname) != null;
                    }

                    if (pcs.length > 2) {
                        newData |= plotData(xVal, pcs[1], "Mean", testname) != null;
                        newData |= plotData(xVal, pcs[2], "Diastolic", testname) != null;
                    } else {
                        newData |= plotData(xVal, pcs[1], "Diastolic", testname) != null;
                    }
                } else {
                    newData |= plotData(xVal, val, testname, testname) != null;
                }
            }

            if (newData) {
                hasData = true;
                dateLow = dateLow == null ? date : date.getTime() < dateLow.getTime() ? date : dateLow;
                dateHigh = dateHigh == null ? date : date.getTime() > dateHigh.getTime() ? date : dateHigh;
            }
        }
    }

    if (hasData) {
        double xLow = useAge ? dateToAge(dateLow) : dateLow.getTime();
        double xHigh = useAge ? dateToAge(dateHigh) : dateHigh.getTime();
        plotRange(xLow, xHigh, StrUtil.piece(getValue(colcount, row), " "));
        String pctileRPC = percentiles.get(testid);

        if (pctileRPC != null && chkPercentiles.isChecked()) {
            List<String> pctiles = broker.callRPCList(pctileRPC, null, testid, patient.getId().getIdPart(),
                    DateUtils.addDays(dateLow, -3000), DateUtils.addDays(dateHigh, 3000), getDefaultUnits());

            for (String pctile : pctiles) {
                String pcs[] = StrUtil.split(pctile, StrUtil.U, 3);
                FMDate date = new FMDate(pcs[1]);
                plotPercentile(useAge ? dateToAge(date) : date.getTime(), pcs[2], pcs[0]);
            }
        }

        chart.run();
    }
}

From source file:org.cesecore.certificates.ca.internal.SernoGeneratorRandom.java

private void init() {
    // Init random number generator for random serial numbers. 
    // SecureRandom provides a cryptographically strong random number generator (RNG).
    try {/* ww w  . j a va2 s .  c  om*/
        // Use a specified algorithm if ca.rngalgorithm is provided and it's not set to default
        if (!StringUtils.isEmpty(algorithm) && !StringUtils.containsIgnoreCase(algorithm, "default")) {
            random = SecureRandom.getInstance(algorithm);
            log.info("Using " + algorithm + " serialNumber RNG algorithm.");
        } else if (!StringUtils.isEmpty(algorithm)
                && StringUtils.equalsIgnoreCase(algorithm, "defaultstrong")) {
            // If defaultstrong is specified and we use >=JDK8 try the getInstanceStrong to get a guaranteed strong random number generator.
            // Note that this may give you a generator that takes >30 seconds to create a single random number. 
            // On JDK8/Linux this gives you a NativePRNGBlocking, while SecureRandom.getInstance() gives a NativePRNG.
            try {
                final Method methodGetInstanceStrong = SecureRandom.class
                        .getDeclaredMethod("getInstanceStrong");
                random = (SecureRandom) methodGetInstanceStrong.invoke(null);
                log.info("Using SecureRandom.getInstanceStrong() with " + random.getAlgorithm()
                        + " for serialNumber RNG algorithm.");
            } catch (NoSuchMethodException | SecurityException | IllegalAccessException
                    | IllegalArgumentException | InvocationTargetException e) {
                throw new IllegalStateException(
                        "SecureRandom.getInstanceStrong() is not available or failed invocation. (This method was added in Java 8.)");
            }
        } else if (!StringUtils.isEmpty(algorithm) && StringUtils.equalsIgnoreCase(algorithm, "default")) {
            // We entered "default" so let's use a good default SecureRandom this should be good enough for just about everyone (on Linux at least)
            // On Linux the default Java implementation uses the (secure) /dev/(u)random, but on windows something else
            // On JDK8/Linux this gives you a NativePRNG, while SecureRandom.getInstanceStrong() gives a NativePRNGBlocking.
            random = new SecureRandom();
            log.info("Using default " + random.getAlgorithm() + " serialNumber RNG algorithm.");
        }
    } catch (NoSuchAlgorithmException e) {
        //This state is unrecoverable, and since algorithm is set in configuration requires a redeploy to handle
        throw new IllegalStateException("Algorithm " + algorithm + " was not a valid algorithm.", e);
    }
    if (random == null) {
        //This state is unrecoverable, and since algorithm is set in configuration requires a redeploy to handle
        throw new IllegalStateException("Algorithm " + algorithm + " was not a valid algorithm.");
    }
    // Call nextBytes directly after in order to force seeding if not already done. SecureRandom typically seeds on first call.
    random.nextBytes(new byte[20]);
}

From source file:org.cesecore.keys.token.BaseCryptoToken.java

/**
 * This method extracts a PrivateKey from the keystore and wraps it, using a symmetric encryption key
 *
 * @param privKeyTransform - transformation algorithm
 * @param spec - transformation algorithm spec (e.g: IvParameterSpec for CBC mode)
 * @param encryptionKeyAlias - alias of the symmetric key that will encrypt the private key
 * @param privateKeyAlias - alias for the PrivateKey to be extracted
 * @return byte[] with the encrypted extracted key
 * @throws NoSuchAlgorithmException if privKeyTransform is null, empty, in an invalid format, or if no Provider supports a CipherSpi
 *             implementation for the specified algorithm.
 * @throws NoSuchPaddingException if privKeyTransform contains a padding scheme that is not available.
 * @throws NoSuchProviderException if BouncyCastle is not registered in the security provider list.
 * @throws InvalidKeyException if the encryption key derived from encryptionKeyAlias was invalid.
 * @throws IllegalBlockSizeException if the Cipher created using privKeyTransform is a block cipher, no padding has been requested, and the length
 *             of the encoding of the key to be wrapped is not a multiple of the block size.
 * @throws CryptoTokenOfflineException if Crypto Token is not available or connected, or key with alias does not exist.
 * @throws InvalidAlgorithmParameterException if spec id not valid or supported.
 * @throws PrivateKeyNotExtractableException if the key is not extractable, does not exist or encryption fails
 *//*w  ww.j  av  a  2  s. c  o  m*/
public byte[] extractKey(String privKeyTransform, AlgorithmParameterSpec spec, String encryptionKeyAlias,
        String privateKeyAlias) throws NoSuchAlgorithmException, NoSuchPaddingException,
        NoSuchProviderException, InvalidKeyException, IllegalBlockSizeException, CryptoTokenOfflineException,
        PrivateKeyNotExtractableException, InvalidAlgorithmParameterException {

    if (doPermitExtractablePrivateKey()) {
        // get encryption key
        Key encryptionKey = getKey(encryptionKeyAlias);
        // get private key to wrap
        PrivateKey privateKey = getPrivateKey(privateKeyAlias);
        if (privateKey == null) {
            throw new PrivateKeyNotExtractableException(
                    "Extracting key with alias '" + privateKeyAlias + "' return null.");
        }

        // since SUN PKCS11 Provider does not implements WRAP_MODE,
        // ENCRYPT_MODE with encoded private key will be used instead, giving the same result
        Cipher c = null;
        c = Cipher.getInstance(privKeyTransform, getEncProviderName());
        if (spec == null) {
            c.init(Cipher.ENCRYPT_MODE, encryptionKey);
        } else {
            c.init(Cipher.ENCRYPT_MODE, encryptionKey, spec);
        }

        // wrap key
        byte[] encryptedKey;
        try {
            byte[] data = privateKey.getEncoded();
            if (StringUtils.containsIgnoreCase(privKeyTransform, "NoPadding")) {
                // We must add PKCS7/PKCS5 padding ourselves to the data
                final PKCS7Padding padding = new PKCS7Padding();
                // Calculate the number of pad bytes needed
                final int rem = data.length % c.getBlockSize();
                final int padlen = c.getBlockSize() - rem;
                if (log.isDebugEnabled()) {
                    log.debug("Padding key data with " + padlen + " bytes, using PKCS7/5Padding. Total len: "
                            + (data.length + padlen));
                }
                byte[] newdata = Arrays.copyOf(data, data.length + padlen);
                padding.addPadding(newdata, data.length);
                data = newdata;
            }
            encryptedKey = c.doFinal(data);
        } catch (BadPaddingException e) {
            throw new PrivateKeyNotExtractableException(
                    "Extracting key with alias '" + privateKeyAlias + "' failed.");
        }

        return encryptedKey;
    } else {
        final String msg = intres.getLocalizedMessage("token.errornotextractable", privateKeyAlias,
                encryptionKeyAlias);
        throw new PrivateKeyNotExtractableException(msg);
    }
}

From source file:org.cleverbus.admin.services.log.LogParserConfig.java

public boolean isMatchesFilter(String propertyValue, int propertyIndex) {
    String expectedValue = filter.get(getPropertyNames().get(propertyIndex));
    return expectedValue == null || StringUtils.containsIgnoreCase(propertyValue, expectedValue);
}

From source file:org.cleverbus.core.alerts.AlertsPropertiesConfiguration.java

/**
 * Initializes configuration from properties.
 *///from   w w  w . j a  va  2  s  . c o  m
private void initProps() {
    // example of alert configuration
    //        alerts.900.id=WAITING_MSG_ALERT
    //        alerts.900.limit=0
    //        alerts.900.sql=SELECT COUNT(*) FROM message WHERE state = 'WAITING_FOR_RES'
    //        alerts.900.enabled=true
    //        alerts.900.mail.subject=There are %d message(s) in WAITING_FOR_RESPONSE state for more then %d seconds.
    //        alerts.900.mail.body=Alert: notification about WAITING messages

    // get relevant properties for alerts
    List<String> propNames = new ArrayList<String>();

    Enumeration<?> propNamesEnum = properties.propertyNames();
    while (propNamesEnum.hasMoreElements()) {
        String propName = (String) propNamesEnum.nextElement();

        if (propName.startsWith(ALERT_PROP_PREFIX)) {
            propNames.add(propName);
        }
    }

    // get alert IDs
    Set<String> orders = new HashSet<String>();

    Pattern pattern = Pattern.compile("alerts\\.(\\d+)\\.id");
    for (String propName : propNames) {
        Matcher matcher = pattern.matcher(propName);

        if (matcher.matches()) {
            String order = StringUtils.substringBetween(propName, ALERT_PROP_PREFIX, ".");

            if (orders.contains(order)) {
                throw new IllegalStateException(
                        "Wrong alert's configuration - alert order '" + order + "' was already used.");
            } else {
                orders.add(order);
            }
        }
    }

    // get property values
    Set<String> ids = new HashSet<String>();
    for (String order : orders) {
        String propPrefix = ALERT_PROP_PREFIX + order + ".";

        String id = properties.getProperty(propPrefix + ID_PROP);

        // check if id is unique
        if (ids.contains(id)) {
            throw new IllegalStateException("Wrong alert's configuration - id '" + id + "' is not unique.");
        } else {
            ids.add(id);
        }

        String limit = properties.getProperty(propPrefix + LIMIT_PROP);
        String sql = properties.getProperty(propPrefix + SQL_PROP);

        // check if sql contains count()
        if (!StringUtils.containsIgnoreCase(sql, "count(")) {
            throw new IllegalStateException(
                    "Wrong alert's configuration - SQL clause for id '" + id + "' doesn't contain count().");
        }

        String enabled = properties.getProperty(propPrefix + ENABLED_PROP);
        enabled = enabled == null ? "true" : enabled;

        String subject = properties.getProperty(propPrefix + MAIL_SBJ_PROP);
        String body = properties.getProperty(propPrefix + MAIL_BODY_PROP);

        // add new alert
        try {
            AlertInfo alertInfo = new AlertInfo(id, Long.valueOf(limit), sql, BooleanUtils.toBoolean(enabled),
                    subject, body);

            addAlert(alertInfo);
        } catch (Exception ex) {
            throw new IllegalStateException("Wrong alert's configuration - conversion error", ex);
        }
    }
}

From source file:org.codelabor.example.lang.StringUtilsTest.java

@Test
public void testContainsIgnoreCase() {
    String text = "ABCD";
    String searchString = "a";
    Assert.assertEquals(true, StringUtils.containsIgnoreCase(text, searchString));
}

From source file:org.codinjutsu.tools.jenkins.security.DefaultSecurityClient.java

protected void checkResponse(int statusCode, String responseBody) throws AuthenticationException {
    if (statusCode == HttpURLConnection.HTTP_NOT_FOUND) {
        throw new AuthenticationException("Not found");
    }//from w w w .  jav a 2  s .c o m

    if (statusCode == HttpURLConnection.HTTP_FORBIDDEN || statusCode == HttpURLConnection.HTTP_UNAUTHORIZED) {
        if (StringUtils.containsIgnoreCase(responseBody, BAD_CRUMB_DATA)) {
            throw new AuthenticationException("CSRF enabled -> Missing or bad crumb data");
        }

        throw new AuthenticationException("Unauthorized -> Missing or bad credentials", responseBody);
    }

    if (HttpURLConnection.HTTP_INTERNAL_ERROR == statusCode) {
        throw new AuthenticationException("Server Internal Error: Server unavailable");
    }
}

From source file:org.diffkit.diff.sns.DKPoiSheet.java

/**
 * map the "builtin" formats to Types//from w  ww . ja va  2 s  .co m
 */
private static Type mapTypeForFormatString(String format_) {
    if (format_ == null)
        return null;
    if (format_.equalsIgnoreCase("general"))
        return Type.DECIMAL;
    else if (format_.equals("0"))
        return Type.INTEGER;
    else if (format_.equals("0.00"))
        return Type.DECIMAL;
    else if (format_.equals("#,##0"))
        return Type.INTEGER;
    else if (format_.equals("#,##0.00"))
        return Type.DECIMAL;
    else if (format_.equals("0%"))
        return Type.INTEGER;
    else if (format_.equals("0.00%"))
        return Type.DECIMAL;
    else if (format_.equalsIgnoreCase("mm/dd/yy"))
        return Type.DATE;
    else if (format_.equalsIgnoreCase("YYYY\\-MM\\-DD"))
        return Type.DATE;
    else if (StringUtils.startsWithIgnoreCase(format_, "hh:mm:ss"))
        return Type.TIME;
    else if (StringUtils.startsWithIgnoreCase(format_, "hh:mm"))
        return Type.TIME;
    else if (StringUtils.startsWithIgnoreCase(format_, "h:mm"))
        return Type.TIME;
    else if (StringUtils.startsWithIgnoreCase(format_, "h:mm:ss"))
        return Type.TIME;
    else if (StringUtils.containsIgnoreCase(format_, "dd/yy")
            && StringUtils.containsIgnoreCase(format_, "hh:mm"))
        return Type.TIMESTAMP;
    else if (format_.equalsIgnoreCase("m/d/yy"))
        return Type.DATE;
    else if (format_.equalsIgnoreCase("d-mmm-yy"))
        return Type.DATE;
    else if (format_.equalsIgnoreCase("d-mmm"))
        return Type.DATE;
    else if (format_.equalsIgnoreCase("mmm-yy"))
        return Type.DATE;
    else if (format_.equalsIgnoreCase("m/d/yy h:mm"))
        return Type.TIMESTAMP;
    else if (format_.equals("$#,##0_);($#,##0)"))
        return Type.INTEGER;
    else if (format_.equals("$#,##0_);[Red]($#,##0)"))
        return Type.INTEGER;
    else if (format_.equals("$#,##0.00);($#,##0.00)"))
        return Type.DECIMAL;
    else if (format_.equals("$#,##0.00_);[Red]($#,##0.00)"))
        return Type.DECIMAL;
    else if (format_.equals("0.00E+00"))
        return Type.DECIMAL;
    else if (format_.equals("# ?/?"))
        return Type.REAL;
    else if (format_.equals("# ??/??"))
        return Type.REAL;
    else if (format_.equals("#,##0_);[Red](#,##0)"))
        return Type.INTEGER;
    else if (format_.equals("#,##0.00_);(#,##0.00)"))
        return Type.DECIMAL;
    else if (format_.equals("#,##0.00_);[Red](#,##0.00)"))
        return Type.DECIMAL;
    else if (format_.equalsIgnoreCase("mm:ss"))
        return Type.TIME;
    else if (format_.equalsIgnoreCase("[h]:mm:ss"))
        return Type.TIME;
    else if (format_.equalsIgnoreCase("mm:ss.0"))
        return Type.TIME;
    else if (format_.equals("##0.0E+0"))
        return Type.INTEGER;
    else
        return Type.DECIMAL;
}