📄 directory.java
字号:
throw new ErrMsgException(e.getMessage());
}
// 如果上传出错,则写相应的出错信息
if (ret==-4 || ret==-3 ) {
throw new ErrMsgException(fileupload.getErrMessage(request));
} else {
if (ret==fileupload.RET_SUCCESS) {
// 使用随机名称写入磁盘
fileupload.writeFile(true);
Vector v = fileupload.getFiles();
if (v.size()>0) {
FileInfo fi = (FileInfo) v.elementAt(0);
if (fi != null)
logo = fi.getDiskName();
}
}
}
String code = fileupload.getFieldValue("code");
String name = fileupload.getFieldValue("name");
if (code == null) {
throw new ErrMsgException(SkinUtil.LoadString(request, "res.forum.Directory", "err_need_code"));
}
if (name==null) {
throw new ErrMsgException(SkinUtil.LoadString(request, "res.forum.Directory", "err_need_name"));
}
Leaf leaf = getLeaf(code);
String dellogo = StrUtil.getNullString(fileupload.getFieldValue("dellogo"));
if (fileupload.getFiles().size()>0 || dellogo.equals("1")) {
String lg = leaf.getLogo();
// 如果原有文件存在,则删除文件
if (lg!=null && !lg.equals("")) {
try {
File file = new File(realpath + lg);
file.delete();
}
catch (Exception e) {
logger.info(e.getMessage());
}
}
}
String description = fileupload.getFieldValue("description");
String ih = StrUtil.getNullString(fileupload.getFieldValue("isHome"));
boolean isHome = ih.equals("true") ? true : false;
String strtype = fileupload.getFieldValue("type");
int type = Integer.parseInt(strtype);
String theme = fileupload.getFieldValue("theme").trim();
String skin = fileupload.getFieldValue("skin").trim();
String locked = fileupload.getFieldValue("isLocked");
int isLocked = Integer.parseInt(locked);
String color = fileupload.getFieldValue("color");
String strWebeditAllowType = fileupload.getFieldValue("webeditAllowType");
int webeditAllowType = Leaf.WEBEDIT_ALLOW_TYPE_UBB_NORMAL;
if (StrUtil.isNumeric(strWebeditAllowType))
webeditAllowType = Integer.parseInt(strWebeditAllowType);
String plugin2Code = StrUtil.getNullStr(fileupload.getFieldValue("plugin2Code"));
String strCheckMsg = fileupload.getFieldValue("checkMsg");
int checkMsg = StrUtil.toInt(strCheckMsg, 0);
int delMode = StrUtil.toInt(fileupload.getFieldValue("delMode"), 0);
int displayStyle = StrUtil.toInt(fileupload.getFieldValue("displayStyle"), Leaf.DISPLAY_STYLE_VERTICAL);
String parentCode = fileupload.getFieldValue("parentCode");
if (!parentCode.equals(leaf.getParentCode())) {
// 节点不能改变其父节点为其子节点
Leaf lf = getLeaf(parentCode); // 取得新的父节点
while (lf!=null && !lf.getCode().equals(lf.CODE_ROOT)) {
// 从parentCode节点往上遍历,如果找到leaf.getParentCode()则证明不合法
String pCode = lf.getParentCode();
if (pCode.equals(leaf.getCode()))
throw new ErrMsgException(SkinUtil.LoadString(request, "res.forum.Directory", "err_parent_code"));
// throw new ErrMsgException("不能将其子节点更改为父节点");
lf = getLeaf(pCode);
}
}
leaf.setName(name);
leaf.setDescription(description);
leaf.setIsHome(isHome);
//logger.info("isHome:" + isHome);
leaf.setType(type);
leaf.setTheme(theme);
leaf.setSkin(skin);
leaf.setLocked(isLocked==1?true:false);
if (dellogo.equals("1"))
leaf.setLogo("");
else if (fileupload.getFiles().size() > 0)
leaf.setLogo(logo);
leaf.setColor(color);
leaf.setWebeditAllowType(webeditAllowType);
leaf.setPlugin2Code(plugin2Code);
leaf.setCheckMsg(checkMsg);
leaf.setDelMode(delMode);
leaf.setDisplayStyle(displayStyle);
boolean re = false;
if (parentCode.equals(leaf.getParentCode()))
re = leaf.update();
else
re = leaf.updateParent(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) {
throw new ErrMsgException(SkinUtil.LoadString(request, "res.forum.Directory", "err_need_code"));
}
if ( direction == null ) {
throw new ErrMsgException(SkinUtil.LoadString(request, "res.forum.Directory", "err_need_direction"));
}
Leaf lf = new Leaf(code);
return lf.move(direction);
}
public Leaf getLeaf(String code) {
Leaf leaf = new Leaf();
return leaf.getLeaf(code);
}
public Leaf getBrother(String code, String direction) throws
ErrMsgException {
Leaf lf = getLeaf(code);
return lf.getBrother(direction);
}
public Vector getChildren(String code) throws ErrMsgException {
Leaf leaf = getLeaf(code);
return leaf.getChildren();
}
/**
* 取得菜单,以layer级目录为大标题,layer+1级目录为小标题
* @param root_code String 所属的根目录
*/
public Menu getMenu(String root_code) throws ErrMsgException {
Directory dir = new Directory();
Leaf leaf = dir.getLeaf(root_code);
Menu menu = new Menu();
MenuItem mi = new MenuItem();
menu.addItem(mi);
mi.setHeadLeaf(leaf);
Vector children = leaf.getChildren();
Iterator ir = children.iterator();
while (ir.hasNext()) {
Leaf lf = (Leaf) ir.next();
mi.addChildLeaf(lf);
}
return menu;
}
/**
* 修复因为BUG或者误操作致树形结构被破坏的问题
*/
public void repairLeaf(Leaf lf) {
Vector children = lf.getChildren();
// 重置孩子节点数
lf.setChildCount(children.size());
Iterator ir = children.iterator();
int orders = 1;
while (ir.hasNext()) {
Leaf lfch = (Leaf)ir.next();
// 重置孩子节点的排列顺序
lfch.setOrders(orders);
System.out.println(getClass() + " leaf name=" + lfch.getName() + " orders=" + orders);
lfch.update();
orders ++;
}
// 重置层数
int layer = 2;
String parentCode = lf.getParentCode();
while (!parentCode.equals(lf.CODE_ROOT)) {
// System.out.println(getClass() + "leaf parentCode=" + parentCode);
Leaf parentLeaf = getLeaf(parentCode);
if (parentLeaf==null || !parentLeaf.isLoaded())
break;
else {
parentCode = parentLeaf.getParentCode();
}
layer ++;
}
lf.setLayer(layer);
lf.update();
}
// 修复根结点为leaf的树
public void repairTree(Leaf leaf) throws Exception {
// System.out.println(getClass() + "leaf name=" + leaf.getName());
repairLeaf(leaf);
Directory dir = new Directory();
Vector children = dir.getChildren(leaf.getCode());
int size = children.size();
if (size == 0)
return;
Iterator ri = children.iterator();
// 写跟贴
while (ri.hasNext()) {
Leaf childlf = (Leaf) ri.next();
repairTree(childlf);
}
// 刷新缓存
leaf.removeAllFromCache();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -