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

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

Introduction

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

Prototype

public static String deleteWhitespace(String str) 

Source Link

Document

Deletes all whitespaces from a String as defined by Character#isWhitespace(char) .

Usage

From source file:edu.ku.brc.specify.plugins.latlon.DDDDPanel.java

/**
 * Helper method for setting the data into the UI.
 * @param doLatitude true does latitude, false does longitude
 *///from w  w w  . j ava2 s  .  co m
protected void getDataFromUI(final boolean doLatitude) {
    if (doLatitude) {
        String str = latitudeDD.getText();
        if (StringUtils.isNotEmpty(StringUtils.deleteWhitespace(str))) {
            latitude = convertDDDDStrToDDDDBD(str, NORTH_SOUTH[latitudeDir.getSelectedIndex()]);
            latitudeStr = latitudeTF.getText();

        } else {
            latitude = null;
            latitudeStr = null;
        }

    } else {
        String str = longitudeDD.getText();
        if (StringUtils.isNotEmpty(StringUtils.deleteWhitespace(str))) {
            longitude = convertDDDDStrToDDDDBD(str, EAST_WEST[longitudeDir.getSelectedIndex()]);
            longitudeStr = latitudeTF.getText();

        } else {
            longitude = null;
            longitudeStr = null;
        }
    }
}

From source file:edu.ku.brc.af.ui.forms.validation.ValComboBoxFromQuery.java

/**
 * Creates the UI for the ComboBox./*from w  w  w.ja  v a  2  s .  co  m*/
 * @param objTitle the title of one object needed for the Info Button
 */
public void init(final String objTitle, final int btnMask) {
    fieldNames = split(StringUtils.deleteWhitespace(keyName), ",");

    // strip off any table prefixes
    for (int i = 0; i < fieldNames.length; i++) {
        String fName = fieldNames[i];
        if (fName.indexOf('.') > -1) {
            fieldNames[i] = StringUtils.substringAfterLast(fName, ".");
        }
    }

    boolean hasSearchDlg = StringUtils.isNotEmpty(tableInfo.getSearchDialog());
    boolean hasSearchBtn = (btnMask & CREATE_SEARCH_BTN) != 0;
    boolean hasCloneBtn = (btnMask & CREATE_CLONE_BTN) != 0;
    boolean hasEditBtn = (btnMask & CREATE_EDIT_BTN) != 0;
    boolean hasAddBtn = (btnMask & CREATE_NEW_BTN) != 0;
    final boolean hasViewBtn = (btnMask & CREATE_VIEW_BTN) != 0;

    StringBuilder sb = new StringBuilder("p:g,1px,p,1px,p");
    if (hasSearchDlg) {
        sb.append(",1px,p");
    }
    if (hasCloneBtn) {
        sb.append(",1px,p");
    }
    PanelBuilder pb = new PanelBuilder(new FormLayout(sb.toString(), "c:p"), this);
    CellConstraints cc = new CellConstraints();

    pb.add(textWithQuery, cc.xy(1, 1));

    PermissionSettings perm = AppContextMgr.isSecurityOn() ? tableInfo.getPermissions() : null;

    int x = 3;
    if (hasEditBtn || hasViewBtn) {
        String iconName;
        String ttName;
        if (hasEditBtn && (perm == null || perm.canModify())) {
            iconName = "EditIcon";
            ttName = "EditRecordTT";

        } else {
            iconName = "InfoIcon";
            ttName = "ShowRecordInfoTT";
        }

        editBtn = createBtn(iconName, ttName, objTitle);
        pb.add(editBtn, cc.xy(x, 1));
        x += 2;
    }

    if (hasAddBtn && (perm == null || perm.canAdd())) {
        createBtn = createBtn("CreateObj", "NewRecordTT", objTitle);
        pb.add(createBtn, cc.xy(x, 1));
        x += 2;
    }

    if (hasCloneBtn && (perm == null || perm.canAdd())) {
        cloneBtn = createBtn("CloneObj", "CloneRecordTT", objTitle);
        pb.add(cloneBtn, cc.xy(x, 1));
        x += 2;
    }

    if (hasSearchDlg && hasSearchBtn && (perm == null || perm.canAdd())) {
        textWithQuery.setAddAddItem(hasAddBtn); // set to true if there is an add btn
        searchBtn = createBtn("Search", "SearchForRecordTT", objTitle);
        pb.add(searchBtn, cc.xy(x, 1));
        x += 2;
    }

    if (!UIHelper.isMacOS()) {
        setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
    }

    bgColor = textWithQuery.getTextField().getBackground();
    if (valTextColor == null || requiredFieldColor == null) {
        valTextColor = AppPrefsCache.getColorWrapper("ui.formatting.valtextcolor");
        requiredFieldColor = AppPrefsCache.getColorWrapper("ui.formatting.requiredfieldcolor");
    }

    AppPrefsCache.addChangeListener("ui.formatting.requiredfieldcolor", this);

    if (searchBtn != null) {
        defaultSearchAction = new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                displaySearchDialog();
            }
        };
        searchBtn.addActionListener(defaultSearchAction);
    }

    if (editBtn != null) {
        defaultEditAction = new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                currentMode = MODE.Editting;
                createEditFrame(false, false, hasViewBtn);
            }
        };
        editBtn.addActionListener(defaultEditAction);
    }

    if (createBtn != null) {
        defaultNewAction = new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                doNewAction(null);
            }
        };
        createBtn.addActionListener(defaultNewAction);
    }

    if (cloneBtn != null) {
        defaultCloneAction = new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dataObj = (FormDataObjIFace) ValComboBoxFromQuery.this.getValue();
                currentMode = MODE.NewAndNotEmpty;
                createEditFrame(true, true, false);
            }
        };
        cloneBtn.addActionListener(defaultCloneAction);
    }
}

