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:com.intuit.karate.Script.java

public static void setValueByPath(String name, String path, String exp, ScriptContext context) {
    name = StringUtils.trim(name);//from w ww .  j  av a  2  s.  c  o  m
    if ("request".equals(name) || "url".equals(name)) {
        throw new RuntimeException("'" + name + "' is not a variable," + " use the form '* " + name
                + " <expression>' to initialize the " + name + ", and <expression> can be a variable");
    }
    path = StringUtils.trimToNull(path);
    if (path == null) {
        Pair<String, String> pair = parseVariableAndPath(name);
        name = pair.getLeft();
        path = pair.getRight();
    }
    if (isJsonPath(path)) {
        ScriptValue target = context.vars.get(name);
        ScriptValue value = eval(exp, context);
        switch (target.getType()) {
        case JSON:
            DocumentContext dc = target.getValue(DocumentContext.class);
            JsonUtils.setValueByPath(dc, path, value.getAfterConvertingFromJsonOrXmlIfNeeded());
            break;
        case MAP:
            Map<String, Object> map = target.getValue(Map.class);
            DocumentContext fromMap = JsonPath.parse(map);
            JsonUtils.setValueByPath(fromMap, path, value.getAfterConvertingFromJsonOrXmlIfNeeded());
            context.vars.put(name, fromMap);
            break;
        default:
            throw new RuntimeException("cannot set json path on unexpected type: " + target);
        }
    } else if (isXmlPath(path)) {
        Document doc = context.vars.get(name, Document.class);
        ScriptValue sv = eval(exp, context);
        switch (sv.getType()) {
        case XML:
            Node node = sv.getValue(Node.class);
            XmlUtils.setByPath(doc, path, node);
            break;
        default:
            XmlUtils.setByPath(doc, path, sv.getAsString());
        }
    } else {
        throw new RuntimeException("unexpected path: " + path);
    }
}

From source file:com.hubrick.vertx.s3.client.S3Client.java

private MultiMap populateContinueMultipartUploadHeaders(
        ContinueMultipartUploadRequest continueMultipartPutObjectRequest) {
    final MultiMap headers = MultiMap.caseInsensitiveMultiMap();

    if (StringUtils.trimToNull(continueMultipartPutObjectRequest.getContentMD5()) != null) {
        headers.add(Headers.CONTENT_MD5, StringUtils.trim(continueMultipartPutObjectRequest.getContentMD5()));
    }/*from w ww  .ja v a  2  s  . c o  m*/

    return headers;
}

From source file:net.centro.rtb.monitoringcenter.MonitoringCenter.java

private static boolean matchesStartsWithFilter(String name, String startsWithFilter) {
    startsWithFilter = StringUtils.trimToNull(startsWithFilter);
    if (startsWithFilter == null) {
        return true;
    }/*  w ww . j a v a  2  s. c  o m*/

    if (startsWithFilter.indexOf('*') == -1) {
        return name.startsWith(startsWithFilter);
    } else {
        if (!startsWithFilter.endsWith("*")) {
            startsWithFilter += "*";
        }

        String regex = ("\\Q" + startsWithFilter + "\\E").replace("*", "\\E.*\\Q");
        return name.matches(regex);
    }
}

From source file:com.webbfontaine.valuewebb.action.rimm.RefSelect.java

@Factory(value = "applicantTins", scope = ScopeType.EVENT)
public List<SelectItem> getTINs() {
    UserProperties userProperties = (UserProperties) Component.getInstance(UserProperties.class,
            ScopeType.SESSION, true);/* www. j a v  a  2s.co m*/

    if (StringUtils.trimToNull(userProperties.getTIN()) == null) {
        return Collections.EMPTY_LIST;
    }
    String[] tinsStr = userProperties.getTIN().split(",");

    List<SelectItem> tins = new ArrayList(tinsStr.length + 1);
    tins.add(new SelectItem(""));
    for (String tin : tinsStr) {
        tins.add(new SelectItem(tin));
    }
    return tins;
}

From source file:com.hubrick.vertx.s3.client.S3Client.java

private MultiMap populateCopyObjectHeaders(CopyObjectRequest copyObjectRequest) {
    final MultiMap headers = MultiMap.caseInsensitiveMultiMap();

    if (StringUtils.trimToNull(copyObjectRequest.getCacheControl()) != null) {
        headers.add(Headers.CACHE_CONTROL, StringUtils.trim(copyObjectRequest.getCacheControl()));
    }// ww  w  .  j  av a2s  .  c om
    if (StringUtils.trimToNull(copyObjectRequest.getContentDisposition()) != null) {
        headers.add(Headers.CONTENT_DISPOSITION, StringUtils.trim(copyObjectRequest.getContentDisposition()));
    }
    if (StringUtils.trimToNull(copyObjectRequest.getContentEncoding()) != null) {
        headers.add(Headers.CONTENT_ENCODING, StringUtils.trim(copyObjectRequest.getContentEncoding()));
    }
    if (StringUtils.trimToNull(copyObjectRequest.getContentType()) != null) {
        headers.add(Headers.CONTENT_TYPE, StringUtils.trim(copyObjectRequest.getContentType()));
    }
    if (StringUtils.trimToNull(copyObjectRequest.getExpires()) != null) {
        headers.add(Headers.EXPIRES, StringUtils.trim(copyObjectRequest.getExpires()));
    }

    for (Map.Entry<String, String> meta : copyObjectRequest.getAmzMeta()) {
        headers.add(Headers.X_AMZ_META_PREFIX + meta.getKey(), StringUtils.trim(meta.getValue()));
    }

    if (copyObjectRequest.getAmzMetadataDirective() != null) {
        headers.add(Headers.X_AMZ_METADATA_DIRECTIVE, copyObjectRequest.getAmzMetadataDirective().name());
    }
    if (StringUtils.trimToNull(copyObjectRequest.getAmzCopySourceIfMatch()) != null) {
        headers.add(Headers.X_AMZ_COPY_SOURCE_IF_MATCH,
                StringUtils.trim(copyObjectRequest.getAmzCopySourceIfMatch()));
    }
    if (StringUtils.trimToNull(copyObjectRequest.getAmzCopySourceIfNoneMatch()) != null) {
        headers.add(Headers.X_AMZ_COPY_SOURCE_IF_NONE_MATCH,
                StringUtils.trim(copyObjectRequest.getAmzCopySourceIfNoneMatch()));
    }
    if (StringUtils.trimToNull(copyObjectRequest.getAmzCopySourceIfUnmodifiedSince()) != null) {
        headers.add(Headers.X_AMZ_COPY_SOURCE_IF_UNMODIFIED_SINCE,
                StringUtils.trim(copyObjectRequest.getAmzCopySourceIfUnmodifiedSince()));
    }
    if (StringUtils.trimToNull(copyObjectRequest.getAmzCopySourceIfModifiedSince()) != null) {
        headers.add(Headers.X_AMZ_COPY_SOURCE_IF_MODIFIED_SINCE,
                StringUtils.trim(copyObjectRequest.getAmzCopySourceIfModifiedSince()));
    }
    if (copyObjectRequest.getAmzStorageClass() != null) {
        headers.add(Headers.X_AMZ_STORAGE_CLASS, copyObjectRequest.getAmzStorageClass().name());
    }
    if (copyObjectRequest.getAmzTaggingDirective() != null) {
        headers.add(Headers.X_AMZ_TAGGING_DIRECTIVE, copyObjectRequest.getAmzTaggingDirective().name());
    }
    if (StringUtils.trimToNull(copyObjectRequest.getAmzWebsiteRedirectLocation()) != null) {
        headers.add(Headers.X_AMZ_WEBSITE_REDIRECT_LOCATION,
                StringUtils.trim(copyObjectRequest.getAmzWebsiteRedirectLocation()));
    }

    return headers;
}

