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:de.mogwai.common.web.ValueBindingConverter.java

public static ValueBinding convertTo(FacesContext aContext, ValueBinding aBinding) {
    if (StringUtils.isEmpty(aBinding.getExpressionString())) {
        return aBinding;
    }//ww w .j av  a 2  s.co  m
    return aContext.getApplication().createValueBinding(aBinding.getExpressionString());
}

From source file:com.github.dbourdette.otto.source.TimeFrame.java

public static TimeFrame safeValueOf(String name, TimeFrame defaultValue) {
    if (StringUtils.isEmpty(name)) {
        return defaultValue;
    }//from   w w w  . jav a 2 s  .c  om

    try {
        return TimeFrame.valueOf(name);
    } catch (Exception e) {
        return defaultValue;
    }
}

From source file:com.dc.gameserver.extComponents.Kit.DateUtil.java

/**
 * ?//from w w  w  . j  a v a2s.  c om
 * @param startTime
 * @return
 * @throws Exception
 */
public static Date getStartTime(String startTime) throws Exception {
    if (StringUtils.isEmpty(startTime)) {
        startTime = DEFAULT_STARTTIME;
    }
    return DateUtil.DATEFORMAT_DAY.parse(startTime);
}

From source file:net.sourceforge.fenixedu.util.PersonNameFormatter.java

public static String prettyPrint(String uglyDuckling) {

    if (StringUtils.isEmpty(uglyDuckling)) {
        return uglyDuckling;
    }/*from   ww w .j  a va 2 s . co  m*/

    uglyDuckling = removeDuplicateSpaces(uglyDuckling.trim());
    String[] lowerCaseName = uglyDuckling.toLowerCase().split(" ");
    StringBuilder capitalizedName = new StringBuilder();

    for (int i = 0; i < lowerCaseName.length; i++) {

        if (!containsNoneSpecialChars(lowerCaseName[i]) && !allCapSet.contains(lowerCaseName[i])) {
            capitalizedName.append(capitalizeWordWithSpecChars(lowerCaseName[i]));
        } else {
            // Exception to the general case: if "A" is the last
            // word
            // converts to UPPERCASE
            // (needed for courses that occur in alternative
            // semesters)
            if (i == (lowerCaseName.length - 1) & lowerCaseName[i].equals("a")) {
                capitalizedName.append(lowerCaseName[i].toUpperCase());
            } else {
                capitalizedName.append(capitalizeWord(lowerCaseName[i], false));
            }
        }

        capitalizedName.append(" ");
    }

    return capitalizedName.toString().substring(0, capitalizedName.length() - 1);
}

From source file:de.thischwa.pmcms.model.domain.pojo.TemplateType.java

public static TemplateType getType(final String name) {
    if (StringUtils.isEmpty(name))
        return null;
    for (TemplateType type : TemplateType.values()) {
        if (type.toString().toLowerCase().equals(name.toLowerCase()))
            return type;
    }//from   w  w  w  .  j  a  v  a 2 s. c  o m
    return null;
}

From source file:com.mmj.app.common.util.URLUtils.java

@SuppressWarnings("unchecked")
public static Map<String, Object> getParams(URL url) {
    Map<String, Object> paramMap = new HashMap<String, Object>();
    String query = url.getQuery();
    if (query == null) {
        return paramMap;
    }/*from ww w.ja  v  a2s  .  co  m*/
    String[] params = query.split(split);
    for (String param : params) {
        if (StringUtils.isEmpty(param)) {
            continue;
        }
        String name = param.substring(0, param.indexOf("="));
        String value = param.substring(param.indexOf("=") + 1, param.length());
        if (paramMap.containsKey(name)) {
            Object object = paramMap.get(name);
            List<String> values = null;
            if (object instanceof List) {
                values = (List<String>) object;
            } else {
                values = new ArrayList<String>();
                values.add(object.toString());
            }
            values.add(value);
            paramMap.put(name, values);
        } else {
            paramMap.put(name, value);
        }
    }
    return paramMap;
}

