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

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

Introduction

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

Prototype

public static boolean equalsIgnoreCase(final CharSequence str1, final CharSequence str2) 

Source Link

Document

Compares two CharSequences, returning true if they represent equal sequences of characters, ignoring case.

null s are handled without exceptions.

Usage

From source file:com.glaf.core.db.mybatis2.SqlMapClientTemplate.java

public Object executeBatch(final List<SqlExecutor> sqlExecutors) throws DataAccessException {
    return execute(new SqlMapClientCallback<Object>() {
        public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
            executor.startBatch();//from   w ww .  j  a v  a 2 s  . c  o m
            int batch = 0;
            for (SqlExecutor sqlExecutor : sqlExecutors) {
                String statementId = sqlExecutor.getStatementId();
                String operation = sqlExecutor.getOperation();
                Object parameter = sqlExecutor.getParameter();
                if (StringUtils.equalsIgnoreCase("insert", operation)) {
                    executor.insert(statementId, parameter);
                } else if (StringUtils.equalsIgnoreCase("update", operation)) {
                    executor.update(statementId, parameter);
                } else if (StringUtils.equalsIgnoreCase("delete", operation)) {
                    executor.delete(statementId, parameter);
                }
                batch++;
                // ?500????
                if (batch == 500) {
                    executor.executeBatch();
                    batch = 0;
                }
            }
            executor.executeBatch();
            return null;
        }
    });
}

From source file:fr.scc.elo.controller.PlayerController.java

private Comparator<Player> getComparator(EloType type, String sort, String updown) {
    return new Comparator<Player>() {
        @Override//  w w  w  .  j  av a 2  s . com
        public int compare(Player p1, Player p2) {
            if (type == null) {
                if (StringUtils.equalsIgnoreCase(sort, "moyenne")) {
                    if (StringUtils.equals(updown, "up")) {
                        return p1.getEloComparator().compareTo(p2.getEloComparator());
                    } else {
                        return p2.getEloComparator().compareTo(p1.getEloComparator());
                    }
                }
                if (StringUtils.equals(updown, "up")) {
                    return p1.getName().compareTo(p2.getName());
                } else {
                    return p2.getName().compareTo(p1.getName());
                }
            }
            if (StringUtils.equals(updown, "up")) {
                return p1.getElo(type).compareTo(p2.getElo(type));
            } else {
                return p2.getElo(type).compareTo(p1.getElo(type));
            }
        }
    };
}

From source file:com.ottogroup.bi.streaming.operator.json.decode.Base64ContentDecoder.java

/**
 * Decodes the provided {@link Base64} encoded string. Prior decoding a possibly existing prefix is removed from the encoded string.
 * The result which is received from {@link Decoder#decode(byte[])} as array of bytes is converted into a string representation which
 * follows the given encoding // w  w w  .ja  v  a  2 s  . c om
 * @param base64EncodedString
 *          The {@link Base64} encoded string
 * @param noValuePrefix
 *          An optional prefix attached to string after encoding (eg to mark it as base64 value) which must be removed prior decoding
 * @param encoding
 *          The encoding applied on converting the resulting byte array into a string representation  
 * @return
 */
protected String decodeBase64(final String base64EncodedString, final String noValuePrefix,
        final String encoding) throws UnsupportedEncodingException {

    // if the base64 encoded string is either empty or holds only the prefix that must be removed before decoding, the method returns an empty string
    if (StringUtils.isBlank(base64EncodedString)
            || StringUtils.equalsIgnoreCase(base64EncodedString, noValuePrefix))
        return "";

    // remove optional prefix and decode - if the prefix does not exist, simply decode the input
    byte[] result = null;
    if (StringUtils.startsWith(base64EncodedString, noValuePrefix))
        result = Base64.getDecoder().decode(StringUtils.substring(base64EncodedString, noValuePrefix.length()));
    else
        result = Base64.getDecoder().decode(base64EncodedString);

    // if the result array is either null or empty the method returns an empty string
    if (result == null || result.length < 1)
        return "";

    // otherwise: the method tries to convert the array into a proper string representation following the given encoding
    return new String(result, (StringUtils.isNotBlank(encoding) ? encoding : "UTF-8"));
}

