public IteratorProxy(int type, Iterator iterator, Authorization authorization,
ForumPermissions permissions)
{
this.iterator = iterator;
this.authorization = authorization;
this.permissions = permissions;
// Load the appropriate proxy factory depending on the type of object
// that we're iterating through. Each proxy factory is responsible
// for checking that the user has permission to view the object, and
// then wrapping it with an appropriate proxy.
switch (type) {
// CATEGORY
case JiveGlobals.FORUM_CATEGORY:
// Create a class that wraps forums with proxies.
proxyFactory = new ProxyFactory() {
public Object createProxy(Object obj, Authorization auth,
ForumPermissions perms)
{
ForumCategory category = (ForumCategory)obj;
// Create a new permissions object with the combination
// of the permissions of this object and tempPermissions.
int parentPerms = perms.toInt();
// Never inherit the show category permission.
ForumPermissions newPerms = new ForumPermissions(
ForumPermissions.setBit(parentPerms,
ForumPermissions.SHOW_CATEGORY, false));
ForumPermissions catPerms = category.getPermissions(auth);
newPerms = new ForumPermissions(catPerms, newPerms);
// Return the object if the user has permission.
if (newPerms.get(ForumPermissions.READ_FORUM) ||
newPerms.get(ForumPermissions.SHOW_CATEGORY) ||
newPerms.get(ForumPermissions.MODERATE_MESSAGES) ||
newPerms.get(ForumPermissions.MODERATE_THREADS) ||
newPerms.get(ForumPermissions.FORUM_ADMIN) ||
newPerms.get(ForumPermissions.CATEGORY_ADMIN) ||
newPerms.get(ForumPermissions.SYSTEM_ADMIN))
{
return new ForumCategoryProxy(category, auth, newPerms);
}
// Otherwise return null.
else {
return null;
}
}
};
break;
public Object getNextElement() {
while (iterator.hasNext()) {
Object element = proxyFactory.createProxy(iterator.next(),
authorization, permissions);
if (element != null) {
return element;
}
}
return null;
}
发表于 @ 2003年05月30日 14:54:00 | 评论( loading... ) | 举报| 收藏