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.prowidesoftware.swift.model.field.Field50.java

/**
 * Get the Name And Address as a concatenation of component1 to component4.
 * @return the Name And Address from components
 *//*from  w w  w .j a v  a2 s  .co  m*/
public String getNameAndAddress() {
    StringBuilder result = new StringBuilder();
    for (int i = 1; i < 5; i++) {
        if (StringUtils.isNotBlank(getComponent(i))) {
            if (result.length() > 0) {
                result.append(com.prowidesoftware.swift.io.writer.FINWriterVisitor.SWIFT_EOL);
            }
            result.append(StringUtils.trimToEmpty(getComponent(i)));
        }
    }
    return result.toString();
}

From source file:com.iyonger.apm.web.controller.PerfTestController.java

@RequestMapping(value = "/new")
public String saveOne(PerfTest perfTest, long runId, ModelMap model) {
    User user = getCurrentUser();// w  ww. ja v a2  s . c om
    validate(user, null, perfTest);
    // Point to the head revision
    perfTest.setTestName(StringUtils.trimToEmpty(perfTest.getTestName()));
    perfTest.setScriptRevision(-1L);
    //perfTest.prepare(isClone);
    perfTest = perfTestService.save(user, perfTest);

    ApiTestRun run = apiTestRunService.findById(runId);
    run.setPerfTestId(perfTest.getId());
    apiTestRunService.save(run);

    model.clear();

    return "redirect:/perftest/" + perfTest.getId();

}

From source file:com.prowidesoftware.swift.model.field.Field59F.java

/**
 * Serializes the fields' components into the single string value (SWIFT format)
 *//* w  w w.  j av a  2s  . co m*/
@Override
public String getValue() {
    final StringBuilder result = new StringBuilder();
    if (StringUtils.isNotEmpty(getComponent1())) {
        result.append("/");
        result.append(StringUtils.trimToEmpty(getComponent1()));
    }
    for (int comp = 2; comp <= 8; comp++) {
        if (StringUtils.isNotEmpty(getComponent(comp)) || StringUtils.isNotEmpty(getComponent(comp + 1))) {
            if (result.length() > 0) {
                result.append(com.prowidesoftware.swift.io.writer.FINWriterVisitor.SWIFT_EOL);
            }
            result.append(StringUtils.trimToEmpty(getComponent(comp)));
            result.append('/');
            result.append(StringUtils.trimToEmpty(getComponent(comp + 1)));
            comp++;
        }
    }
    return result.toString();
}

From source file:nc.noumea.mairie.appock.entity.Adresse.java

private String construitReprMultiLigneNonBlanche(List<String> listeLigne, String separateur) {
    List<String> listeLigneRetenu = new ArrayList<>();
    for (String ligne : listeLigne) {
        if (!StringUtils.isBlank(ligne)) {
            listeLigneRetenu.add(StringUtils.trimToEmpty(ligne));
        }/*  w  ww .  j  a  v a  2 s  . c o  m*/
    }
    return StringUtils.join(listeLigneRetenu, separateur);
}

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

public static ExporterMessage export(String informe, long funcion, String destino, EnumFormatoArchivo tipo,
        String select, Object[] args) {
    Bitacora.trace(Exporter.class, "export", informe, String.valueOf(funcion), destino, String.valueOf(tipo));
    Long rastro = null;//from  w  ww . j a v  a 2s.c om
    try {
        informe = StringUtils.trimToEmpty(informe);
        if (STP.esIdentificadorArchivoValido(informe)) {
            if (TLC.getControlador().esFuncionAutorizada(funcion)) {
                rastro = TLC.getControlador().ponerInformePendiente(funcion);
                return export(informe, rastro, TLC.getControlador().getUsuario().getIdUsuario(), destino, tipo,
                        select, args, false);
            } else {
                throw new ExcepcionAplicacion(Bitacora.getTextoMensaje(CBM2.FUNCION_NO_AUTORIZADA, informe));
            }
        } else {
            throw new ExcepcionAplicacion(
                    Bitacora.getTextoMensaje(CBM2.IDENTIFICADOR_ARCHIVO_INVALIDO, informe));
        }
    } catch (Exception ex) {
        EnumCondicionEjeFun condicion = EnumCondicionEjeFun.EJECUCION_CANCELADA;
        String mensaje = ThrowableUtils.getString(ex);
        Auditor.grabarRastroInforme(rastro, condicion, null, mensaje);
        TLC.getBitacora().error(mensaje);
    }
    return null;
}

