chx 学习jForum笔记七-ForumAction二

2010.12.8 接昨天。

下面这句是存在于net.jforum.view.forum/ForumAction.java中

 

    public void list()
    {
        this.setTemplateName(TemplateKeys.FORUMS_LIST); //这句没看懂,从字面看应该是设置模板的名称
        this.context.put("allCategories", ForumCommon.getAllCategoriesAndForums (true));//页面显示的所有分类和板块(检查有无未读的贴子)

        this.context.put("topicsPerPage", Integer.valueOf(SystemGlobals.getIntValue(ConfigKeys.TOPICS_PER_PAGE))); //总主题数

…………

 

 

在net.jforum.view.forum.common/ForumCommon.java中

     public static List<Category> getAllCategoriesAndForums(boolean checkUnreadPosts) //取所有分类和板块(检查有无未读的贴子)
    {
        return getAllCategoriesAndForums (SessionFacade.getUserSession(), //取当前用户SESSION
                SystemGlobals.getIntValue(ConfigKeys.ANONYMOUS_USER_ID), //取游客ID
                SessionFacade.getTopicsReadTime(),                       //取最后阅读时间
                checkUnreadPosts);                                       //检查有无未读的贴子
    }

 

在net.jforum.view.forum.common/ForumCommon.java中

    public static List<Category> getAllCategoriesAndForums(final UserSession userSession, final int anonymousUserId,
            final Map<Integer, Long> tracking, boolean origCheckUnreadPosts)
    {
        boolean checkUnreadPosts = origCheckUnreadPosts; //是否检查未读的贴子
        long lastVisit = 0;             //初始值0
        int userId = anonymousUserId;   //初始值游客ID
       
        if (userSession != null) {      //非游客
            lastVisit = userSession.getLastVisit().getTime(); //最后登录时间
            userId = userSession.getUserId(); //用户ID
        }
        // Do not check for unread posts if the user is not logged in
        checkUnreadPosts = checkUnreadPosts && (userId != anonymousUserId); //是否检查未读的贴子
        final List<Category> categories = ForumRepository.getAllCategories (userId);  //取所有分类
        if (!checkUnreadPosts) {   //不需返回未读帖子
            return categories;
        }
        final List<Category> returnCategories = new ArrayList<Category>();
        for (Iterator<Category> iter = categories.iterator(); iter.hasNext(); ) {
            Category category = new Category(iter.next()); //递归分类
            for (Iterator<Forum> tmpIterator = category.getForums().iterator(); tmpIterator.hasNext(); ) {
                Forum forum = tmpIterator.next(); //递归分类下的板块
                ForumCommon.checkUnreadPosts (forum, tracking, lastVisit);  //检查未读帖子
            }

            returnCategories.add(category);//需返回的分类
        }
        return returnCategories;
    }

 

在net.jforum.view.forum.common/ForumCommon.java中

    public static List<Category> getAllCategories(int userId)
    {
        final PermissionControl permissionControl = SecurityRepository.get(userId);  //取权限
        final List<Category> list = new ArrayList<Category>(); //所有分类
        Set<Category> categoriesSet = (Set<Category>)cache.get(FQN, CATEGORIES_SET);    //缓存中取分类集
        if (categoriesSet == null) { //缓存未取到
            synchronized (ForumRepository.instance) {
                if (categoriesSet == null) {
                    LOGGER.warn("Categories set returned null from the cache. Trying to reload");
                    try {
ForumRepository.instance.loadCategories (DataAccessDriver.getInstance().newCategoryDAO());//取分类到缓存
ForumRepository.instance.loadForums (DataAccessDriver.getInstance().newForumDAO());//取板块到缓存
                    }
                    catch (Exception e) {
                        throw new CategoryNotFoundException("Failed to get the category", e);
                    }
                    categoriesSet = (Set<Category>)cache.get(FQN, CATEGORIES_SET); //缓存中取分类集
                    if (categoriesSet == null) { //仍然为空则报错
                        throw new CategoryNotFoundException("Could not find all categories. There must be a problem with the cache");
                    }
                }
            }
        }
        for (final Iterator<Category> iter = ((Set<Category>)cache.get(FQN, CATEGORIES_SET)).iterator(); iter.hasNext(); ) {
            final Category category = getCategory (permissionControl, iter.next().getId());
            if (category != null) {
                list.add(category); //留下用户有权处理的分类
            }           
        }
        return list;
    }

 

其中ForumRepository. loadCategories及ForumRepository.instance.loadForums在前面(笔记一末及笔记二)有过分析。是将数据表中的分类读出至缓存中,loadForums将板块分类关系表读出至缓存中。

 

 

    public static Category getCategory(final PermissionControl permissonControl, final int categoryId)
    {
        if (! isCategoryAccessible (permissonControl, categoryId)) { //无权处理
            return null;
        }

   //有权处理
        return (Category)cache.get(FQN, Integer.toString(categoryId)); //从缓存中读出分类
    }

 

    public static boolean isCategoryAccessible(final PermissionControl permissionControl, final int categoryId)
    {  //是否有权处理分类
        return permissionControl.canAccess(SecurityConstants.PERM_CATEGORY, Integer.toString(categoryId));
    }


 

明天再看checkUnreadPosts(final Forum forum, final Map<Integer, Long> tracking, final long lastVisit)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值