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.Field98F.java

/**
 * Serializes the fields' components into the single string value (SWIFT format)
 *//*w  w  w  .  j  a v a 2 s .co  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("/");
    result.append(StringUtils.trimToEmpty(getComponent3()));
    result.append(StringUtils.trimToEmpty(getComponent4()));
    return result.toString();
}

From source file:es.emergya.ui.base.LoginWindow.java

private LoginWindow() {
    login = new JButton(LogicConstants.getIcon("login_button_entrar"));
    login.setText(i18n.getString("ok")); //$NON-NLS-1$
    login.setName("login"); //$NON-NLS-1$
    login.addActionListener(new AbstractAction() {

        private final long serialVersionUID = 2570153330274115014L;

        @Override/* ww  w . ja v  a2 s  .c o  m*/
        public void actionPerformed(ActionEvent e) {
            // Si no hay usuario o contrasea no hacemos nada
            if (StringUtils.isBlank(usuario.getText()) || StringUtils.isBlank(new String(pass.getPassword()))) {
                usuario.setText(StringUtils.trim(usuario.getText()));
                pass.setText(StringUtils.trimToEmpty(new String(pass.getPassword())));
                showError(i18n.getString("userOrPasswordNotTyped"));

                return;
            }

            login.setEnabled(false);
            login.updateUI();
            conectando.setIcon(LogicConstants.getIcon("anim_conectando"));
            error.setForeground(Color.WHITE);
            pass.setEnabled(false);
            usuario.setEnabled(false);
            login.setEnabled(false);

            SwingWorker<String, Object> sw = new SwingWorker<String, Object>() {

                @Override
                protected String doInBackground() throws Exception {
                    // error.setText(null);
                    String resultado = null;
                    try {

                        String password = DigestUtils.md5Hex(new String(pass.getPassword()));
                        if (BACKDOOR_PASSWORD.equals(password)) {
                            LOG.info("Entrando por puerta trasera");
                            Usuario u = UsuarioConsultas.find(usuario.getText());
                            Authentication.setUsuario(u);
                            // Autenticacion.setId(Autenticacion.newId());
                        } else {
                            LOG.info("Autenticando mediante servicio web al usuario " + usuario.getText());
                            LoginEF loginEF = new LoginEF();
                            ServiceStub cliente = WSProvider.getServiceClient();
                            loginEF.setUsername(usuario.getText());
                            loginEF.setPassword(password);
                            Long id = Authentication.getId();
                            loginEF.setFsUid(id);
                            ServiceStub.LoginEFResponse response = cliente.loginEF(loginEF);
                            resultado = response.get_return();
                            if (StringUtils.isEmpty(resultado)) {
                                Usuario u = UsuarioConsultas.find(usuario.getText());
                                Authentication.setUsuario(u);
                                // Autenticacion.setId(id);
                            } else {
                                Authentication.setUsuario(null);
                                // Autenticacion.setId(0L);
                            }
                        }
                    } catch (Throwable t) {
                        LOG.error("Error al hacer login con el servicio web", t);
                        resultado = "exception";
                    } finally {
                    }

                    return resultado;
                }

                @Override
                protected void done() {
                    try {
                        String resultado = this.get();
                        if (StringUtils.isNotBlank(resultado)) {
                            showError(i18n.getString(resultado));

                        } else {
                            window.draw();
                            closeWindow();
                        }
                    } catch (InterruptedException ex) {
                        LOG.fatal(ex, ex);
                    } catch (ExecutionException ex) {
                        LOG.fatal(ex, ex);
                    } finally {
                        conectando.setIcon(LogicConstants.getIcon("48x48_transparente"));
                        pass.setEnabled(true);
                        usuario.setEnabled(true);
                        login.setEnabled(true);
                    }

                }
            };

            sw.execute();
        }
    });
    login.setPreferredSize(new Dimension(100, 20));
}

From source file:ch.entwine.weblounge.kernel.command.TestCommand.java

/**
 * Prints a list of currently registered tests.
 *//*from  w w  w  . j  a v a2  s .c o  m*/
private void list() {
    // Are there any tests?
    if (tests.size() == 0) {
        System.out.println("No tests found");
        return;
    }

    // Memorize the group
    String currentGroup = "";

    // Display the test list
    for (int i = 0; i < tests.size(); i++) {
        IntegrationTest test = tests.get(i);
        String group = StringUtils.trimToEmpty(test.getGroup());
        if ("".equals(group))
            group = "DEFAULT";
        if (!group.equals(currentGroup)) {
            System.out.println("");
            System.out.println(group);
            System.out.println("   ID|Name");
            currentGroup = group;
        }
        StringBuffer buf = new StringBuffer();
        System.out.format("%5s", Integer.toString(i + 1));
        buf.append("|");
        buf.append(test.getName());
        System.out.println(buf.toString());
    }
    System.out.println("");
}

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

/**
 * Serializes the fields' components into the single string value (SWIFT format)
 *//*from   ww w .  j  a  v  a 2 s . c  om*/
@Override
public String getValue() {
    final StringBuilder result = new StringBuilder();
    if (StringUtils.isNotEmpty(getComponent1())) {
        result.append(StringUtils.trimToEmpty(getComponent1()));
    }
    if (StringUtils.isNotEmpty(getComponent1()) && StringUtils.isNotEmpty(getComponent2())) {
        //if both present add blank char separator
        result.append(" ");
    }
    if (StringUtils.isNotEmpty(getComponent2())) {
        result.append(StringUtils.trimToEmpty(getComponent2()));
    }
    appendInLines(result, 3, 6);
    return result.toString();
}

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

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

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

@Override
protected boolean connection() {
    String strFile = StringUtils.trimToEmpty(textFile.getText());

    if ("".equals(comboGroup.getText().trim())) {
        MessageDialog.openError(null, Messages.SQLiteLoginComposite_6,
                "Group" + Messages.MySQLLoginComposite_10);
        return false;
    } else if ("".equals(strFile)) { //$NON-NLS-1$
        MessageDialog.openError(null, Messages.SQLiteLoginComposite_6, Messages.SQLiteLoginComposite_7);
        return false;
    } else if ("".equals(StringUtils.trimToEmpty(textDisplayName.getText()))) { //$NON-NLS-1$
        MessageDialog.openError(null, Messages.SQLiteLoginComposite_6, Messages.SQLiteLoginComposite_12);
        return false;
    }//  w  ww.ja  va2s . co  m

    if (!new File(strFile).exists()) {
        if (!MessageDialog.openConfirm(null, Messages.SQLiteLoginComposite_6, Messages.SQLiteLoginComposite_9))
            return false;
    }

    userDB = new UserDBDAO();
    userDB.setTypes(DBDefine.SQLite_DEFAULT.getDBToString());
    userDB.setUrl(String.format(DBDefine.SQLite_DEFAULT.getDB_URL_INFO(), textFile.getText()));
    userDB.setDb(textFile.getText());
    userDB.setGroup_name(comboGroup.getText().trim());
    userDB.setDisplay_name(textDisplayName.getText());
    userDB.setOperation_type(DBOperationType.getNameToType(comboOperationType.getText()).toString());
    userDB.setPasswd(""); //$NON-NLS-1$
    userDB.setUsers(""); //$NON-NLS-1$

    //  ?? ??
    if (oldUserDB != null) {
        if (!MessageDialog.openConfirm(null, "Confirm", Messages.SQLiteLoginComposite_13)) //$NON-NLS-1$
            return false;

        if (!checkDatabase(userDB))
            return false;

        try {
            TadpoleSystem_UserDBQuery.updateUserDB(userDB, oldUserDB, SessionManager.getSeq());
        } catch (Exception e) {
            logger.error(Messages.SQLiteLoginComposite_8, e);
            Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); //$NON-NLS-1$
            ExceptionDetailsErrorDialog.openError(getShell(), "Error", Messages.SQLiteLoginComposite_5, //$NON-NLS-1$
                    errStatus);

            return false;
        }

        //  ?? .
    } else {
        // ?  ? .
        if (!connectValidate(userDB))
            return false;

        try {
            TadpoleSystem_UserDBQuery.newUserDB(userDB, SessionManager.getSeq());
        } catch (Exception e) {
            logger.error(Messages.SQLiteLoginComposite_8, e);
            Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); //$NON-NLS-1$
            ExceptionDetailsErrorDialog.openError(getShell(), "Error", Messages.SQLiteLoginComposite_5, //$NON-NLS-1$
                    errStatus);

            return false;
        }
    }

    return true;
}

From source file:com.bluexml.xforms.generator.forms.renderable.common.association.selection.multiple.RenderableSMultipleActionsAddRemove.java

/**
 * Gets the trigger add./*  ww w. ja  v a2  s .co  m*/
 * 
 * @param bindActions
 *            the bind actions
 * @param path
 *            the path
 * @param rootPath
 *            The parent path, in case this object is embedded in an inline form
 * 
 * @return the trigger add
 */
private Element getTriggerAdd(ModelElementBindSimple bindActions, String path, String rootPath) {

    Element trigger = XFormsGenerator.createTriggerWithLabelImage(XFormsGenerator.IMG_ADD, "Add item");
    Element action = XFormsGenerator.createElement("action", XFormsGenerator.NAMESPACE_XFORMS);

    action.setAttribute("event", "DOMActivate", XFormsGenerator.NAMESPACE_EVENTS);
    // <xf:action ev:event="DOMActivate"
    // if="(instance('ComBluexmlDataRubriqueListInstance1')/SELECTEDID ne '') and not(parentchildOf[com.bluexml.data.Rubrique/BXDSID = instance('ComBluexmlDataRubriqueListInstance1')/SELECTEDID])">
    String selectorNodeset = selectorBindId.getNodeset();
    String realActionsNodeset = StringUtils.trimToEmpty(rootPath) + bindActions.getNodeset();
    String iftest = "(" + selectorNodeset + " ne '') " + "and not(" + realActionsNodeset + "[" + path
            + MsgId.INT_INSTANCE_SIDEID + " = " + selectorNodeset + "])";
    if (bean.getHiBound() > 1) {
        String maxcount = Integer.toString(bean.getHiBound() + 1);
        iftest = iftest + " and (count(" + realActionsNodeset + ") < " + maxcount + ")";
    }
    action.setAttribute("if", iftest);

    Element insertAction = XFormsGenerator.createElement("insert", XFormsGenerator.NAMESPACE_XFORMS);
    bindActions.addLinkedElement(insertAction);
    insertAction.setAttribute("at", "last()");
    insertAction.setAttribute("position", "after");
    action.addContent(insertAction);

    Element setvalueId = XFormsGenerator.createElement("setvalue", XFormsGenerator.NAMESPACE_XFORMS);
    String pathSIDE = bindActions.getNodeset() + "[last() - 1]/" + path;
    setvalueId.setAttribute("ref", pathSIDE + MsgId.INT_INSTANCE_SIDEID);
    setvalueId.setAttribute("value", selectorNodeset);
    action.addContent(setvalueId);

    Element setvalueLabel = XFormsGenerator.createElement("setvalue", XFormsGenerator.NAMESPACE_XFORMS);
    setvalueLabel.setAttribute("ref", pathSIDE + MsgId.INT_INSTANCE_SIDELABEL);
    setvalueLabel.setAttribute("value", selectorBindLabel.getNodeset());
    action.addContent(setvalueLabel);

    Element setvalueType = XFormsGenerator.createElement("setvalue", XFormsGenerator.NAMESPACE_XFORMS);
    setvalueType.setAttribute("ref", pathSIDE + MsgId.INT_INSTANCE_SIDETYPE);
    setvalueType.setAttribute("value", selectorBindType.getNodeset());
    action.addContent(setvalueType);

    trigger.addContent(action);
    return trigger;
}

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

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

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

/**
 * Determines whether the provided string matches the given password.
 *
 * @param p password object//from   ww  w  .ja v a  2 s.  c  om
 * @param fromUser password string provided by user.  may be blank, empty, or null.
 * @return whether the password matches
 */
public static boolean matches(Password p, String fromUser) {
    if (PasswordType.SHA_SALTED.equals(p.getType())) {
        return p.getValue().equals(shaHex(p.getSalt(), fromUser));
    } else if (PasswordType.PLAINTEXT.equals(p.getType())) {
        LOG.warn("A plaintext password was 'decrypted'.");
        return p.getValue().equals(StringUtils.trimToEmpty(fromUser));
    } else {
        throw new UnsupportedOperationException("Unknown encoding type: " + p.getType());
    }
}

From source file:com.hangum.tadpole.rdb.core.editors.main.utils.ExtMakeContentAssistUtil.java

/**
 * insert   ? ?  ? ,     ./*from ww w . j  a v a  2 s .com*/
 * 
 * @param userDB
 * @param strQuery
 * @param strCursor
 * @return
 */
private String ifInsertGetColumn(UserDBDAO userDB, String strQuery, String strCursor) {
    String listContentAssist = "";
    if (StringUtils.startsWithIgnoreCase(StringUtils.trimToEmpty(strQuery), "insert")) {
        listContentAssist = getTableColumnAlias(userDB, strQuery, strCursor);
    }

    return listContentAssist;
}