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.hangum.tadpole.rdb.core.dialog.export.SQLToStringDialog.java

private void sqlToStr() {
    String variable = textVariable.getText();
    if (StringUtils.trim(variable).equals("")) {
        variable = SQLToJavaConvert.DEFAULT_VARIABLE;
        textVariable.setText(variable);/*from   ww w .  j  ava 2  s.co  m*/
    }

    StringBuffer sbStr = new StringBuffer();
    String[] sqls = parseSQL();

    SQLToLanguageConvert slt = new SQLToLanguageConvert(
            (EditorDefine.SQL_TO_APPLICATION) comboLanguageType.getData(comboLanguageType.getText()));
    for (int i = 0; i < sqls.length; i++) {
        if ("".equals(StringUtils.trimToEmpty(sqls[i])))
            continue;

        if (i == 0)
            sbStr.append(slt.sqlToString(variable, sqls[i]));
        else
            sbStr.append(slt.sqlToString(variable + i, sqls[i]));

        //  ?    .
        sbStr.append("\r\n");
    }

    textConvert.setText(sbStr.toString());
}

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

/**
 * Serializes the fields' components into the single string value (SWIFT format)
 *//*from  w  ww  .j a  v a  2 s  .c  o m*/
@Override
public String getValue() {
    final StringBuilder result = new StringBuilder();
    result.append(":");
    result.append(StringUtils.trimToEmpty(getComponent1()));
    result.append("//");
    if (StringUtils.isNotEmpty(getComponent2())) {
        result.append(StringUtils.trimToEmpty(getComponent2()));
    }
    result.append(StringUtils.trimToEmpty(getComponent3()));
    result.append(StringUtils.trimToEmpty(getComponent4()));
    return result.toString();
}

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

@Override
public void crateComposite() {
    GridLayout gridLayout = new GridLayout(1, false);
    gridLayout.verticalSpacing = 3;//w  ww .j  av  a  2 s. com
    gridLayout.horizontalSpacing = 3;
    gridLayout.marginHeight = 3;
    gridLayout.marginWidth = 3;
    setLayout(gridLayout);
    setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    Composite compositeBody = new Composite(this, SWT.NONE);
    compositeBody.setLayout(new GridLayout(2, false));
    compositeBody.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));

    Label lblOperationType = new Label(compositeBody, SWT.NONE);
    lblOperationType.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));
    lblOperationType.setText(Messages.MySQLLoginComposite_lblOperationType_text);

    comboOperationType = new Combo(compositeBody, SWT.READ_ONLY);
    comboOperationType.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    for (DBOperationType opType : DBOperationType.values()) {
        comboOperationType.add(opType.getTypeName());
    }
    comboOperationType.select(1);

    Label lblGroupName = new Label(compositeBody, SWT.NONE);
    lblGroupName.setText(Messages.MySQLLoginComposite_lblGroupName_text);
    comboGroup = new Combo(compositeBody, SWT.NONE);
    comboGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    for (String strGroup : listGroupName)
        comboGroup.add(strGroup);

    Label lblNewLabel_1 = new Label(compositeBody, SWT.NONE);
    lblNewLabel_1.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));
    lblNewLabel_1.setText(Messages.DBLoginDialog_lblNewLabel_1_text);

    textDisplayName = new Text(compositeBody, SWT.BORDER);
    textDisplayName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    new Label(compositeBody, SWT.NONE);
    new Label(compositeBody, SWT.NONE);

    Label lblHost = new Label(compositeBody, SWT.NONE);
    lblHost.setText(Messages.DBLoginDialog_1);

    textHost = new Text(compositeBody, SWT.BORDER);
    textHost.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    Label lblNewLabelPort = new Label(compositeBody, SWT.NONE);
    lblNewLabelPort.setText(Messages.DBLoginDialog_5);

    textPort = new Text(compositeBody, SWT.BORDER);
    textPort.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    Label lblNewLabelDatabase = new Label(compositeBody, SWT.NONE);
    lblNewLabelDatabase.setLayoutData(new GridData(SWT.LEFT, SWT.BOTTOM, false, false, 1, 1));
    lblNewLabelDatabase.setText(Messages.DBLoginDialog_4);

    textDatabase = new Text(compositeBody, SWT.BORDER);
    textDatabase.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    Label lblUser = new Label(compositeBody, SWT.NONE);
    lblUser.setText(Messages.DBLoginDialog_2);

    textUser = new Text(compositeBody, SWT.BORDER);
    textUser.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    Label lblPassword = new Label(compositeBody, SWT.NONE);
    lblPassword.setText(Messages.DBLoginDialog_3);

    textPassword = new Text(compositeBody, SWT.BORDER | SWT.PASSWORD);
    textPassword.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    Button btnPing = new Button(compositeBody, SWT.NONE);
    btnPing.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            String host = StringUtils.trimToEmpty(textHost.getText());
            String port = StringUtils.trimToEmpty(textPort.getText());

            if ("".equals(host) || "".equals(port)) { //$NON-NLS-1$ //$NON-NLS-2$
                MessageDialog.openError(null, Messages.DBLoginDialog_10, Messages.DBLoginDialog_11);
                return;
            }

            try {
                if (isPing(host, port)) {
                    MessageDialog.openInformation(null, Messages.DBLoginDialog_12, Messages.DBLoginDialog_13);
                } else {
                    MessageDialog.openError(null, Messages.DBLoginDialog_14, Messages.DBLoginDialog_15);
                }
            } catch (NumberFormatException nfe) {
                MessageDialog.openError(null, Messages.MySQLLoginComposite_3, Messages.MySQLLoginComposite_4);
            }
        }
    });
    btnPing.setText(Messages.DBLoginDialog_btnPing_text);

    init();
}