From source file:edu.ku.brc.af.ui.forms.persist.ViewLoader.java

/**
 * Returns a resource string if it is suppose to
 * @param label the label or the label key
 * @return Returns a resource string if it is suppose to
 *//*from w w  w .  j  a  v a 2 s  . c o m*/
protected static String getResourceLabel(final String label) {
    if (isNotEmpty(label) && StringUtils.deleteWhitespace(label).length() > 0) {
        return instance.doingResourceLabels ? getResourceString(label) : label;
    }
    // else
    return "";

}

From source file:com.haulmont.cuba.gui.app.core.categories.AttributeEditor.java

protected void fillAttributeCode() {
    CategoryAttribute attribute = getItem();
    if (StringUtils.isBlank(attribute.getCode()) && StringUtils.isNotBlank(attribute.getName())) {
        String categoryName = StringUtils.EMPTY;
        if (attribute.getCategory() != null) {
            categoryName = StringUtils.defaultString(attribute.getCategory().getName());
        }/*from   w  w w.  j  a  va  2 s. c o  m*/
        attribute.setCode(StringUtils.deleteWhitespace(categoryName + attribute.getName()));
    }
}

From source file:edu.harvard.hul.ois.fits.tools.mediainfo.MediaInfoUtil.java

private String convertToNormalizedData(String originalString, String labelToPreserve) {
    return StringUtils.deleteWhitespace(originalString.replace(labelToPreserve, "")) + labelToPreserve;

}

From source file:edu.ku.brc.af.ui.db.DatabaseLoginPanel.java

/**
 * Enables or disables the UI based of the values of the controls. The Login button doesn't
 * become enabled unless everything is filled in. It also expands the "Extra" options if any of
 * them are missing a value/*from  ww  w.  jav  a2s .  com*/
 */
protected void updateUIControls() {
    if (extraPanel == null || isLoggingIn) {
        return;
    }

    String dbName = StringUtils.deleteWhitespace(databases.getTextField().getText());
    String uName = username.getText();
    String pwd = new String(password.getPassword());

    boolean shouldEnable = StringUtils.isNotEmpty(uName) && StringUtils.isNotEmpty(pwd)
            && (servers.getComboBox().getSelectedIndex() != -1
                    || StringUtils.isNotEmpty(servers.getTextField().getText()))
            && StringUtils.isNotEmpty(dbName);

    if (shouldEnable && (StringUtils.contains(uName, ' ') || StringUtils.contains(uName, ','))) {
        shouldEnable = false;
        setMessage(getResourceString("NO_SPC_USRNAME"), true); //$NON-NLS-1$

    } else if (shouldEnable && (StringUtils.contains(pwd, ' ') || StringUtils.contains(pwd, ','))) {
        shouldEnable = false;
        setMessage(getResourceString("NO_SPC_PWDNAME"), true); //$NON-NLS-1$

    } else if (shouldEnable && (StringUtils.contains(dbName, ' ') || StringUtils.contains(dbName, ','))) {
        shouldEnable = false;
        setMessage(getResourceString("NO_SPC_DBNAME"), true); //$NON-NLS-1$

    } else if (dbDriverCBX.getSelectedIndex() == -1) {
        shouldEnable = false;
        setMessage(getResourceString("MISSING_DRIVER"), true); //$NON-NLS-1$
        if (!extraPanel.isVisible()) {
            moreBtn.doClick();
        }
    }

    loginBtn.setEnabled(shouldEnable);

    if (shouldEnable) {
        setMessage("", false); //$NON-NLS-1$
    }
}

