documentmgr.java

来自「cwbbs 云网论坛源码」· Java 代码 · 共 1,162 行 · 第 1/3 页

JAVA
1,162
字号
package cn.js.fan.module.cms;import java.io.*;import java.util.*;import javax.servlet.*;import javax.servlet.http.*;import cn.js.fan.base.*;import cn.js.fan.db.*;import cn.js.fan.module.cms.plugin.*;import cn.js.fan.module.cms.plugin.base.*;import cn.js.fan.module.cms.search.*;import cn.js.fan.module.cms.template.*;import cn.js.fan.module.pvg.*;import cn.js.fan.util.*;import cn.js.fan.util.file.*;import cn.js.fan.web.*;import com.cloudwebsoft.framework.template.*;import com.cloudwebsoft.framework.util.*;import com.redmoon.kit.util.*;import org.apache.log4j.*;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 static String getWebEditPage() {        Config cfg = new Config();        boolean isWebEdit = cfg.getBooleanProperty("cms.editor_default_webedit");        if (isWebEdit)            return "fckwebedit.jsp";        else            return "fckwebedit_new.jsp";    }        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(request));            }            if (ret == -4) {                throw new ErrMsgException(mfu.getErrMessage(request));            }        } catch (IOException e) {            logger.error("doUpload:" + e.getMessage());        }        return mfu;    }    public boolean Operate(ServletContext application,                           HttpServletRequest request, IPrivilege privilege) throws            ErrMsgException {                                        CMSMultiFileUploadBean mfu = doUpload(application, request);        fileUpload = mfu;        String op = StrUtil.getNullStr(mfu.getFieldValue("op"));        String dir_code = StrUtil.getNullStr(mfu.getFieldValue("dir_code"));        dirCode = dir_code;        Leaf lf = new Leaf();        lf = lf.getLeaf(dir_code);        if (lf==null)            throw new ErrMsgException("目录" + dir_code + "不存在!");        Document doc = new Document();        if (op.equals("edit")) {            String idstr = StrUtil.getNullString(mfu.getFieldValue("id"));            if (!StrUtil.isNumeric(idstr))                throw new ErrMsgException(SkinUtil.LoadString(request,                        SkinUtil.ERR_ID));            int 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,                        SkinUtil.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);                }                                Config cfg = new Config();                boolean isCreateHtml = cfg.getBooleanProperty("cms.html_auto");                if (isCreateHtml) {                    createHtml(request, doc, 1);                                                            String sql = SQLBuilder.getDirDocListSql(dir_code);                                                            int total = doc.getDocCount(sql);                    int listPageSize = cfg.getIntProperty("cms.listPageSize");                    ListDocPagniator paginator = new ListDocPagniator(request, total, listPageSize);                                        int pageNum = paginator.pageNo2Num(doc.getPageNo());                    createListPageHtml(request, doc.getDirCode(), pageNum);                                        createColumnPageHtmlOfDoc(request, doc);                }            }            return re;        } else {                        if (!lf.isPost()) {                LeafPriv lp = new LeafPriv(dir_code);                if (!lp.canUserAppend(privilege.getUser(request)))                    throw new ErrMsgException(SkinUtil.LoadString(request,                            SkinUtil.PVG_INVALID));            }            boolean re = false;            try {                re = doc.create(application, mfu, privilege.getUser(request));            } catch (ResKeyException e) {                throw new ErrMsgException(e.getMessage(request));            }            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);                }                                Config cfg = new Config();                boolean isCreateHtml = cfg.getBooleanProperty("cms.html_auto");                if (isCreateHtml) {                    doc = doc.getDocument(doc.getId());                    createHtml(request, doc, 1);                    if (doc.getExamine()==Document.EXAMINE_PASS) {                                                int listPageHtmlCreateCount = cfg.getIntProperty("cms.listPageHtmlCreateCount");                        for (int k=1; k<=listPageHtmlCreateCount; k++) {                            createListPageHtml(request, doc.getDirCode(), k);                        }                    }                                        createColumnPageHtmlOfDoc(request, doc);                }            }            return re;        }    }        public void createColumnPageHtmlOfDoc(HttpServletRequest request, Document doc) {        Leaf plf = new Leaf();        plf = plf.getLeaf(doc.getDirCode());        String parentCode = plf.getParentCode();        while (!parentCode.equals(Leaf.ROOTCODE)) {            plf = plf.getLeaf(parentCode);            if (plf == null || !plf.isLoaded())                break;            if (plf.getType()==Leaf.TYPE_COLUMN) {                createColumnPageHtml(request, plf.getCode());                break;            }            parentCode = plf.getParentCode();        }    }    public void delBatch(HttpServletRequest request, boolean isDustbin) 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, isDustbin);        }    }    public void resumeBatch(HttpServletRequest request) throws ErrMsgException {        String strids = ParamUtil.get(request, "ids");        String[] ids = StrUtil.split(strids, ",");        if (ids==null)            return;                Config cfg = new Config();        boolean isAutoHtml = cfg.getBooleanProperty("cms.html_auto");        int len = ids.length;        Document doc = null;        for (int i=0; i<len; i++) {            doc = getDocument(Integer.parseInt(ids[i]));            doc.UpdateExamine(Document.EXAMINE_PASS);            if (isAutoHtml) {                createAllPageHtml(request, doc);            }        }    }    public boolean resume(HttpServletRequest request, int id) throws ErrMsgException {        Document doc = getDocument(id);        boolean re = doc.UpdateExamine(Document.EXAMINE_PASS);        if (re) {                        Config cfg = new Config();            boolean isAutoHtml = cfg.getBooleanProperty("cms.html_auto");            if (isAutoHtml) {                createAllPageHtml(request, doc);            }        }        return re;    }    public void passExamineBatch(HttpServletRequest request, int EXAMINE_STATUS) 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(EXAMINE_STATUS);                                 createListPageHtml(request, doc.getDirCode(), 1);                                createColumnPageHtmlOfDoc(request, doc);            }            else {                throw new ErrMsgException(Privilege.MSG_INVALID);            }        }    }        public boolean del(HttpServletRequest request, int id, IPrivilege privilege, boolean isDustbin) throws            ErrMsgException {        Document doc = new Document();        doc = getDocument(id);        if (doc == null || !doc.isLoaded()) {            throw new ErrMsgException(SkinUtil.LoadString(request,                    "res.cms.Document", "err_file_not_found"));        }                Config cfg = new Config();        boolean isDelHtml = cfg.getBooleanProperty("cms.html_auto");        if (isDelHtml) {            delAllPageHtml(request, doc);        }        LeafPriv lp = new LeafPriv(doc.getDirCode());        if (lp.canUserDel(privilege.getUser(request))) {            boolean re = false;            if (isDustbin) {                re = doc.UpdateExamine(Document.EXAMINE_DUSTBIN);            }            else {                                re = doc.del();                if (re) {                                        Indexer idx = new Indexer();                    idx.delDocument(id);                }            }            if (isDelHtml) {                                                createColumnPageHtmlOfDoc(request, doc);            }            return re;        }        else            throw new ErrMsgException(Privilege.MSG_INVALID);    }    public boolean UpdateSummary(ServletContext application,                                 HttpServletRequest request,                                 IPrivilege privilege) throws            ErrMsgException {        CMSMultiFileUploadBean mfu = doUpload(application, request);        fileUpload = mfu;        int id = 0;        try {            id = Integer.parseInt(mfu.getFieldValue("id"));        } catch (Exception e) {            throw new ErrMsgException(SkinUtil.LoadString(request,                    SkinUtil.ERR_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);        }        boolean re = false;        try {            re = doc.UpdateSummary(application, mfu);        } catch (ResKeyException e) {            throw new ErrMsgException(e.getMessage(request));        }        return re;    }    public void clearDustbin(HttpServletRequest request) throws ErrMsgException {        Document doc = new Document();        doc.clearDustbin();    }    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,

⌨️ 快捷键说明

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