StringUtils.isBlank(null) = true
StringUtils.isBlank("") = true
StringUtils.isBlank(" ") = true
StringUtils.isBlank("bob") = false
StringUtils.isBlank(" bob ") = false
StringUtils.isBlank(null) = true
StringUtils.isBlank("") = true
StringUtils.isBlank(" ") = true
StringUtils.isBlank(" ") = true
StringUtils.isBlank("\t \n \f \r") = true //For tabs, newlines, the form feed character and StringUtils.isBlank (carriage return) all knowledge is blank
StringUtils.isBlank("\b") = false //"\b"As the word boundary.
StringUtils.isBlank("bob") = false
StringUtils.isBlank(" bob ") = false
String someWhiteSpace = " \t \n";
StringUtils.isEmpty(someWhiteSpace); // false
StringUtils.isBlank(someWhiteSpace); // true
public void testIsBlank() {
assertTrue(StringUtils.isBlank(null));
assertTrue(StringUtils.isBlank(""));
assertTrue(StringUtils.isBlank(StringUtilsTest.WHITESPACE));
assertFalse(StringUtils.isBlank("foo"));
assertFalse(StringUtils.isBlank(" foo "));
}
public class CheckEmptyString {
public static void main(String[] args) {
String var1 = null;
String var2 = "";
String var3 = " ttt";
String var4 = "Hello World";
System.out.println("var1 is blank? = " + StringUtils.isBlank(var1));
System.out.println("var2 is blank? = " + StringUtils.isBlank(var2));
System.out.println("var3 is blank? = " + StringUtils.isBlank(var3));
System.out.println("var4 is blank? = " + StringUtils.isBlank(var4));
System.out.println("var1 is not blank? = " + StringUtils.isNotBlank(var1));
System.out.println("var2 is not blank? = " + StringUtils.isNotBlank(var2));
System.out.println("var3 is not blank? = " + StringUtils.isNotBlank(var3));
System.out.println("var4 is not blank? = " + StringUtils.isNotBlank(var4));
System.out.println("var1 is empty? = " + StringUtils.isEmpty(var1));
System.out.println("var2 is empty? = " + StringUtils.isEmpty(var2));
System.out.println("var3 is empty? = " + StringUtils.isEmpty(var3));
System.out.println("var4 is empty? = " + StringUtils.isEmpty(var4));
System.out.println("var1 is not empty? = " + StringUtils.isNotEmpty(var1));
System.out.println("var2 is not empty? = " + StringUtils.isNotEmpty(var2));
System.out.println("var3 is not empty? = " + StringUtils.isNotEmpty(var3));
System.out.println("var4 is not empty? = " + StringUtils.isNotEmpty(var4));
}
}
@GetMapping(value = "/{pagename}")
public String page(@PathVariable String pagename, HttpServletRequest request) {
ContentVo contents = contentService.getContents(pagename);
if (null == contents) {
return this.render_404();
}
if (contents.getAllowComment()) {
String cp = request.getParameter("cp");
if (StringUtils.isBlank(cp)) {
cp = "1";
}
PageInfo<CommentBo> commentsPaginator = commentService.getComments(contents.getCid(), Integer.parseInt(cp), 6);
request.setAttribute("comments", commentsPaginator);
}
request.setAttribute("article", contents);
updateArticleHit(contents.getCid(), contents.getHits());
return this.render("page");
}
private String getRemoteIp(@NotNull final RequestContext context) {
final HttpServletRequest request = WebUtils.getHttpServletRequest(context);
String userAddress = request.getRemoteAddr();
logger.debug("Remote Address = {}", userAddress);
if (StringUtils.isNotBlank(this.alternativeRemoteHostAttribute)) {
userAddress = request.getHeader(this.alternativeRemoteHostAttribute);
logger.debug("Header Attribute [{}] = [{}]", this.alternativeRemoteHostAttribute, userAddress);
if (StringUtils.isBlank(userAddress)) {
userAddress = request.getRemoteAddr();
logger.warn("No value could be retrieved from the header [{}]. Falling back to [{}].",
this.alternativeRemoteHostAttribute, userAddress);
}
}
return userAddress;
}
public static Map<String, Map<String, Object>> getUpdateYamlScript(final ScriptClass scriptClass) {
final Updater updater = scriptClass.getUpdater();
Map<String, Object> properties = new LinkedHashMap<>();
addNotEmptyProperty(JCR_PRIMARY_TYPE, HIPPOSYS_UPDATERINFO, properties);
addNotEmptyProperty(HIPPOSYS_BATCHSIZE, updater.batchSize(), properties);
addNotEmptyProperty(HIPPOSYS_DESCRIPTION, updater.description(), properties);
addNotEmptyProperty(HIPPOSYS_DRYRUN, updater.dryRun(), properties);
addNotEmptyProperty(HIPPOSYS_PARAMETERS, updater.parameters(), properties);
if (StringUtils.isBlank(updater.xpath())) {
addNotEmptyProperty(HIPPOSYS_PATH, updater.path(), properties);
}
addNotEmptyProperty(HIPPOSYS_QUERY, updater.xpath(), properties);
addNotEmptyProperty(HIPPOSYS_SCRIPT, removeEmptyIndents(scriptClass.getContent()), properties);
addNotEmptyProperty(HIPPOSYS_THROTTLE, updater.throttle(), properties);
return Collections.singletonMap(getBootstrapPath(scriptClass), properties);
}
public int update(long id, ReviewStatus reviewStatus, String reviewer, long zkMtime) throws ShepherException {
if (StringUtils.isBlank(reviewer) || reviewStatus == null) {
throw ShepherException.createIllegalParameterException();
}
try {
return snapshotMapper.update(id, reviewStatus.getValue(), reviewer, new Date(zkMtime));
} catch (Exception e) {
throw ShepherException.createDBUpdateErrorException();
}
}
public void processCommentsForPageUpdate(final JSONObject page) throws Exception {
final String pageId = page.getString(Keys.OBJECT_ID);
final List<JSONObject> comments = commentDao.getComments(pageId, 1, Integer.MAX_VALUE);
for (final JSONObject comment : comments) {
final String commentId = comment.getString(Keys.OBJECT_ID);
final String sharpURL = Comments.getCommentSharpURLForPage(page, commentId);
comment.put(Comment.COMMENT_SHARP_URL, sharpURL);
if (StringUtils.isBlank(comment.optString(Comment.COMMENT_ORIGINAL_COMMENT_ID))) {
comment.put(Comment.COMMENT_ORIGINAL_COMMENT_ID, "");
}
if (StringUtils.isBlank(comment.optString(Comment.COMMENT_ORIGINAL_COMMENT_NAME))) {
comment.put(Comment.COMMENT_ORIGINAL_COMMENT_NAME, "");
}
commentDao.update(commentId, comment);
}
}