Example usage for org.apache.http.util TextUtils isBlank

List of usage examples for org.apache.http.util TextUtils isBlank

Introduction

In this page you can find the example usage for org.apache.http.util TextUtils isBlank.

Prototype

public static boolean isBlank(CharSequence charSequence) 

Source Link

Usage

From source file:cn.aage.robot.http.util.Args.java

public static <T extends CharSequence> T notBlank(final T argument, final String name) {
    if (argument == null) {
        throw new IllegalArgumentException(name + " may not be null");
    }//  w w w .  j av a 2  s.c  om
    if (TextUtils.isBlank(argument)) {
        throw new IllegalArgumentException(name + " may not be blank");
    }
    return argument;
}

From source file:by.serzh.beatsub.servers.AddServerController.java

private boolean validate(String host, String username, String password) {
    if (!UrlValidator.getInstance().isValid("http://" + host)) {
        setError("add_server.error_host");
        return false;
    } else if (TextUtils.isBlank(username)) {
        setError("add_server.error_username");
        return false;
    } else if (TextUtils.isBlank(password)) {
        setError("add_server.error_password");
        return false;
    } else {//from   w  w  w .j  a  v a 2  s .  co  m
        return true;
    }
}

From source file:cn.aage.robot.http.entity.ContentType.java

ContentType(final String mimeType, final NameValuePair[] params) throws UnsupportedCharsetException {
    this.mimeType = mimeType;
    this.params = params;
    final String s = getParameter("charset");
    this.charset = !TextUtils.isBlank(s) ? Charset.forName(s) : null;
}

From source file:me.ixfan.wechatkit.user.UserManager.java

/**
 * ?? UnionId ?????UnionId ?/* w ww.  ja va 2  s . c  om*/
 *
 * @param openId  OpenId
 * @param lang zh_CN zh_TW ?en  zh_CN
 * @return {@link WeChatFollower}
 * @throws WeChatApiErrorException API??
 */
public WeChatFollower getUserInfo(final String openId, String lang) throws WeChatApiErrorException {
    Args.notBlank(openId, "OpenId");
    if (TextUtils.isBlank(lang)) {
        lang = "zh_CN";
    }
    Args.check(lang.equals("zh_CN") || lang.equals("zh_TW") || lang.equals("en"),
            "'lang' ? zh_CN, zh_TW  en.");

    final String url = WeChatConstants.WECHAT_GET_USER_INFO
            .replace("${ACCESS_TOKEN}", super.tokenManager.getAccessToken()).replace("${OPENID}", openId)
            .replace("${LANG}", lang);
    JsonObject jsonResponse;
    try {
        jsonResponse = HttpClientUtil.sendGetRequestAndGetJsonResponse(url);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    if (jsonResponse.has("subscribe")) {
        return WeChatFollower.fromJson(jsonResponse);
    } else {
        throw new WeChatApiErrorException(jsonResponse.get("errcode").getAsInt(),
                jsonResponse.get("errmsg").getAsString());
    }
}

From source file:me.ixfan.wechatkit.user.UserManager.java

/**
 * ?????100?//from   w ww  . j a v a  2 s. c om
 * @param openIds  OpenId 
 * @param lang zh_CN zh_TW ?en  zh-CN
 * @return {@link WeChatFollower}s
 * @throws WeChatApiErrorException API??
 */
public List<WeChatFollower> batchGetUserInfo(final List<String> openIds, String lang)
        throws WeChatApiErrorException {
    Args.notEmpty(openIds, "OpenIds");
    if (TextUtils.isBlank(lang)) {
        lang = "zh_CN";
    }
    Args.check(lang.equals("zh_CN") || lang.equals("zh_TW") || lang.equals("en"),
            "'lang' ? zh_CN, zh_TW  en.");

    final String finalLang = lang;
    JsonObject jsonResponse;
    try {
        final List<Map<String, String>> data = new ArrayList<>();
        openIds.forEach(openid -> {
            Map<String, String> map = new HashMap<>();
            map.put("openid", openid);
            map.put("lang", finalLang);
            data.add(map);
        });
        final Map<String, List<Map<String, String>>> jsonMap = new HashMap<>();
        jsonMap.put("user_list", data);
        Gson gson = new Gson();
        jsonResponse = HttpClientUtil
                .sendPostRequestWithJsonBody(WeChatConstants.WECHAT_POST_BATCH_GET_USER_INFO
                        .replace("${ACCESS_TOKEN}", super.tokenManager.getAccessToken()), gson.toJson(jsonMap));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    if (jsonResponse.has("user_info_list")) {
        return WeChatFollower.batchFromJson(jsonResponse.get("user_info_list").getAsJsonArray());
    } else {
        throw new WeChatApiErrorException(jsonResponse.get("errcode").getAsInt(),
                jsonResponse.get("errmsg").getAsString());
    }
}

From source file:cn.aage.robot.http.entity.ContentType.java

/**
 * Creates a new instance of {@link ContentType}.
 *
 * @param mimeType MIME type. It may not be <code>null</code> or empty. It may not contain
 *                 characters <">, <;>, <,> reserved by the HTTP specification.
 * @param charset  charset. It may not contain characters <">, <;>, <,> reserved by the HTTP
 *                 specification. This parameter is optional.
 * @return content type/* w w  w .ja  v  a 2s. c  om*/
 * @throws UnsupportedCharsetException Thrown when the named charset is not available in
 *                                     this instance of the Java virtual machine
 */
public static ContentType create(final String mimeType, final String charset)
        throws UnsupportedCharsetException {
    return create(mimeType, !TextUtils.isBlank(charset) ? Charset.forName(charset) : null);
}

From source file:com.epam.catgenome.manager.gene.GeneRegisterer.java

private GeneFeature processFileContents(GeneFile geneFile, File indexFile, File largeScaleIndexFile,
        File transcriptIndexFile, FeatureIndexedFileRegistrationRequest request) throws IOException {
    boolean doIndex = TextUtils.isBlank(request.getIndexPath());
    GeneFeature feature = null;//from w ww .  ja v a2 s . c o  m
    GeneFeature firstFeature = null;
    lastFeature = null;

    // histogram stuff
    int featuresCount = 0;

    List<FeatureIndexEntry> allEntries = new ArrayList<>();
    // main loop - here we process gene file, add it's features to an index and create helper files: large scale
    // and transcript
    while (iterator.hasNext()) {
        // read the next line if available
        final long filePointer = iterator.getPosition();
        //add the feature to the index
        feature = (GeneFeature) iterator.next();

        if (firstFeature == null) {
            firstFeature = feature;
            lastFeature = feature;
            initializeHistogram(firstFeature);
        }

        featuresCount = processFeature(feature, featuresCount, doIndex, allEntries, request.isDoIndex(),
                filePointer);
    }

    processLastFeature(feature, featuresCount, geneFile, allEntries, request.isDoIndex());

    makeIndexes(geneFile, metaMap, indexFile, largeScaleIndexFile, transcriptIndexFile, doIndex, request);

    writerLargeScale.flush();
    writerTranscript.flush();

    return firstFeature;
}

From source file:com.github.dockerjava.jaxrs.connector.ApacheConnector.java

private static String[] split(final String s) {
    if (TextUtils.isBlank(s)) {
        return null;
    }/*from   ww  w . jav  a 2 s . c o m*/
    return s.split(" *, *");
}