From source file:egovframework.com.utl.wed.filter.CkImageSaver.java

protected boolean isAllowFileType(String fileName) {
    boolean isAllow = false;
    if (allowFileTypeArr != null && allowFileTypeArr.length > 0) {
        for (String allowFileType : allowFileTypeArr) {
            if (StringUtils.equalsIgnoreCase(allowFileType, StringUtils.substringAfterLast(fileName, "."))) {
                isAllow = true;//from   w w w  .  j a v  a 2s  . c o m
                break;
            }
        }
    } else {
        isAllow = true;
    }

    return isAllow;
}

From source file:com.eryansky.common.web.struts2.utils.Struts2Utils.java

/**
 * ?contentTypeheaders./*  ww w .  jav a  2 s  .c  om*/
 */
private static HttpServletResponse initResponseHeader(final String contentType, final String... headers) {
    //?headers?
    String encoding = DEFAULT_ENCODING;
    boolean noCache = DEFAULT_NOCACHE;
    for (String header : headers) {
        String headerName = StringUtils.substringBefore(header, ":");
        String headerValue = StringUtils.substringAfter(header, ":");

        if (StringUtils.equalsIgnoreCase(headerName, HEADER_ENCODING)) {
            encoding = headerValue;
        } else if (StringUtils.equalsIgnoreCase(headerName, HEADER_NOCACHE)) {
            noCache = Boolean.parseBoolean(headerValue);
        } else {
            throw new IllegalArgumentException(headerName + "??header");
        }
    }

    HttpServletResponse response = ServletActionContext.getResponse();

    //headers?
    String fullContentType = contentType + ";charset=" + encoding;
    response.setContentType(fullContentType);
    if (noCache) {
        ServletUtils.setDisableCacheHeader(response);
    }

    return response;
}

From source file:com.ottogroup.bi.spqr.operator.kafka.emitter.KafkaTopicEmitter.java

/**
 * @see com.ottogroup.bi.spqr.pipeline.component.MicroPipelineComponent#initialize(java.util.Properties)
 *///  www .j  a va  2 s . c  o  m
public void initialize(Properties properties)
        throws RequiredInputMissingException, ComponentInitializationFailedException {

    /////////////////////////////////////////////////////////////////////////
    // input extraction and validation

    if (properties == null)
        throw new RequiredInputMissingException("Missing required properties");

    clientId = StringUtils.lowerCase(StringUtils.trim(properties.getProperty(CFG_OPT_KAFKA_CLIENT_ID)));
    if (StringUtils.isBlank(clientId))
        throw new RequiredInputMissingException("Missing required kafka client id");

    zookeeperConnect = StringUtils
            .lowerCase(StringUtils.trim(properties.getProperty(CFG_OPT_ZOOKEEPER_CONNECT)));
    if (StringUtils.isBlank(zookeeperConnect))
        throw new RequiredInputMissingException("Missing required zookeeper connect");

    topicId = StringUtils.lowerCase(StringUtils.trim(properties.getProperty(CFG_OPT_TOPIC_ID)));
    if (StringUtils.isBlank(topicId))
        throw new RequiredInputMissingException("Missing required topic");

    brokerList = StringUtils.lowerCase(StringUtils.trim(properties.getProperty(CFG_OPT_BROKER_LIST)));
    if (StringUtils.isBlank(brokerList))
        throw new RequiredInputMissingException("Missing required broker list");

    String charsetName = StringUtils.trim(properties.getProperty(CFG_OPT_CHARSET));
    try {
        if (StringUtils.isNotBlank(charsetName))
            charset = Charset.forName(charsetName);
        else
            charset = Charset.forName("UTF-8");
    } catch (Exception e) {
        throw new RequiredInputMissingException(
                "Invalid character set provided: " + charsetName + ". Error: " + e.getMessage());
    }

    messageAcking = StringUtils
            .equalsIgnoreCase(StringUtils.trim(properties.getProperty(CFG_OPT_MESSAGE_ACKING)), "true");
    //
    /////////////////////////////////////////////////////////////////////////

    if (logger.isDebugEnabled())
        logger.debug("kafka emitter[id=" + this.id + ", client=" + clientId + ", topic=" + topicId + ", broker="
                + brokerList + ", zookeeper=" + zookeeperConnect + ", charset=" + charset.name()
                + ", messageAck=" + messageAcking + "]");

    // initialize the producer only if it is not already exist --- typically assigned through test case!
    if (kafkaProducer == null) {
        Properties props = new Properties();
        props.put(CFG_ZK_CONNECT, zookeeperConnect);
        props.put(CFG_BROKER_LIST, brokerList);
        props.put(CFG_REQUEST_REQUIRED_ACKS, (messageAcking ? "1" : "0"));
        props.put(CFG_CLIENT_ID, clientId);
        this.kafkaProducer = new Producer<>(new ProducerConfig(props));
    }
}