From source file:com.hubrick.vertx.s3.client.S3Client.java

private Map<String, String> populateGetObjectQueryParams(GetObjectRequest getObjectRequest) {
    final Map<String, String> queryParams = new HashMap<>();

    if (StringUtils.trimToNull(getObjectRequest.getResponseCacheControl()) != null) {
        queryParams.put("response-cache-control", StringUtils.trim(getObjectRequest.getResponseCacheControl()));
    }/*from   w  ww  . j  a v a2 s . c  om*/
    if (StringUtils.trimToNull(getObjectRequest.getResponseContentDisposition()) != null) {
        queryParams.put("response-content-disposition",
                StringUtils.trim(getObjectRequest.getResponseContentDisposition()));
    }
    if (StringUtils.trimToNull(getObjectRequest.getResponseContentEncoding()) != null) {
        queryParams.put("response-content-encoding",
                StringUtils.trim(getObjectRequest.getResponseContentEncoding()));
    }
    if (StringUtils.trimToNull(getObjectRequest.getResponseContentLanguage()) != null) {
        queryParams.put("response-content-language",
                StringUtils.trim(getObjectRequest.getResponseContentLanguage()));
    }
    if (StringUtils.trimToNull(getObjectRequest.getResponseContentType()) != null) {
        queryParams.put("response-content-type", StringUtils.trim(getObjectRequest.getResponseContentType()));
    }
    if (StringUtils.trimToNull(getObjectRequest.getResponseExpires()) != null) {
        queryParams.put("response-expires", StringUtils.trim(getObjectRequest.getResponseExpires()));
    }

    return queryParams;
}

From source file:co.touchlab.squeaky.processor.AnnotationProcessor.java

private CodeBlock getFieldConfig(List<DatabaseTableHolder> databaseTableHolders, FieldTypeGen config,
        DatabaseField databaseField, String indexNameBase) {
    DataType dataType = findFieldDataType(databaseTableHolders, (TypeElement) config.databaseElement, config);

    CodeBlock.Builder builder = CodeBlock.builder();

    builder.add("new $T( " + "$S," + "$S," + "$S," + "$L," + //isId
            "$L," + "$L," + "$T.$L," + "$T.class," + "$L," + //canBeNull
            "$S," + "$L," + "$L," + "$L," + "$L," + //uniqueIndex
            "$S," + "$S," + "$S," + "$L)", FieldType.class, indexNameBase, config.fieldName, config.columnName,
            config.isId, config.isGeneratedId, config.foreign, DataType.class, dataType,
            ClassName.get(config.dataTypeMirror), databaseField.canBeNull(),
            StringUtils.trimToNull(databaseField.format()), databaseField.unique(), databaseField.uniqueCombo(),
            databaseField.index(), databaseField.uniqueIndex(),
            StringUtils.trimToNull(databaseField.indexName()),
            StringUtils.trimToNull(databaseField.uniqueIndexName()), config.defaultValue,
            config.foreignAutoRefresh);/*w ww. j  a  va2s.  c  o  m*/

    return builder.build();
}

From source file:com.hubrick.vertx.s3.client.S3Client.java

private MultiMap populateGetObjectHeaders(GetObjectRequest getObjectRequest) {
    final MultiMap headers = MultiMap.caseInsensitiveMultiMap();

    if (StringUtils.trimToNull(getObjectRequest.getRange()) != null) {
        headers.add(Headers.RANGE, StringUtils.trim(getObjectRequest.getRange()));
    }//from   ww  w.  j  a va2s  .  com
    if (StringUtils.trimToNull(getObjectRequest.getIfModifiedSince()) != null) {
        headers.add(Headers.IF_MODIFIED_SINCE, StringUtils.trim(getObjectRequest.getIfModifiedSince()));
    }
    if (StringUtils.trimToNull(getObjectRequest.getIfUnmodifiedSince()) != null) {
        headers.add(Headers.IF_UNMODIFIED_SINCE, StringUtils.trim(getObjectRequest.getIfUnmodifiedSince()));
    }
    if (StringUtils.trimToNull(getObjectRequest.getIfMatch()) != null) {
        headers.add(Headers.IF_MATCH, StringUtils.trim(getObjectRequest.getIfMatch()));
    }
    if (StringUtils.trimToNull(getObjectRequest.getIfNoneMatch()) != null) {
        headers.add(Headers.IF_NONE_MATCH, StringUtils.trim(getObjectRequest.getIfNoneMatch()));
    }

    return headers;
}

From source file:com.hubrick.vertx.s3.client.S3Client.java

private MultiMap populateHeadObjectHeaders(HeadObjectRequest headObjectRequest) {
    final MultiMap headers = MultiMap.caseInsensitiveMultiMap();

    if (StringUtils.trimToNull(headObjectRequest.getRange()) != null) {
        headers.add(Headers.RANGE, StringUtils.trim(headObjectRequest.getRange()));
    }/*from w  w  w .  java  2 s  .c  o  m*/
    if (StringUtils.trimToNull(headObjectRequest.getIfModifiedSince()) != null) {
        headers.add(Headers.IF_MODIFIED_SINCE, StringUtils.trim(headObjectRequest.getIfModifiedSince()));
    }
    if (StringUtils.trimToNull(headObjectRequest.getIfUnmodifiedSince()) != null) {
        headers.add(Headers.IF_UNMODIFIED_SINCE, StringUtils.trim(headObjectRequest.getIfUnmodifiedSince()));
    }
    if (StringUtils.trimToNull(headObjectRequest.getIfMatch()) != null) {
        headers.add(Headers.IF_MATCH, StringUtils.trim(headObjectRequest.getIfMatch()));
    }
    if (StringUtils.trimToNull(headObjectRequest.getIfNoneMatch()) != null) {
        headers.add(Headers.IF_NONE_MATCH, StringUtils.trim(headObjectRequest.getIfNoneMatch()));
    }

    return headers;
}

From source file:com.hubrick.vertx.s3.client.S3Client.java

private Map<String, String> populateGetBucketQueryParams(GetBucketRequest listObjectsRequest) {
    final Map<String, String> queryParams = new HashMap<>();
    queryParams.put("list-type", "2");

    if (StringUtils.trimToNull(listObjectsRequest.getContinuationToken()) != null) {
        queryParams.put("continuation-token", StringUtils.trim(listObjectsRequest.getContinuationToken()));
    }//  w  w w. j  av a 2s.  c om
    if (StringUtils.trimToNull(listObjectsRequest.getDelimiter()) != null) {
        queryParams.put("delimiter", StringUtils.trim(listObjectsRequest.getDelimiter()));
    }
    if (StringUtils.trimToNull(listObjectsRequest.getEncodingType()) != null) {
        queryParams.put("encoding-type", StringUtils.trim(listObjectsRequest.getEncodingType()));
    }
    if (StringUtils.trimToNull(listObjectsRequest.getFetchOwner()) != null) {
        queryParams.put("fetch-owner", StringUtils.trim(listObjectsRequest.getFetchOwner()));
    }
    if (listObjectsRequest.getMaxKeys() != null) {
        queryParams.put("max-keys", StringUtils.trim(listObjectsRequest.getMaxKeys().toString()));
    }
    if (StringUtils.trimToNull(listObjectsRequest.getPrefix()) != null) {
        queryParams.put("prefix", StringUtils.trim(listObjectsRequest.getPrefix()));
    }
    if (StringUtils.trimToNull(listObjectsRequest.getStartAfter()) != null) {
        queryParams.put("start-after", StringUtils.trim(listObjectsRequest.getStartAfter()));
    }

    return queryParams;
}