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:de.willuhn.jameica.hbci.server.KontoauszugPdfUtil.java

/**
 * Erzeugt den Pfad fuer den zu speichernden Kontoauszug.
 * @param k das Konto./*from  w w  w.j a  v  a  2  s  .c om*/
 * @param ka der Kontoauszug. Optional. Wenn er fehlt, werden Default-Werte verwendet.
 * @param path Ordner, in dem die Kontoauszuege gespeichert werden.
 * @param folder Template fuer den Unterordner.
 * @param name Template fuer den Dateinamen.
 * @return der Pfad.
 * @throws RemoteException
 * @throws ApplicationException
 */
public static String createPath(Konto k, Kontoauszug ka, String path, String folder, String name)
        throws RemoteException, ApplicationException {
    if (k == null)
        throw new ApplicationException(i18n.tr("Kein Konto angegeben"));

    Map<String, Object> ctx = new HashMap<String, Object>();

    {
        String iban = StringUtils.trimToNull(k.getIban());
        if (iban == null)
            iban = StringUtils.trimToEmpty(k.getKontonummer());

        ctx.put("iban", iban.replaceAll(" ", ""));
    }

    {
        String bic = StringUtils.trimToNull(k.getBic());
        if (bic == null)
            bic = StringUtils.trimToEmpty(k.getBLZ());

        ctx.put("bic", bic.replaceAll(" ", ""));
    }

    {
        Calendar cal = Calendar.getInstance();
        if (ka != null) {
            if (ka.getErstellungsdatum() != null)
                cal.setTime(ka.getErstellungsdatum());
            else if (ka.getAusfuehrungsdatum() != null)
                cal.setTime(ka.getAusfuehrungsdatum());
        }

        Integer i = ka != null && ka.getJahr() != null ? ka.getJahr() : null;
        ctx.put("jahr", i != null ? i.toString() : Integer.toString(cal.get(Calendar.YEAR)));
        ctx.put("monat", String.format("%02d", cal.get(Calendar.MONTH) + 1));
        ctx.put("tag", String.format("%02d", cal.get(Calendar.DATE)));
        ctx.put("stunde", String.format("%02d", cal.get(Calendar.HOUR_OF_DAY)));
        ctx.put("minute", String.format("%02d", cal.get(Calendar.MINUTE)));
    }

    {
        Integer i = ka != null && ka.getNummer() != null ? ka.getNummer() : null;
        ctx.put("nummer", String.format("%03d", i != null ? i.intValue() : 1));
    }

    VelocityService velocity = Application.getBootLoader().getBootable(VelocityService.class);
    StringBuilder sb = new StringBuilder();

    /////////////////////////////
    // Pfad
    {
        if (path == null || path.length() == 0)
            path = Application.getPluginLoader().getPlugin(HBCI.class).getResources().getWorkPath();
        sb.append(path);

        if (!path.endsWith(File.separator))
            sb.append(File.separator);
    }
    //
    /////////////////////////////

    /////////////////////////////
    // Unter-Ordner
    {
        if (folder != null && folder.length() > 0) {
            try {
                // Velocity-Escaping machen wir. Das sollte der User nicht selbst machen muessen
                // Eigentlich wird hier nur "\$" gegen "\\$" ersetzt. Die zusaetzlichen
                // Die extra Escapings sind fuer Java selbst in String-Literalen.
                folder = folder.replace("\\$", "\\\\$");
                folder = velocity.merge(folder, ctx);
            } catch (Exception e) {
                Logger.error("folder template invalid: \"" + folder + "\"", e);
            }
            sb.append(folder);
            if (!folder.endsWith(File.separator))
                sb.append(File.separator);
        }
    }
    //
    /////////////////////////////

    /////////////////////////////
    // Dateiname
    {
        if (name == null || name.length() == 0 && ka != null)
            name = ka.getDateiname();

        if (name == null || name.length() == 0)
            name = MetaKey.KONTOAUSZUG_TEMPLATE_NAME.getDefault();

        try {
            name = velocity.merge(name, ctx);
        } catch (Exception e) {
            Logger.error("name template invalid: \"" + name + "\"", e);
        }
        sb.append(name);

        // Dateiendung noch anhaengen.
        Format f = Format.find(ka != null ? ka.getFormat() : null);
        if (f == null)
            f = Format.PDF;

        sb.append(".");
        sb.append(f.getExtention());
    }

    return sb.toString();
}

From source file:com.egt.core.util.Utils.java

public static String trimSuffix(String message, String suffix) {
    String mensaje = StringUtils.trimToEmpty(message);
    int i = mensaje.indexOf(suffix);
    if (i > 0) {
        mensaje = mensaje.substring(0, i);
    }//from  www  .j a v a  2  s.c  o m
    return mensaje;
}

