videodb.java

来自「cwbbs 云网论坛源码」· Java 代码 · 共 119 行

JAVA
119
字号
package com.redmoon.blog;import com.cloudwebsoft.framework.base.QObjectDb;import com.redmoon.kit.util.FileInfo;import java.util.Calendar;import com.redmoon.forum.util.ForumFileUpload;import java.util.Vector;import cn.js.fan.web.Global;import javax.servlet.http.HttpServletRequest;import java.io.File;import com.redmoon.forum.Config;import com.redmoon.forum.util.ForumFileUtil;import com.cloudwebsoft.framework.util.LogUtil;import com.cloudwebsoft.framework.db.JdbcTemplate;import cn.js.fan.util.ResKeyException;import cn.js.fan.util.ParamChecker;import cn.js.fan.util.ErrMsgException;import com.redmoon.forum.person.UserDb;import com.redmoon.forum.Privilege;import cn.js.fan.web.SkinUtil;public class VideoDb extends QObjectDb {    public static final String videoBasePath = "blog/video";    public VideoDb() {    }    public boolean create(JdbcTemplate jt, ParamChecker paramChecker) throws            ResKeyException, ErrMsgException {        boolean re = super.create(jt, paramChecker);        if (re) {            refreshList("" + getLong("blog_id"));        }        return re;    }    public String getVideoUrl(HttpServletRequest request) {        com.redmoon.forum.Config cfg = com.redmoon.forum.Config.getInstance();        String attachmentBasePath = request.getContextPath() + "/upfile/" +                                    videoBasePath + "/";        boolean isFtpUsed = cfg.getBooleanProperty("forum.ftpUsed");        if (getInt("is_remote")==1 && isFtpUsed) {            attachmentBasePath = cfg.getRemoteBaseUrl();            attachmentBasePath += videoBasePath + "/";        }        return attachmentBasePath + getString("video");    }    public String writeVideo(HttpServletRequest request, ForumFileUpload fu) throws ErrMsgException {                Privilege privilege = new Privilege();        if (!privilege.canUploadAttachment(request))            throw new ErrMsgException(SkinUtil.LoadString(request, "res.forum.MsgDb", "err_space_full"));        if (fu.getRet() == fu.RET_SUCCESS) {            Vector v = fu.getFiles();            FileInfo fi = null;            if (v.size() > 0)                fi = (FileInfo) v.get(0);            String vpath = "";            if (fi != null) {                                Calendar cal = Calendar.getInstance();                String year = "" + (cal.get(cal.YEAR));                String month = "" + (cal.get(cal.MONTH) + 1);                vpath = videoBasePath + "/" + year + "/" + month + "/";                String filepath = Global.getRealPath() + "upfile/" + vpath;                                fu.setSavePath(filepath);                                fu.setRemoteBasePath(vpath);                                fu.writeFile(true);                                UserDb ud = new UserDb();                ud = ud.getUser(privilege.getUser(request));                ud.setDiskSpaceUsed(ud.getDiskSpaceUsed() + fi.getSize());                ud.save();                return year + "/" + month + "/" + fi.getDiskName();            }        }        return "";    }    public boolean del(JdbcTemplate jt) throws ResKeyException {        boolean re = false;        re = super.del(jt);        if (re) {            delVideo();            refreshList("" + getLong("blog_id"));        }        return re;    }    public void delVideo() {        String video = getString("video");        if (video != null && !video.equals("")) {            Config cfg = Config.getInstance();            boolean isFtpUsed = cfg.getBooleanProperty("forum.ftpUsed");            if (isFtpUsed) {                if (getInt("is_remote")==1) {                    ForumFileUtil ffu = new ForumFileUtil();                    ffu.delFtpFile(videoBasePath + "/" + video);                }            } else {                try {                    File file = new File(Global.realPath + "upfile/" + videoBasePath + "/" + video);                    file.delete();                } catch (Exception e) {                    LogUtil.getLog(getClass()).error("delVideo:" + e.getMessage());                }            }        }    }}

⌨️ 快捷键说明

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