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

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

Introduction

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

Prototype

public static boolean isEmpty(String str) 

Source Link

Document

Checks if a String is empty ("") or null.

Usage

From source file:kirchnerei.glatteis.page.RequestKind.java

public static RequestKind fromString(String name) {
    if (StringUtils.isEmpty(name)) {
        return UNKNOWN;
    }/*  w w  w  .  ja v  a 2  s  . co  m*/
    try {
        return valueOf(name.toUpperCase());
    } catch (Exception e) {
        return UNKNOWN;
    }
}

From source file:com.pureinfo.tgirls.sns.SNSDataHelper.java

public static List<User> getFriends(String _taobaoId, HttpServletRequest _request) {

    if (StringUtils.isEmpty(_taobaoId)) {
        return null;
    }//from w w  w. jav  a  2 s .  com

    String sessionId = (String) CookieUtils.getRequestCookieValue(_request, SessionConstants.TAOBAO_SESSION_ID);

    try {
        ListResponse<com.taobao.api.sns.pojo.user.User> lr = TOPAPI.getInstance()
                .getFriends(Long.parseLong(_taobaoId), 1, 100, sessionId);
        IUserMgr mgr = (IUserMgr) ArkContentHelper.getContentMgrOf(User.class);
        List<User> result = new ArrayList<User>();

        if (lr.isSuccess() && lr.getObjs() != null) {
            for (Iterator iterator = lr.getObjs().iterator(); iterator.hasNext();) {
                com.taobao.api.sns.pojo.user.User user = (com.taobao.api.sns.pojo.user.User) iterator.next();
                User tgirlUser = mgr.getUserByTaobaoId(user.getUserid() + "");
                if (tgirlUser != null) {
                    result.add(tgirlUser);
                }

            }
        }

        return result;
    } catch (Exception e) {
        e.printStackTrace(System.err);
    }

    return null;

}

From source file:kaleidoscope.util.HttpUtils.java

public static Locale getLocale(String acceptLanguage) {
    Locale locale = null;//w  w w  .ja v  a2  s  . c o  m

    if (StringUtils.isEmpty(acceptLanguage) != true) {
        StringTokenizer langToken = new StringTokenizer(acceptLanguage, ",; ");
        String language = langToken.nextToken().replace('-', '_');

        StringTokenizer localeToken = new StringTokenizer(language, "_");
        switch (localeToken.countTokens()) {
        case 1:
            locale = new Locale(localeToken.nextToken());
            break;
        case 2:
            locale = new Locale(localeToken.nextToken(), localeToken.nextToken());
            break;
        case 3:
            locale = new Locale(localeToken.nextToken(), localeToken.nextToken(), localeToken.nextToken());
            break;
        }
    }

    if (locale == null) {
        locale = Locale.getDefault();
    }

    return locale;
}

From source file:controllers.TAXIProxy.java

public static F.Promise<Result> index(String query) {

    if (StringUtils.isEmpty(query)) {

        F.Promise.promise(new F.Function0<Object>() {
            @Override// ww  w  .j  av  a2s  . com
            public Object apply() throws Throwable {
                return ok(Json.toJson("Query parameter (q) not provided "));
            }

        });
    }

    final String baseUrl = "http://designtaxi.com/";

    F.Promise<WSResponse> wsResponsePromise = WS.url(baseUrl + "news-search.php")
            .setQueryParameter("news_keyword", query).get();

    return wsResponsePromise.map(new F.Function<WSResponse, Result>() {
        @Override
        public Result apply(WSResponse wsResponse) throws Throwable {

            String body = wsResponse.getBody();
            List<Map<String, String>> results = new ArrayList<Map<String, String>>();

            try {
                // Insert into map
                org.jsoup.nodes.Document doc = Jsoup.parse(body);
                Elements items = doc.select("div.news-cover");

                // Iterate through results
                for (Element item : items) {
                    Map<String, String> keyValue = new LinkedHashMap<String, String>();

                    keyValue.put("image", baseUrl + item.select("img").attr("src"));
                    keyValue.put("title", item.select("a.addthis_button_expanded").attr("addthis:title"));

                    // Connect to each and every article to get date and first sentence as content
                    try {
                        org.jsoup.nodes.Document articleDoc = Jsoup
                                .connect(item.select("a.addthis_button_expanded").attr("addthis:url"))
                                .userAgent("Mozilla").get();

                        // If connection successful(STATUS 200), the add content and date keys to map
                        keyValue.put("content", articleDoc.select("div#news-content").text().substring(0,
                                articleDoc.select("div#news-content").text().indexOf(".") + 1) + ".");
                        keyValue.put("date", articleDoc.select("span.date").text());

                    } catch (IOException e) {
                        System.out.println(e);
                    }

                    keyValue.put("url", item.select("a.addthis_button_expanded").attr("addthis:url"));

                    results.add(keyValue);
                }

            } catch (DOMException e) {
                e.printStackTrace();
            }

            return ok(Json.toJson(results));
        }
    });
}

From source file:azkaban.jobtype.javautils.ValidationUtils.java

