List of usage examples for org.apache.commons.lang StringUtils isEmpty
public static boolean isEmpty(String str)
Checks if a String is empty ("") or null.
From source file:controllers.CNBCProxy.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 av a 2 s. c o m public Object apply() throws Throwable { return ok(Json.toJson("Query parameter (q) not provided ")); } }); } String target = "all"; String categories = "exclude"; String partnerId = "2000"; // ?target=all&categories=exclude&partnerId=2000&keywords=apple F.Promise<WSResponse> wsResponsePromise = WS.url("http://search.cnbc.com/main.do") .setQueryParameter("target", target).setQueryParameter("categories", categories) .setQueryParameter("partnerId", partnerId).setQueryParameter("keywords", 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 { // Parse html document org.jsoup.nodes.Document doc = Jsoup.parse(body); Elements items = doc.select("div:not(.clr).padL.padR"); // Choose elements that contain classes "padL" and "padR", but not "clr" // Iterate through results for (Element item : items) { Map<String, String> keyValue = new LinkedHashMap<String, String>(); // Add the keys and values keyValue.put("title", item.select("a").text()); keyValue.put("content", item.select("span.cnbc_bio_content").text()); keyValue.put("date", CalculateDateFormat(Long .parseLong(item.getElementsByTag("script").html().replaceAll("[^0-9]", ""), 10))); // Edit the date format 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.ms.commons.message.utils.MessageUtil.java
/** * //from w w w . j av a 2s. c o m * * @param array * @return */ public static String[] removeEmptyElement(String[] array) { if (array == null) { return new String[0]; } int removeCount = 0; for (int i = 0; i < array.length; i++) { if (StringUtils.isEmpty(array[i])) { removeCount += 1; } } if (removeCount > 0) { String[] newArray = new String[array.length - removeCount]; int index = 0; for (int i = 0; i < array.length; i++) { if (StringUtils.isNotEmpty(array[i])) { newArray[index] = array[i]; index += 1; } } return newArray; } return array; }
From source file:controllers.CNNProxy.java
public static F.Promise<Result> index(String query) { if (StringUtils.isEmpty(query)) { F.Promise.promise(new F.Function0<Object>() { @Override/*from w ww . j av a 2 s. c o m*/ public Object apply() throws Throwable { return ok(Json.toJson("Query parameter (q) not provided ")); } }); } String feedUrl = "http://searchapp.cnn.com/search/query.jsp"; //query = query + "&type=all"; String page = "1"; String npp = "10"; String start = "1"; String type = "all"; String bucket = "true"; String sort = "relevance"; String csiID = "csi1"; F.Promise<WSResponse> wsResponsePromise = WS.url(feedUrl).setQueryParameter("page", page) .setQueryParameter("npp", npp).setQueryParameter("start", start).setQueryParameter("text", query) .setQueryParameter("type", type).setQueryParameter("bucket", bucket).setQueryParameter("sort", sort) .setQueryParameter("csiID", csiID).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>> ret = new ArrayList<Map<String, String>>(); try { // Reach json code into html response from ajax call org.jsoup.nodes.Document doc = Jsoup.parse(body); Element resultElement = doc.select("textarea#jsCode").first(); String resultString = resultElement.text(); // Parse the json code JSONObject obj = new JSONObject(resultString); JSONArray array = new JSONArray(obj.get("results").toString()); JSONArray internalArray = new JSONArray(array.get(0).toString()); // Insert each result's elements into map with corresponding key for (int i = 0; i < internalArray.length(); i++) { JSONObject elementObj = new JSONObject(internalArray.get(i).toString()); String image = elementObj.get("thumbnail").toString(); String title = elementObj.get("title").toString(); String content = elementObj.get("description").toString(); String date = elementObj.get("mediaDateUts").toString(); String url = elementObj.get("url").toString(); Map<String, String> keyValue = new LinkedHashMap<String, String>(); keyValue.put("image", image); keyValue.put("title", title); keyValue.put("content", content); keyValue.put("date", date); keyValue.put("url", url); ret.add(keyValue); } } catch (DOMException e) { e.printStackTrace(); } return ok(Json.toJson(ret)); } }); }
From source file:AIR.Common.Web.UrlHelper.java
public static boolean IsHttpProtocol(String uriString) { if (StringUtils.isEmpty(uriString)) return false; return (uriString.startsWith("http:")) || uriString.startsWith("https:"); }
From source file:controllers.TREEProxy.java
public static F.Promise<Result> index(String query) { if (StringUtils.isEmpty(query)) { F.Promise.promise(new F.Function0<Object>() { @Override/*w w w. j a va 2 s .c om*/ public Object apply() throws Throwable { return ok(Json.toJson("Query parameter (q) not provided ")); } }); } String basicUrl = "https://www.googleapis.com/customsearch/v1element"; // Additional query parameters String key = "AIzaSyCVAXiUzRYsML1Pv6RwSG1gunmMikTzQqY"; String rsz = "filtered_cse"; final int num = 10; String hl = "el"; String cx = "017401606067716418337:btpggki1yw8"; F.Promise<WSResponse> wsResponsePromise = WS.url(basicUrl).setQueryParameter("key", key) .setQueryParameter("rsz", rsz).setQueryParameter("num", Integer.toString(num)) .setQueryParameter("hl", hl).setQueryParameter("cx", cx).setQueryParameter("q", 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 { JSONObject initialBody = new JSONObject(body); JSONArray resultArray = (JSONArray) initialBody.get("results"); for (int i = 0; i < resultArray.length(); i++) { Map<String, String> keyValue = new LinkedHashMap<String, String>(); JSONObject innerObj = new JSONObject(resultArray.get(i).toString()); JSONObject metaTags = (JSONObject) innerObj.get("richSnippet"); JSONObject ogTags = (JSONObject) metaTags.get("metatags"); keyValue.put("image", ogTags.get("ogImage").toString()); keyValue.put("title", ogTags.get("ogTitle").toString()); keyValue.put("content", ogTags.get("ogDescription").toString()); keyValue.put("date", innerObj.get("contentNoFormatting").toString().substring(0, innerObj.get("contentNoFormatting").toString().indexOf(".."))); keyValue.put("url", ogTags.get("ogUrl").toString()); results.add(keyValue); } } catch (DOMException e) { e.printStackTrace(); } return ok(Json.toJson(results)); } }); }
From source file:com.intuit.tank.vm.common.util.ValidationUtil.java
/** * Is this formatted as a variable//from ww w . j a v a2s . c om * * @param key * The variable name * @return TRUE if it is formatted as a variable; FALSE otherwise */ public static boolean isVariable(String key) { if (StringUtils.isEmpty(key)) { return false; } if (key.charAt(0) == identifierChar) { return true; } return false; }
From source file:net.duckling.ddl.util.FileTypeUtils.java
public static boolean isClbDealImage(String fileName) { if (StringUtils.isEmpty(fileName)) { return false; }/* ww w . ja v a 2 s. c om*/ String f = fileName.toLowerCase(); for (String suffix : pictureSuffix) { if (f.endsWith(suffix)) { return true; } } return false; }
From source file:com.photon.phresco.commons.CIPasswordScrambler.java
public static String mask(String password) throws PhrescoException { if (StringUtils.isEmpty(password)) { return StringUtils.EMPTY; }//w w w. j a va2 s . co m try { return new String(Base64.encode(password.getBytes("UTF-8"))); } catch (UnsupportedEncodingException e) { throw new PhrescoException(e); } }
From source file:controllers.FASTCOProxy.java
public static F.Promise<Result> index(String query) { if (StringUtils.isEmpty(query)) { F.Promise.promise(new F.Function0<Object>() { @Override/*from ww w .ja va 2s . c o m*/ public Object apply() throws Throwable { return ok(Json.toJson("Query parameter (q) not provided ")); } }); } String basicUrl = "http://www.fastcodesign.com/api/v1/search"; // Additional query parameters String paged = "0"; int limit = 10; F.Promise<WSResponse> wsResponsePromise = WS.url(basicUrl).setQueryParameter("q", query) .setQueryParameter("paged", paged).setQueryParameter("limit", Integer.toString(limit)).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 { JSONObject initialBody = new JSONObject(body); JSONArray resultArray = (JSONArray) initialBody.get("items"); for (int i = 0; i < resultArray.length(); i++) { Map<String, String> keyValue = new LinkedHashMap<String, String>(); JSONObject element = (JSONObject) resultArray.get(i); // Get title keyValue.put("title", element.get("title").toString()); // Get content keyValue.put("content", element.get("deck").toString()); // Get date element = (JSONObject) resultArray.get(i); element = (JSONObject) element.get("date"); element = (JSONObject) element.get("updated"); keyValue.put("date", element.get("long").toString()); // Get url element = (JSONObject) resultArray.get(i); keyValue.put("url", "www." + element.get("url").toString().substring(2)); results.add(keyValue); } } catch (DOMException e) { e.printStackTrace(); } return ok(Json.toJson(results)); } }); }
From source file:com.baifendian.swordfish.execserver.job.impexp.ImpExpUtil.java
/** * ???//w w w . j av a2 s. c om */ public static String exceptBackQuota(String str) { // ???2 if (StringUtils.isEmpty(str) || str.length() < 2) { return str; } char first = str.charAt(0); if (first == '`') { str = str.substring(1); } char last = str.charAt(str.length() - 1); if (last == '`') { str = str.substring(0, str.length() - 1); } return str; }