⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 leaf.java

📁 源码/软件简介: 云网论坛1.1RC国际版是采用JSP开发的集论坛、CMS(网站内容管理系统)、博客、聊天室、商城、交友、语音灌水等于一体的门户式社区。拥有CWBBS ( Cloud Web BBS
💻 JAVA
📖 第 1 页 / 共 3 页
字号:

    public int getChildCount() {
        return child_count;
    }

    public Vector getChildren() {
        Vector v = new Vector();
        String sql = "select code from sq_board where parent_code=? order by orders";
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        Conn conn = new Conn(connname);
        try {
            pstmt = conn.prepareStatement(sql);
            pstmt.setString(1, code);
            rs = conn.executePreQuery();
            if (rs != null) {
                while (rs.next()) {
                    String c = rs.getString(1);
                    //logger.info("child=" + c);
                    v.addElement(getLeaf(c));
                }
            }
        } catch (SQLException e) {
            logger.error("getChildren: " + e.getMessage());
        } finally {
            if (rs != null) {
                try {
                    rs.close();
                } catch (Exception e) {}
                rs = null;
            }
            if (pstmt != null) {
                try {
                    pstmt.close();
                } catch (Exception e) {}
                pstmt = null;
            }
            if (conn != null) {
                conn.close();
                conn = null;
            }
        }
        return v;
    }

    /**
     * 取出code结点的所有孩子结点
     * @param code String
     * @return ResultIterator
     * @throws ErrMsgException
     */
    public Vector getAllChild(Vector vt, Leaf leaf) throws ErrMsgException {
        Vector children = leaf.getChildren();
        if (children.isEmpty())
            return children;
        vt.addAll(children);
        Iterator ir = children.iterator();
        while (ir.hasNext()) {
            Leaf lf = (Leaf) ir.next();
            getAllChild(vt, lf);
        }
        return children;
    }

    public String toString() {
        return "Leaf is " + name;
    }

    private int type;

    public synchronized boolean update() {
        // String sql = "update sq_board set name=" + StrUtil.sqlstr(name) +
        //             ",description=" + StrUtil.sqlstr(description) +
        //             ",type=" + type + ",isHome=" + (isHome ? "1" : "0") + ",add_id=" + addId +
        //             ",logo=" + StrUtil.sqlstr(logo) + ",today_count,today_date,topic_count,post_count where code=" + StrUtil.sqlstr(code);
        String sql = "update sq_board set name=?,description=?,type=?";
        sql += ",isHome=?,add_id=?,logo=?,today_count=?,today_date=?,topic_count=?,post_count=?,theme=?,skin=?,islocked=?,boardRule=?,color=?,child_count=?,webeditAllowType=?,plugin2Code=? where code=?";
        int r = 0;
        Conn conn = new Conn(connname);
        PreparedStatement ps = null;
        try {
            ps = conn.prepareStatement(sql);
            ps.setString(1, name);
            ps.setString(2, description);
            ps.setInt(3, type);
            ps.setInt(4, isHome?1:0);
            ps.setLong(5, addId);
            ps.setString(6, logo);
            ps.setInt(7, todayCount);
            ps.setString(8, DateUtil.toLongString(todayDate));
            ps.setInt(9, topicCount);
            ps.setInt(10, postCount);
            ps.setString(11, theme);
            ps.setString(12, skin);
            ps.setInt(13, locked?1:0);
            ps.setString(14, boardRule);
            ps.setString(15, color);
            ps.setInt(16, child_count);
            ps.setInt(17, webeditAllowType);
            ps.setString(18, plugin2Code);
            ps.setString(19, code);
            r = conn.executePreUpdate();
        } catch (Exception e) {
            logger.error("update:" + e.getMessage());
        }
        finally {
            removeAllFromCache();

            if (ps != null) {
                try {
                    ps.close();
                } catch (Exception e) {}
                ps = null;
            }
            if (conn != null) {
                conn.close();
                conn = null;
            }
        }
        boolean re = r == 1 ? true : false;

        return re;
    }

    /**
     * 更改了分类
     * @param newDirCode String
     * @return boolean
     */
    public synchronized boolean updateParent(String newParentCode) throws ErrMsgException {
        if (newParentCode.equals(parent_code))
            return false;
        if (newParentCode.equals(code))
            throw new ErrMsgException("不能将本节点设为父节点!");

        // 把该结点加至新父结点,作为其最后一个孩子,同设其layer为父结点的layer + 1
        Leaf lfparent = getLeaf(newParentCode);
        int oldorders = orders;
        int neworders = lfparent.getChildCount() + 1;
        int parentLayer = lfparent.getLayer();

        String sql = "update sq_board set name=" + StrUtil.sqlstr(name) +
                     ",description=" + StrUtil.sqlstr(description) +
                     ",type=" + type + ",isHome=" + (isHome ? "1" : "0") +
                     ",add_id=" + addId + ",logo=" + StrUtil.sqlstr(logo) +
                     ",parent_code=" + StrUtil.sqlstr(newParentCode) + ",orders=" +
                     neworders +
                     ",layer=" + (parentLayer + 1) + ",theme=" + StrUtil.sqlstr(theme) +
                     ",skin=" + StrUtil.sqlstr(skin) + ",islocked=" + ((locked)?1:0) + ",color=" + StrUtil.sqlstr(color) + ",plugin2Code=" + StrUtil.sqlstr(plugin2Code) +
                     " where code=" + StrUtil.sqlstr(code);

        String oldParentCode = parent_code;
        parent_code = newParentCode;
        RMConn conn = new RMConn(connname);
        int r = 0;
        try {
            r = conn.executeUpdate(sql);
            try {
                if (r == 1) {
                    removeAllFromCache();

                    // 更新原来父结点中,位于本leaf之后的orders
                    sql = "select code from sq_board where parent_code=" + StrUtil.sqlstr(oldParentCode) +
                          " and orders>" + oldorders;
                    ResultIterator ri = conn.executeQuery(sql);
                    while (ri.hasNext()) {
                        ResultRecord rr = (ResultRecord)ri.next();
                        Leaf clf = getLeaf(rr.getString(1));
                        clf.setOrders(clf.getOrders() - 1);
                        clf.update();
                    }

                    // 更新其所有子结点的layer
                    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();
                    }

                    // 将其原来的父结点的孩子数-1
                    Leaf oldParentLeaf = getLeaf(oldParentCode);
                    oldParentLeaf.setChildCount(oldParentLeaf.getChildCount() - 1);
                    oldParentLeaf.update();

                    // 将其新父结点的孩子数 + 1
                    Leaf newParentLeaf = getLeaf(newParentCode);
                    newParentLeaf.setChildCount(newParentLeaf.getChildCount() + 1);
                    newParentLeaf.update();
                }
            } catch (Exception e) {
                logger.error("updateParent1: " + e.getMessage());
            }
        } catch (SQLException e) {
            logger.error("updateParent2: " + e.getMessage());
        }
        boolean re = r == 1 ? true : false;
        removeAllFromCache();

        return re;
    }

    public boolean AddChild(Leaf childleaf) throws
            ErrMsgException {
        // 计算得出插入结点的orders
        int childorders = child_count + 1;

        String updatesql = "";
        String insertsql = "insert into sq_board (code,name,parent_code,description,orders,root_code,child_count,layer,type,logo,theme,skin,islocked,color,add_date,today_date,webeditAllowType,isHome,plugin2Code) 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(childleaf.getLogo()) + "," + StrUtil.sqlstr(childleaf.getTheme()) + "," + StrUtil.sqlstr(childleaf.getSkin()) +
                "," + (childleaf.isLocked()?1:0) + "," + StrUtil.sqlstr(childleaf.getColor()) + "," + StrUtil.sqlstr("" + System.currentTimeMillis()) + "," + StrUtil.sqlstr("" + System.currentTimeMillis()) + "," + childleaf.getWebeditAllowType() + "," + (childleaf.isHome?1:0) + "," + StrUtil.sqlstr(childleaf.getPlugin2Code()) + ")";

        if (!SecurityUtil.isValidSql(insertsql))
            throw new ErrMsgException("请勿输入非法字符如;号等!");
        Conn conn = new Conn(connname);
        try {
            //更改根结点的信息
            updatesql = "Update sq_board set child_count=child_count+1" +
                        " where code=" + StrUtil.sqlstr(code);
            conn.beginTrans();
            conn.executeUpdate(insertsql);
            conn.executeUpdate(updatesql);
            conn.commit();
        } catch (SQLException e) {
            conn.rollback();
            logger.error("AddChild: " + e.getMessage());
            return false;
        } finally {
            removeAllFromCache();
            if (conn != null) {
                conn.close();
                conn = null;
            }
        }

        return true;
    }

    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(ServletContext application, Leaf leaf) {
        // 删除版块下对应的贴子
        if (leaf.getType() == leaf.TYPE_BOARD) {
            MsgDb md = new MsgDb();
            md.delMsgOfBoard(application, leaf.getCode());
        }

        // 删除版块下对应的render
        BoardRenderDb brd = new BoardRenderDb();
        brd = brd.getBoardRenderDb(leaf.getCode());
        if (brd != null && brd.isLoaded()) {
            brd.del();
        }
        // 删除版块下对应的entrance
        EntranceMgr em = new EntranceMgr();
        Vector vEntrancePlugin = em.getAllEntranceUnitOfBoard(leaf.getCode());
        if (vEntrancePlugin.size() > 0) {
            Iterator irpluginentrance = vEntrancePlugin.iterator();
            while (irpluginentrance.hasNext()) {
                EntranceUnit eu = (EntranceUnit) irpluginentrance.next();
                BoardEntranceDb bed = new BoardEntranceDb();
                bed = bed.getBoardEntranceDb(leaf.getCode(), eu.getCode());
                bed.del();
            }
        }
        // 删除版块下对应的版主
        BoardManagerDb bmd = new BoardManagerDb();
        Iterator ir = bmd.getBoardManagers(leaf.getCode()).iterator();
        while (ir.hasNext()) {
            UserDb ud = (UserDb) ir.next();
            bmd = bmd.getBoardManagerDb(leaf.getCode(), ud.getName());
            bmd.del();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -