📄 common.java
字号:
}else{
for (String obj : usermsgList) {
usermsg +=obj+" = 0 ";
}
}
}
Map<String,String> replaces=new TreeMap<String, String>();
replaces.put("digestposts", " 精华帖数 ");
replaces.put("posts", " 发帖数 ");
replaces.put("oltime", " 在线时间(小时) ");
replaces.put("pageviews", " 页面浏览量 ");
replaces.put("or", " 或者 ");
replaces.put("and", " 并且 ");
if(extcredits!=null&&extcredits.size()>0){
for (Integer i = 1; i <= 8; i++) {
Map<String,String> extcredit=extcredits.get(i);
if(extcredit!=null){
replaces.put("extcredits"+i, extcredit.get("title"));
}else{
replaces.put("extcredits"+i, "自定义积分"+i);
}
}
}
Set<String> dsessions=replaces.keySet();
for (String dsession : dsessions) {
formulamessage=formulamessage.replaceAll(dsession, replaces.get(dsession));
usermsg=usermsg.replaceAll(dsession, replaces.get(dsession));
}
Map<String,String> messages=new HashMap<String, String>();
messages.put("formulamessage", formulamessage);
messages.put("usermsg", usermsg);
return messages;
}
return null;
}
public static Object setValues(Object bean, String fieldName, String value) {
try {
Field field = bean.getClass().getDeclaredField(fieldName);
StringBuffer setMethod = new StringBuffer();
setMethod.append("set");
setMethod.append(fieldName.substring(0, 1).toUpperCase());
setMethod.append(fieldName.substring(1, fieldName.length()));
Method method = bean.getClass().getMethod(setMethod+"",field.getType());
method.invoke(bean, convert(value, field.getType()));
} catch (Exception e) {
e.printStackTrace();
}
return bean;
}
public static Object setValues(Object bean,HttpServletRequest request) {
try {
Field[] fields = bean.getClass().getDeclaredFields();
String paraName = "";
String paraValue = "";
String setMethod = "";
for (int i = 0; i < fields.length; i++) {
paraName = fields[i].getName();
paraValue = request.getParameter(paraName);
if (paraValue != null && !"".equals(paraValue)) {
setMethod = "set"+paraName.substring(0,1).toUpperCase()+paraName.substring(1,paraName.length());
Method method = bean.getClass().getMethod(setMethod,fields[i].getType());
method.invoke(bean, convert(paraValue,fields[i].getType()));
}
}
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (NoSuchMethodException e){
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
return bean;
}
@SuppressWarnings("unchecked")
public static Object convert(String source, Class type) {
String typeName = type.getName();
Object target = null;
if (typeName.equals("java.lang.String")) {
target = source;
} else if (typeName.equals("java.lang.Integer")) {
target = Integer.parseInt(source);
} else if (typeName.equals("java.lang.Long")) {
target = Long.parseLong(source);
} else if (typeName.equals("java.lang.Short")) {
target = new Short(source);
} else if (typeName.equals("java.lang.Byte")) {
target = new Byte(source);
}
return target;
}
public static Object getValues(Object bean, String fieldName) {
Object paraValue = null;
try {
Method method = bean.getClass().getMethod("get"+fieldName.substring(0, 1).toUpperCase()+fieldName.substring(1, fieldName.length()));
paraValue = method.invoke(bean);
} catch (Exception e) {
e.printStackTrace();
}
return paraValue;
}
private static Map<String, Object> getValues(Object bean, List<String> fields, Map<String, Object> fieldsMap) {
try {
Field[] beanFields = bean.getClass().getDeclaredFields();
if (fieldsMap == null) {
fieldsMap = new HashMap<String, Object>();
}
int fieldLength = fields.size();
String paraName =null;
String getMethod=null;
for (int i = 0; i < fieldLength; i++) {
paraName = fields.get(i);
Method method = null;
Object paraValue = null;
int beanFieldLength = beanFields.length;
for (int j = 0; j < beanFieldLength; j++) {
if (paraName.equals(beanFields[j].getName())) {
getMethod = "get"+paraName.substring(0, 1).toUpperCase()+paraName.substring(1, paraName.length());
method = bean.getClass().getMethod(getMethod);
paraValue = method.invoke(bean, new Object[0]);
break;
}
}
if (method != null) {
if (paraValue instanceof Short) {
paraValue = String.valueOf(paraValue);
}
fieldsMap.put(paraName, paraValue);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return fieldsMap;
}
public static int toDigit(String value) {
return toDigit(value,2147483647l,0l).intValue();
}
public static Long toDigit(String value, Long maxValue, Long minValue) {
long digit = minValue;
if (value != null) {
StringBuffer sbValue = new StringBuffer();
int length = value.length();
for (int i = 0; i < length; i++) {
if ((i == 0 && value.charAt(0) == '-') || Character.isDigit(value.charAt(i))) {
sbValue.append(value.charAt(i));
} else {
break;
}
}
if (sbValue.length()>0) {
if(sbValue.length()>20 && sbValue.charAt(0)=='-'){
digit = Long.MIN_VALUE;
}else if(sbValue.length()>19){
digit = Long.MAX_VALUE;
}else{
digit = Long.valueOf(sbValue.toString());;
}
}
}
if (digit < minValue) {
return minValue;
} else if (digit > maxValue) {
return maxValue;
} else {
return digit;
}
}
public static String getRandStr(int length, boolean isOnlyNum) {
String randStrs = "0123456789abcdefghigklmnopqrstuvtxyzABCDEFGHIGKLMNOPQRSTUVWXYZ";
int size=isOnlyNum?10:62;
StringBuffer sRand = new StringBuffer();
for (int i = 0; i < length; i++) {
sRand.append(randStrs.charAt(random.nextInt(size)));
}
randStrs=null;
return sRand.toString();
}
public static List<String> getStr(String content, String regex) {
List<String> strList = new ArrayList<String>();
try {
Perl5Matcher patternMatcher=new Perl5Matcher();
if (patternMatcher.contains(content, new Perl5Compiler().compile(regex))) {
MatchResult result = patternMatcher.getMatch();
for (int i = 0; i < result.groups(); i++) {
strList.add(result.group(i));
}
result=null;
}
} catch (MalformedPatternException e) {
e.printStackTrace();
}
return strList;
}
public static String checkpost(String subject, String message,Map<String, String> settings, Map<String, String> admingroups) {
if (Common.strlen(subject) > 80) {
return "对不起,您的标题超过 80 个字符,请返回修改标题长度。";
}
if (admingroups==null||Common.toDigit(admingroups.get("disablepostctrl"), 255L, 0L) == 0) {
int maxpostsize = Common.toDigit(settings.get("maxpostsize"), 1000000000L,0L).intValue();
int minpostsize = Common.toDigit(settings.get("minpostsize"), 1000000000L,0L).intValue();
if (maxpostsize > 0 && Common.strlen(message) > maxpostsize) {
return "对不起,您的帖子超过 " + maxpostsize + " 个字符的限制,请返回修改。";
} else if (minpostsize > 0&& (Common.strlen(message.replaceAll("\\[quote\\].+?\\[quote\\]", "")) < minpostsize)) {
return "对不起,您的帖子小于 " + minpostsize + " 个字符的限制,请返回修改。";
}
}
return null;
}
public static boolean isEmpty(Object obj) {
if (obj == null || obj.toString().equals("")) {
return true;
}
return false;
}
public static Date addTime(int field, int amount) {
Calendar calendar = getGMTCalendar();
calendar.add(field, amount);
return calendar.getTime();
}
public static boolean isNum(String value) {
boolean flag = true;
if (value != null) {
int length = value.length();
for (int i = 0; i < length; i++) {
if ((i == 0 && value.charAt(0) == '-')|| Character.isDigit(value.charAt(i))) {
} else {
flag = false;
break;
}
}
}
return flag;
}
public static int dataToInteger(String ymd) {
return dataToInteger(ymd,"yyyy-MM-dd HH:mm");
}
public static int dataToInteger(String ymd,String pattern) {
SimpleDateFormat format = new SimpleDateFormat(pattern);
try {
if(ymd.equals("")){
return 0;
}
Date ndate = format.parse(ymd);
if (format.format(ndate).equals(ymd)) {
return (int)(ndate.getTime()/1000);
}
else {
return 0;
}
} catch (Exception e) {
return -1;
}
}
public static Map<String,String> procThread(Map<String,String> thread,double ppp)
{
int replies = Integer.valueOf(thread.get("replies"));
int views = Integer.valueOf(thread.get("views"));
int special = Integer.valueOf(thread.get("special"));
if (replies>views) {
thread.put("views", thread.get("replies"));
}
double postsnum = special > 0 ? replies : replies + 1;
if (postsnum > ppp) {
StringBuffer pagelinks = new StringBuffer();
int topicpages = (int)Math.ceil(postsnum/ppp);
for (int i = 1; i<=6&&i <= topicpages; i++) {
pagelinks.append("<a href=\"viewthread.jsp?tid="+ thread.get("tid") + "&page=" + i + "\" target=\"_blank\">" + i + "</a> ");
}
if (topicpages > 6) {
pagelinks.append(" .. <a href=\"viewthread.jsp?tid="+ thread.get("tid") + "&page=" + topicpages + "\" target=\"_blank\">"+ topicpages + "</a> ");
}
thread.put("multipage", " " + pagelinks);
}
Integer highlight=Integer.valueOf(thread.get("highlight"));
if(highlight>0)
{
String[] colorarray={"", "red", "orange", "yellow", "green", "cyan", "blue", "purple", "gray"};
StringBuffer style=new StringBuffer();
style.append(" style=\"");
style.append(highlight>=40?"font-weight: bold;":"");
highlight=highlight%40;
style.append(highlight>=20?"font-style: italic;":"");
highlight=highlight%20;
style.append(highlight>=10?"text-decoration: underline;":"");
highlight=highlight%10;
style.append("color: "+colorarray[highlight]);
style.append("\"");
thread.put("highlight", style.toString());
colorarray=null;
style=null;
}
else{
thread.put("highlight", "");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -