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

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

Introduction

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

Prototype

public static String trimToEmpty(String str) 

Source Link

Document

Removes control characters (char <= 32) from both ends of this String returning an empty String ("") if the String is empty ("") after the trim or if it is null.

Usage

From source file:com.alibaba.cobar.client.router.config.support.InternalRuleLoader4DefaultInternalRouter.java

public void loadRulesAndEquipRouter(List<InternalRule> rules, DefaultCobarClientInternalRouter router,
        Map<String, Object> functionsMap) {
    if (CollectionUtils.isEmpty(rules)) {
        return;//from ww  w.jav a 2 s .  com
    }

    for (InternalRule rule : rules) {
        String namespace = StringUtils.trimToEmpty(rule.getNamespace());
        String sqlAction = StringUtils.trimToEmpty(rule.getSqlmap());
        String shardingExpression = StringUtils.trimToEmpty(rule.getShardingExpression());
        String destinations = StringUtils.trimToEmpty(rule.getShards());

        Validate.notEmpty(destinations, "destination shards must be given explicitly.");

        if (StringUtils.isEmpty(namespace) && StringUtils.isEmpty(sqlAction)) {
            throw new IllegalArgumentException("at least one of 'namespace' or 'sqlAction' must be given.");
        }
        if (StringUtils.isNotEmpty(namespace) && StringUtils.isNotEmpty(sqlAction)) {
            throw new IllegalArgumentException(
                    "'namespace' and 'sqlAction' are alternatives, can't guess which one to use if both of them are provided.");
        }

        if (StringUtils.isNotEmpty(namespace)) {
            List<Set<IRoutingRule<IBatisRoutingFact, List<String>>>> ruleSequence = setUpRuleSequenceContainerIfNecessary(
                    router, namespace);

            if (StringUtils.isEmpty(shardingExpression)) {

                ruleSequence.get(3).add(new IBatisNamespaceRule(namespace, destinations));
            } else {
                IBatisNamespaceShardingRule insr = new IBatisNamespaceShardingRule(namespace, destinations,
                        shardingExpression);
                if (MapUtils.isNotEmpty(functionsMap)) {
                    insr.setFunctionMap(functionsMap);
                }
                ruleSequence.get(2).add(insr);
            }
        }
        if (StringUtils.isNotEmpty(sqlAction)) {
            List<Set<IRoutingRule<IBatisRoutingFact, List<String>>>> ruleSequence = setUpRuleSequenceContainerIfNecessary(
                    router, StringUtils.substringBeforeLast(sqlAction, "."));

            if (StringUtils.isEmpty(shardingExpression)) {
                ruleSequence.get(1).add(new IBatisSqlActionRule(sqlAction, destinations));
            } else {
                IBatisSqlActionShardingRule issr = new IBatisSqlActionShardingRule(sqlAction, destinations,
                        shardingExpression);
                if (MapUtils.isNotEmpty(functionsMap)) {
                    issr.setFunctionMap(functionsMap);
                }
                ruleSequence.get(0).add(issr);
            }
        }
    }
}

From source file:ml.shifu.shifu.core.processor.ShifuTestProcessor.java

public int run() {
    LOG.info("Step Start: test");
    int status = 0;

    try {//ww  w. j  ava  2  s.com
        setUp(ModelInspector.ModelStep.TEST);

        if (isToTestFilter()) {
            String testTarget = StringUtils.trimToEmpty(getTestTarget());
            if (StringUtils.isBlank(testTarget)) { // test filter in training dataset
                status = runFilterTest(modelConfig);
            } else if (testTarget.equals("*")) { // test filters in train and eval dataset
                status = runFilterTest(modelConfig);
                for (EvalConfig evalConfig : this.modelConfig.getEvals()) {
                    status += runFilterTest(evalConfig);
                }
            } else {
                String[] evalNames = testTarget.split(",");
                for (String evalName : evalNames) {
                    EvalConfig evalConfig = this.modelConfig
                            .getEvalConfigByName(StringUtils.trimToEmpty(evalName));
                    if (evalConfig == null) {
                        LOG.error("Eval - {} doesn't exist!");
                        status = 1;
                        break;
                    }

                    status += runFilterTest(evalConfig);
                }
            }
        }
    } catch (Exception e) {
        LOG.error("Fail to run test for Shifu.", e);
        status = 1;
    }

    return (status > 0 ? 1 : 0);
}

From source file:com.hangum.tadpole.commons.libs.core.utils.ValidChecker.java

/**
 * combo checker util//from  w w w  .  ja v a  2s.com
 * 
 * @param text
 * @param msg
 * @return
 */
public static boolean checkTextCtl(Combo text, String msg) {
    if ("".equals(StringUtils.trimToEmpty(text.getText()))) { //$NON-NLS-1$
        MessageDialog.openWarning(null, Messages.get().Warning, msg + Messages.get().CheckTextString);
        text.setFocus();

        return false;
    }

    return true;
}

From source file:com.hangum.tadpole.commons.util.UnicodeUtils.java

/**
 * ? ? ascii    ??  //w ww . j a v  a 2  s . co  m
 * 
 * @param content
 * @return
 */
public static String getUnicode(String content) {
    StringBuffer sbData = new StringBuffer();

    for (int i = 0; i < content.length(); i++) {
        char c = content.charAt(i);
        UnicodeBlock ub = UnicodeBlock.of(c);
        //         logger.debug("[check unicode]" + c + "[ascii code]" + (int)c);

        if (ub.equals(UnicodeBlock.BASIC_LATIN))
            sbData.append(c);
        else {
            //            Character.UnicodeBlock unicodeBlock = Character.UnicodeBlock.of(c);

            if (logger.isDebugEnabled())
                logger.debug("[unicode] [" + c + "]");

            if (UnicodeBlock.HANGUL_SYLLABLES.equals(ub) || UnicodeBlock.HANGUL_COMPATIBILITY_JAMO.equals(ub)
                    || UnicodeBlock.HANGUL_JAMO.equals(ub) || UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS.equals(ub)
                    || UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A.equals(ub)
                    || UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B.equals(ub)
                    || UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS.equals(ub)
                    || UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS_SUPPLEMENT.equals(ub)
                    || UnicodeBlock.HIRAGANA.equals(ub) || UnicodeBlock.KATAKANA.equals(ub)
                    || UnicodeBlock.KATAKANA_PHONETIC_EXTENSIONS.equals(ub)) {

                sbData.append(c);
                //
                // html ?     ? ? ascii code 160 ?.
                //
            } else if ((int) c == 160) {
                sbData.append(" ");
            }
            //            } else
            //               logger.debug("[i won't unicode block] [" + (int)c + "]");
            //            }
        }
    }

    return StringUtils.trimToEmpty(sbData.toString());

}

From source file:edu.lafayette.metadb.model.dataman.DataExporter.java

/**
 * Export data from a project for one item. 
 * @param projectName The project name.//  w  w w.  j av a 2  s  .c  o m
 * @param itemNumber The item number to export.
 * @param delimiter The delimiter to use when writing the export (currently TSV/CSV)
 * @param encoder The character set encoding.
 * @param technical Flag indicating whether to include technical data in the export file.
 * @param replaceEntity Flag indicating whether to escape special characters with their HTML entity codes.
 * @return a String[] representing one row in the exported data file.
 */
public static String[] exportData(String projectName, int itemNumber, char delimiter, String encoder,
        boolean technical, boolean replaceEntity) {
    ArrayList adminDescData = null;
    Item it = ItemsDAO.getItem(projectName, itemNumber);
    adminDescData = it.getData(Global.MD_TYPE_DESC);
    adminDescData.addAll(it.getData(Global.MD_TYPE_ADMIN));

    ArrayList techData = new ArrayList();
    if (technical)
        techData = ItemsDAO.getTechData(projectName, itemNumber);

    String[] out = new String[adminDescData.size() + techData.size()];
    for (int i = 0; i < adminDescData.size(); i++) {
        try {
            String outStr = StringUtils.trimToEmpty(
                    new String(((AdminDescItem) adminDescData.get(i)).getData().getBytes("UTF-8"), encoder)
                            .replace('\t', ' '));
            out[i] = (replaceEntity ? StringEscapeUtils.escapeHtml(outStr)//outStr.replaceAll("&", "&#38;").replaceAll("[\"]", "&#34;").replaceAll("%", "&#37;").replaceAll("'", "&#39;").replaceAll(",", "&#44;")
                    : outStr);
        } catch (Exception e) {
            MetaDbHelper.logEvent(e);
            out[i] = ((AdminDescItem) adminDescData.get(i)).getData();
        }
    }
    //MetaDbHelper.note("Exporting tech data");
    for (int i = 0; i < techData.size(); i++)
        try {
            out[i + adminDescData.size()] = StringUtils
                    .trimToEmpty(new String(((Metadata) techData.get(i)).getData().getBytes("UTF-8"), encoder)
                            .replace('\t', ' '));
        } catch (Exception e) {
            MetaDbHelper.logEvent(e);
            out[i + adminDescData.size()] = ((Metadata) techData.get(i)).getData();
        }

    return out;
}

From source file:de.drv.dsrv.spoc.web.service.impl.SpocRoutingServiceImpl.java

