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

📄 doccontent.java

📁 oa 源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            dcm.refreshDel(docId, pageNum);            for (int i = pageNum + 1; i < doc.getPageCount(); i++)                dcm.refreshUpdate(docId, pageNum);        } catch (SQLException e) {            re = false;            logger.error(e.getMessage());        } finally {            if (rs != null) {                try {                    rs.close();                } catch (Exception e) {}                rs = null;            }            if (conn != null) {                conn.close();                conn = null;            }        }        return re;    }    public synchronized boolean save(ServletContext application,                                     CMSMultiFileUploadBean mfu) throws            ErrMsgException {        String isuploadfile = StrUtil.getNullString(mfu.getFieldValue(                "isuploadfile"));                if (isuploadfile.equals("false"))            return saveWithoutFile(application, mfu);        String FilePath = StrUtil.getNullString(mfu.getFieldValue("filepath"));                        String tempAttachFilePath = Global.getRealPath() + FilePath +                                    "/";        mfu.setSavePath(tempAttachFilePath);         File f = new File(tempAttachFilePath);        if (!f.isDirectory()) {            f.mkdirs();        }        ResultSet rs = null;        Conn conn = new Conn(connname);        try {                        String sql = "select path from cms_images where mainkey=" + docId +                         " and kind='" + IMGKIND + "' and subkey=" + pageNum + "";            rs = conn.executeQuery(sql);            if (rs != null) {                String fpath = "";                while (rs.next()) {                    fpath = rs.getString(1);                    if (fpath != null) {                        File virtualFile = new File(Global.getRealPath() + fpath);                        virtualFile.delete();                    }                }            }            if (rs != null) {                rs.close();                rs = null;            }                        sql = "delete from cms_images where mainkey=" + docId +                  " and kind='" + IMGKIND + "' and subkey=" + pageNum + "";            conn.executeUpdate(sql);                        int ret = mfu.getRet();            if (ret == 1) {                mfu.writeFile(false);                Vector files = mfu.getFiles();                                java.util.Enumeration e = files.elements();                String filepath = "";                sql = "";                while (e.hasMoreElements()) {                    FileInfo fi = (FileInfo) e.nextElement();                    filepath = FilePath + "/" + fi.getName();                    sql =                            "insert into cms_images (path,mainkey,kind,subkey) values (" +                            StrUtil.sqlstr(filepath) + "," + docId +                            ",'" + IMGKIND + "'," + pageNum + ")";                    conn.executeUpdate(sql);                }            } else                throw new ErrMsgException("save:上传失败!ret=" + ret);        } catch (Exception e) {            logger.error("save:" + e.getMessage());        } finally {            if (rs != null) {                try {                    rs.close();                } catch (Exception e) {}                rs = null;            }            if (conn != null) {                conn.close();                conn = null;            }        }        saveWithoutFile(application, mfu);        return true;    }        public synchronized boolean saveWithoutFile(ServletContext application,                                                CMSMultiFileUploadBean mfu) throws            ErrMsgException {        content = StrUtil.getNullString(mfu.getFieldValue("htmlcode"));        Document doc = new Document();        doc = doc.getDocument(docId);        Leaf lf = new Leaf();        lf = lf.getLeaf(doc.getDirCode());        String userName = lf.getRootCode();        Conn conn = new Conn(connname);        boolean re = true;        try {            String FilePath = StrUtil.getNullString(mfu.getFieldValue(                    "filepath"));                                                            String tempAttachFilePath = Global.getRealPath() + FilePath +                                    "/";                        mfu.setSavePath(tempAttachFilePath);             long allSize = 0;            String sisDdxc = StrUtil.getNullString(mfu.getFieldValue("isDdxc"));            if (sisDdxc.equals("true")) {                String[] attachFileNames = mfu.getFieldValues("attachFileName");                String[] clientFilePaths = mfu.getFieldValues("clientFilePath");                int len = 0;                if (attachFileNames != null)                    len = attachFileNames.length;                String sql = "";                int orders = getAttachmentMaxOrders() + 1;                for (int i = 0; i < len; i++) {                    String filepath = mfu.getSavePath() + attachFileNames[i];                    String name = mfu.getUploadFileName(clientFilePaths[i]);                    sql =                            "insert into netdisk_document_attach (fullpath,doc_id,name,diskname,visualpath,page_num,orders,uploadDate,USER_NAME) values (" +                            StrUtil.sqlstr(filepath) + "," + docId + "," +                            StrUtil.sqlstr(name) + "," +                            StrUtil.sqlstr(attachFileNames[i]) + "," +                            StrUtil.sqlstr(FilePath) + "," + pageNum + "," + orders + ",NOW()," + StrUtil.sqlstr(userName) + ")";                    conn.executeUpdate(sql);                    orders ++;                }            } else {                File f = new File(tempAttachFilePath);                if (!f.isDirectory()) {                    f.mkdirs();                }                                Vector attachs = mfu.getAttachments();                Iterator attir = attachs.iterator();                while (attir.hasNext()) {                    FileInfo fi = (FileInfo)attir.next();                    allSize += fi.getSize();                }                UserDb ud = new UserDb();                ud = ud.getUserDb(doc.getNick());                if (ud.getDiskSpaceUsed() + allSize > ud.getDiskSpaceAllowed())                    throw new ErrMsgException("您上传的文件太大了,超出了允许的磁盘空间!");                                                mfu.writeAttachment(true);                Iterator ir = attachs.iterator();                String sql = "";                int orders = getAttachmentMaxOrders() + 1;                while (ir.hasNext()) {                    FileInfo fi = (FileInfo) ir.next();                    String filepath = mfu.getSavePath() + fi.getDiskName();                    sql =                            "insert into netdisk_document_attach (fullpath,doc_id,name,diskname,visualpath,page_num,orders,file_size,ext,uploadDate,USER_NAME) values (" +                            StrUtil.sqlstr(filepath) + "," + docId + "," +                            StrUtil.sqlstr(fi.getName()) +                            "," + StrUtil.sqlstr(fi.getDiskName()) + "," +                            StrUtil.sqlstr(FilePath) + "," + pageNum + "," + orders + "," + fi.getSize() + "," + StrUtil.sqlstr(fi.getExt()) + ",NOW()," + StrUtil.sqlstr(userName) + ")";                    conn.executeUpdate(sql);                    orders ++;                }                                ud.setDiskSpaceUsed(ud.getDiskSpaceUsed() + allSize);                ud.save();            }            PreparedStatement pstmt = conn.prepareStatement(SAVE);            pstmt.setString(1, content);            pstmt.setInt(2, docId);            pstmt.setInt(3, pageNum);            re = conn.executePreUpdate() == 1 ? true : false;            pstmt.close();                        DocContentCacheMgr dcm = new DocContentCacheMgr();            dcm.refreshUpdate(docId, pageNum);        } catch (SQLException e) {            re = false;            logger.error(e.getMessage());        } finally {            if (conn != null) {                conn.close();                conn = null;            }        }        return re;    }    public int getDocId() {        return docId;    }    public int getPageNum() {        return pageNum;    }        public static int getContentCount(int doc_id) {        DocContentCacheMgr dcm = new DocContentCacheMgr();        return dcm.getContentCount(doc_id);    }    public boolean create(ServletContext application,                          CMSMultiFileUploadBean mfu, int doc_id,                          String content, int pageNum) throws            ErrMsgException {        String sql = "";        String FilePath = StrUtil.getNullString(mfu.getFieldValue("filepath"));                        String tempAttachFilePath = Global.getRealPath() + FilePath +                                    "/";        mfu.setSavePath(tempAttachFilePath);         File f = new File(tempAttachFilePath);        if (!f.isDirectory()) {            f.mkdirs();        }        Conn conn = new Conn(connname);        boolean re = true;        try {                        int ret = mfu.getRet();                        if (ret == mfu.RET_SUCCESS) {                                mfu.writeFile(false);                 Vector files = mfu.getFiles();                java.util.Enumeration e = files.elements();                String filepath = "";                sql = "";                while (e.hasMoreElements()) {                    FileInfo fi = (FileInfo) e.nextElement();                    filepath = FilePath + "/" + fi.getName();                    sql =                            "insert into cms_images (path,mainkey,kind,subkey) values (" +                            StrUtil.sqlstr(filepath) + "," + docId +                            ",'" + IMGKIND + "'," + this.pageNum + ")";                    conn.executeUpdate(sql);                }            } else                throw new ErrMsgException("上传失败!ret=" + ret);            re = createWithoutFile(application, mfu, doc_id, content, pageNum);        } catch (SQLException e) {            logger.error("create:" + e.getMessage());        } finally {            if (conn != null) {                conn.close();                conn = null;            }        }        return re;    }    private Vector attachments = new Vector();    public Vector getAttachments() {        return attachments;    }    public synchronized boolean delAttachment(int attachId) {        Attachment am = new Attachment(attachId);        boolean re = am.del();                if (re) {                        DocContentCacheMgr dcm = new DocContentCacheMgr();            dcm.refreshUpdate(docId, pageNum);        }        return re;    }    public synchronized boolean updateAttachmentName(int attachId,            String newname) {        String sql = "update netdisk_document_attach set name=? where id=?";        Conn conn = new Conn(connname);        boolean re = false;        try {            PreparedStatement pstmt = conn.prepareStatement(sql);            pstmt.setString(1, newname);            pstmt.setInt(2, attachId);            re = conn.executePreUpdate() == 1 ? true : false;        } catch (SQLException e) {            logger.error(e.getMessage());        } finally {                        DocContentCacheMgr dcm = new DocContentCacheMgr();            dcm.refreshUpdate(docId, pageNum);            if (conn != null) {                conn.close();                conn = null;            }        }        return re;    }    public int getAttachmentMaxOrders() {        String GETMAXORDERS =                "select max(orders) from netdisk_document_attach where doc_id=? and page_num=?";        Conn conn = new Conn(connname);        ResultSet rs = null;        int maxorders = -1;        try {                        PreparedStatement pstmt = conn.prepareStatement(GETMAXORDERS);            pstmt.setInt(1, docId);            pstmt.setInt(2, pageNum);            rs = conn.executePreQuery();            if (rs != null) {                if (rs.next()) {                    maxorders = rs.getInt(1);                }            }        } catch (SQLException e) {            logger.error("getMaxOrders:" + e.getMessage());        } finally {            if (conn != null) {                conn.close();                conn = null;            }        }        return maxorders;    }    public boolean moveAttachment(int attachId, String direction) {        Attachment attach = new Attachment(attachId);        boolean re = false;        int orders = attach.getOrders();        if (direction.equals("up")) {            if (orders == 1)                return true;            else {                Attachment upperAttach = new Attachment(orders - 1, docId,                        pageNum);                if (upperAttach.isLoaded()) {                    upperAttach.setOrders(orders);                    upperAttach.save();                }                attach.setOrders(orders - 1);                re = attach.save();            }        } else {            int maxorders = getAttachmentMaxOrders();            if (orders == maxorders) {                return true;            } else {                Attachment lowerAttach = new Attachment(orders + 1, docId,                        pageNum);                if (lowerAttach.isLoaded()) {                    lowerAttach.setOrders(orders);                    lowerAttach.save();                }                attach.setOrders(orders + 1);                re = attach.save();            }        }                DocContentCacheMgr dcm = new DocContentCacheMgr();        dcm.refreshUpdate(docId, pageNum);        return re;    }}

⌨️ 快捷键说明

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