From source file:com.hangum.tadpole.rdb.core.dialog.db.UpdateDeleteConfirmDialog.java

/**
 * initialize data//  w  ww.jav  a  2s. com
 */
private void initData() {
    String strSQL = reqQuery.getSql();
    if (reqQuery.getSqlStatementType() == PublicTadpoleDefine.SQL_STATEMENT_TYPE.PREPARED_STATEMENT) {
        strSQL = reqQuery.getSqlAddParameter();
    }

    textQuery.setText(strSQL);
    try {
        QueryDMLInfoDTO dmlInfoDto = new QueryDMLInfoDTO();
        UpdateDeleteParser parser = new UpdateDeleteParser();
        parser.parseQuery(strSQL, dmlInfoDto);

        String strObjecName = dmlInfoDto.getObjectName();
        String strWhereAfter = StringUtils.substringAfterLast(strSQL.toLowerCase(), "where");

        if (logger.isDebugEnabled()) {
            logger.debug("=============================================================================");
            logger.debug("object name : " + strObjecName);
            logger.debug("where after query: " + strWhereAfter);
            logger.debug("=============================================================================");
        }

        String sqlSelect = "select * from " + strObjecName;
        if (!StringUtils.trimToEmpty(strWhereAfter).equals("")) {
            sqlSelect += " where " + strWhereAfter;

            isWhere = true;
        }

        if (isWhere) {
            QueryExecuteResultDTO rsDAO = QueryUtils.executeQuery(userDB, sqlSelect, 0,
                    GetPreferenceGeneral.getPageCount());
            createTableColumn(reqQuery, tvQueryResult, rsDAO, false);

            tvQueryResult.setLabelProvider(new SQLResultLabelProvider(reqQuery.getMode(), rsDAO));
            tvQueryResult.setContentProvider(new ArrayContentProvider());
            final TadpoleResultSet trs = rsDAO.getDataList();
            tvQueryResult.setInput(trs.getData());
            TableUtil.packTable(tvQueryResult.getTable());

            if (trs.getData().size() < GetPreferenceGeneral.getPageCount()) {
                labelSummaryText.setText(Messages.get().CheckDataAndRunQeury + " ("
                        + String.format(Messages.get().UpdateDeleteConfirmDialog_findData, trs.getData().size())
                        + ")");
            } else {
                labelSummaryText.setText(Messages.get().CheckDataAndRunQeury + " (" + String.format(
                        Messages.get().UpdateDeleteConfirmDialog_findDataOver, trs.getData().size()) + ")");
            }

            tvQueryResult.getTable().setToolTipText(sqlSelect);
        } else {
            if (logger.isDebugEnabled())
                logger.debug("mabe all data delete");
        }

        //  ui  .
        compositeData.setVisible(isWhere);
        compositeWhere.setVisible(!isWhere);
        compositeWhere.getParent().layout(true);

    } catch (Exception e) {
        logger.error("initialize sql", e);
    }
}

From source file:jp.co.nemuzuka.service.impl.TodoServiceImpl.java

/**
 * TODO./*from   w w  w  .  j  a  v a2 s  .c o m*/
 * ???TODO???
 * @param tag (?)
 * @param mail 
 */
private void putTodoTag(String tag, String mail) {

    if (StringUtils.isEmpty(tag)) {
        return;
    }

    String[] tags = tag.split(",");
    Set<String> tagSet = new LinkedHashSet<String>();
    for (String target : tags) {
        String tagName = StringUtils.trimToEmpty(target);
        if (StringUtils.isEmpty(tagName)) {
            continue;
        }
        tagSet.add(tagName);
    }

    if (tagSet.size() == 0) {
        return;
    }
    todoTagService.put(tagSet.toArray(new String[0]), mail);
}

From source file:com.fiveamsolutions.nci.commons.util.SecurityUtils.java

/**
 * Checks a candidate password against business rules.  Rules are:
 * <ul>/*w w  w.  j  a va2s.c o m*/
 * <li>Cannot have leading or trailing whitespace
 * <li>Must be at least 6 characters in length
 * <li>Must contain at least one ascii uppercase letter
 * <li>Must contain at least one ascii lowercase letter
 * <li>Must contain at least one number or special character
 * </ul>
 *
 * @param candidate a candidate password to test
 * @return whether the candidate passes all checks
 */
