forked from UlricQin/TBlog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoreTool.java
More file actions
118 lines (99 loc) · 2.56 KB
/
Copy pathCoreTool.java
File metadata and controls
118 lines (99 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package my.toolbox;
import java.util.Collection;
import javax.servlet.http.HttpServletRequest;
import my.mvc.RequestContext;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.iperl.beans.User;
import org.iperl.service.UserService;
import org.jsoup.Jsoup;
import org.jsoup.safety.Whitelist;
public class CoreTool {
public static HttpServletRequest request(){
if(RequestContext.get() == null){
return null;
} else {
return RequestContext.get().request();
}
}
public static User user(){
if(RequestContext.get() == null || RequestContext.get().request() == null){
return null;
}
User user = UserService.GetLoginUser(RequestContext.get().request());
return user;
}
public static long page_count(long total_cnt, int page_size) {
if (total_cnt <= 0) {
return 0;
}
if (page_size <= 0) {
return 1;
}
return (total_cnt + page_size - 1) / page_size;
}
public static boolean obj_is_null(Object obj) {
return obj == null;
}
public static boolean obj_is_not_null(Object obj) {
if (obj instanceof String) {
return !StringUtils.isBlank((String) obj);
} else {
return obj != null;
}
}
public static String sub_str(String src, int size) {
if (StringUtils.isBlank(src)) {
return "";
}
src = Jsoup.clean(src, Whitelist.basic());
int len = src.length();
if (len > size) {
src = src.substring(0, size);
return Jsoup.clean(src, Whitelist.basicWithImages());
} else {
return src;
}
}
public static String sub_str_none(String src, int size) {
if (StringUtils.isBlank(src)) {
return "";
}
src = Jsoup.clean(src, Whitelist.none());
int len = src.length();
if (len > size) {
return src.substring(0, size);
} else {
return src;
}
}
public static boolean is_empty(Collection coll){
return CollectionUtils.isEmpty(coll);
}
public static int str_len(String str){
if(StringUtils.isBlank(str)){
return 0;
}else {
return str.length();
}
}
public static boolean is_blank(String str){
return StringUtils.isBlank(str);
}
public static boolean is_not_blank(String str){
return StringUtils.isNotBlank(str);
}
public static String nl2br(String content) {
return StringUtils.replace(content, "\n", "<br />");
}
public static String nobr(String str){
return StringUtils.replace(str, "<br />", "");
}
public static String htmlSpecialChars(String str) {
str = str.replaceAll("&", "&");
str = str.replaceAll("<", "<");
str = str.replaceAll(">", ">");
str = str.replaceAll("\"", """);
return str;
}
}