From source file:com.bluexml.xforms.generator.forms.ModelElement.java

protected String buildEnumActionUriFragment(SelectBean selectBean) {
    String enumName;// w ww  .j a  v a  2 s  .  c o  m
    if (selectBean.getEnumeration() != null) {
        enumName = ModelTools.getCompleteName(selectBean.getEnumeration());
    } else {
        enumName = selectBean.getOperatorType();
    }
    // StringBuffer sb = new StringBuffer(enumName);
    // sb.append("/");
    // sb.append(StringUtils.trimToEmpty(selectBean.getEnumParent()));
    // sb.append("/");
    // sb.append(StringUtils.trimToEmpty(selectBean.getEnumContext()));
    // sb.append("/");
    // if (selectBean.isLimited()) {
    // sb.append("1");
    // } else {
    // sb.append("0");
    // }
    String parent = selectBean.getEnumParent();
    String context = selectBean.getEnumContext();
    String limit = selectBean.isLimited() ? "1" : "0";

    StringBuffer sb = new StringBuffer();
    sb.append(MsgId.INT_ACT_PARAM_ENUM_RAWTYPE + "=" + enumName);
    sb.append("&" + MsgId.INT_ACT_PARAM_ENUM_FILTER_PARENT + "=" + StringUtils.trimToEmpty(parent));
    sb.append("&" + MsgId.INT_ACT_PARAM_ENUM_FILTER_DATA + "=" + StringUtils.trimToEmpty(context));
    sb.append("&" + MsgId.INT_ACT_PARAM_ENUM_LIMITED + "=" + limit);

    return sb.toString();
}

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

/**
 * Serializes the fields' components into the single string value (SWIFT format)
 */// w  w w .  j  a v a 2s .c o m
@Override
public String getValue() {
    final StringBuilder result = new StringBuilder();
    if (StringUtils.isNotEmpty(getComponent1())) {
        if (!StringUtils.contains(getComponent1(), "/")) {
            result.append("/");
        }
        result.append(StringUtils.trimToEmpty(getComponent1()));
    }
    if (StringUtils.isNotEmpty(getComponent2()) || StringUtils.isNotEmpty(getComponent3())) {
        result.append(com.prowidesoftware.swift.io.writer.FINWriterVisitor.SWIFT_EOL);
        result.append(StringUtils.trimToEmpty(getComponent2()));
        result.append("/");
        result.append(StringUtils.trimToEmpty(getComponent3()));
    }
    if (StringUtils.isNotEmpty(getComponent4()) || StringUtils.isNotEmpty(getComponent5())) {
        result.append(com.prowidesoftware.swift.io.writer.FINWriterVisitor.SWIFT_EOL);
        result.append(StringUtils.trimToEmpty(getComponent4()));
        result.append("/");
        result.append(StringUtils.trimToEmpty(getComponent5()));
    }
    if (StringUtils.isNotEmpty(getComponent6()) || StringUtils.isNotEmpty(getComponent7())) {
        result.append(com.prowidesoftware.swift.io.writer.FINWriterVisitor.SWIFT_EOL);
        result.append(StringUtils.trimToEmpty(getComponent6()));
        result.append("/");
        result.append(StringUtils.trimToEmpty(getComponent7()));
    }
    if (StringUtils.isNotEmpty(getComponent8()) || StringUtils.isNotEmpty(getComponent9())) {
        result.append(com.prowidesoftware.swift.io.writer.FINWriterVisitor.SWIFT_EOL);
        result.append(StringUtils.trimToEmpty(getComponent8()));
        result.append("/");
        result.append(StringUtils.trimToEmpty(getComponent9()));
    }
    return result.toString();
}

From source file:com.pieframework.model.repository.ModelStore.java

public static List<ExpressionEntry> parseInstanceFile(File file) throws IOException {
    List<ExpressionEntry> retList = new ArrayList<ExpressionEntry>();
    LineIterator it = FileUtils.lineIterator(file);
    try {//w w w  . j  a v  a 2s.c o  m
        while (it.hasNext()) {
            String line = it.nextLine();
            if (StringUtils.startsWith(line, "#")) {
                // ignore comments
            } else {
                String expression = StringUtils.trimToEmpty(StringUtils.substringBefore(line, "="));
                String value = StringUtils.trimToEmpty(StringUtils.substringAfter(line, "="));
                if (StringUtils.isNotEmpty(expression) && StringUtils.isNotEmpty(value)) {
                    retList.add(new ExpressionEntry().withExpression(expression).withValue(value));
                }
            }
        }
    } finally {
        it.close();
    }
    return retList;
}

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

public static String getExtensionNombreArchivo(String archivo, Long usuario) {
    String str = StringUtils.trimToEmpty(archivo);
    String dir = Utils.getSpooledFilesDir(usuario);
    String ext = getExtensionArchivo(archivo);
    if (StringUtils.isNotBlank(ext)) {
        File file = new File(dir + str);
        if (file.isFile()) {
            return ext.toUpperCase();
        }//from  w  w w  .  ja  v a2 s  .  c o m
    }
    return null;
}

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

@SuppressWarnings("PMD.AvoidThrowingRawExceptionTypes")
private static String shaHex(String salt, String pass) {
    try {//w w  w.  j a  va  2s.c  om
        return DigestUtils.shaHex((salt + StringUtils.trimToEmpty(pass)).getBytes("US-ASCII"));
    } catch (UnsupportedEncodingException e) {
        // Cannot happen - java spec guarantees US-ASCII is available (see Charset)
        throw new RuntimeException(e);
    }
}

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

/**
 * Serializes the fields' components into the single string value (SWIFT format)
 *//*ww w  . ja v a2 s. c om*/
@Override
public String getValue() {
    final StringBuilder result = new StringBuilder();
    result.append(":");
    result.append(StringUtils.trimToEmpty(getComponent1()));
    result.append("/");
    if (org.apache.commons.lang.StringUtils.isNotEmpty(getComponent2())) {
        result.append(StringUtils.trimToEmpty(getComponent2()));
    }
    result.append("/");
    result.append(StringUtils.trimToEmpty(getComponent3()));
    result.append("/");
    if (org.apache.commons.lang.StringUtils.isNotEmpty(getComponent4())) {
        result.append(StringUtils.trimToEmpty(getComponent4()));
    }
    result.append(StringUtils.trimToEmpty(getComponent5()));
    if (org.apache.commons.lang.StringUtils.isNotEmpty(getComponent6())) {
        result.append("/");
        result.append(StringUtils.trimToEmpty(getComponent6()));
    }
    return result.toString();
}

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