From source file:eu.eidas.auth.engine.SamlEngine.java

/**
 * Gets the country from X.509 Certificate.
 *
 * @param keyInfo the key info//from  www  .ja va 2 s  .  c o  m
 * @return the country
 */
private String getCountry(KeyInfo keyInfo) {
    LOG.trace("Recover country information.");
    try {
        org.opensaml.xml.signature.X509Certificate xmlCert = keyInfo.getX509Datas().get(0).getX509Certificates()
                .get(0);

        // Transform the KeyInfo to X509Certificate.
        X509Certificate cert = CertificateUtil.toCertificate(xmlCert.getValue());

        String distName = cert.getSubjectDN().toString();

        distName = StringUtils.deleteWhitespace(StringUtils.upperCase(distName));

        String countryCode = "C=";
        int init = distName.indexOf(countryCode);

        String result = "";
        if (init > StringUtils.INDEX_NOT_FOUND) {
            // Exist country code.
            int end = distName.indexOf(',', init);

            if (end <= StringUtils.INDEX_NOT_FOUND) {
                end = distName.length();
            }

            if (init < end && end > StringUtils.INDEX_NOT_FOUND) {
                result = distName.substring(init + countryCode.length(), end);
                //It must be a two characters value
                if (result.length() > 2) {
                    result = result.substring(0, 2);
                }
            }
        }
        return result.trim();
    } catch (EIDASSAMLEngineException e) {
        LOG.error(SAML_EXCHANGE, "BUSINESS EXCEPTION : Procces getCountry from certificate: " + e.getMessage(),
                e);
        throw new EIDASSAMLEngineRuntimeException(e);
    }
}

From source file:com.taobao.adfs.util.Utilities.java

public static List<String> getListenAddressList(String[]... features) throws IOException {
    String[] includes = features.length > 0 ? features[0] : null;
    String[] excludes = features.length > 1 ? features[1] : null;
    String[] fields = features.length > 2 ? features[2] : new String[] { "4" };
    String commandForGetListeningAddress = "netstat -lntp | grep tcp" + "|awk '{print ";
    for (String field : fields) {
        commandForGetListeningAddress += "$" + field + "\",\" ";
    }//from w w w  .j  av  a2 s . c om
    commandForGetListeningAddress += "}'";
    String addresses = Utilities.runCommand(commandForGetListeningAddress, null, null, null);
    List<String> addressList = new ArrayList<String>();
    for (String address : addresses.split("\n")) {
        address = StringUtils.deleteWhitespace(address);
        if (stringFilter(address, includes, excludes))
            addressList.add(address);
    }
    return addressList;
}

From source file:com.taobao.adfs.util.Utilities.java

public static void killProcesses(String pids) throws IOException {
    pids = StringUtils.deleteWhitespace(pids).replaceAll(" ", "");
    String[] pidArray = pids.replace("\n", ",").split(",");
    for (String pid : pidArray) {
        killProcess(pid);/*from   ww  w  . ja v  a  2  s . co  m*/
    }
}

From source file:net.sf.firemox.tools.MToolKit.java

/**
 * Return the specified string without any local white spaces. Would be
 * replaced when//from   w w  w . j  ava  2  s .c om
 * {@link org.apache.commons.lang.StringUtils#deleteWhitespace(String)} would
 * work.
 * 
 * @param string
 *          the string to normalize.
 * @return the given string without any space char.
 * @see Character#isWhitespace(char)
 */
public static String replaceWhiteSpaces(String string) {
    final StringBuilder workingString = new StringBuilder(StringUtils.deleteWhitespace(string));
    for (int count = workingString.length(); count-- > 0;) {
        if (Character.isSpaceChar(workingString.charAt(count))) {
            // delete this char
            workingString.deleteCharAt(count);
        }
    }
    return workingString.toString();
}