@SuppressWarnings("PMD.CyclomaticComplexity")
public static boolean isAcceptablePassword(String candidate) {
    // Change to return String[] of violations (which could be keys to resource file)
    // if we want to move to configurable rules
    if (!StringUtils.trimToEmpty(candidate).equals(candidate)) {
        return false;
    }
    if (candidate.length() < MIN_PASSWORD_LENGTH) {
        return false;
    }
    if (!candidate.matches(".*[a-z]+.*")) {
        return false;
    }
    if (!candidate.matches(".*[A-Z]+.*")) {
        return false;
    }
    if (!candidate.matches(".*\\p{Punct}+.*") && !candidate.matches(".*\\p{Digit}+.*")) {
        return false;
    }

    return true;
}

From source file:com.huateng.ebank.business.common.service.CommonService.java

/**
 *
 * Description: ???23893788-0/*from ww  w.  j a  v a2 s . co m*/
 *
 * Modified by Robin Suo For Jira BMS-2329 ???8??
 *
 * @param no ??
 * @return ?boolean
 * @author mengyf
 * @version v1.0,2008-11-19
 */
public boolean checkOrgCode(String no) {
    // ??
    if (StringUtils.isBlank(no)) {
        return false;
    }

    // 
    String orgCode = StringUtils.trimToEmpty(no);

    // ??10?? ?8?9???10??
    if (!Pattern.matches("^[A-Z0-9]{8}\\-[\\d{1}|X]$", orgCode)) {
        return false;
    }

    int[] tempInt = new int[8];
    int[] factor = { 3, 7, 9, 10, 5, 8, 4, 2 };

    int sum = 0;
    if (orgCode.charAt(8) != 45) {
        return false;
    }
    for (int i = 0; i < 10; i++) {
        int c = orgCode.charAt(i);
        if (c <= 122 && c >= 97) {
            return false;
        }
    }

    /*
     * Blocked by Robin Suo For Jira BMS-2329 int fir_value =
     * orgCode.charAt(0); int sec_value = orgCode.charAt(1);
     *
     * if (fir_value >= 65 && fir_value <= 90) { tempInt[0] = (fir_value +
     * 32) - 87; } else if (fir_value >= 48 && fir_value <= 57) { tempInt[0] =
     * fir_value - 48; } else { return false; } sum += factor[0] *
     * tempInt[0];
     *
     * if (sec_value >= 65 && sec_value <= 90) { tempInt[1] = (sec_value -
     * 65) + 10; } else if (sec_value >= 48 && sec_value <= 57) { tempInt[1] =
     * sec_value - 48; } else { return false; } sum += factor[1] *
     * tempInt[1];
     *
     */

    for (int j = 0; j < 8; j++) {
        if (orgCode.charAt(j) >= 65 && orgCode.charAt(j) <= 90) {
            tempInt[j] = orgCode.charAt(j) - 65 + 10;
        } else if (orgCode.charAt(j) >= 48 && orgCode.charAt(j) <= 57) {
            tempInt[j] = orgCode.charAt(j) - 48;
        } else {
            return false;
        }
        sum += factor[j] * tempInt[j];
    }

    // ??
    int balance = 11 - sum % 11;

    // ???
    int last_value = orgCode.charAt(9);

    // ?
    if (!((last_value == 88 && balance == 10) // ?1?'X'?10
            || (balance == 11 && last_value == 48) // ?211?'0'
            || balance == last_value - 48 // ?3balance == last_value -
    // 48
    )) {
        return false;
    }

    return true;
}

From source file:com.thihy.jacoco.data.BundleCoverageDataWriter.java

private void writeMethodCoverage(IMethodCoverage methodCoverage) {
    try {/*from  w w w  . j a  v  a2s . c  o  m*/
        //out.writeByte(BLOCK_METHOD_COVERAGE_DATA);
        writeSourceNode(methodCoverage);
        out.writeUTF(StringUtils.trimToEmpty(methodCoverage.getSignature()));
        out.writeUTF(methodCoverage.getDesc());
    } catch (final IOException e) {
        throw new RuntimeException(e);
    }
}