@Override
public void crateComposite() {
    GridLayout gridLayout = new GridLayout(1, false);
    gridLayout.verticalSpacing = 3;/* w  w  w . java  2s  .  c  o m*/
    gridLayout.horizontalSpacing = 3;
    gridLayout.marginHeight = 3;
    gridLayout.marginWidth = 3;
    setLayout(gridLayout);
    setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    Composite compositeBody = new Composite(this, SWT.NONE);
    compositeBody.setLayout(new GridLayout(2, false));
    compositeBody.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));

    Label lblOperationType = new Label(compositeBody, SWT.NONE);
    lblOperationType.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));
    lblOperationType.setText(Messages.MySQLLoginComposite_lblOperationType_text);

    comboOperationType = new Combo(compositeBody, SWT.READ_ONLY);
    comboOperationType.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    for (DBOperationType opType : DBOperationType.values()) {
        comboOperationType.add(opType.getTypeName());
    }
    comboOperationType.select(1);

    Label lblGroupName = new Label(compositeBody, SWT.NONE);
    lblGroupName.setText(Messages.MySQLLoginComposite_lblGroupName_text);
    comboGroup = new Combo(compositeBody, SWT.NONE);
    comboGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    for (String strGroup : listGroupName)
        comboGroup.add(strGroup);

    Label lblNewLabel_1 = new Label(compositeBody, SWT.NONE);
    lblNewLabel_1.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));
    lblNewLabel_1.setText(Messages.DBLoginDialog_lblNewLabel_1_text);

    textDisplayName = new Text(compositeBody, SWT.BORDER);
    textDisplayName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    new Label(compositeBody, SWT.NONE);
    new Label(compositeBody, SWT.NONE);

    Label lblHost = new Label(compositeBody, SWT.NONE);
    lblHost.setText(Messages.DBLoginDialog_1);

    textHost = new Text(compositeBody, SWT.BORDER);
    textHost.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    Label lblNewLabelPort = new Label(compositeBody, SWT.NONE);
    lblNewLabelPort.setText(Messages.DBLoginDialog_5);

    textPort = new Text(compositeBody, SWT.BORDER);
    textPort.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    Label lblNewLabelDatabase = new Label(compositeBody, SWT.NONE);
    lblNewLabelDatabase.setLayoutData(new GridData(SWT.LEFT, SWT.BOTTOM, false, false, 1, 1));
    lblNewLabelDatabase.setText(Messages.DBLoginDialog_4);

    textDatabase = new Text(compositeBody, SWT.BORDER);
    textDatabase.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    Label lblUser = new Label(compositeBody, SWT.NONE);
    lblUser.setText(Messages.DBLoginDialog_2);

    textUser = new Text(compositeBody, SWT.BORDER);
    textUser.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    Label lblPassword = new Label(compositeBody, SWT.NONE);
    lblPassword.setText(Messages.DBLoginDialog_3);

    textPassword = new Text(compositeBody, SWT.BORDER | SWT.PASSWORD);
    textPassword.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    Label lblLocale = new Label(compositeBody, SWT.NONE);
    lblLocale.setText(Messages.MySQLLoginComposite_lblLocale_text);

    comboLocale = new Combo(compositeBody, SWT.READ_ONLY);
    comboLocale.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    for (String val : DBLocaleUtils.getMySQLList())
        comboLocale.add(val);
    comboLocale.setVisibleItemCount(12);
    comboLocale.select(0);

    Button btnPing = new Button(compositeBody, SWT.NONE);
    btnPing.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            String host = StringUtils.trimToEmpty(textHost.getText());
            String port = StringUtils.trimToEmpty(textPort.getText());

            if ("".equals(host) || "".equals(port)) { //$NON-NLS-1$ //$NON-NLS-2$
                MessageDialog.openError(null, Messages.DBLoginDialog_10, Messages.DBLoginDialog_11);
                return;
            }

            try {
                if (isPing(host, port)) {
                    MessageDialog.openInformation(null, Messages.DBLoginDialog_12, Messages.DBLoginDialog_13);
                } else {
                    MessageDialog.openError(null, Messages.DBLoginDialog_14, Messages.DBLoginDialog_15);
                }
            } catch (NumberFormatException nfe) {
                MessageDialog.openError(null, Messages.MySQLLoginComposite_3, Messages.MySQLLoginComposite_4);
            }
        }
    });
    btnPing.setText(Messages.DBLoginDialog_btnPing_text);

    init();
}