From source file:controllers.NYTProxy.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 .j a  va  2s .  c om*/
            public Object apply() throws Throwable {
                return ok(Json.toJson("Query parameter (q) not provided "));
            }

        });
    }

    String basicUrl = "http://query.nytimes.com/svc/add/v1/sitesearch.json";

    // Additional query parameters
    String spotlight = "true";
    String facet = "true";

    F.Promise<WSResponse> wsResponsePromise = WS.url(basicUrl).setQueryParameter("q", query)
            .setQueryParameter("spotlight", spotlight).setQueryParameter("facet", facet).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 {
                // Reach json code into html response from ajax call
                org.jsoup.nodes.Document doc = Jsoup.parse(body);
                String resultJSONbody = doc.select("body").first().text();

                // Parse the json code
                JSONObject resultJSONobj = new JSONObject(resultJSONbody);
                resultJSONobj = (JSONObject) resultJSONobj.get("response");

                // Reach array of results and set to JSONArray
                JSONArray resultJSONarray = new JSONArray(resultJSONobj.get("docs").toString());

                // Insert each result's elements into map with corresponding key
                for (int i = 0; i < resultJSONarray.length(); i++) {
                    // Set internal map
                    Map<String, String> keyValue = new LinkedHashMap<String, String>();

                    // Set basic image url where image exists
                    String basicImgUrl = "http://static01.nyt.com/";
                    resultJSONobj = (JSONObject) resultJSONarray.get(i);

                    // Check if article contains "multimedia" key (image), else it shall be empty list
                    if (resultJSONobj.getJSONArray("multimedia").length() != 0) {
                        // Iterate through multimedia list of values and get the thumbnail image's url
                        for (int j = 0; j < resultJSONobj.getJSONArray("multimedia").length(); j++) {
                            if (resultJSONobj.getJSONArray("multimedia").getJSONObject(j).getString("subtype")
                                    .equals("thumbnail")) {
                                // Prepend the basic image url
                                keyValue.put("image", basicImgUrl + resultJSONobj.getJSONArray("multimedia")
                                        .getJSONObject(j).getString("url"));
                                break;
                            }
                        }

                    }

                    keyValue.put("title", resultJSONobj.getJSONObject("headline").getString("main"));
                    keyValue.put("content", resultJSONobj.getString("snippet").replace("</strong>", ""));

                    // Format date
                    String date = resultJSONobj.getString("pub_date").substring(0,
                            resultJSONobj.getString("pub_date").length() - 1);
                    Pattern pattern = Pattern.compile("[A-Z]");
                    Matcher matcher = pattern.matcher(date);

                    if (matcher.find()) {
                        date = date.substring(0, date.indexOf(matcher.group(0))) + " " + matcher.group(0) + " "
                                + date.substring(date.indexOf(matcher.group(0)) + 1, date.length());
                    }

                    keyValue.put("date", date);
                    keyValue.put("url", resultJSONobj.getString("web_url"));

                    results.add(keyValue);

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

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

From source file:iddb.core.util.PasswordUtils.java

public static boolean checkPassword(String raw_password, String encoded_password) {
    if (StringUtils.isEmpty(encoded_password) || StringUtils.isEmpty(raw_password))
        return false;
    if (!encoded_password.contains("$"))
        return false;
    // get the salt from the encoded password
    String[] part = StringUtils.split(encoded_password, "$");
    String hashPassword = HashUtils.getSHA1Hash(part[0] + raw_password);
    return (hashPassword.equals(part[1]));
}

From source file:com.zf.util.Post_NetNew.java

public static String pn(Map<String, String> pams) throws Exception {
    if (null == pams) {
        return "";
    }//from www . j ava 2s .co m
    String strtmp = "url";
    URL url = new URL(pams.get(strtmp));
    pams.remove(strtmp);
    strtmp = "body";
    String body = pams.get(strtmp);
    pams.remove(strtmp);
    strtmp = "POST";
    if (StringUtils.isEmpty(body))
        strtmp = "GET";
    HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
    httpConn.setUseCaches(false);
    httpConn.setRequestMethod(strtmp);
    for (String pam : pams.keySet()) {
        httpConn.setRequestProperty(pam, pams.get(pam));
    }
    if ("POST".equals(strtmp)) {
        httpConn.setDoOutput(true);
        httpConn.setDoInput(true);
        DataOutputStream dos = new DataOutputStream(httpConn.getOutputStream());
        dos.writeBytes(body);
        dos.flush();
    }
    int resultCode = httpConn.getResponseCode();
    StringBuilder sb = new StringBuilder();
    sb.append(resultCode).append("\n");
    String readLine;
    InputStream stream;
    try {
        stream = httpConn.getInputStream();
    } catch (Exception ignored) {
        stream = httpConn.getErrorStream();
    }
    try {
        BufferedReader responseReader = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
        while ((readLine = responseReader.readLine()) != null) {
            sb.append(readLine).append("\n");
        }
    } catch (Exception ignored) {
    }

    return sb.toString();
}

From source file:com.mmj.app.biz.cons.BooleanEnum.java

public static BooleanEnum getByName(String name) {
    if (StringUtils.isEmpty(name)) {
        return null;
    }//from ww  w.ja  v  a2  s .  co m
    for (BooleanEnum state : values()) {
        if (StringUtils.equals(state.getName(), name)) {
            return state;
        }
    }
    return null;
}