leaf.java
来自「cwbbs 云网论坛源码」· Java 代码 · 共 833 行 · 第 1/2 页
JAVA
833 行
clf.update(); } Vector vt = new Vector(); getAllChild(vt, this); int childcount = vt.size(); Iterator ir = vt.iterator(); while (ir.hasNext()) { Leaf childlf = (Leaf) ir.next(); int layer = parentLayer + 1 + 1; String pcode = childlf.getParentCode(); while (!pcode.equals(code)) { layer++; Leaf lfp = getLeaf(pcode); pcode = lfp.getParentCode(); } childlf.setLayer(layer); childlf.update(); } Leaf oldParentLeaf = getLeaf(oldParentCode); oldParentLeaf.setChildCount(oldParentLeaf.getChildCount() - 1); oldParentLeaf.update(); Leaf newParentLeaf = getLeaf(newParentCode); newParentLeaf.setChildCount(newParentLeaf.getChildCount() + 1); newParentLeaf.update(); } } catch (Exception e) { logger.error("update: " + e.getMessage()); } } catch (SQLException e) { logger.error("update: " + e.getMessage()); } boolean re = r == 1 ? true : false; if (re) { removeFromCache(code); } return re; } public boolean AddChild(Leaf childleaf) throws ErrMsgException { int childorders = child_count + 1; String updatesql = ""; String insertsql = "insert into directory (code,name,parent_code,description,orders,root_code,child_count,layer,type,add_date,price,isHome,pluginCode,template_doc_id,logo,is_post) values ("; insertsql += StrUtil.sqlstr(childleaf.getCode()) + "," + StrUtil.sqlstr(childleaf.getName()) + "," + StrUtil.sqlstr(code) + "," + StrUtil.sqlstr(childleaf.getDescription()) + "," + childorders + "," + StrUtil.sqlstr(root_code) + ",0," + (layer + 1) + "," + childleaf.getType() + "," + StrUtil.sqlstr("" + System.currentTimeMillis()) + "," + childleaf.getPrice() + "," + (childleaf.getIsHome() ? "1" : "0") + "," + StrUtil.sqlstr(childleaf.getPluginCode()) + "," + childleaf.getTemplateDocId() + "," + StrUtil.sqlstr(childleaf.getLogo()) + "," + (post?1:0) + ")"; if (!SecurityUtil.isValidSql(insertsql)) throw new ErrMsgException("SQL error."); Conn conn = new Conn(connname); try { updatesql = "Update directory set child_count=child_count+1" + " where code=" + StrUtil.sqlstr(code); conn.beginTrans(); conn.executeUpdate(insertsql); conn.executeUpdate(updatesql); removeFromCache(code); conn.commit(); LeafPriv lp = new LeafPriv(); lp.add(childleaf.getCode()); } catch (SQLException e) { conn.rollback(); logger.error("AddChild: " + e.getMessage()); return false; } finally { if (conn != null) { conn.close(); conn = null; } } return true; } public void removeFromCache(String code) { try { rmCache.remove(code, dirCache); LeafChildrenCacheMgr.remove(code); } catch (Exception e) { logger.error("removeFromCache: " + e.getMessage()); } } public void removeAllFromCache() { try { rmCache.invalidateGroup(dirCache); LeafChildrenCacheMgr.removeAll(); } catch (Exception e) { logger.error("removeAllFromCache: " + e.getMessage()); } } public Leaf getLeaf(String code) { Leaf leaf = null; try { leaf = (Leaf) rmCache.getFromGroup(code, dirCache); } catch (Exception e) { logger.error("getLeaf1: " + e.getMessage()); } if (leaf == null) { leaf = new Leaf(code); if (leaf != null) { if (!leaf.isLoaded()) leaf = null; else { try { rmCache.putInGroup(code, dirCache, leaf); } catch (Exception e) { logger.error("getLeaf2: " + e.getMessage()); } } } } else { leaf.renew(); } return leaf; } public boolean delsingle(Leaf leaf) { Document doc = new Document(); try { doc.delDocumentByDirCode(leaf.getCode()); } catch (ErrMsgException e) { logger.error("delsingle:" + e.getMessage()); } LeafPriv lp = new LeafPriv(leaf.getCode()); lp.delPrivsOfDir(); UserGroupPrivDb ugpd = new UserGroupPrivDb(); ugpd.delUserGroupPrivOfDir(leaf.getCode()); RMConn rmconn = new RMConn(connname); try { String sql = "delete from directory where code=" + StrUtil.sqlstr(leaf.getCode()); boolean r = rmconn.executeUpdate(sql) == 1 ? true : false; sql = "update directory set orders=orders-1 where parent_code=" + StrUtil.sqlstr(leaf.getParentCode()) + " and orders>" + leaf.getOrders(); rmconn.executeUpdate(sql); sql = "update directory set child_count=child_count-1 where code=" + StrUtil.sqlstr(leaf.getParentCode()); rmconn.executeUpdate(sql); removeAllFromCache(); } catch (SQLException e) { logger.error("delsingle: " + e.getMessage()); return false; } return true; } public synchronized void del(Leaf leaf) { delsingle(leaf); Iterator children = leaf.getChildren().iterator(); while (children.hasNext()) { Leaf lf = (Leaf) children.next(); del(lf); } } public Leaf getBrother(String direction) { String sql; RMConn rmconn = new RMConn(connname); Leaf bleaf = null; try { if (direction.equals("down")) { sql = "select code from directory where parent_code=" + StrUtil.sqlstr(parent_code) + " and orders=" + (orders + 1); } else { sql = "select code from directory where parent_code=" + StrUtil.sqlstr(parent_code) + " and orders=" + (orders - 1); } ResultIterator ri = rmconn.executeQuery(sql); if (ri != null && ri.hasNext()) { ResultRecord rr = (ResultRecord) ri.next(); bleaf = getLeaf(rr.getString(1)); } } catch (SQLException e) { logger.error("getBrother: " + e.getMessage()); } return bleaf; } public boolean move(String direction) { String sql = ""; boolean isexist = false; Leaf bleaf = getBrother(direction); if (bleaf != null) { isexist = true; } if (isexist) { Conn conn = new Conn(connname); try { conn.beginTrans(); if (direction.equals("down")) { sql = "update directory set orders=orders+1" + " where code=" + StrUtil.sqlstr(code); conn.executeUpdate(sql); sql = "update directory set orders=orders-1" + " where code=" + StrUtil.sqlstr(bleaf.getCode()); conn.executeUpdate(sql); } if (direction.equals("up")) { sql = "update directory set orders=orders-1" + " where code=" + StrUtil.sqlstr(code); conn.executeUpdate(sql); sql = "update directory set orders=orders+1" + " where code=" + StrUtil.sqlstr(bleaf.getCode()); conn.executeUpdate(sql); } conn.commit(); removeFromCache(code); removeFromCache(bleaf.getCode()); LeafChildrenCacheMgr.remove(parent_code); } catch (Exception e) { conn.rollback(); logger.error("move: " + e.getMessage()); return false; } finally { if (conn != null) { conn.close(); conn = null; } } } return true; } public void setOrders(int orders) { this.orders = orders; } public void setPluginCode(String pluginCode) { this.pluginCode = pluginCode; } public void setPrice(double price) { this.price = price; } public void setTemplateDocId(int templateDocId) { this.templateDocId = templateDocId; } public void setDocCount(int docCount) { this.docCount = docCount; } public void setTemplateCatalog(String templateCatalog) { this.templateCatalog = templateCatalog; } public void setLogo(String logo) { this.logo = logo; } public void setPost(boolean post) { this.post = post; } public void setChildCount(int childCount) { this.child_count = childCount; } public TemplateCatalogDb getTemplateCatalogDb() throws ErrMsgException { TemplateCatalogDb tcd = new TemplateCatalogDb(); if (type == TYPE_COLUMN || type == TYPE_SUB_SITE || type==TYPE_LIST || type==TYPE_DOCUMENT) { if (!templateCatalog.equals(TemplateCatalogDb.CATALOG_CODE_DEFAULT)) { tcd = tcd.getTemplateCatalogDb(templateCatalog); return tcd; } } String parentcode = getParentCode(); Leaf plf = new Leaf(); while (!parentcode.equals(Leaf.ROOTCODE)) { plf = plf.getLeaf(parentcode); if (plf == null || !plf.isLoaded()) break; if (plf.getType() == Leaf.TYPE_COLUMN || plf.getType() == Leaf.TYPE_SUB_SITE) { if (!plf.getTemplateCatalog().equals(TemplateCatalogDb. CATALOG_CODE_DEFAULT)) { tcd = tcd.getTemplateCatalogDb(plf.getTemplateCatalog()); return tcd; } } parentcode = plf.getParentCode(); } return tcd.getDefaultTemplateCatalogDb(); } public TemplateDb getTemplateDb() throws ErrMsgException { TemplateCatalogDb tcd = getTemplateCatalogDb(); TemplateDb td = new TemplateDb(); if (getType() == Leaf.TYPE_COLUMN || getType() == Leaf.TYPE_SUB_SITE) { int columnId = tcd.getInt("doc_column"); if (columnId != TemplateDb.TYPE_CODE_DEFAULT) { return td.getTemplateDb(columnId); } } else if (getType() == Leaf.TYPE_LIST) { int listId = tcd.getInt("doc_list"); if (listId != TemplateDb.TYPE_CODE_DEFAULT) { return td.getTemplateDb(listId); } } else { int docId = tcd.getInt("doc"); if (docId != TemplateDb.TYPE_CODE_DEFAULT) { return td.getTemplateDb(docId); } } return td.getDefaultTemplate(this); } public String getListHtmlPath() { String path = code; String pCode = getParentCode(); while (!pCode.equals(Leaf.ROOTCODE)) { Leaf pleaf = getLeaf(pCode); if (pleaf == null || !pleaf.isLoaded()) break; pCode = pleaf.getParentCode(); path = pleaf.getCode() + "/" + path; } return "doc/root/" + path; } public String getListHtmlNameByPageNo(int pageNo) { Config cfg = new Config(); return getListHtmlPath() + "/" + code + "_" + pageNo + "." + cfg.getProperty("cms.html_ext"); } public String getListHtmlNameByPageNum(HttpServletRequest request, int pageNum) { String sql = SQLBuilder.getDirDocListSql(code); Document doc = new Document(); int total = doc.getDocCount(sql); Config cfg = new Config(); int pageSize = cfg.getIntProperty("cms.listPageSize"); ListDocPagniator paginator = new ListDocPagniator(request, total, pageSize); int pageNo = paginator.pageNum2No(pageNum); return getListHtmlNameByPageNo(pageNo); } private int templateId = -1; private boolean loaded = false; private String pluginCode; private double price; private int templateDocId; private int docCount = 0; private String templateCatalog = TemplateCatalogDb.CATALOG_CODE_DEFAULT; private String logo; private boolean post = false;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?