From source file:ke.co.tawi.babblesms.server.servlet.export.csv.ExportCsv.java

/**
 * Returns a zipped MS Excel file of the data specified for exporting.
 *
 * @param request// w  w w  . j  a  va  2  s  . com
 * @param response
 * @throws ServletException, IOException
 */
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    ServletOutputStream out = response.getOutputStream();
    response.setContentType("application/zip");
    response.setHeader("Cache-Control", "cache, must-revalidate");
    response.setHeader("Pragma", "public");

    HttpSession session = request.getSession(false);
    Account account;
    String fileName;

    String exportExcelOption = request.getParameter("exportExcel");

    String sessionEmail = (String) session.getAttribute(SessionConstants.ACCOUNT_SIGN_IN_KEY);

    Element element = accountsCache.get(sessionEmail);
    account = (Account) element.getObjectValue();

    fileName = new StringBuffer(account.getUsername()).append(" ").append(SPREADSHEET_NAME).toString();

    response.setHeader("Content-Disposition",
            "attachment; filename=\"" + StringUtils.replace(fileName, ".xlsx", ".zip") + "\"");

    File excelFile = new File(FileUtils.getTempDirectoryPath() + File.separator + fileName);
    File csvFile = new File(StringUtils.replace(excelFile.getCanonicalPath(), ".xlsx", ".csv"));
    File zippedFile = new File(StringUtils.replace(excelFile.getCanonicalPath(), ".xlsx", ".zip"));

    // These are to determine whether or not we have created a CSV & Excel file on disk
    boolean successCSVFile = true, successExcelFile = true;

    if (StringUtils.equalsIgnoreCase(exportExcelOption, "Export All")) { //export all pages
        successCSVFile = dbFileUtils.sqlResultToCSV(getExportTopupsSqlQuery(account), csvFile.toString(), '|');

        if (successCSVFile) {
            successExcelFile = AllTopupsExportUtil.createExcelExport(csvFile.toString(), "|",
                    excelFile.toString());
        }

    } else if (StringUtils.equalsIgnoreCase(exportExcelOption, "Export Page")) { //export a single page

        InboxPage inboxPage = (InboxPage) session.getAttribute("currentInboxPage");

        successExcelFile = AllTopupsExportUtil.createExcelExport(inboxPage.getContents(), networkHash,
                networkHash, "|", excelFile.toString());

    } else { //export search results

        InboxPage topupPage = (InboxPage) session.getAttribute("currentSearchPage");

        successExcelFile = AllTopupsExportUtil.createExcelExport(topupPage.getContents(), networkHash,
                networkHash, "|", excelFile.toString());
    }

    if (successExcelFile) { // If we successfully created the MS Excel File on disk  
        // Zip the Excel file
        List<File> filesToZip = new ArrayList<>();
        filesToZip.add(excelFile);
        ZipUtil.compressFiles(filesToZip, zippedFile.toString());

        // Push the file to the request
        FileInputStream input = FileUtils.openInputStream(zippedFile);
        IOUtils.copy(input, out);
    }

    out.close();

    FileUtils.deleteQuietly(excelFile);
    FileUtils.deleteQuietly(csvFile);
    FileUtils.deleteQuietly(zippedFile);
}