From source file:com.egt.core.jsf.JSF.java

public static String getWebuiString(UIComponent uic, String key) {
    //      Bitacora.trace(JSF.class, "getWebuiString-1", uic, key);
    FacesContext fc = FacesContext.getCurrentInstance();
    UIViewRoot uivr = fc.getViewRoot();/* w  w w . j  a v  a2s . c om*/
    ResourceBundle rb = fc.getApplication().getResourceBundle(fc, "bundle");
    String x = StringUtils.trimToEmpty(uivr.getViewId()).replace("/", "").replace(JS.JSP_SUFFIX, "_");
    String y = StringUtils.trimToEmpty(uic.getId());
    String z = StringUtils.isBlank(key) ? "" : "_" + key;
    String k = x + y + z;
    if (StringUtils.isNotBlank(k)) {
        String v = getWebuiString(rb, k);
        // <editor-fold defaultstate="collapsed">
        //          if (v == null) {
        //              k = y + z;
        //              v = getWebuiString(rb, k);
        //          }
        // </editor-fold>
        return v;
    }
    return null;
}

From source file:com.hangum.tadpole.rdb.core.dialog.dbconnect.composite.MSSQLLoginComposite.java

@Override
public boolean makeUserDBDao(boolean isTest) {
    if (!isValidateInput(isTest))
        return false;

    String dbUrl = "";
    String strHost = StringUtils.trimToEmpty(textHost.getText());
    String strPort = StringUtils.trimToEmpty(textPort.getText());
    String strDB = StringUtils.trimToEmpty(textDatabase.getText());

    if (StringUtils.contains(strHost, "\\")) {

        String strIp = StringUtils.substringBefore(strHost, "\\");
        String strInstance = StringUtils.substringAfter(strHost, "\\");

        dbUrl = String.format(getSelectDB().getDB_URL_INFO(), strIp, strPort, strDB) + ";instance="
                + strInstance;//from w w w  .  j  av a  2  s  .com
    } else if (StringUtils.contains(strHost, "/")) {

        String strIp = StringUtils.substringBefore(strHost, "/");
        String strInstance = StringUtils.substringAfter(strHost, "/");

        dbUrl = String.format(getSelectDB().getDB_URL_INFO(), strIp, strPort, strDB) + ";instance="
                + strInstance;

    } else {
        dbUrl = String.format(getSelectDB().getDB_URL_INFO(), strHost, strPort, strDB);
    }
    if (!"".equals(textJDBCOptions.getText())) {
        if (StringUtils.endsWith(dbUrl, ";")) {
            dbUrl += textJDBCOptions.getText();
        } else {
            dbUrl += ";" + textJDBCOptions.getText();
        }
    }

    if (logger.isDebugEnabled())
        logger.debug("[db url]" + dbUrl);

    userDB = new UserDBDAO();
    userDB.setDbms_type(getSelectDB().getDBToString());
    userDB.setUrl(dbUrl);
    userDB.setUrl_user_parameter(textJDBCOptions.getText());
    userDB.setDb(StringUtils.trimToEmpty(textDatabase.getText()));
    userDB.setGroup_name(StringUtils.trimToEmpty(preDBInfo.getComboGroup().getText()));
    userDB.setDisplay_name(StringUtils.trimToEmpty(preDBInfo.getTextDisplayName().getText()));

    String dbOpType = PublicTadpoleDefine.DBOperationType
            .getNameToType(preDBInfo.getComboOperationType().getText()).name();
    userDB.setOperation_type(dbOpType);
    if (dbOpType.equals(PublicTadpoleDefine.DBOperationType.PRODUCTION.name())
            || dbOpType.equals(PublicTadpoleDefine.DBOperationType.BACKUP.name())) {
        userDB.setIs_lock(PublicTadpoleDefine.YES_NO.YES.name());
    }

    userDB.setHost(StringUtils.trimToEmpty(textHost.getText()));
    userDB.setPort(StringUtils.trimToEmpty(textPort.getText()));
    userDB.setUsers(StringUtils.trimToEmpty(textUser.getText()));
    userDB.setPasswd(StringUtils.trimToEmpty(textPassword.getText()));

    // ? ?? ? .
    userDB.setRole_id(PublicTadpoleDefine.USER_ROLE_TYPE.ADMIN.toString());

    // others connection  .
    setOtherConnectionInfo();

    return true;
}

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

/**
 * Search files on the query./*  w w  w .j  a va  2  s  . co m*/
 *
 * @param user  current user
 * @param query query string
 * @param model model
 * @return script/list
 */
