📄 leaf.java
字号:
}
// 删除版块下对应的boardCode
BoardScoreDb bsd = new BoardScoreDb();
bsd.delBoardScoreDbsOfBoard(leaf.getCode());
String sql = "delete from sq_board where code=" + StrUtil.sqlstr(leaf.getCode());
Conn conn = new Conn(connname);
try {
conn.beginTrans();
boolean r = conn.executeUpdate(sql) == 1 ? true : false;
sql = "update sq_board set orders=orders-1 where parent_code=" + StrUtil.sqlstr(leaf.getParentCode()) + " and orders>" + leaf.getOrders();
conn.executeUpdate(sql);
sql = "update sq_board set child_count=child_count-1 where code=" + StrUtil.sqlstr(leaf.getParentCode());
conn.executeUpdate(sql);
conn.commit();
String lg = leaf.getLogo();
// 如果原有文件存在,则删除文件
if (lg!=null && !lg.equals("")) {
try {
String realPath = application.getRealPath("/");
String realpath = realPath + "forum/images/board_logo/";
File file = new File(realpath + lg);
file.delete();
}
catch (Exception e) {
logger.info("delsingle:" + e.getMessage());
}
}
removeAllFromCache();
} catch (SQLException e) {
conn.rollback();
logger.error("delsingle:" + e.getMessage());
return false;
}
finally {
if (conn!=null) {
conn.close();
conn = null;
}
}
return true;
}
public synchronized void del(ServletContext application, Leaf leaf) {
delsingle(application, leaf);
Iterator children = getChildren().iterator();
while (children.hasNext()) {
Leaf lf = (Leaf) children.next();
del(application, 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 sq_board where parent_code=" +
StrUtil.sqlstr(parent_code) +
" and orders=" + (orders + 1);
} else {
sql = "select code from sq_board 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 = "";
// 取出该结点的移动方向上的下一个兄弟结点的orders
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 sq_board set orders=orders+1" +
" where code=" + StrUtil.sqlstr(code);
conn.executeUpdate(sql);
sql = "update sq_board set orders=orders-1" +
" where code=" + StrUtil.sqlstr(bleaf.getCode());
conn.executeUpdate(sql);
}
if (direction.equals("up")) {
sql = "update sq_board set orders=orders-1" +
" where code=" + StrUtil.sqlstr(code);
conn.executeUpdate(sql);
sql = "update sq_board set orders=orders+1" +
" where code=" + StrUtil.sqlstr(bleaf.getCode());
conn.executeUpdate(sql);
}
conn.commit();
} catch (Exception e) {
conn.rollback();
logger.error("move: " + e.getMessage());
return false;
} finally {
removeAllFromCache();
if (conn != null) {
conn.close();
conn = null;
}
}
}
return true;
}
public void setChildCount(int childCount) {
this.child_count = childCount;
}
public void setOrders(int orders) {
this.orders = orders;
}
public void setLayer(int layer) {
this.layer = layer;
}
public void setLocked(boolean locked) {
this.locked = locked;
}
public void setBoardRule(String boardRule) {
this.boardRule = boardRule;
}
public void setColor(String color) {
this.color = color;
}
public void setWebeditAllowType(int webeditAllowType) {
this.webeditAllowType = webeditAllowType;
}
public void setPlugin2Code(String plugin2Code) {
this.plugin2Code = plugin2Code;
}
public Vector getAllPlugin2() {
Vector v = new Vector();
String[] ary = StrUtil.split(plugin2Code, ",");
if (ary!=null) {
Plugin2Mgr pm = new Plugin2Mgr();
Plugin2Unit pu = null;
int len = ary.length;
for (int i=0; i<len; i++) {
pu = pm.getPlugin2Unit(ary[i]);
if (pu!=null)
v.addElement(pu);
}
}
return v;
}
public boolean isUsePlugin2(String code) {
String[] ary = StrUtil.split(plugin2Code, ",");
if (ary != null) {
int len = ary.length;
Plugin2Mgr pm = new Plugin2Mgr();
Plugin2Unit pu = null;
for (int i = 0; i < len; i++) {
if (ary[i].equals(code))
return true;
}
}
return false;
}
public String getMenuString(Leaf lf) throws ErrMsgException {
if (lf.getChildCount()==0)
return "";
String str = "";
try {
str = (String) rmCache.getFromGroup("menu_" + lf.getCode(), dirCache);
} catch (Exception e) {
logger.error("getMenuString: " + e.getMessage());
}
if (str==null) {
StringBuffer sb = new StringBuffer(200);
sb.append("one");
ShowBoardsToString(sb, lf, lf.getLayer());
str = sb.toString();
try {
rmCache.putInGroup("menu_" + lf.getCode(), dirCache, str);
}
catch (Exception e) {
logger.error("getMenuString2:" + e.getMessage());
}
}
return str;
}
// 显示根结点为leaf的树
public void ShowBoardsToString(StringBuffer sb, Leaf leaf, int rootlayer) throws ErrMsgException {
// 不显示根
if (sb.toString().equals("one")) {
sb.delete(0, sb.length());
}
else
ShowLeafToString(sb, leaf, rootlayer);
Directory dir = new Directory();
Vector children = dir.getChildren(leaf.getCode());
int size = children.size();
if (size == 0)
return;
int i = 0;
Iterator ri = children.iterator();
while (ri.hasNext()) {
Leaf childlf = (Leaf) ri.next();
if (childlf.getIsHome())
ShowBoardsToString(sb, childlf, rootlayer);
}
}
/**
* 里面只能用单引号,以便于在页面脚本中写出
* @param sb StringBuffer
* @param leaf Leaf
* @param rootlayer int
* @throws Exception
*/
public void ShowLeafToString(StringBuffer sb, Leaf leaf, int rootlayer) {
String code = leaf.getCode();
String name = leaf.getName();
int layer = leaf.getLayer();
String blank = "";
int d = layer-rootlayer;
for (int i=0; i<d; i++) {
blank += " ";
}
if (leaf.getIsHome()) {
if (leaf.getChildCount() > 0) {
if (leaf.getType() == leaf.TYPE_DOMAIN)
sb.append("<a>" + blank + "╋ " + name + "</option><BR>");
else if (leaf.getType() == leaf.TYPE_BOARD)
sb.append("<a href='listtopic.jsp?boardcode=" +
StrUtil.UrlEncode(code) + "'>" + blank + "├『" +
name + "』</option><BR>");
} else {
if (leaf.getType() == leaf.TYPE_DOMAIN)
sb.append("<a>" + blank + "╋ " + name + "</option><BR>");
else if (leaf.getType() == leaf.TYPE_BOARD)
sb.append("<a href='listtopic.jsp?boardcode=" +
StrUtil.UrlEncode(code) + "'>" + blank + "├『" +
name +
"』</option><BR>");
}
}
}
/**
* 每个节点有两个Cache,一是本身,另一个是用于存储其孩子结点的cache
* @param code String
*/
/* public void removeFromCache(String code) {
try {
// 节点如果有增加、删除、修改时,全用removeAllFromCache
Leaf lf = getLeaf(code);
// 更新其孩子结点缓存
LeafChildrenCacheMgr.remove(code);
// 更新其祖先结点的孩子结点缓存
String pcode = lf.getParentCode();
// while (!pcode.equals("-1")) {
// 只需更改其父结点的孩子缓存
if (!pcode.equals("-1")) {
LeafChildrenCacheMgr.remove(pcode);
Leaf leaf = getLeaf(pcode);
pcode = leaf.getParentCode();
}
// 删除其本身的缓存
rmCache.remove(code, dirCache);
} catch (Exception e) {
logger.error("removeFromCache: " + e.getMessage());
}
}
*/
private String logo;
private int todayCount = 0;
private java.util.Date todayDate;
private int topicCount = 0;
private int postCount = 0;
private String theme = "default";
private String skin = "default";
private boolean loaded = false;
private boolean locked;
private String boardRule;
private String color = "";
private int webeditAllowType = WEBEDIT_ALLOW_TYPE_UBB_NORMAL;
private String plugin2Code;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -