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:ml.shifu.shifu.core.binning.MunroPatBinning.java

@Override
public void addData(String val) {
    String fval = StringUtils.trimToEmpty(val);
    try {/*from   w w  w  . j a v a2s.  c  o  m*/
        Double dval = Double.parseDouble(fval);
        estimator.add(dval);
    } catch (NumberFormatException e) {
        super.incInvalidValCnt();
    }
}

From source file:com.alibaba.cobar.client.router.rules.AbstractEntityAttributeRule.java

public void setAttributePattern(String attributePattern) {
    Validate.notEmpty(StringUtils.trimToEmpty(attributePattern));
    this.attributePattern = attributePattern;
}

From source file:com.haulmont.cuba.web.toolkit.ui.converters.StringToDatatypeConverter.java

@Override
public Object convertToModel(String value, Class<?> targetType, Locale locale) throws ConversionException {
    try {//from   w  w w .j av  a 2  s.c  o  m
        if (locale == null) {
            locale = VaadinSession.getCurrent().getLocale();
        }

        if (isTrimming()) {
            value = StringUtils.trimToEmpty(value);
        }

        if (locale != null) {
            return datatype.parse(value, locale);
        }

        return datatype.parse(value);
    } catch (ParseException e) {
        throw new ConversionException(e);
    }
}

From source file:com.hangum.tadpole.commons.libs.core.utils.ValidChecker.java

/**
 * Text checker util//from www  .  ja  v a  2 s .  c  o  m
 * 
 * @param text
 * @param msg
 * @return
 */
public static boolean checkTextCtl(Text text, String msg) {
    if ("".equals(StringUtils.trimToEmpty(text.getText()))) { //$NON-NLS-1$
        MessageDialog.openWarning(null, Messages.get().Warning, msg + Messages.get().CheckTextString);
        text.setFocus();

        return false;
    }

    return true;
}

From source file:adalid.util.io.SmallFile.java

private void init(String path, Charset[] charsets) {
    _name = path;// w ww.j  av a  2  s .  c  o m
    //      _extension = StringUtils.substringAfter(StringUtils.substringAfterLast(path, FS), ".");
    _extension = StringUtils.trimToEmpty(StringUtils.substringAfterLast(path, "."));
    _path = Paths.get(path);
    _charsets = charsets;
}

From source file:net.hillsdon.reviki.wiki.renderer.creole.CreoleLinkContentsSplitter.java

/**
 * Splits links of the form target or text|target where target is
 * //  w  w w .java 2s  .com
 * PageName wiki:PageName PageName#fragment wiki:PageName#fragment
 * A String representing an absolute URI scheme://valid/absolute/uri
 * Any character not in the `unreserved`, `punct`, `escaped`, or `other` categories (RFC 2396),
 * and not equal '/' or '@', is %-encoded. 
 * 
 * @param in The String to split
 * @return The split LinkParts
 */
LinkParts split(final String in) {
    String target = StringUtils.trimToEmpty(StringUtils.substringBefore(in, "|"));
    String text = StringUtils.trimToNull(StringUtils.substringAfter(in, "|"));
    if (target == null) {
        target = "";
    }
    if (text == null) {
        text = target;
    }
    // Link target can be PageName, wiki:PageName or a URL.
    URI uri = null;
    try {
        URL url = new URL(target);

        uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(),
                url.getQuery(), url.getRef());
        if (uri.getPath() == null || !uri.isAbsolute()) {
            uri = null;
        }
    } catch (URISyntaxException e) {
        // uri remains null
    } catch (MalformedURLException e) {
        // uri remains null
    }

    if (uri != null) {
        return new LinkParts(text, uri);
    } else {
        // Split into wiki:pageName
        String[] parts = target.split(":", 2);
        String wiki = null;
        String pageName = target;
        if (parts.length == 2) {
            wiki = parts[0];
            pageName = parts[1];
        }

        // Split into pageName#fragment
        parts = pageName.split("#", 2);
        String fragment = null;
        if (parts.length == 2) {
            pageName = parts[0];
            fragment = parts[1];
        }

        // Split into pageName/attachment
        parts = pageName.split("/", 2);
        String attachment = null;
        if (parts.length == 2) {
            pageName = parts[0];
            attachment = parts[1];
        }

        return new LinkParts(text, wiki, pageName, fragment, attachment);
    }
}

From source file:com.egt.core.jsf.component.ColumnaTabla.java

/**
 * {@inheritDoc}/*from   w  w w  .j  a  v  a  2s  .  c  om*/
 */
@Override
public String getHeaderText() {
    String superstr = super.getHeaderText();
    if (StringUtils.isBlank(superstr)) {
        return superstr;
    } else if (getValueExpression("headerText") != null) {
        return superstr;
    }
    String supertip = super.getToolTip();
    if (supertip != null && getValueExpression("toolTip") == null && supertip.startsWith("BundleParametros.")) {
        int i = supertip.indexOf('.');
        String key = supertip.substring(i + 1);
        String str = BundleParametros.getString(key, BundleParametros.TOOLTIP, true);
        if (str != null) {
            return str;
        }
    }
    String webuistr = JSF.getWebuiString(this, "text");
    if (webuistr == null) {
        String prefix = "tableColumn";
        String thisid = StringUtils.trimToEmpty(this.getId());
        String altkey = thisid.startsWith(prefix) ? thisid.substring(prefix.length()) : null;
        String styles = StringUtils.trimToEmpty(this.getStyleClass());
        //          boolean b = super.getSort() == null;
        webuistr = StringUtils.lowerCase(JSF.getWebuiString(superstr, altkey, styles));
    }
    return webuistr == null ? superstr : webuistr;
}

From source file:com.timeinc.seleniumite.environment.EnvironmentUtils.java

public static String applyEnvVars(String input) {
    String rval = input;/*from  ww  w .  j  a v a2  s.  co m*/
    if (rval != null) {
        int sIdx = rval.indexOf("${");
        while (sIdx != -1) {
            int eIdx = rval.indexOf("}", sIdx + 2);
            if (eIdx == -1) {
                throw new IllegalArgumentException("Environment variable started but not closed in : " + input);
            }

            String varName = rval.substring(sIdx + 2, eIdx);
            String varVal = StringUtils.trimToEmpty(EnvironmentUtils.findEnvOrProperty(varName));
            LOG.debug("Converted env variable {} to {}", varName, mask(varVal));
            rval = rval.substring(0, sIdx) + varVal + rval.substring(eIdx + 1);
            sIdx = rval.indexOf("${");
        }
    }
    return rval;
}

From source file:net.di2e.ecdr.commons.util.GeospatialUtils.java

/**
 * Converts from a opensearch geo extension polygon which is defined in latitude, longitude pairs, in clockwise
 * order around the polygon, with the last point being the same as the first in order to close the polygon.
 * //from w w  w.  j a  v a  2s  .c  o m
 * @param polygon
 * @return WKT String representation of the polygon
 */
public static String polygonToWKT(String polygon) {
    StringBuilder wkt = new StringBuilder("POLYGON((");
    int coordinatePair = 0;
    String[] coords = polygon.split(",");
    int size = coords.length;
    LOGGER.trace("Trying to convert polygon with value [{}] to WKT", polygon);
    for (int i = size - 1; i >= 0; i--) {
        coordinatePair++;
        if (coordinatePair == 2) {
            wkt.append(" ");
        } else if (coordinatePair > 2) {
            wkt.append(",");
            coordinatePair = 1;
        }
        wkt.append(StringUtils.trimToEmpty(coords[i]));
    }
    wkt.append("))");
    LOGGER.trace("Converted polygon with value [{}] to WKT [{}]", polygon, wkt);
    return wkt.toString();
}

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

public String getStringKey() {
    return StringUtils.trimToEmpty(_key);
}