@RequestMapping(value = "/search/**")
public String search(User user, @RequestParam(required = true, value = "query") final String query,
        ModelMap model) {
    final String trimmedQuery = StringUtils.trimToEmpty(query);
    List<FileEntry> searchResult = newArrayList(
            filter(fileEntryService.getAll(user), new Predicate<FileEntry>() {
                @Override
                public boolean apply(@Nullable FileEntry input) {
                    return input.getFileType() != FileType.DIR && StringUtils
                            .containsIgnoreCase(new File(input.getPath()).getName(), trimmedQuery);
                }
            }));
    model.addAttribute("query", query);
    model.addAttribute("files", searchResult);
    model.addAttribute("currentPath", "");
    return "script/list";
}

From source file:eionet.meta.dao.domain.DataElement.java

/**
 * String representation of the element attribute value.
 *
 * @return value or related concept label depending on the element type
 *///ww w.j  ava  2 s  .  c om
public String getValueText() {
    return isRelationalElement() ? StringUtils.trimToEmpty(getRelatedConceptLabel())
            : StringUtils.trimToEmpty(getAttributeValue())
                    + (getAttributeLanguage() != null ? " [" + getAttributeLanguage() + "]" : "");
}

From source file:adalid.commons.util.StrUtils.java

public static String getIdentificadorSql(String prefix, String string, String suffix, int maxLength) {
    if (StringUtils.isBlank(string)) {
        return string;
    }//from w w w  .  j av  a2 s  . c o m
    char separator = string.contains("$") ? '$' : '_';
    String trimmedPrefix = StringUtils.trimToEmpty(prefix);
    String trimmedString = StringUtils.trimToEmpty(string);
    String trimmedSuffix = StringUtils.trimToEmpty(suffix);
    String shorterString = trimmedPrefix + trimmedString + trimmedSuffix;
    String endlessString = shorterString;
    if (maxLength > 0 && shorterString.length() > maxLength) {
        String numericCode = separator + getNumericCode(trimmedString);
        String[] chunks = StringUtils.split(trimmedString, separator);
        String[] shorterChunks = new String[chunks.length];
        int chunkCount = chunks.length;
        int separators = chunkCount - 1;
        int available1 = maxLength - trimmedPrefix.length() - numericCode.length() - trimmedSuffix.length();
        int available2 = available1 - separators;
        int averageChunkLength = chunkCount > 1 ? available2 / chunkCount : available1;
        if (available1 > 0 && available2 > 0 && averageChunkLength > 0) {
            int overAverageChunkCount = 0;
            int lastOverAverageChunkIndex = 0;
            int used = 0;
            int chunkLength;
            String chunk;
            for (int i = 0; i < chunks.length; i++) {
                chunk = chunks[i];
                chunkLength = chunk.length();
                if (chunkLength > averageChunkLength) {
                    overAverageChunkCount++;
                    lastOverAverageChunkIndex = i;
                    used += averageChunkLength;
                } else {
                    used += chunkLength;
                }
            }
            int free = available2 - used;
            int over = overAverageChunkCount == 0 ? 0
                    : Long.valueOf(Math.round((double) free / overAverageChunkCount)).intValue();
            int plus, size;
            for (int i = 0; i < chunks.length; i++) {
                chunk = chunks[i];
                chunkLength = chunk.length();
                if (chunkLength > averageChunkLength) {
                    plus = averageChunkLength + over > chunkLength ? chunkLength - averageChunkLength : over;
                    if (i == lastOverAverageChunkIndex) {
                        size = averageChunkLength + free;
                        free = 0;
                    } else if (free < plus) {
                        size = averageChunkLength;
                    } else {
                        size = averageChunkLength + plus;
                        free -= plus;
                    }
                } else {
                    size = chunkLength;
                }
                if (chunk.contains("_")) {
                    shorterChunks[i] = getElementoIdentificadorSql(chunk, Math.min(size, chunkLength));
                } else {
                    shorterChunks[i] = chunk.substring(0, Math.min(size, chunkLength));
                }
            }
            shorterString = trimmedPrefix + StringUtils.join(shorterChunks, separator) + numericCode
                    + trimmedSuffix;
        } else if (available1 > 0) {
            shorterString = trimmedPrefix + trimmedString.substring(0, available1) + numericCode
                    + trimmedSuffix;
        } else {
            shorterString = trimmedPrefix + numericCode + trimmedSuffix;
        }
    }
    //      logIdentificadorSql(endlessString, shorterString);
    return shorterString;
}

From source file:com.fiveamsolutions.nci.commons.data.security.AbstractUser.java

/**
 * Get the display name for the current user, which is "last, first (institute code [, institute code]*)".
 * @return the display name for this current user
 *//*from w w  w  . j ava 2 s . c  om*/
@Transient
public String getDisplayName() {
    StringBuffer displayName = new StringBuffer();
    displayName.append(StringUtils.trimToEmpty(getLastName()));
    displayName.append(", ");
    displayName.append(StringUtils.trimToEmpty(getFirstName()));
    return StringUtils.trimToEmpty(displayName.toString());
}

From source file:com.vangent.hieos.services.xds.bridge.mapper.CDAToXDSMapper.java

/**
 * Method description/*from w w  w  .jav  a 2 s. co  m*/
 *
 *
 * @param result
 * @param rootField
 * @param extensionField
 */
private void remapForXON(Map<String, String> result, ContentVariableName rootField,
        ContentVariableName extensionField) {

    String root = result.get(rootField.toString());

    root = StringUtils.trimToEmpty(root);

    String ext = result.get(extensionField.toString());

    ext = StringUtils.trimToEmpty(ext);

    if (StringUtils.isBlank(ext)) {

        // "Case 1 - root only"
        // extension becomes root, root becomes blank
        result.put(extensionField.toString(), root);
        result.put(rootField.toString(), "");

    } else {

        // "Case 2 - root and extension"
        // put root into proper format
        String isoroot = String.format("&%s&ISO", root);

        result.put(rootField.toString(), isoroot);
    }
}

From source file:com.hangum.tadpole.manager.core.editor.executedsql.ExecutedSQLEditor.java

/**
 * search/*  ww w.  j  a  v a 2  s  . co m*/
 */
private void search() {
    //  ? ?? .
    clearGrid();
    mapSQLHistory.clear();

    // check all db
    String db_seq = "";
    if (!comboDatabase.getText().equals("All")) {
        searchUserDBDAO = (UserDBDAO) comboDatabase.getData(comboDatabase.getText());
        db_seq = "" + searchUserDBDAO.getSeq();
    } else {
        searchUserDBDAO = null;
        for (int i = 0; i < listUserDBDAO.size(); i++) {
            UserDBDAO userDB = listUserDBDAO.get(i);
            if (i == (listUserDBDAO.size() - 1))
                db_seq += ("" + userDB.getSeq());
            else
                db_seq += userDB.getSeq() + ",";
        }
    }

    Calendar cal = Calendar.getInstance();
    cal.set(dateTimeStart.getYear(), dateTimeStart.getMonth(), dateTimeStart.getDay(), 0, 0, 0);
    long startTime = cal.getTimeInMillis();

    cal.set(dateTimeEnd.getYear(), dateTimeEnd.getMonth(), dateTimeEnd.getDay(), 23, 59, 59);
    long endTime = cal.getTimeInMillis();
    int duringExecute = Integer.parseInt(textMillis.getText());

    String strSearchTxt = "%" + StringUtils.trimToEmpty(textSearch.getText()) + "%";

    try {
        List<SQLHistoryDAO> listSQLHistory = TadpoleSystem_ExecutedSQL.getExecuteQueryHistoryDetail(
                comboTypes.getText(), db_seq, startTime, endTime, duringExecute, strSearchTxt);
        for (SQLHistoryDAO sqlHistoryDAO : listSQLHistory) {
            mapSQLHistory.put("" + gridHistory.getRootItemCount(), sqlHistoryDAO);

            GridItem item = new GridItem(gridHistory, SWT.V_SCROLL | SWT.H_SCROLL);

            String strSQL = StringUtils.strip(sqlHistoryDAO.getStrSQLText());
            int intLine = StringUtils.countMatches(strSQL, "\n");
            if (intLine >= 1) {
                int height = (intLine + 1) * 24;
                if (height > 100)
                    item.setHeight(100);
                else
                    item.setHeight(height);
            }

            item.setText(0, "" + gridHistory.getRootItemCount());
            item.setText(1, sqlHistoryDAO.getDbName());
            item.setText(2, Utils.dateToStr(sqlHistoryDAO.getStartDateExecute()));
            logger.debug(Utils.convLineToHtml(strSQL));
            item.setText(3, Utils.convLineToHtml(strSQL));
            item.setToolTipText(3, strSQL);

            item.setText(4, "" + ((sqlHistoryDAO.getEndDateExecute().getTime()
                    - sqlHistoryDAO.getStartDateExecute().getTime()) / 1000f));
            item.setText(5, "" + sqlHistoryDAO.getRows());
            item.setText(6, sqlHistoryDAO.getResult());

            item.setText(7, Utils.convLineToHtml(sqlHistoryDAO.getMesssage()));
            item.setToolTipText(7, sqlHistoryDAO.getMesssage());

            item.setText(8, sqlHistoryDAO.getUserName());
            item.setText(9, sqlHistoryDAO.getIpAddress());

            if ("F".equals(sqlHistoryDAO.getResult())) {
                item.setBackground(SWTResourceManager.getColor(240, 180, 167));
            } else {
                item.setBackground(SWTResourceManager.getColor(SWT.COLOR_GRAY));
            }
        }
    } catch (Exception ee) {
        logger.error("Executed SQL History call", ee); //$NON-NLS-1$
    }
}