From source file:com.mirth.connect.model.Connector.java

@Override
public void migrate3_1_0(DonkeyElement element) {
    DonkeyElement properties = element.getChildElement("properties");

    DonkeyElement responseProperties = properties.getChildElement("responseConnectorProperties");
    if (responseProperties != null) {
        DonkeyElement transformer = element.getChildElement("transformer");
        if (transformer != null) {
            /*/*from  w w  w  .ja  va  2  s. c o m*/
             * If the connector is a file reader that is processing batch messages for the
             * delimited data type and there is no method of batch splitting specified, then
             * disable batch processing because pre 3.1.0 the entire message would have been
             * processed. Post 3.1.0 a method of batch splitting is always explicitly specified.
             */
            if (StringUtils.equals(properties.getAttribute("class"),
                    "com.mirth.connect.connectors.file.FileReceiverProperties")) {
                DonkeyElement processBatchElement = properties.getChildElement("processBatch");
                if (processBatchElement != null) {
                    boolean processBatch = StringUtils.equals(processBatchElement.getTextContent(), "true");

                    DonkeyElement inboundProperties = transformer.getChildElement("inboundProperties");
                    boolean delimitedDataType = StringUtils.equals(inboundProperties.getAttribute("class"),
                            "com.mirth.connect.plugins.datatypes.delimited.DelimitedDataTypeProperties");

                    if (delimitedDataType && processBatch) {
                        DonkeyElement batchProperties = inboundProperties.getChildElement("batchProperties");
                        DonkeyElement splitByRecordElement = batchProperties
                                .getChildElement("batchSplitByRecord");

                        if (splitByRecordElement != null) {
                            boolean splitByRecord = StringUtils.equalsIgnoreCase(
                                    batchProperties.getChildElement("batchSplitByRecord").getTextContent(),
                                    "true");
                            boolean splitByDelimiter = StringUtils.isNotEmpty(
                                    batchProperties.getChildElement("batchMessageDelimiter").getTextContent());
                            boolean splitByGroupingColumn = StringUtils.isNotEmpty(
                                    batchProperties.getChildElement("batchGroupingColumn").getTextContent());
                            boolean splitByJavaScript = StringUtils.isNotEmpty(
                                    batchProperties.getChildElement("batchScript").getTextContent());

                            // If no split method is set then disable batch processing
                            if (!splitByRecord && !splitByDelimiter && !splitByGroupingColumn
                                    && !splitByJavaScript) {
                                processBatchElement.setTextContent("false");
                            }
                        }
                    }
                }
            }
        }
    }
}

From source file:com.nridge.core.base.io.xml.DataFieldXML.java

