📄 bbscsutil.java
字号:
public static String getUserWebFilePath(String userID) {
StringBuffer sb = new StringBuffer();
int num = Math.abs(userID.hashCode());
sb.append(Constant.ROOTPATH);
sb.append("user/");
sb.append(num % 100);
sb.append("/");
sb.append(userID);
sb.append("/");
File ft = new File(sb.toString());
if (!ft.exists()) {
ft.mkdirs();
}
return sb.toString();
}
public static String getUserWebPath(String userID) {
StringBuffer sb = new StringBuffer();
int num = Math.abs(userID.hashCode());
sb.append("user/");
sb.append(num % 100);
sb.append("/");
sb.append(userID);
sb.append("/");
return sb.toString();
}
public static String getUpFilePath(long bid, long adate) {
StringBuffer sb = new StringBuffer();
sb.append(Constant.ROOTPATH);
sb.append(getUpFileWebPath(bid, adate));
File ft = new File(sb.toString());
if (!ft.exists()) {
ft.mkdirs();
}
return sb.toString();
}
public static String getUpFileWebPath(long bid, long adate) {
StringBuffer sb = new StringBuffer();
sb.append("upload/");
sb.append( (bid % 20));
sb.append("/");
sb.append(bid);
sb.append("/");
sb.append(Util.formatDate4(new Date(adate)));
sb.append("/");
return sb.toString();
}
public static String getIncludePath() {
StringBuffer sb = new StringBuffer();
sb.append(Constant.ROOTPATH);
sb.append("include/");
File ft = new File(sb.toString());
if (!ft.exists()) {
ft.mkdirs();
}
return sb.toString();
}
public static String getFileExt(String fileName) {
if (fileName != null) {
String fileExt = "";
fileName = fileName.toLowerCase();
int index = fileName.lastIndexOf(".");
fileExt = fileName.substring(index, fileName.length());
return fileExt;
}
else {
return "";
}
}
public static void saveUpFile(String path, InputStream stream) throws FileNotFoundException,
IOException {
OutputStream bos = new FileOutputStream(path);
IOUtils.copy(stream, bos);
}
public static boolean isAllowPicFile(String fileName) {
String[] filExts = {"jpg", "jpeg", "gif"};
return FilenameUtils.isExtension(fileName, filExts);
}
public static boolean isPicFile(String fileName) {
String[] filExts = {"jpg", "jpeg", "gif", "png", "bmp"};
return FilenameUtils.isExtension(fileName, filExts);
}
public static boolean isFlashFile(String fileName) {
return FilenameUtils.isExtension(fileName, "swf");
}
public static long getOnlineInTime() {
return System.currentTimeMillis() - 180000;
}
public static boolean isTodayTime(long atime) {
Calendar cld = Calendar.getInstance();
//cld.setTime(new Date());
int year = cld.get(Calendar.YEAR);
int month = cld.get(Calendar.MONTH);
int day = cld.get(Calendar.DAY_OF_MONTH);
Calendar todaycld = Calendar.getInstance();
todaycld.set(year, month, day, 0, 0, 0);
if (atime >= todaycld.getTime().getTime()) {
return true;
}
else {
return false;
}
}
public static boolean isLastdayTime(long atime) {
Calendar cld = Calendar.getInstance();
//cld.setTime(new Date());
cld.add(Calendar.DAY_OF_MONTH, -1);
int year = cld.get(Calendar.YEAR);
int month = cld.get(Calendar.MONTH);
int day = cld.get(Calendar.DAY_OF_MONTH);
Calendar lastdaycld = Calendar.getInstance();
lastdaycld.set(year, month, day, 0, 0, 0);
if (atime >= lastdaycld.getTime().getTime()) {
return true;
}
else {
return false;
}
}
public static boolean isTodayTime(long atime, String timeZone) {
return isTodayTime(new Date(atime), timeZone);
}
public static boolean isYesterdayTime(long atime, String timeZone) {
return isYesterdayTime(new Date(atime), timeZone);
}
public static boolean isTodayTime(Date atime, String timeZone) {
Calendar cld = Calendar.getInstance(TimeZone.getTimeZone(timeZone));
cld.set(Calendar.MILLISECOND, 0);
int nowyear = cld.get(Calendar.YEAR);
int nowmonth = cld.get(Calendar.MONTH);
int nowday = cld.get(Calendar.DAY_OF_MONTH);
Calendar c = Calendar.getInstance(TimeZone.getTimeZone(timeZone));
c.setTime(atime);
c.set(Calendar.MILLISECOND, 0);
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
//int second = c.get(Calendar.SECOND);
if (year == nowyear && month == nowmonth && day == nowday) {
return true;
}
else {
return false;
}
}
public static boolean isYesterdayTime(Date atime, String timeZone) {
Calendar cld = Calendar.getInstance(TimeZone.getTimeZone(timeZone));
cld.set(Calendar.MILLISECOND, 0);
cld.add(Calendar.DAY_OF_MONTH, -1);
int yyear = cld.get(Calendar.YEAR);
int ymonth = cld.get(Calendar.MONTH);
int yday = cld.get(Calendar.DAY_OF_MONTH);
Calendar c = Calendar.getInstance(TimeZone.getTimeZone(timeZone));
c.setTime(atime);
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
//int second = c.get(Calendar.SECOND);
if (year == yyear && month == ymonth && day == yday) {
return true;
}
else {
return false;
}
}
public static String formatDateTime(Date date, String format) {
SimpleDateFormat outFormat = new SimpleDateFormat(format);
return outFormat.format(date);
}
public static String formatDateTime(Date date, String format, String timeZone) {
//Calendar c = Calendar.getInstance(TimeZone.getTimeZone(timeZone));
//c.setTime(date);
//c.set(Calendar.MILLISECOND, 0);
SimpleDateFormat outFormat = new SimpleDateFormat(format);
Calendar c = Calendar.getInstance();
c.setTimeInMillis(date.getTime());
c.set(Calendar.MILLISECOND, 0);
c.setTimeZone(TimeZone.getTimeZone(timeZone));
return outFormat.format(c.getTime());
}
public static String getFileTypeIcon(String fileExt) {
String fileTypeIcon = (String) Constant.ICON_MAP.get(fileExt);
if (fileTypeIcon == null) {
fileTypeIcon = "default.icon.gif";
}
return fileTypeIcon;
}
public static String getSpeShortString(String s, int len, String fillstr) {
int ilen = Math.max(0, len - fillstr.length());
char ch = ' ';
int reallen = 0;
for (int i = 0; i < s.length(); i++) {
ch = s.charAt(i);
if ( ( (int) ch > 32) && ( (int) ch < 128)) {
reallen++;
}
else {
reallen += 2;
}
}
if (reallen <= len) {
return s;
}
StringBuffer buf = new StringBuffer();
reallen = 0;
for (int i = 0; i < s.length(); i++) {
ch = s.charAt(i);
buf.append(ch);
if ( ( (int) ch > 32) && ( (int) ch < 128)) {
reallen++;
}
else {
reallen += 2;
}
if (reallen >= ilen) {
return buf.append(fillstr).toString();
}
}
return buf.toString();
}
public static String getTitleColorOptions(int haveTitleColorp, Locale locale) {
StringBuffer sb = new StringBuffer();
sb.append("<option value=\"0\">");
sb.append(Constant.MESSAGE.getMessage(locale, "bbscs.default"));
//sb.append("默认");
sb.append("</option>");
if (haveTitleColorp == 1) {
for (int i = 1; i < Constant.TITLECOLOR.length; i++) {
sb.append("<option value=\"");
sb.append(i);
sb.append("\" class=\"titleColor");
sb.append(i);
sb.append("\">");
sb.append(Constant.TITLECOLOR[i]);
sb.append("</option>");
}
}
return sb.toString();
}
public static Vector getPostPriceValues(String[] prices) {
Vector v = new Vector();
for (int i = 0; i < prices.length; i++) {
v.add(new LabelValueBean(prices[i], prices[i]));
}
return v;
}
public static String getUBB2HTML(String txt) {
if (txt != null) {
AutoFilter af = new AutoFilter(txt);
txt = af.getFilteredStr();
}
return txt;
}
public static List array2List(String[] ids) {
List l = new ArrayList();
if (ids != null) {
for (int i = 0; i < ids.length; i++) {
l.add(ids[i]);
}
}
return l;
}
public static Locale getLocale(String localeStr) {
String[] locale_strs = localeStr.split("_");
if (locale_strs != null && locale_strs.length == 2) {
return new Locale(locale_strs[0], locale_strs[1]);
}
else {
return new Locale("zh", "CN");
}
}
public static Vector getHourValues() {
Vector v = new Vector();
for (int i = 0; i < 24; i++) {
v.add(new LabelValueBean(String.valueOf(i), String.valueOf(i)));
}
return v;
}
public static void main(String[] args) {
//System.out.print( (90l * 24l * 3600000l));
System.out.println(replaceSmile("{8}{70}"));
//System.out.println(replaceHtml("ddddaaaa>dssdsd<eewry"));
//System.out.println(getActionMappingURLWithoutPrefix("login?action=index&userName=laoer"));
//Locale locale = new Locale("zh", "CN");
//String locale_str = locale.toString();
//System.out.println(locale_str);
//String[] locale_strs = locale_str.split("_");
//System.out.println(locale_strs.length + " " + locale_strs[0] + " " + locale_strs[1]);
//System.out.println(filterScript("<Script>aaa</Script>"));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -