| 1 41 package com.mvnforum.auth; 42 43 import java.util.*; 44 45 import com.mvnforum.db.ForumBean; 46 import com.mvnforum.db.ForumCache; 47 import org.apache.commons.logging.Log; 48 import org.apache.commons.logging.LogFactory; 49 50 54 class ForumListPermission { 55 56 private static Log log = LogFactory.getLog(ForumListPermission.class); 57 58 ArrayList forumList = new ArrayList(); 59 60 boolean allForumsPermission = false; 61 62 boolean bypassPrivateForum = false; 63 64 public ForumListPermission() { 65 } 66 67 void setAllForumsPermission(boolean permission) { 68 allForumsPermission = permission; 69 } 70 71 void setForumPermission(int forumID, boolean permission) { 72 Iterator iter = forumList.iterator(); 74 while (iter.hasNext()) { 75 int currentForumID = ((Integer ) iter.next()).intValue(); 76 if (currentForumID == forumID) { 77 iter.remove(); 78 } 79 } 81 if (permission) { 83 forumList.add(new Integer (forumID)); 85 } 86 } 87 88 boolean hasPermission(int forumID) { 89 90 for (int i = 0; i < forumList.size(); i++) { 91 int currentForumID = ((Integer )forumList.get(i)).intValue(); 92 if (currentForumID == forumID) { 93 return true; 94 } 95 } 96 97 if (allForumsPermission) { 99 if (bypassPrivateForum) { 100 return true; 101 } 102 103 try { 104 ForumBean forumBean = ForumCache.getInstance().getBean(forumID); 105 if (forumBean.getForumType() == ForumBean.FORUM_TYPE_DEFAULT) { 106 return true; 107 } 108 } catch (Exception ex) { 109 log.error("Cannot get the ForumBean in ForumListPermission", ex); 110 } 111 } 112 113 return false; 115 } 116 117 boolean hasPermssionInAnyForums() { 118 119 if (forumList.size() > 0) { 121 return true; 123 } 124 125 if (allForumsPermission) { 127 if (bypassPrivateForum) { 128 return true; 129 } 130 131 try { 132 Collection forumBeans = ForumCache.getInstance().getBeans(); 133 for (Iterator iter = forumBeans.iterator(); iter.hasNext(); ) { 134 ForumBean forumBean = (ForumBean)iter.next(); 135 if (forumBean.getForumType() == ForumBean.FORUM_TYPE_DEFAULT) { 136 return true; 137 } 138 } 139 } catch (Exception ex) { 140 log.error("Cannot get ForumBeans in ForumListPermission", ex); 141 } 142 } 143 144 return false; 146 } 147 148 public boolean isBypassPrivateForum() { 149 return bypassPrivateForum; 150 } 151 152 public void setBypassPrivateForum(boolean ignorePrivateOption) { 153 this.bypassPrivateForum = ignorePrivateOption; 154 } 155 } 156 | Popular Tags |