imgstoredirmgr.java
来自「cwbbs 云网论坛源码」· Java 代码 · 共 197 行
JAVA
197 行
package cn.js.fan.module.cms;import java.sql.*;import javax.servlet.http.*;import cn.js.fan.db.*;import cn.js.fan.security.*;import cn.js.fan.util.*;import cn.js.fan.web.*;import org.apache.log4j.*;import java.util.Vector;import java.util.Iterator;import cn.js.fan.module.cms.IDirectory;public class ImgStoreDirMgr { String connname = ""; Logger logger = Logger.getLogger(ImgStoreDirMgr.class.getName()); public ImgStoreDirMgr() { connname = Global.defaultDB; if (connname.equals("")) logger.info("Directory:默认数据库名不能为空"); } public boolean AddChild(HttpServletRequest request) throws ErrMsgException { String name = "", code = "", parent_code = ""; name = ParamUtil.get(request, "name", false); if (name == null) throw new ErrMsgException("名称不能为空!"); code = ParamUtil.get(request, "code").trim(); if (code.equals("")) throw new ErrMsgException("编码不能为空!"); if (!StrUtil.isSimpleCode(code)) throw new ErrMsgException("编码请使用字母、数字、-或_!"); parent_code = ParamUtil.get(request, "parent_code").trim(); if (parent_code.equals("")) throw new ErrMsgException("父结点不能为空!"); String description = ParamUtil.get(request, "description"); int type = ParamUtil.getInt(request, "type"); ImgStoreDirDb lf = new ImgStoreDirDb(); lf.setName(name); lf.setCode(code); lf.setParentCode(parent_code); lf.setDescription(description); lf.setType(type); ImgStoreDirDb dd = getImgStoreDirDb(parent_code); return dd.AddChild(lf); } public void del(String delcode) throws ErrMsgException { ImgStoreDirDb lf = getImgStoreDirDb(delcode); lf.del(lf); } public synchronized boolean update(HttpServletRequest request) throws ErrMsgException { String code = ParamUtil.get(request, "code", false); String name = ParamUtil.get(request, "name", false); String description = ParamUtil.get(request, "description"); boolean isHome = ParamUtil.get(request, "isHome").equals("true") ? true : false; int type = ParamUtil.getInt(request, "type"); if (code == null || name == null) { throw new ErrMsgException("code与name项必填!"); } String parentCode = ParamUtil.get(request, "parentCode"); ImgStoreDirDb leaf = getImgStoreDirDb(code); if (code.equals(parentCode)) { throw new ErrMsgException("请选择正确的父节点!"); } if (!parentCode.equals(leaf.getParentCode())) { ImgStoreDirDb lf = getImgStoreDirDb(parentCode); while (lf!=null && !lf.getCode().equals(lf.ROOTCODE)) { String pCode = lf.getParentCode(); if (pCode.equals(leaf.getCode())) throw new ErrMsgException("不能将其子节点更改为父节点"); lf = getImgStoreDirDb(pCode); } } leaf.setName(name); leaf.setDescription(description); leaf.setIsHome(isHome); leaf.setType(type); boolean re = false; if (parentCode.equals(leaf.getParentCode())) { logger.info("update:name=" + name); re = leaf.save(); } else re = leaf.save(parentCode); return re; } public synchronized boolean move(HttpServletRequest request) throws ErrMsgException { String code = ParamUtil.get(request, "code", false); String direction = ParamUtil.get(request, "direction", false); if (code == null || direction == null) { throw new ErrMsgException("编码与方向项必填!"); } ImgStoreDirDb dd = getImgStoreDirDb(code); return dd.move(direction); } public ImgStoreDirDb getImgStoreDirDb(String code) { ImgStoreDirDb dd = new ImgStoreDirDb(); return dd.getImgStoreDirDb(code); } public ImgStoreDirDb getBrother(String code, String direction) throws ErrMsgException { ImgStoreDirDb dd = getImgStoreDirDb(code); return dd.getBrother(direction); } public Vector getChildren(String code) throws ErrMsgException { ImgStoreDirDb dd = getImgStoreDirDb(code); return dd.getChildren(); } public void repairLeaf(ImgStoreDirDb lf) { Vector children = lf.getChildren(); lf.setChildCount(children.size()); Iterator ir = children.iterator(); int orders = 1; while (ir.hasNext()) { ImgStoreDirDb lfch = (ImgStoreDirDb)ir.next(); lfch.setOrders(orders); lfch.save(); orders ++; } int layer = 2; String parentCode = lf.getParentCode(); if (lf.getCode().equals(lf.ROOTCODE)) { layer = 1; } else { if (parentCode.equals(lf.ROOTCODE)) layer = 2; else { while (!parentCode.equals(lf.ROOTCODE)) { ImgStoreDirDb parentLeaf = getImgStoreDirDb(parentCode); if (parentLeaf == null || !parentLeaf.isLoaded()) break; else { parentCode = parentLeaf.getParentCode(); } layer++; } } } lf.setLayer(layer); lf.save(); } public void repairTree(ImgStoreDirDb leaf) throws Exception { repairLeaf(leaf); Vector children = getChildren(leaf.getCode()); int size = children.size(); if (size == 0) return; Iterator ri = children.iterator(); while (ri.hasNext()) { ImgStoreDirDb childlf = (ImgStoreDirDb) ri.next(); repairTree(childlf); } ImgStoreDirCache dc = new ImgStoreDirCache(); dc.removeAllFromCache(); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?