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.BBProxy.java
public static F.Promise<Result> index(String query) { if (StringUtils.isEmpty(query)) { F.Promise.promise(new F.Function0<Object>() { @Override// w ww . j ava2 s . c om public Object apply() throws Throwable { return ok(Json.toJson("Query parameter (q) not provided ")); } }); } F.Promise<WSResponse> wsResponsePromise = WS.url("http://www.bloomberg.com/search") .setQueryParameter("query", 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>> ret = new ArrayList<Map<String, String>>(); try { // Insert into map org.jsoup.nodes.Document doc = Jsoup.parse(body); Elements items = doc.getElementsByClass("search-result"); for (Element item : items) { Map<String, String> keyValue = new LinkedHashMap<String, String>(); keyValue.put("image", item.getElementsByClass("search-result-story__thumbnail__image").attr("src")); keyValue.put("title", item.getElementsByClass("search-result-story__headline").text()); int index = item.getElementsByClass("search-result-story__body").text() .indexOf(" (Source: Bloomberg"); if (index == -1) { keyValue.put("content", item.getElementsByClass("search-result-story__body").text()); } else { keyValue.put("content", item.getElementsByClass("search-result-story__body").text() .substring(0, index)); } keyValue.put("date", item.getElementsByClass("published-at").text()); keyValue.put("url", "www.bloomberg.com/" + item.getElementsByClass("search-result-story__thumbnail__link").attr("href")); ret.add(keyValue); } } catch (DOMException e) { e.printStackTrace(); } return ok(Json.toJson(ret)); } }); }
From source file:com.cloudera.nav.plugin.model.HdfsIdGenerator.java
public static String generateHdfsEntityId(String sourceId, String fileSystemPath) { Preconditions.checkArgument(!StringUtils.isEmpty(sourceId) && !StringUtils.isEmpty(fileSystemPath), "SourceId and fileSystemPath " + "must be supplied to generate HDFS entity identity"); return MD5IdGenerator.generateIdentity(sourceId, fileSystemPath); }
From source file:com.nec.harvest.util.StringUtil.java
/** * Change a number to string and format it with style by user define * //from w ww. j a v a 2 s . c o m * @param fill * Character to fill up * @param total * Length of string return * @param number * Number to convert * @return String return */ public static <T> String numberToStringWithUserFillUp(String fill, int total, T number) { if (StringUtils.isEmpty(fill)) { throw new IllegalArgumentException("Number to string fill character must not be null or empty"); } // nts mean that number to string String nts = String.valueOf(number); int fillUp = total - nts.length(); if (fillUp > 0) { nts = StringUtils.repeat(fill, fillUp) + nts; } return nts; }
From source file:com.cloudera.nav.sdk.model.CustomIdGenerator.java
public static String generateIdentity(String... args) { for (String s : args) { Preconditions.checkArgument(!StringUtils.isEmpty(s), "An identity component must not be null or empty"); }// ww w . j a v a 2 s. co m return MD5IdGenerator.generateIdentity(args); }
From source file:com.cy.dctms.common.util.ValidateUtil.java
/** * ? ????571-88175786?// www .j a v a 2s . com * @return false:?; true:? * */ public static boolean validatePhone(String telephone) { if (StringUtils.isEmpty(telephone)) { return false; } Pattern pattern = Pattern.compile("^((0\\d{2,3})-)(\\d{7,8})(-(\\d{3,}))?$"); Matcher macher = pattern.matcher(telephone); return macher.matches(); }
From source file:com.liferay.maven.plugins.util.Validator.java
public static boolean isNull(String s) { return StringUtils.isEmpty(s); }
From source file:com.zb.app.external.wechat.cons.WeixinMsgType.java
public static WeixinMsgType getMsgType(String value) { if (StringUtils.isEmpty(value)) { return null; }/*from w ww . j a v a 2 s . c o m*/ for (WeixinMsgType type : values()) { if (type.name().equals(value)) { return type; } } return null; }
From source file:cognition.common.utils.ArrayUtil.java
public static boolean isStringArrayEmpty(String[] array) { if (array == null) return true; for (String a : array) { if (!StringUtils.isEmpty(a)) { return false; }/* w ww .j av a2 s .co m*/ } return true; }
From source file:com.infullmobile.jenkins.plugin.restrictedregister.security.hudson.form.RequiredFieldsChecker.java
public static void checkRequiredFields(JSONObject payload, IFormField... requiredFields) throws RegistrationException { final List<IFormField> emptyFields = new ArrayList<>(); for (IFormField field : requiredFields) { if (!payload.has(field.getFieldName()) || StringUtils.isEmpty(payload.getString(field.getFieldName()))) { emptyFields.add(field);/*from w w w .ja va 2 s . c o m*/ } } if (!emptyFields.isEmpty()) { throw new RegistrationException("One or more field is empty.", emptyFields.toArray(new IFormField[emptyFields.size()])); } }
From source file:controllers.NWProxy.java
public static F.Promise<Result> index(String query) { if (StringUtils.isEmpty(query)) { F.Promise.promise(new F.Function0<Object>() { @Override//w w w. ja v a 2s . c o m public Object apply() throws Throwable { return ok(Json.toJson("Query parameter (q) not provided ")); } }); } final String officialUrl = "http://www.newsweek.com"; F.Promise<WSResponse> wsResponsePromise = WS.url(officialUrl + "/search/site/" + 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("li.search-result"); // All articles belong to this class for (Element item : items) { Map<String, String> keyValue = new LinkedHashMap<String, String>(); keyValue.put("image", item.select("img").attr("src")); keyValue.put("title", item.select("h2").select("a").text()); keyValue.put("content", item.select("div.article-summary").first().text()); // Get date from each article separately org.jsoup.nodes.Document articleDoc = RedirectionHandler( officialUrl + item.select("a").attr("href")); keyValue.put("date", articleDoc.select("span.timedate").text()); keyValue.put("url", officialUrl + item.select("a").attr("href")); results.add(keyValue); } } catch (DOMException e) { e.printStackTrace(); } return ok(Json.toJson(results)); } }); }