Example usage for org.apache.commons.lang3 StringUtils trimToNull

List of usage examples for org.apache.commons.lang3 StringUtils trimToNull

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils trimToNull.

Prototype

public static String trimToNull(final String str) 

Source Link

Document

Removes control characters (char <= 32) from both ends of this String returning null if the String is empty ("") after the trim or if it is null .

Usage

From source file:io.restassured.config.MultiPartConfig.java

private MultiPartConfig(String defaultControlName, String defaultFileName, String defaultSubtype,
        String defaultBoundary, boolean isUserConfigured) {
    this.defaultControlName = defaultControlName;
    this.defaultBoundary = defaultBoundary;
    this.defaultFileName = StringUtils.trimToNull(defaultFileName);
    this.defaultSubtype = StringUtils.trimToNull(defaultSubtype);
    AssertParameter.notNull(this.defaultControlName, "Default control name");
    AssertParameter.notNull(this.defaultSubtype, "Default subtype");
    this.isUserConfigured = isUserConfigured;
}

From source file:com.jkoolcloud.tnt4j.streams.utils.Range.java

/**
 * Parses string defining range values. Range definition separator is '{@value #RANGE_SEPARATOR}'.
 * /* www.  ja  v  a  2  s.  c om*/
 * @param rangeStr
 *            range definition string to parse
 * @param pattern
 *            RegEx pattern to use
 * @return string array where first element defines range lower bound and second element defines upper bound
 * @throws Exception
 *             if range string can't be parsed
 */
protected static String[] parseRange(String rangeStr, Pattern pattern) throws Exception {
    String cs = StringUtils.trimToNull(rangeStr);
    if (StringUtils.isEmpty(cs)) {
        throw new IllegalArgumentException(
                StreamsResources.getString(StreamsResources.RESOURCE_BUNDLE_NAME, "Range.range.string.empty"));
    }
    int rCharIdx = cs.indexOf(RANGE_SEPARATOR);

    String[] numStrs = new String[2];
    int si = 0;
    Matcher m = pattern.matcher(cs);
    while (m.find()) {
        String g = m.group();
        if (StringUtils.isNotEmpty(g)) {
            numStrs[si++] = g;
        }
        m.end();
    }

    String fromStr = null;
    String toStr = null;

    if (rCharIdx == -1) { // no range separator symbol found - unary range
        fromStr = numStrs.length > 0 ? numStrs[0] : null;
        toStr = fromStr;
    } else {
        if (rCharIdx == 0) { // unbound low range
            toStr = numStrs.length > 0 ? numStrs[0] : null;
        } else if (rCharIdx == cs.length()) { // unbound high range
            fromStr = numStrs.length > 0 ? numStrs[0] : null;
        } else { // bounded range
            fromStr = numStrs.length > 0 ? numStrs[0] : null;
            toStr = numStrs.length > 1 ? numStrs[1] : null;
        }
    }

    numStrs[0] = fromStr;
    numStrs[1] = toStr;

    return numStrs;
}

From source file:com.threewks.thundr.user.controller.AuthorisedInterceptor.java

@SuppressWarnings("unchecked")
@Override/*w  ww .  ja v a2  s  .  co m*/
public View before(Authorised annotation, Request req, Response resp) {
    Session session = getSession(req, resp);
    if (session != null && session.isAuthenticated()) {
        User user = session.getUser();
        if (user != null) {
            Roles roles = user.getRoles();
            String[] all = annotation.all();
            String[] any = annotation.any();
            boolean hasAll = all == null || all.length == 0 || roles.hasRoles(all);
            boolean hasAny = any == null || any.length == 0 || roles.hasAnyRole(any);
            if (hasAll && hasAny) {
                return null;
            }
        }
    }
    String redirect = StringUtils.trimToNull(annotation.redirect());
    if (redirect != null) {
        return redirectToRouteOrPath(redirect);
    }
    throw new ForbiddenException("Insufficient authorisation");
}

From source file:com.jayway.restassured.specification.ProxySpecification.java

private ProxySpecification(String host, int port, String scheme, String username, String password) {
    this.host = StringUtils.trimToNull(host);
    this.scheme = StringUtils.trimToNull(scheme);
    notNull(this.host, "Proxy host");
    notNull(this.scheme, "Proxy scheme");
    if (port < 1) {
        if (scheme.equalsIgnoreCase(HTTP)) {
            port = DEFAULT_HTTP_PORT;//  w ww. j ava2 s  .co m
        } else if (scheme.equalsIgnoreCase(HTTPS)) {
            port = DEFAULT_HTTPS_PORT;
        } else {
            throw new IllegalArgumentException("Cannot determine proxy port");
        }
    }
    this.username = StringUtils.trimToNull(username);
    this.password = StringUtils.trimToNull(password);
    this.port = port;
}

From source file:io.restassured.specification.ProxySpecification.java

