📄 doccontent.java
字号:
re = true; DocContentCacheMgr dcm = new DocContentCacheMgr(); 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 flow_cms_images where mainkey=" + docId + " and kind='document' 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(fpath); virtualFile.delete(); } } } if (rs != null) { rs.close(); rs = null; } sql = "delete from flow_cms_images where mainkey=" + docId + " and kind='document' 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 = mfu.getSavePath() + fi.getName(); sql = "insert into flow_cms_images (path,mainkey,kind,subkey) values (" + StrUtil.sqlstr(filepath) + "," + docId + ",'document'," + 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")); Conn conn = new Conn(connname); boolean re = true; try { String FilePath = StrUtil.getNullString(mfu.getFieldValue( "filepath")); String tempAttachFilePath = Global.getRealPath() + FilePath + "/"; mfu.setSavePath(tempAttachFilePath); 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 flow_document_attach (fullpath,doc_id,name,diskname,visualpath,page_num,orders) values (" + StrUtil.sqlstr(filepath) + "," + docId + "," + StrUtil.sqlstr(name) + "," + StrUtil.sqlstr(attachFileNames[i]) + "," + StrUtil.sqlstr(FilePath) + "," + pageNum + "," + orders + ")"; conn.executeUpdate(sql); orders ++; } } else { File f = new File(tempAttachFilePath); if (!f.isDirectory()) { f.mkdirs(); } mfu.writeAttachment(true); Vector attachs = mfu.getAttachments(); 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 flow_document_attach (fullpath,doc_id,name,diskname,visualpath,page_num,orders) values (" + StrUtil.sqlstr(filepath) + "," + docId + "," + StrUtil.sqlstr(fi.getName()) + "," + StrUtil.sqlstr(fi.getDiskName()) + "," + StrUtil.sqlstr(FilePath) + "," + pageNum + "," + orders + ")"; conn.executeUpdate(sql); orders ++; } } 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("saveWithoutFile:" + 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 = mfu.getSavePath() + fi.getName(); sql = "insert into flow_cms_images (path,mainkey,kind,subkey) values (" + StrUtil.sqlstr(filepath) + "," + docId + ",'document'," + 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; 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 flow_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; if (re) { DocContentCacheMgr dcm = new DocContentCacheMgr(); dcm.refreshUpdate(docId, pageNum); } } catch (SQLException e) { logger.error(e.getMessage()); } finally { if (conn != null) { conn.close(); conn = null; } } return re; } public int getAttachmentMaxOrders() { String GETMAXORDERS = "select max(orders) from flow_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 + -