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 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 getAllCategoriesAndForums(final UserSession userSession, final int anonymousUserId,
            final Map 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 categories = ForumRepository.getAllCategories (userId);  //取所有分类
        if (!checkUnreadPosts) {   //不需返回未读帖子
            return categories;
        }
        final List returnCategories = new ArrayList();
        for (Iterator iter = categories.iterator(); iter.hasNext(); ) {
            Category category = new Category(iter.next()); //递归分类
            for (Iterator 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 getAllCategories(int userId)
    {
        final PermissionControl permissionControl = SecurityRepository.get(userId);  //取权限
        final List list = new ArrayList(); //所有分类
        Set categoriesSet = (Set)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)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 iter = ((Set)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 tracking, final long lastVisit)

你可能感兴趣的:(jForum)