List of usage examples for org.apache.commons.lang3 StringUtils defaultIfBlank
public static <T extends CharSequence> T defaultIfBlank(final T str, final T defaultStr)
Returns either the passed in CharSequence, or if the CharSequence is whitespace, empty ("") or null , the value of defaultStr .
StringUtils.defaultIfBlank(null, "NULL") = "NULL" StringUtils.defaultIfBlank("", "NULL") = "NULL" StringUtils.defaultIfBlank(" ", "NULL") = "NULL" StringUtils.defaultIfBlank("bat", "NULL") = "bat" StringUtils.defaultIfBlank("", null) = null
From source file:mobile.service.AuthService.java
/** * //from w ww. j a va2 s . com * * @param username ?? * @param password ? * @param timeZoneOffset ?????+8480 */ public static ServiceVOResult<CommonVO> login(String username, String password, Integer timeZoneOffset) { Session session = Context.current().session(); TimeZoneUtils.setTimeZoneOffset2Session(session, timeZoneOffset); ObjectNodeResult loginResult = User.login(username, password, false); ServiceVOResult<CommonVO> serviceVOResult = ServiceVOResult.create(loginResult); if (serviceVOResult.isSuccess()) { User user = loginResult.getUser(); CommonVO vo = CommonVO.create(); ObjectNode userNode = Json.newObject(); userNode.put("id", user.getId()); userNode.put("name", user.getName()); userNode.put("avatar_190", user.getAvatar(190)); userNode.put("avatar_70", user.getAvatar(70)); userNode.put("avatar_22", user.getAvatar(22)); userNode.put("phoneNumber", StringUtils.defaultIfBlank(loginResult.getUser().phoneNumber, null)); vo.set("user", userNode); vo.set("token", UserAuthService.getTokenInSession(session)); serviceVOResult.setVo(vo); } return serviceVOResult; }
From source file:com.ppcxy.cyfm.showcase.demos.utilities.string.ApacheStringUtilsDemo.java
@Test public void nullSafe() { // ?//from w w w . ja v a 2 s. c o m assertThat(StringUtils.isNotBlank(null)).isFalse(); assertThat(StringUtils.isNotBlank("")).isFalse(); assertThat(StringUtils.isNotBlank(" ")).isFalse(); assertThat(StringUtils.isNotEmpty(" ")).isTrue(); // nullblankdefault assertThat(StringUtils.defaultString(null)).isEqualTo(""); assertThat(StringUtils.defaultString(null, "defaultStr")).isEqualTo("defaultStr"); assertThat(StringUtils.defaultIfBlank(null, "defaultStr")).isEqualTo("defaultStr"); assertThat(StringUtils.defaultIfBlank(" ", "defaultStr")).isEqualTo("defaultStr"); }
From source file:badminton.common.Util.StringUtil.java
/** * ?blank??0/* w ww . j a v a 2 s .c o m*/ * * @param str * @param defaultStr * @return defaultStr:,str:? */ public static String defaultIfBlank(final String str, final String defaultStr) { return StringUtils.defaultIfBlank(str, defaultStr); }
From source file:net.eledge.android.toolkit.db.internal.SQLBuilder.java
public static String getIdField(Class<?> clazz) { for (Field field : clazz.getFields()) { if (field.isAnnotationPresent(Id.class)) { Column column = field.getAnnotation(Column.class); return StringUtils.defaultIfBlank(column.name(), field.getName().toLowerCase(Locale.ENGLISH)); }//from w w w . j a v a 2 s . co m } return null; }
From source file:com.omnigon.aem.common.utils.url.DefaultSlingUrlBuilder.java
DefaultSlingUrlBuilder(final RequestPathInfo pathInfo) { this.contentPath = pathInfo.getResourcePath(); Collections.addAll(this.selectors, pathInfo.getSelectors()); this.extension = StringUtils.defaultIfBlank(pathInfo.getExtension(), HTML_EXTENSION); this.suffix = pathInfo.getSuffix(); }
From source file:com.sonicle.webtop.core.app.util.ClassHelper.java
public static Class loadClass(String className, Class requiredParentClass, String targetDescription) { String tdesc = StringUtils.defaultIfBlank(targetDescription, "Target"); try {/* w w w. j a v a 2 s . co m*/ Class clazz = Class.forName(className); if (!requiredParentClass.isAssignableFrom(clazz)) throw new ClassCastException(); return clazz; } catch (ClassNotFoundException ex) { LOGGER.debug("{} class not found [{}]", tdesc, className); } catch (ClassCastException ex) { LOGGER.warn("A valid {} class must extends '{}' class", tdesc, requiredParentClass.toString()); } catch (Throwable t) { LOGGER.error("Unable to load class [{}]", className, t); } return null; }
From source file:com.adaptris.core.fs.FsHelper.java
/** * Create a file reference from a URL using the platform default encoding for the URL. * /* www . ja va2 s . c o m*/ * @param url the URL. * @param charset the encoding that the url is considered to be in. * @return a File object * @throws UnsupportedEncodingException if the encoding was not supported. */ public static File createFileReference(URL url, String charset) throws UnsupportedEncodingException { String charSetToUse = StringUtils.defaultIfBlank(charset, System.getProperty("file.encoding")); String filename = URLDecoder.decode(url.getPath(), charSetToUse); // Cope with file://localhost/./config/blah -> /./config/blah is the result of getPath() // Munge that properly. if (filename.startsWith("/.")) { filename = filename.substring(1); } return new File(filename); }
From source file:com.esri.geoportal.harvester.unc.UncFolder.java
/** * Creates instance of the UNC folder./* www . ja va 2s . com*/ * @param broker broker * @param folder folder * @param matchPattern match pattern * @param since since date */ public UncFolder(UncBroker broker, File folder, String matchPattern, Date since) { this.broker = broker; this.folder = folder; this.matchPattern = StringUtils.defaultIfBlank(matchPattern, DEFAULT_MATCH_PATTERN); this.since = since; }
From source file:com.sonicle.webtop.core.util.LoggerUtils.java
public synchronized static String getServiceVariable() { return StringUtils.defaultIfBlank(MDC.get(VAR_SERVICE), DEFAULT_SERVICE); }
From source file:$.ApplicationAction.java
@Action(method = HttpMethod.GET) public ActionResult appList(@ActionParam("q") String q, @ActionParam("max") int max, @ActionParam("page") int page) { max = max == 0 ? 10 : max;/*from ww w .jav a 2 s . co m*/ q = StringUtils.defaultIfBlank(q, ""); Page<? extends Application> apps = appManager.findApplicationByNamespace(q, new PageRequest(page, max)); return new ActionResult("freemarker", "/view/application/application-list.ftl").addToModel("apps", apps); }