private ProxySpecification(String host, int port, String scheme, String username, String password) {
    this.host = StringUtils.trimToNull(host);
    this.scheme = StringUtils.trimToNull(scheme);
    AssertParameter.notNull(this.host, "Proxy host");
    AssertParameter.notNull(this.scheme, "Proxy scheme");
    if (port < 1) {
        if (scheme.equalsIgnoreCase(HTTP)) {
            port = DEFAULT_HTTP_PORT;//from  ww w .jav  a  2s.  c  om
        } else if (scheme.equalsIgnoreCase(HTTPS)) {
            port = DEFAULT_HTTPS_PORT;
        } else {
            throw new IllegalArgumentException("Cannot determine proxy port");
        }
    }
    this.username = StringUtils.trimToNull(username);
    this.password = StringUtils.trimToNull(password);
    this.port = port;
}

From source file:com.xjl.pt.form.controller.LicenseController.java

/**
 *  /*from   w w w  .  ja  v  a 2s  .co  m*/
 */
@ResponseBody
@RequestMapping(value = "/query/{page}/{rows}", method = RequestMethod.GET, consumes = "application/json")
public BootstrapGridTable query(HttpServletRequest request, @PathVariable Integer page,
        @PathVariable Integer rows) {
    String search = StringUtils.trimToNull(request.getParameter("search"));
    List<Licence> list = licenceService.query(search, page, rows);
    List<DictItem> itemTypeLicenceItems = this.dictItemService
            .queryByDictId("9b48ca78-6366-4598-8509-64bf26ca3832", 1, 1000);
    List<DictItem> itemTypeSourceItems = this.dictItemService
            .queryByDictId("8c438833-0803-41eb-abcb-63d06902cf66", 1, 1000);
    for (Licence licence : list) {
        if (null != licence && null != licence.getLicenceId()) {
            licence.setLicenceItemCount(this.licenceService.countByLicense(licence.getLicenceId()));
        }
        //???
        licence.setLicenceStatus$name(
                DictItemTools.getDictItemNames(licence.getLicenceStatus(), itemTypeLicenceItems));
        //?????
        licence.setLicenceSourceType$name(
                DictItemTools.getDictItemNames(licence.getLicenceSourceType(), itemTypeSourceItems));
        //?
        licence.setIssuingDateStr(format.format(licence.getIssuingDate()));
        licence.setExirationDateStr(format.format(licence.getExpirationDate()));
    }
    return BootstrapGridTable.getInstance(list);
}

From source file:com.esri.geoportal.commons.ckan.client.Client.java

/**
 * Creates instance of the client.//ww  w . j  av a 2 s  .  c  om
 * @param httpClient HTTP client
 * @param url base URL
 * @param apiKey API key
 */
public Client(CloseableHttpClient httpClient, URL url, String apiKey) {
    this.httpClient = httpClient;
    this.url = url;
    this.apiKey = StringUtils.trimToNull(apiKey);

    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
}

From source file:net.sibcolombia.sibsp.model.RecordFilter.java

/**
 * @return true if the record matches this filter criteria
 *//*from  w  w w.j a v  a  2s  . com*/
public boolean matches(String[] record, int newColumn) {
    if (record != null && comparator != null && column != null) {
        String val;
        if (newColumn < 0) {
            val = record.length < column ? null : StringUtils.trimToNull(record[column]);
        } else {
            val = record.length < newColumn ? null : StringUtils.trimToNull(record[newColumn]);
        }
        switch (comparator) {
        case IsNULL:
            return val == null;
        case IsNotNULL:
            return val != null;
        case Equals:
            return val != null && val.equals(param);
        case NotEquals:
            return val == null || !val.equals(param);
        }
    }
    return true;
}

From source file:com.opensymphony.xwork2.util.location.LocationImpl.java

/**
 * Build a location for a given URI and line and column numbers.
 *
 * @param description description for location
 * @param uri the resource URI/*from  w  w w.  ja v  a  2  s . co m*/
 * @param line the line number (starts at 1)
 * @param column the column number (starts at 1)
 */
public LocationImpl(String description, String uri, int line, int column) {
    if (StringUtils.isEmpty(uri)) {
        this.uri = null;
        this.line = -1;
        this.column = -1;
    } else {
        this.uri = uri;
        this.line = line;
        this.column = column;
    }
    this.description = StringUtils.trimToNull(description);
}

From source file:cn.vlabs.clb.server.dao.SQLReader.java

public String next() throws WrongSQL {
    if (!isClosed()) {
        StringBuffer buffer = new StringBuffer();

        String line = null;//from   w w  w . j a v  a  2  s  .  c o  m
        try {
            while ((line = reader.readLine()) != null) {
                line = line.trim();
                if (isDelimiter(line)) {
                    changeDelimiter(line);
                } else if (isComment(line)) {
                    // FIXME Do not support multiline comment, Just throw off now.
                    log.info(line);
                } else {
                    if (line.endsWith(delimeter)) {
                        line = line.substring(0, line.length() - delimeter.length());
                        buffer.append(line + "\n");
                        return StringUtils.trimToNull(buffer.toString());
                    } else
                        buffer.append(line + "\n");
                }
            }
        } catch (IOException e) {
            log.error(e.getMessage());
            log.debug("", e);
            close();
        }
        if (line == null) {
            close();
        }
        return StringUtils.trimToNull(buffer.toString());
    }
    return null;
}