@Override
public URI getFachverfahrenUrl(final String version, final String profile, final String procedure,
        final String dataType) {

    // Evtl. vorhandene Leerzeichen und Zeilenumbrueche eliminieren (und
    // null-Werte in leere Strings umwandeln).
    final String trimmedVersion = StringUtils.trimToEmpty(version);
    final String trimmedProfile = StringUtils.trimToEmpty(profile);
    final String trimmedProcedure = StringUtils.trimToEmpty(procedure);
    final String trimmedDataType = StringUtils.trimToEmpty(dataType);

    // Zu den uebergebenen Werten wird die passende URL aus der SPoC-DB
    // geholt./*from  w  w w .  j a  va 2s.c o m*/
    final SPoCConfigDTO spocConfigDTO = this.spocConfigDAO.selectConfig(trimmedProcedure, trimmedDataType,
            trimmedProfile, trimmedVersion);

    final URI fachverfahrenUri = null;
    if (spocConfigDTO != null) {
        final String startUrl = spocConfigDTO.getStartUrl();
        if (startUrl != null) {
            try {
                return new URI(startUrl);
            } catch (final URISyntaxException exc) {
                LOG.error("Ung\u00fcltiger DB-Eintrag f\u00fcr die Parameter version=" + version + ", profile="
                        + profile + ", procedure=" + procedure + ", dataType=" + dataType + ": " + startUrl,
                        exc);
            }
        }
    }

    return fachverfahrenUri;
}

From source file:com.timeinc.seleniumite.environment.RemoteTestingEnvironment.java

@Override
public String shortSummary() {
    String rval = StringUtils.trimToEmpty(platform) + "/" + StringUtils.trimToEmpty(browserName) + "/"
            + StringUtils.trimToEmpty(browserVersion);
    if (otherData != null && otherData.size() > 0) {
        rval += "/" + otherData.toString();
    }//from   w  w w  .j  av a 2s.  co  m

    return rval;
}

From source file:com.egt.core.db.util.Reporter.java

public static EnumFormatoInforme getReportType(String formato) {
    String str = StringUtils.trimToEmpty(formato);
    EnumFormatoInforme tipo = EnumFormatoInforme.PDF;
    if (EnumFormatoInforme.XLS.getExtension().equalsIgnoreCase(str)) {
        tipo = EnumFormatoInforme.XLS;/*  w  ww  . ja v a  2s  .  com*/
    }
    return tipo;
}

From source file:de.hybris.eventtracking.ws.services.DefaultRawEventEnricher.java

/**
 * @see de.hybris.eventtracking.ws.services.RawEventEnricher#enrich(java.lang.String,
 *      javax.servlet.http.HttpServletRequest)
 *///from w  w w .j  a va 2  s  .c  o m
@Override
public String enrich(final String json, final HttpServletRequest req) {
    final HttpSession session = req.getSession();
    final String sessionId = session.getId();
    final String timestamp = Integer.toString(Math.round(System.currentTimeMillis() / 1000)); // seconds since Unix epoch
    final UserModel user = userService.getCurrentUser();
    String userId = null;
    String userEmail = null;
    if (user != null && CustomerModel.class.isAssignableFrom(user.getClass())) {
        userId = ((CustomerModel) user).getCustomerID();
        userEmail = ((CustomerModel) user).getContactEmail();
    }
    userId = StringUtils.trimToEmpty(userId);
    userEmail = StringUtils.trimToEmpty(userEmail);
    final Chainr chainr = Chainr.fromSpec(JsonUtils
            .jsonToList(String.format(ENRICHMENT_SPEC_TEMPLATE, sessionId, timestamp, userId, userEmail)));
    Map<String, Object> jsonObjectMap;
    try {
        jsonObjectMap = JsonUtils.javason(json);
    } catch (final IOException e) {
        throw new RuntimeException(e);
    }
    return JsonUtils.toJsonString(chainr.transform(jsonObjectMap));
}

From source file:com.hangum.tadpole.engine.sql.util.executer.procedure.PostgreSQLProcedureExecuter.java

/**
 * execute script/*  www.  jav a  2s .co m*/
 */
public String getMakeExecuteScript() throws Exception {
    StringBuffer sbQuery = new StringBuffer();
    if (!"".equals(procedureDAO.getPackagename())) {
        sbQuery.append("SELECT " + procedureDAO.getPackagename() + "." + procedureDAO.getSysName() + "(");
    } else {
        sbQuery.append("SELECT " + procedureDAO.getSysName() + "(");
    }

    List<InOutParameterDAO> inList = getInParameters();
    InOutParameterDAO inOutParameterDAO = inList.get(0);
    String[] inParams = StringUtils.split(inOutParameterDAO.getRdbType(), ",");
    for (int i = 0; i < inParams.length; i++) {
        String name = StringUtils.trimToEmpty(inParams[i]);

        if (i == (inParams.length - 1))
            sbQuery.append(String.format(":%s", name));
        else
            sbQuery.append(String.format(":%s, ", name));
    }
    sbQuery.append(");");

    if (logger.isDebugEnabled())
        logger.debug("Execute Procedure query is\t  " + sbQuery.toString());

    return sbQuery.toString();
}