public DataField load(Element anElement) throws IOException {
    Attr nodeAttr;/*  www. j a  va  2  s.  c om*/
    Node nodeItem;
    DataField dataField;
    Element nodeElement;
    Field.Type fieldType;
    String nodeName, nodeValue;

    String attrValue = anElement.getAttribute("name");
    if (StringUtils.isNotEmpty(attrValue)) {
        String fieldName = attrValue;
        attrValue = anElement.getAttribute("type");
        if (StringUtils.isNotEmpty(attrValue))
            fieldType = Field.stringToType(attrValue);
        else
            fieldType = Field.Type.Text;
        dataField = new DataField(fieldType, fieldName);

        NamedNodeMap namedNodeMap = anElement.getAttributes();
        int attrCount = namedNodeMap.getLength();
        for (int attrOffset = 0; attrOffset < attrCount; attrOffset++) {
            nodeAttr = (Attr) namedNodeMap.item(attrOffset);
            nodeName = nodeAttr.getNodeName();
            nodeValue = nodeAttr.getNodeValue();

            if (StringUtils.isNotEmpty(nodeValue)) {
                if ((StringUtils.equalsIgnoreCase(nodeName, "name"))
                        || (StringUtils.equalsIgnoreCase(nodeName, "type"))
                        || (StringUtils.equalsIgnoreCase(nodeName, "rangeType")))
                    continue;
                else if (StringUtils.equalsIgnoreCase(nodeName, "title"))
                    dataField.setTitle(nodeValue);
                else if (StringUtils.equalsIgnoreCase(nodeName, "isMultiValue"))
                    dataField.setMultiValueFlag(StrUtl.stringToBoolean(nodeValue));
                else if (StringUtils.equalsIgnoreCase(nodeName, "displaySize"))
                    dataField.setDisplaySize(Field.createInt(nodeValue));
                else if (StringUtils.equalsIgnoreCase(nodeName, "sortOrder"))
                    dataField.setSortOrder(Field.Order.valueOf(nodeValue));
                else if (StringUtils.equalsIgnoreCase(nodeName, "defaultValue"))
                    dataField.setDefaultValue(nodeValue);
                else
                    dataField.addFeature(nodeName, nodeValue);
            }
        }
        String rangeType = anElement.getAttribute("rangeType");
        if (StringUtils.isNotEmpty(rangeType)) {
            NodeList nodeList = anElement.getChildNodes();
            for (int i = 0; i < nodeList.getLength(); i++) {
                nodeItem = nodeList.item(i);

                if (nodeItem.getNodeType() != Node.ELEMENT_NODE)
                    continue;

                nodeName = nodeItem.getNodeName();
                if (StringUtils.equalsIgnoreCase(nodeName, "Range")) {
                    nodeElement = (Element) nodeItem;
                    dataField.setRange(mRangeXML.load(nodeElement));
                } else if (StringUtils.equalsIgnoreCase(nodeName, "Value")) {
                    nodeValue = XMLUtl.getNodeStrValue(nodeItem);
                    String mvDelimiter = dataField.getFeature(Field.FEATURE_MV_DELIMITER);
                    if (StringUtils.isNotEmpty(mvDelimiter))
                        dataField.expand(nodeValue, mvDelimiter.charAt(0));
                    else
                        dataField.expand(nodeValue);
                }
            }
        } else {
            nodeItem = (Node) anElement;
            if (dataField.isFeatureTrue(Field.FEATURE_IS_CONTENT))
                nodeValue = XMLUtl.getNodeCDATAValue(nodeItem);
            else
                nodeValue = XMLUtl.getNodeStrValue(nodeItem);
            if (dataField.isMultiValue()) {
                String mvDelimiter = dataField.getFeature(Field.FEATURE_MV_DELIMITER);
                if (StringUtils.isNotEmpty(mvDelimiter))
                    dataField.expand(nodeValue, mvDelimiter.charAt(0));
                else
                    dataField.expand(nodeValue);
            } else
                dataField.setValue(nodeValue);
        }
    } else
        dataField = null;

    return dataField;
}

From source file:com.founder.fix.fixflow.explorer.util.ResultUtils.java

/**
 * ?contentTypeheaders.//from www  .j  av a 2s  .  com
 */
private HttpServletResponse initResponseHeader(final String contentType, final String... headers) {
    // ?headers?
    String encoding = DEFAULT_ENCODING;
    boolean noCache = DEFAULT_NOCACHE;
    for (String header : headers) {
        String headerName = StringUtils.substringBefore(header, ":");
        String headerValue = StringUtils.substringAfter(header, ":");

        if (StringUtils.equalsIgnoreCase(headerName, HEADER_ENCODING)) {
            encoding = headerValue;
        } else if (StringUtils.equalsIgnoreCase(headerName, HEADER_NOCACHE)) {
            noCache = Boolean.parseBoolean(headerValue);
        } else {
            throw new IllegalArgumentException(headerName + "??header");
        }
    }

    // headers?
    String fullContentType = contentType + ";charset=" + encoding;
    response.setContentType(fullContentType);
    if (noCache) {
        setDisableCacheHeader(response);
    }

    return response;
}