⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 util.java

📁 BBS-CS(天乙社区) v5.2.2源码版
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        System.out.println("Error: Method: dbconn.gb2iso :" + e.getMessage());
      }
      try {
        str = new String(tmpbyte, "ISO8859_1");
      }
      catch (Exception e) {
        System.out.println("Error: Method: dbconn.gb2iso :" + e.getMessage());
      }
    }
    return str;
  }

  public static String fotmatDate1(Date myDate) {
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
    String strDate = formatter.format(myDate);
    return strDate;
  }

  public static String fotmatDate2(Date myDate) {
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日");
    String strDate = formatter.format(myDate);
    return strDate;
  }

  public static String fotmatDate3(Date myDate) {
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String strDate = formatter.format(myDate);
    return strDate;
  }

  public static String fotmatDate4(Date myDate) {
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
    String strDate = formatter.format(myDate);
    return strDate;
  }

  public static String fotmatDate5(Date myDate) {
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd");
    String strDate = formatter.format(myDate);
    return strDate;
  }

  public static String fotmatDate6(Date myDate) {
    SimpleDateFormat formatter = new SimpleDateFormat("MM-dd HH:mm");
    String strDate = formatter.format(myDate);
    return strDate;
  }

  public static String fotmatDate7(Date myDate) {
    SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
    String strDate = formatter.format(myDate);
    return strDate;
  }

  public static String getNoteType(int mtype) {
    String sMtype = "";
    switch (mtype) {
      case 0:
        sMtype = "note.nstyle0";
        break;
      case 1:
        sMtype = "note.nstyle1";
        break;
      case 2:
        sMtype = "note.nstyle2";
        break;
      case 3:
        sMtype = "note.nstyle3";
        break;
      default:
        sMtype = "note.nstyle0";
        break;
    }
    return sMtype;
  }

  public static String local2iso(String str) {
    if (str != null) {
      byte[] tmpbyte = null;
      try {
        tmpbyte = str.getBytes(Sys.SYSINFO.CHARSET);
      }
      catch (UnsupportedEncodingException e) {
        System.out.println("Error: Method: local2iso :" + e.getMessage());
      }
      try {
        str = new String(tmpbyte, "ISO8859_1");
      }
      catch (UnsupportedEncodingException e) {
        System.out.println("Error: Method: local2iso :" + e.getMessage());
      }
    }
    return str;
  }

  public static String iso2local(String str) {
    if (str != null) {
      byte[] tmpbyte = null;
      try {
        tmpbyte = str.getBytes("ISO8859_1");
      }
      catch (UnsupportedEncodingException e) {
        System.out.println("Error: Method: iso2local :" + e.getMessage());
      }
      try {
        str = new String(tmpbyte, Sys.SYSINFO.CHARSET);
      }
      catch (UnsupportedEncodingException e) {
        System.out.println("Error: Method: iso2local :" + e.getMessage());
      }
    }
    return str;
  }

  public static long getLongTime() {
    Date aDate = new Date();
    long atime = aDate.getTime();
    return atime;
  }

  public static long getaLongTime() {
    return System.currentTimeMillis();
  }

  public static int getTableID(String username) {
    int num = Math.abs(username.hashCode());
    int tableID = (int) (num % 10);
    return tableID;
  }

  public static int getForumID(String forumID) {
    int num = Math.abs(forumID.hashCode());
    int iForumID = (int) (num % 20);
    return iForumID;
  }

  public static String getForumPath(String forumID, long adate) {
    int num = Math.abs(forumID.hashCode());
    String filePath = "";
    filePath = Sys.SYSINFO.FILEPATH + "postfile/" + (num % 20) + "/" + forumID +
        "/" + fotmatDate7(new Date(adate)) + "/";
    File ft = new File(filePath);
    if (!ft.exists()) {
      ft.mkdirs();
    }
    return filePath;
  }

  public static String getImgPath(String forumID, long adate) {
    int num = Math.abs(forumID.hashCode());
    String filePath = "";
    filePath = Sys.SYSINFO.FILEPATH + "imgup/" + (num % 20) + "/" + forumID +
        "/" + fotmatDate7(new Date(adate)) + "/";
    File ft = new File(filePath);
    if (!ft.exists()) {
      ft.mkdirs();
    }
    return filePath;
  }

  public static String getUserImgPath(String username, long userID) {
    int num = Math.abs(username.hashCode());
    String filePath = "";
    filePath = Sys.SYSINFO.FILEPATH + "upload/" + (num % 100) + "/" + userID +
        "/";
    File ft = new File(filePath);
    if (!ft.exists()) {
      ft.mkdirs();
    }
    return filePath;
  }

  public static String getForumPathDir(String forumID, long adate) {
    int num = Math.abs(forumID.hashCode());
    String filePath = "";
    filePath = "postfile/" + (num % 20) + "/" + forumID + "/" +
        fotmatDate7(new Date(adate)) + "/";
    return filePath;
  }

  public static String getImgPathDir(String forumID, long adate) {
    int num = Math.abs(forumID.hashCode());
    String filePath = "";
    filePath = "imgup/" + (num % 20) + "/" + forumID + "/" +
        fotmatDate7(new Date(adate)) + "/";
    return filePath;
  }

  public static String getUserImgPathDir(String username, long userID) {
    int num = Math.abs(username.hashCode());
    String filePath = "";
    filePath = "upload/" + (num % 100) + "/" + userID + "/";
    File ft = new File(filePath);
    if (!ft.exists()) {
      ft.mkdirs();
    }
    return filePath;
  }

  public static String getImgSrcPath(String forumID, long adate,
                                     String fileName) {
    String filePath = getImgPathDir(forumID, adate) + fileName;
    //if (Sys.SYSINFO.SINGLESERVER.equals("no")) {
    filePath = Sys.getURL() + "showimg?picdir=" + filePath;
    //}
    return filePath;
  }

  public static String getUserImgSrcPath(String userName, long userID,
                                         String fileName) {
    String filePath = getUserImgPathDir(userName, userID) + fileName;
    //if (Sys.SYSINFO.SINGLESERVER.equals("no")) {
    filePath = Sys.getURL() + "showimg?picdir=" + filePath;
    //}
    return filePath;
  }

  public static String getImgSrc(String picPath) {
    return Sys.getURL() + "showimg?picdir=" + picPath;
  }

  public static String getPubFilePath() {
    String filePath = "";
    filePath = Sys.SYSINFO.FILEPATH + "include/";
    File ft = new File(filePath);
    if (!ft.exists()) {
      ft.mkdirs();
    }
    return filePath;
  }

  public static String getPubFilePathDir() {
    String filePath = "";
    filePath = "include/";
    return filePath;
  }

  public static String getIndexPath() {
    String filePath = "";
    filePath = Sys.SYSINFO.FILEPATH + "index/";
    File ft = new File(filePath);
    if (!ft.exists()) {
      ft.mkdirs();
    }
    return filePath;
  }

  public static String getPostFilePath() {
    String filePath = "";
    filePath = Sys.SYSINFO.FILEPATH + "postfile";
    File ft = new File(filePath);
    if (!ft.exists()) {
      ft.mkdirs();
    }
    return filePath;
  }

  public static boolean isAllowFile(String flag, String fileName) {
    boolean isAllow = false;
    if (flag.equals("pic")) {
      fileName = fileName.toLowerCase(Sys.getLocale());
      if (fileName.endsWith(".jpg") || fileName.endsWith(".gif")) {
        isAllow = true;
      }
    }
    return isAllow;
  }

  public static String getFileExt(String fileName) {
    String fileExt = "";
    fileName = fileName.toLowerCase(Sys.getLocale());
    int index = fileName.lastIndexOf(".");
    fileExt = fileName.substring(index, fileName.length());
    return fileExt;
  }

  public static String getPostPageBreakStr(String aJspFileName, int totalNum,
                                           int perNum) {
    String str = "";
    if (totalNum > perNum) {
      str = "[<img src='images/multipage.gif' align='absmiddle'>";
      int totalPages = (int) Math.ceil( (totalNum + perNum - 1) / perNum);
      for (int i = 1; i <= totalPages; i++) {
        str += " <a href='" + aJspFileName + i + "'><b>" + i + "</b></a>";
      }
      str += "]";
    }
    return str;
  }

  public static String getPublicFileInfo(String fileName, String sid) {
    String publicStr = "";
    try {
      File fPostFile = new File(getPubFilePath() + fileName);
      if (fPostFile.exists()) {
        FileInputStream bw = new FileInputStream(fPostFile);
        int len = bw.available();
        byte[] str = new byte[len];
        if (bw.read(str) == -1) {
          publicStr = "";
        }
        else {
          //strDetail = new String(str,"UTF8");
          //publicStr = new String(str);
          publicStr = new String(str, "UTF8");
        }
        bw.close();
        bw = null;
      }
      fPostFile = null;
      publicStr = replace(publicStr, "###", sid);
    }
    catch (IOException e) {
    }
    return publicStr;
  }

  public static long getDateLongTime(int year, int month, int day) {
    Calendar myCalendar = Calendar.getInstance();
    myCalendar.set(year, month - 1, day);
    return myCalendar.getTime().getTime();
  }

  public static String[] getBadWordStrs() {
    String[] badWords = Sys.WEBSITE[2].split(",");
    return badWords;
  }

  public static int checkWords(String s) {
    for (int i = 0; i < getBadWordStrs().length; i++) {
      if (s.indexOf(getBadWordStrs()[i]) != -1) {
        return i;
      }
    }
    return -1;
  }

  public static String getCSSPath(long cssID) {
    String filePath = "";
    filePath = Sys.SYSINFO.WEBPATH + "css/" + cssID + "/";
    File ft = new File(filePath);
    if (!ft.exists()) {
      ft.mkdirs();
    }
    return filePath;
  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -