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

📄 musicfilemgr.java

📁 cwbbs 云网论坛源码
💻 JAVA
字号:
package com.redmoon.forum.music;import cn.js.fan.util.ErrMsgException;import javax.servlet.http.HttpServletRequest;import java.io.IOException;import cn.js.fan.web.Global;import javax.servlet.ServletContext;import com.redmoon.kit.util.FileUpload;import com.cloudwebsoft.framework.util.LogUtil;import java.util.Vector;import java.util.Iterator;import com.redmoon.kit.util.FileInfo;import com.cloudwebsoft.framework.db.JdbcTemplate;import cn.js.fan.util.ResKeyException;import cn.js.fan.util.StrUtil;import java.io.File;import java.util.Calendar;import cn.js.fan.util.ParamUtil;import com.redmoon.forum.Privilege;import com.redmoon.forum.Config;import com.redmoon.forum.plugin.score.Gold;public class MusicFileMgr {    public FileUpload fileUpload;    public MusicFileMgr() {    }    public MusicFileDb getMusicFileDb(long id) {        MusicFileDb isfd = new MusicFileDb();        return isfd.getMusicFileDb(id);    }    public void create() {    }    public FileUpload doUpload(ServletContext application,                                           HttpServletRequest request) throws            ErrMsgException {        fileUpload = new FileUpload();        fileUpload.setMaxFileSize(Global.FileSize);         String[] ext = new String[]{"wmv", "wav", "mp3"};        fileUpload.setValidExtname(ext);        int ret = 0;        try {            ret = fileUpload.doUpload(application, request);            if (ret == -3) {                throw new ErrMsgException(fileUpload.getErrMessage(request));            }            if (ret == -4) {                throw new ErrMsgException(fileUpload.getErrMessage(request));            }        } catch (IOException e) {            LogUtil.getLog(getClass()).error("doUpload:" + e.getMessage());        }        return fileUpload;    }    public boolean create(ServletContext application,                          HttpServletRequest request) throws ErrMsgException {        doUpload(application, request);        String dirCode = fileUpload.getFieldValue("dirCode");        String name = StrUtil.getNullStr(fileUpload.getFieldValue("name")).trim();        if (name.equals("")) {            throw new ErrMsgException("文件名称不能为空!");        }        String visualPath = "";        if (fileUpload.getRet() == FileUpload.RET_SUCCESS) {            boolean isLink = StrUtil.getNullStr(fileUpload.getFieldValue(                    "isLink")).equals("true");            if (isLink) {                String url = StrUtil.getNullStr(fileUpload.getFieldValue("url")).                         trim();                if (url.equals("")) {                    throw new ErrMsgException("当文件为链接型时,链接地址不能为空!");                }                try {                    MusicFileDb isfd = new MusicFileDb();                    isfd.setDirCode(dirCode);                    isfd.setName(name);                    isfd.setLink(isLink);                    isfd.setUrl(url);                    isfd.create(new JdbcTemplate());                } catch (ResKeyException e) {                    throw new ErrMsgException(e.getMessage(request));                }            }            else {                Calendar cal = Calendar.getInstance();                String year = "" + (cal.get(cal.YEAR));                String month = "" + (cal.get(cal.MONTH) + 1);                visualPath = year + "/" + month;                String tempAttachFilePath = Global.getRealPath() + "upfile/" +                                            MusicFileDb.baseMusicPath + "/" +                                            visualPath +                                            "/";                fileUpload.setSavePath(tempAttachFilePath);                 File f = new File(tempAttachFilePath);                if (!f.isDirectory()) {                    f.mkdirs();                }                fileUpload.writeFile(true);                Vector v = fileUpload.getFiles();                if (v.size()==0)                    throw new ErrMsgException("当不为链接型时,需上传文件!");                Iterator ir = v.iterator();                while (ir.hasNext()) {                    FileInfo fi = (FileInfo) ir.next();                    fi.getSize();                    try {                        MusicFileDb isfd = new MusicFileDb();                        isfd.setDirCode(dirCode);                        isfd.setExt(fi.getExt());                        isfd.setSize(fi.getSize());                        isfd.setDiskName(fi.getDiskName());                        isfd.setVisualPath(visualPath);                        isfd.setName(name);                        isfd.setLink(isLink);                        isfd.create(new JdbcTemplate());                    } catch (ResKeyException e) {                        throw new ErrMsgException(e.getMessage(request));                    }                }            }            return true;        }        else            return false;    }        public boolean del(HttpServletRequest request, long id) throws            ErrMsgException {        MusicFileDb mfd = new MusicFileDb();        mfd = getMusicFileDb(id);        if (mfd == null || !mfd.isLoaded()) {            throw new ErrMsgException("文件未找到!");        }        boolean re = false;        re = mfd.del(new JdbcTemplate());        return re;    }    public boolean delBatch(HttpServletRequest request) throws ErrMsgException {        String strids = ParamUtil.get(request, "ids");        String[] ids = StrUtil.split(strids, ",");        if (ids==null)            return false;        int len = ids.length;        boolean re = false;        for (int i=0; i<len; i++) {            re = del(request, Long.parseLong(ids[i]));        }        return re;    }    public boolean rename(HttpServletRequest request) throws            ErrMsgException {        long id = ParamUtil.getLong(request, "id");        String name = ParamUtil.get(request, "name");        if (name.equals(""))            throw new ErrMsgException("名称不能为空!");        String url = ParamUtil.get(request, "url");        if (url.equals(""))            throw new ErrMsgException("链接不能为空!");        MusicFileDb doc = new MusicFileDb();        doc = getMusicFileDb(id);        if (doc == null || !doc.isLoaded()) {            throw new ErrMsgException("文件未找到!");        }        boolean re = false;        doc.setName(name);        doc.setUrl(url);        re = doc.save(new JdbcTemplate());        return re;    }}

⌨️ 快捷键说明

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