documentmgr.java

来自「一个用java编写的功能强大的OA系统」· Java 代码 · 共 301 行

JAVA
301
字号
package cn.js.fan.module.cms;import java.io.*;import javax.servlet.*;import javax.servlet.http.*;import cn.js.fan.base.*;import cn.js.fan.module.cms.plugin.*;import cn.js.fan.module.cms.plugin.base.*;import cn.js.fan.util.*;import cn.js.fan.web.*;import org.apache.log4j.*;import com.redmoon.oa.pvg.Privilege;public class DocumentMgr {    Logger logger = Logger.getLogger(DocumentMgr.class.getName());    public DocumentMgr() {    }    public Document getDocument(int id) {        Document doc = new Document();        return doc.getDocument(id);    }    public Document getDocument(HttpServletRequest request, int id,                                IPrivilege privilege) throws            ErrMsgException {        boolean isValid = false;        Document doc = getDocument(id);        LeafPriv lp = new LeafPriv(doc.getDirCode());        if (lp.canUserSee(privilege.getUser(request))) {            return doc;        }        if (!isValid)            throw new ErrMsgException(Privilege.MSG_INVALID);        return getDocument(id);    }        public Document getDocumentByCode(HttpServletRequest request, String code,                                      IPrivilege privilege) throws            ErrMsgException {        boolean isValid = false;        LeafPriv lp = new LeafPriv(code);        if (lp.canUserSee(privilege.getUser(request)))            isValid = true;        if (!isValid)            throw new ErrMsgException(Privilege.MSG_INVALID);        Document doc = new Document();        int id = doc.getIDOrCreateByCode(code, privilege.getUser(request));        return getDocument(id);    }    public CMSMultiFileUploadBean doUpload(ServletContext application, HttpServletRequest request) throws            ErrMsgException {        CMSMultiFileUploadBean mfu = new CMSMultiFileUploadBean();        mfu.setMaxFileSize(Global.FileSize);                         int ret = 0;                try {            ret = mfu.doUpload(application, request);            if (ret == -3) {                throw new ErrMsgException(mfu.getErrMessage());            }            if (ret == -4) {                throw new ErrMsgException(mfu.getErrMessage());            }        } catch (IOException e) {            logger.error("doUpload:" + e.getMessage());            throw new ErrMsgException(e.getMessage());        }        return mfu;    }    public void passExamineBatch(HttpServletRequest request) throws            ErrMsgException {        String strids = ParamUtil.get(request, "ids");        String[] ids = StrUtil.split(strids, ",");        if (ids == null)            return;        int len = ids.length;        Document doc = null;        Privilege privilege = new Privilege();        for (int i = 0; i < len; i++) {            doc = getDocument(Integer.parseInt(ids[i]));            LeafPriv lp = new LeafPriv(doc.getDirCode());            if (lp.canUserExamine(privilege.getUser(request))) {                doc.UpdateExamine(Document.EXAMINE_PASS);            }            else {                throw new ErrMsgException(Privilege.MSG_INVALID);            }        }    }    public void delBatch(HttpServletRequest request) throws ErrMsgException {        Privilege privilege = new Privilege();        String strids = ParamUtil.get(request, "ids");        String[] ids = StrUtil.split(strids, ",");        if (ids==null)            return;        int len = ids.length;        for (int i=0; i<len; i++) {                                    del(request, Integer.parseInt(ids[i]), privilege);        }    }    public boolean Operate(ServletContext application,                           HttpServletRequest request, IPrivilege privilege) throws            ErrMsgException {        CMSMultiFileUploadBean mfu = doUpload(application, request);        String op = StrUtil.getNullStr(mfu.getFieldValue("op"));        String dir_code = StrUtil.getNullStr(mfu.getFieldValue("dir_code"));                boolean isValid = false;        if (op.equals("contribute")) {             isValid = true;        }        else {            LeafPriv lp = new LeafPriv();            lp.setDirCode(dir_code);            if (op.equals("edit")) {                if (lp.canUserModify(privilege.getUser(request)))                    isValid = true;            }            else {                if (lp.canUserAppend(privilege.getUser(request)))                    isValid = true;            }        }        if (!isValid)            throw new ErrMsgException(Privilege.MSG_INVALID);        Document doc = new Document();        if (op.equals("edit")) {            String idstr = StrUtil.getNullString(mfu.getFieldValue("id"));            if (!StrUtil.isNumeric(idstr))                throw new ErrMsgException("标识id=" + idstr + "非法,必须为数字!");            id = Integer.parseInt(idstr);            doc = doc.getDocument(id);            LeafPriv lp = new LeafPriv(doc.getDirCode());            if (!lp.canUserModify(privilege.getUser(request)))                throw new ErrMsgException(SkinUtil.LoadString(request, "pvg_invalid"));            boolean re = doc.Update(application, mfu);            if (re) {                PluginMgr pm = new PluginMgr();                PluginUnit pu = pm.getPluginUnitOfDir(dir_code);                if (pu != null) {                    IPluginDocumentAction ipda = pu.getDocumentAction();                    re = ipda.update(application, request, mfu, doc);                }            }            return re;        } else {            LeafPriv lp = new LeafPriv(dir_code);            if (!lp.canUserAppend(privilege.getUser(request)))                throw new ErrMsgException(SkinUtil.LoadString(request, "pvg_invalid"));            boolean re = doc.create(application, mfu, privilege.getUser(request));            id = doc.getID();            if (re) {                PluginMgr pm = new PluginMgr();                PluginUnit pu = pm.getPluginUnitOfDir(dir_code);                if (pu!=null) {                        IPluginDocumentAction ipda= pu.getDocumentAction();                        doc = doc.getDocument(doc.getID());                        re = ipda.create(application, request, mfu, doc);                }            }            return re;        }    }    public boolean del(HttpServletRequest request, int id, IPrivilege privilege) throws            ErrMsgException {        Document doc = new Document();        doc = getDocument(id);        if (doc==null || !doc.isLoaded()) {            throw new ErrMsgException("文件 " + id + " 不存在!");        }        LeafPriv lp = new LeafPriv(doc.getDirCode());        if (lp.canUserDel(privilege.getUser(request)))            return doc.del();        else            throw new ErrMsgException(Privilege.MSG_INVALID);    }    public boolean UpdateSummary(ServletContext application, HttpServletRequest request,                                 IPrivilege privilege) throws            ErrMsgException {            CMSMultiFileUploadBean mfu = doUpload(application, request);            int id = 0;            try {                id = Integer.parseInt(mfu.getFieldValue("id"));            }            catch (Exception e) {                throw new ErrMsgException("id 非法!");            }            Document doc = new Document();            doc = getDocument(id);            LeafPriv lp = new LeafPriv(doc.getDirCode());            if (!lp.canUserModify(privilege.getUser(request))) {                throw new ErrMsgException(privilege.MSG_INVALID);            }            return doc.UpdateSummary(application, mfu);    }    public boolean increaseHit(HttpServletRequest request, int id,                               IPrivilege privilege) throws            ErrMsgException {        Document doc = getDocument(id);        boolean re = doc.increaseHit();        return re;    }    public boolean UpdateIsHome(HttpServletRequest request, int id,                                IPrivilege privilege) throws            ErrMsgException {        Document doc = new Document();        String v = ParamUtil.get(request, "value");        doc.setID(id);        boolean re = doc.UpdateIsHome(v.equals("y") ? true : false);        return re;    }    public boolean vote(HttpServletRequest request, int id) throws            ErrMsgException {        int votesel = ParamUtil.getInt(request, "votesel");        Document doc = getDocument(id);        boolean re = doc.vote(id, votesel);        return re;    }    public boolean OperatePage(ServletContext application,                           HttpServletRequest request, IPrivilege privilege) throws            ErrMsgException {        CMSMultiFileUploadBean mfu = doUpload(application, request);        String op = StrUtil.getNullStr(mfu.getFieldValue("op"));        String dir_code = StrUtil.getNullStr(mfu.getFieldValue("dir_code"));        boolean isValid = false;        LeafPriv lp = new LeafPriv();        lp.setDirCode(dir_code);        if (op.equals("add")) {            if (lp.canUserAppend(privilege.getUser(request)))                isValid = true;        }        if (op.equals("edit")) {            if (lp.canUserModify(privilege.getUser(request)))                isValid = true;        }        if (!isValid)            throw new ErrMsgException(Privilege.MSG_INVALID);        String strdoc_id = StrUtil.getNullStr(mfu.getFieldValue("id"));        int doc_id = Integer.parseInt(strdoc_id);        Document doc = new Document();        doc = doc.getDocument(doc_id);                if (op.equals("add")) {            String content = StrUtil.getNullStr(mfu.getFieldValue(                    "htmlcode"));            return doc.AddContentPage(application, mfu, content);        }        if (op.equals("edit")) {                        return doc.EditContentPage(application, mfu);        }        return false;    }    public int getId() {        return id;    }    private int id;}

⌨️ 快捷键说明

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