public static void validateNotEmpty(String s, String name) {
    if (StringUtils.isEmpty(s)) {
        throw new IllegalArgumentException(name + " cannot be empty.");
    }/*from   w w  w  .j  a  va2  s  . c om*/
}

From source file:controllers.WDCDProxy.java

public static F.Promise<Result> index(String query) {

    if (StringUtils.isEmpty(query)) {

        F.Promise.promise(new F.Function0<Object>() {
            @Override//from w w w  .jav a  2  s  . c o  m
            public Object apply() throws Throwable {
                return ok(Json.toJson("Query parameter (q) not provided "));
            }

        });
    }

    F.Promise<WSResponse> wsResponsePromise = WS.url("http://www.whatdesigncando.com/")
            .setQueryParameter("s", query).get();

    return wsResponsePromise.map(new F.Function<WSResponse, Result>() {
        @Override
        public Result apply(WSResponse wsResponse) throws Throwable {

            String body = wsResponse.getBody();
            List<Map<String, String>> results = new ArrayList<Map<String, String>>();

            try {
                // Insert into map
                org.jsoup.nodes.Document doc = Jsoup.parse(body);
                Elements items = doc.select("div.item");

                // Iterate through results
                for (Element item : items) {
                    Map<String, String> keyValue = new LinkedHashMap<String, String>();

                    String imageUrl = item.select("a").attr("style");

                    keyValue.put("image", imageUrl.substring(imageUrl.indexOf("'") + 1,
                            imageUrl.indexOf("'", imageUrl.indexOf("'") + 1)));
                    keyValue.put("title", item.select("h3").text());

                    // Get date and the first sentence as "content" from each article separately (or the "sub-title" tag)
                    org.jsoup.nodes.Document articleDoc = Jsoup.connect(item.select("a").attr("href")).get();

                    String datePublished = articleDoc.select("div#maincontent p.metainfo").text().substring(0,
                            articleDoc.select("div#maincontent p.metainfo").text().indexOf("Published"));
                    String firstSentence;

                    if (articleDoc.select("div#maincontent p.sub-title").text().length() == 0) {
                        firstSentence = articleDoc.select("div#maincontent p:not(.metainfo)").text().substring(
                                0,
                                articleDoc.select("div#maincontent p:not(.metainfo)").text().indexOf(".") + 1);
                        firstSentence = firstSentence + ".";
                    } else {
                        firstSentence = articleDoc.select("div#maincontent p.sub-title").text();
                        firstSentence = firstSentence + "..";
                    }

                    keyValue.put("content", firstSentence);
                    keyValue.put("date", datePublished);
                    keyValue.put("url", item.select("a").attr("href"));

                    results.add(keyValue);
                }

            } catch (DOMException e) {
                e.printStackTrace();
            }

            return ok(Json.toJson(results));
        }
    });
}

From source file:com.cloudera.nav.sdk.model.HiveIdGenerator.java

public static String generateTableId(String sourceId, String databaseName, String tableName) {
    Preconditions.checkArgument(//from ww w  .  j a v a  2s  .  c om
            !StringUtils.isEmpty(sourceId) && !StringUtils.isEmpty(databaseName)
                    && !StringUtils.isEmpty(tableName),
            "SourceId, database name, and table name must be supplied to " + "generate Hive table identity");
    return MD5IdGenerator.generateIdentity(sourceId, databaseName.toUpperCase(), tableName.toUpperCase());
}

From source file:com.cloudera.nav.plugin.model.HiveIdGenerator.java

public static String generateTableId(String sourceId, String databaseName, String tableName) {
    Preconditions.checkArgument(//from  w w w  . j  a v  a2 s  . c om
            !StringUtils.isEmpty(sourceId) && !StringUtils.isEmpty(databaseName)
                    && !StringUtils.isEmpty(tableName),
            "SourceId, database name, and table name must be supplied to " + "generate Hive table identity");
    return MD5IdGenerator.generateIdentity(sourceId, databaseName, tableName);
}

From source file:com.mmj.app.web.tools.PicTools.java

/**
 * ??/*from  ww w .ja v a  2s  .  co  m*/
 * 
 * @param url
 * @param picSize
 * @return
 */
public static String processURL(String url, String suffix) {
    if (StringUtils.isEmpty(url)) {
        return StringUtils.EMPTY;
    }
    if (StringUtils.isEmpty(suffix)) {
        return url;
    }
    String pefix = url;
    if (StringUtils.contains(url, "=")) {
        pefix = StringUtils.substringBeforeLast(url, "=");
    } else if (StringUtils.contains(url, "=C")) {
        pefix = StringUtils.substringBeforeLast(url, "=C");
    } else {
        pefix = StringUtils.substringBeforeLast(url, DOT);
    }
    String dotStr = StringUtils.substringAfterLast(url, DOT);
    return pefix + suffix + DOT + dotStr;
}

From source file:com.qualogy.qafe.util.Assert.java

public static void hasLength(String className, String errorMessage) {
    if (StringUtils.isEmpty(className))
        throw new IllegalArgumentException(errorMessage);
}