BlogUtil.java
资源名称:Myblog.rar [点击查看]
上传用户:wlfwy2004
上传日期:2016-12-12
资源大小:33978k
文件大小:2k
源码类别:
Jsp/Servlet
开发平台:
Java
- package com.opensource.blog.comm;
- import java.io.*;
- public class BlogUtil {
- public BlogUtil() {
- }
- public static int getStringLength(String txt) {
- if (txt != null) {
- try {
- return txt.getBytes(Constant.CHARSET).length;
- }
- catch (UnsupportedEncodingException ex) {
- return 0;
- }
- }
- else {
- return 0;
- }
- }
- public static String getUpWebPath(long userID) {
- return "/UserFiles/" + (userID % 20) + "/" + userID + "/";
- }
- public static String getBlogFileWebPath(long id) {
- String filePath = "";
- filePath = "user/" + (id % 20) + "/" + id + "/";
- return filePath;
- }
- public static String getBlogFilePath(long id) {
- String filePath = Constant.ROOTPATH + getBlogFileWebPath(id);
- File ft = new File(filePath);
- if (!ft.exists()) {
- ft.mkdirs();
- }
- return filePath;
- }
- public static String getResultUrl(String msg, String tourl) {
- if (tourl == null || tourl.length() == 0 ||
- tourl.equals(Constant.RECLOSEWIN)) {
- try {
- tourl = "tourl = " +
- java.net.URLEncoder.encode("javascript:window.close();", "GBK");
- }
- catch (Exception e) {
- }
- }
- else {
- try {
- tourl = "tourl=" + java.net.URLEncoder.encode(tourl, "GBK");
- }
- catch (Exception e) {
- }
- }
- return "/result.jsp?" + "msg=" + msg + "&" + tourl;
- }
- public static int[] getLogoSize(String logosize) {
- int[] logosizes = {80, 31};
- if (logosize != null && logosize.length() > 0) {
- String[] sizes = logosize.split("\*");
- if (sizes.length == 2) {
- try {
- logosizes[0] = Integer.parseInt(sizes[0]);
- logosizes[1] = Integer.parseInt(sizes[1]);
- }
- catch (Exception e) {
- }
- }
- }
- return logosizes;
- }
- }