1 53 54 106 107 package com.Yasna.forum; 108 109 import com.Yasna.util.*; 110 111 116 public class ForumPermissions implements Cacheable { 117 118 121 public static final int READ = 0; 122 123 126 public static final int SYSTEM_ADMIN = 1; 127 128 131 public static final int FORUM_ADMIN = 2; 132 133 136 public static final int USER_ADMIN = 3; 137 138 141 public static final int GROUP_ADMIN = 4; 142 143 146 public static final int MODERATOR = 5; 147 148 151 public static final int CREATE_THREAD = 6; 152 153 156 public static final int CREATE_MESSAGE = 7; 157 158 private boolean [] values = new boolean[8]; 159 160 163 public static ForumPermissions full() { 164 return new ForumPermissions(true, true, true, true, true, true, true, true); 165 } 166 167 170 public static ForumPermissions none() { 171 return new ForumPermissions(false, false, false, false, false, false, false, false); 172 } 173 174 177 public static ForumPermissions readOnly() { 178 return new ForumPermissions(true, false, false, false, false, false, false, false); 179 } 180 181 184 public ForumPermissions(boolean READ, boolean SYSTEM_ADMIN, 185 boolean FORUM_ADMIN, boolean USER_ADMIN, boolean GROUP_ADMIN, 186 boolean MODERATOR, boolean CREATE_THREAD, boolean CREATE_MESSAGE) 187 { 188 values[0] = READ; 189 values[1] = SYSTEM_ADMIN; 190 values[2] = FORUM_ADMIN; 191 values[3] = USER_ADMIN; 192 values[4] = GROUP_ADMIN; 193 values[5] = MODERATOR; 194 values[6] = CREATE_THREAD; 195 values[7] = CREATE_MESSAGE; 196 } 197 198 202 public ForumPermissions(ForumPermissions perm1, 203 ForumPermissions perm2) 204 { 205 values[0] = perm1.get(0) || perm2.get(0); 206 values[1] = perm1.get(1) || perm2.get(1); 207 values[2] = perm1.get(2) || perm2.get(2); 208 values[3] = perm1.get(3) || perm2.get(3); 209 values[4] = perm1.get(4) || perm2.get(4); 210 values[5] = perm1.get(5) || perm2.get(5); 211 values[6] = perm1.get(6) || perm2.get(6); 212 values[7] = perm1.get(7) || perm2.get(7); 213 } 214 215 public ForumPermissions(boolean [] permissions) { 216 this.values = permissions; 217 } 218 219 public String toString() { 220 StringBuffer buf = new StringBuffer (); 221 for (int i=0; i<values.length-1; i++) { 222 buf.append(values[i]).append(","); 223 } 224 buf.append(values[values.length -1]); 225 return buf.toString(); 226 } 227 228 231 public boolean get(int type) { 232 if (type < 0 || type > 7) { 233 return false; 234 } 235 return values[type]; 236 } 237 238 242 public boolean isSystemOrForumAdmin() { 243 return (values[FORUM_ADMIN] || values[SYSTEM_ADMIN]); 244 } 245 246 248 public int getSize() { 249 int size = 0; 252 size += CacheSizes.sizeOfObject(); size += CacheSizes.sizeOfObject(); size += CacheSizes.sizeOfBoolean() * 8; return size; 256 } 257 } 258 | Popular Tags |