0001: /**********************************************************************************
0002: * $URL: https://source.sakaiproject.org/svn/content/tags/sakai_2-4-1/content-tool/tool/src/java/org/sakaiproject/content/tool/ResourcesBrowseItem.java $
0003: * $Id: ResourcesBrowseItem.java 22599 2007-03-14 17:19:07Z jimeng@umich.edu $
0004: ***********************************************************************************
0005: *
0006: * Copyright (c) 2007 The Sakai Foundation.
0007: *
0008: * Licensed under the Educational Community License, Version 1.0 (the "License");
0009: * you may not use this file except in compliance with the License.
0010: * You may obtain a copy of the License at
0011: *
0012: * http://www.opensource.org/licenses/ecl1.php
0013: *
0014: * Unless required by applicable law or agreed to in writing, software
0015: * distributed under the License is distributed on an "AS IS" BASIS,
0016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0017: * See the License for the specific language governing permissions and
0018: * limitations under the License.
0019: *
0020: **********************************************************************************/package org.sakaiproject.content.tool;
0021:
0022: import java.io.UnsupportedEncodingException;
0023: import java.util.Collection;
0024: import java.util.Comparator;
0025: import java.util.HashSet;
0026: import java.util.Hashtable;
0027: import java.util.Iterator;
0028: import java.util.LinkedList;
0029: import java.util.List;
0030: import java.util.Map;
0031: import java.util.Set;
0032: import java.util.SortedSet;
0033: import java.util.TreeSet;
0034: import java.util.Vector;
0035:
0036: import org.sakaiproject.content.api.ResourceType;
0037: import org.sakaiproject.content.api.GroupAwareEntity.AccessMode;
0038: import org.sakaiproject.content.cover.ContentHostingService;
0039: import org.sakaiproject.entity.api.ResourceProperties;
0040: import org.sakaiproject.event.cover.NotificationService;
0041: import org.sakaiproject.site.api.Group;
0042: import org.sakaiproject.time.api.Time;
0043: import org.sakaiproject.time.cover.TimeService;
0044: import org.sakaiproject.tool.cover.ToolManager;
0045: import org.sakaiproject.util.ResourceLoader;
0046: import org.sakaiproject.util.Validator;
0047:
0048: /**
0049: * Internal class that encapsulates all information about a resource that is needed in the browse mode.
0050: * This is being phased out as we switch to the resources type registry.
0051: */
0052: public class ResourcesBrowseItem {
0053: /** Resource bundle using current language locale */
0054: private static ResourceLoader rb = new ResourceLoader("content");
0055:
0056: protected static Integer seqnum = new Integer(0);
0057: private String m_itemnum;
0058:
0059: // attributes of all resources
0060: protected String m_name;
0061: protected String m_id;
0062: protected String m_type;
0063:
0064: protected SortedSet m_allSiteGroups;
0065: protected SortedSet m_inheritedGroupRefs;
0066: protected SortedSet m_entityGroupRefs;
0067: protected SortedSet m_allowedRemoveGroupRefs;
0068: protected SortedSet m_allowedAddGroupRefs;
0069: protected Map m_allSiteGroupsMap;
0070:
0071: protected boolean m_canRead;
0072: protected boolean m_canRevise;
0073: protected boolean m_canDelete;
0074: protected boolean m_canCopy;
0075: protected boolean m_isCopied;
0076: protected boolean m_canAddItem;
0077: protected boolean m_canAddFolder;
0078: protected boolean m_canSelect;
0079:
0080: protected boolean m_available;
0081:
0082: protected boolean m_inDropbox;
0083:
0084: protected List m_members;
0085: protected boolean m_isEmpty;
0086: protected boolean m_isHighlighted;
0087: protected boolean m_inheritsHighlight;
0088: protected String m_createdBy;
0089: protected String m_createdTime;
0090: protected String m_modifiedBy;
0091: protected String m_modifiedTime;
0092: protected String m_size;
0093: protected String m_target;
0094: protected String m_container;
0095: protected String m_root;
0096: protected int m_depth;
0097: protected boolean m_hasDeletableChildren;
0098: protected boolean m_hasCopyableChildren;
0099: protected boolean m_copyrightAlert;
0100: protected String m_url;
0101: protected boolean m_isLocal;
0102: protected boolean m_isAttached;
0103: private boolean m_isMoved;
0104: private boolean m_canUpdate;
0105: private boolean m_toobig;
0106: protected String m_access;
0107: protected String m_inheritedAccess;
0108: protected Collection m_groups;
0109:
0110: protected Collection m_oldInheritedGroups;
0111: protected Collection m_oldPossibleGroups;
0112: protected BasicRightsAssignment m_rights;
0113:
0114: protected boolean m_pubview;
0115: protected boolean m_pubview_inherited;
0116: protected boolean m_pubview_possible;
0117: protected boolean m_sortable;
0118: protected boolean m_locked = false;
0119:
0120: /**
0121: * @param id
0122: * @param name
0123: * @param type
0124: */
0125: public ResourcesBrowseItem(String id, String name, String type) {
0126: m_name = name;
0127: m_id = id;
0128: m_type = type;
0129:
0130: Integer snum;
0131: synchronized (seqnum) {
0132: snum = seqnum;
0133: seqnum = new Integer((seqnum.intValue() + 1) % 10000);
0134: }
0135: m_itemnum = "Item00000000".substring(0, 10 - snum.toString()
0136: .length())
0137: + snum.toString();
0138:
0139: m_allowedRemoveGroupRefs = new TreeSet();
0140: m_allowedAddGroupRefs = new TreeSet();
0141: m_allSiteGroups = new TreeSet(new Comparator() {
0142: protected final String DELIM = "::";
0143:
0144: public int compare(Object arg0, Object arg1) {
0145: Group group0 = (Group) arg0;
0146: Group group1 = (Group) arg1;
0147: String string0 = group0.getTitle() + DELIM
0148: + group0.getId();
0149: String string1 = group1.getTitle() + DELIM
0150: + group1.getId();
0151:
0152: return string0.compareTo(string1);
0153: }
0154: });
0155: m_entityGroupRefs = new TreeSet();
0156: m_inheritedGroupRefs = new TreeSet();
0157: m_allSiteGroupsMap = new Hashtable();
0158:
0159: // set defaults
0160: m_rights = new BasicRightsAssignment(m_itemnum, false);
0161: m_members = new LinkedList();
0162: m_canRead = false;
0163: m_canRevise = false;
0164: m_canDelete = false;
0165: m_canCopy = false;
0166: m_available = true;
0167: m_isEmpty = true;
0168: m_toobig = false;
0169: m_isCopied = false;
0170: m_isMoved = false;
0171: m_isAttached = false;
0172: m_canSelect = true; // default is true.
0173: m_hasDeletableChildren = false;
0174: m_hasCopyableChildren = false;
0175: m_createdBy = "";
0176: m_modifiedBy = "";
0177: // m_createdTime = TimeService.newTime().toStringLocalDate();
0178: // m_modifiedTime = TimeService.newTime().toStringLocalDate();
0179: m_size = "";
0180: m_depth = 0;
0181: m_copyrightAlert = false;
0182: m_url = "";
0183: m_target = "";
0184: m_root = "";
0185:
0186: m_pubview = false;
0187: m_pubview_inherited = false;
0188: m_pubview_possible = true;
0189:
0190: m_isHighlighted = false;
0191: m_inheritsHighlight = false;
0192:
0193: m_canAddItem = false;
0194: m_canAddFolder = false;
0195: m_canUpdate = false;
0196:
0197: m_access = AccessMode.INHERITED.toString();
0198: m_groups = new Vector();
0199:
0200: }
0201:
0202: public void setLocked(boolean isLocked) {
0203: m_locked = isLocked;
0204:
0205: }
0206:
0207: public boolean isLocked() {
0208: return m_locked;
0209: }
0210:
0211: public String getItemNum() {
0212: return m_itemnum;
0213: }
0214:
0215: public boolean isAvailable() {
0216: return m_available;
0217: }
0218:
0219: public void setAvailable(boolean available) {
0220: m_available = available;
0221: }
0222:
0223: public boolean isInherited(Group group) {
0224: return this .m_inheritedGroupRefs.contains(group.getReference());
0225: }
0226:
0227: public boolean isLocal(Group group) {
0228: return this .m_entityGroupRefs.contains(group.getReference());
0229: }
0230:
0231: public boolean isPossible(Group group) {
0232: boolean rv = false;
0233:
0234: if (AccessMode.GROUPED.toString()
0235: .equals(this .m_inheritedAccess)) {
0236: rv = this .m_inheritedGroupRefs.contains(group
0237: .getReference());
0238: } else {
0239: rv = this .m_allSiteGroupsMap.containsKey(group
0240: .getReference());
0241: }
0242:
0243: return rv;
0244: }
0245:
0246: public boolean allowedRemove(Group group) {
0247: return this .m_allowedRemoveGroupRefs.contains(group
0248: .getReference());
0249: }
0250:
0251: public SortedSet getAllowedRemoveGroupRefs() {
0252: return m_allowedRemoveGroupRefs;
0253: }
0254:
0255: public void setAllowedRemoveGroupRefs(
0256: Collection allowedRemoveGroupRefs) {
0257: importGroupRefs(allowedRemoveGroupRefs,
0258: this .m_allowedRemoveGroupRefs);
0259: }
0260:
0261: public void addAllowedRemoveGroupRef(String allowedRemoveGroupRef) {
0262: addGroupRefToCollection(allowedRemoveGroupRef,
0263: m_allowedRemoveGroupRefs);
0264: }
0265:
0266: public boolean allowedAdd(Group group) {
0267: return this .m_allowedAddGroupRefs
0268: .contains(group.getReference());
0269: }
0270:
0271: public SortedSet getAllowedAddGroupRefs() {
0272: return m_allowedAddGroupRefs;
0273: }
0274:
0275: public void setAllowedAddGroupRefs(Collection allowedAddGroupRefs) {
0276: importGroupRefs(allowedAddGroupRefs, this .m_allowedAddGroupRefs);
0277: }
0278:
0279: public void addAllowedAddGroupRef(String allowedAddGroupRef) {
0280: addGroupRefToCollection(allowedAddGroupRef,
0281: m_allowedAddGroupRefs);
0282: }
0283:
0284: public List getAllSiteGroups() {
0285: return new Vector(m_allSiteGroups);
0286: }
0287:
0288: public void setAllSiteGroups(Collection allSiteGroups) {
0289: this .m_allSiteGroups.clear();
0290: this .m_allSiteGroupsMap.clear();
0291: addAllSiteGroups(allSiteGroups);
0292: }
0293:
0294: public void addAllSiteGroups(Collection allSiteGroups) {
0295: Iterator it = allSiteGroups.iterator();
0296: while (it.hasNext()) {
0297: Group group = (Group) it.next();
0298: if (!m_allSiteGroupsMap.containsKey(group.getReference())) {
0299: this .m_allSiteGroups.add(group);
0300: m_allSiteGroupsMap.put(group.getReference(), group);
0301: m_allSiteGroupsMap.put(group.getId(), group);
0302: }
0303: }
0304: }
0305:
0306: public SortedSet getEntityGroupRefs() {
0307: return m_entityGroupRefs;
0308: }
0309:
0310: public void setEntityGroupRefs(Collection entityGroupRefs) {
0311: importGroupRefs(entityGroupRefs, this .m_entityGroupRefs);
0312: }
0313:
0314: public void addEntityGroupRef(String entityGroupRef) {
0315: addGroupRefToCollection(entityGroupRef, m_entityGroupRefs);
0316: }
0317:
0318: public SortedSet getInheritedGroupRefs() {
0319: return m_inheritedGroupRefs;
0320: }
0321:
0322: public void setInheritedGroupRefs(Collection inheritedGroupRefs) {
0323: importGroupRefs(inheritedGroupRefs, this .m_inheritedGroupRefs);
0324: }
0325:
0326: public void addInheritedGroupRef(String inheritedGroupRef) {
0327: addGroupRefToCollection(inheritedGroupRef, m_inheritedGroupRefs);
0328: }
0329:
0330: protected void importGroupRefs(Collection groupRefs,
0331: Collection collection) {
0332: collection.clear();
0333: Iterator it = groupRefs.iterator();
0334: while (it.hasNext()) {
0335: Object obj = it.next();
0336: if (obj instanceof Group) {
0337: addGroupRefToCollection(((Group) obj).getReference(),
0338: collection);
0339: } else if (obj instanceof String) {
0340: addGroupRefToCollection((String) obj, collection);
0341: }
0342: }
0343: }
0344:
0345: protected void addGroupRefToCollection(String groupRef,
0346: Collection collection) {
0347: Group group = (Group) m_allSiteGroupsMap.get(groupRef);
0348: if (group != null) {
0349: if (!collection.contains(group.getReference())) {
0350: collection.add(group.getReference());
0351: }
0352: }
0353: }
0354:
0355: public void setIsTooBig(boolean toobig) {
0356: m_toobig = toobig;
0357: }
0358:
0359: public boolean isTooBig() {
0360: return m_toobig;
0361: }
0362:
0363: /**
0364: * @param name
0365: */
0366: public void setName(String name) {
0367: m_name = name;
0368: }
0369:
0370: /**
0371: * @param root
0372: */
0373: public void setRoot(String root) {
0374: m_root = root;
0375: }
0376:
0377: /**
0378: * @return
0379: */
0380: public String getRoot() {
0381: return m_root;
0382: }
0383:
0384: /**
0385: * @return
0386: */
0387: public List getMembers() {
0388: List rv = new LinkedList();
0389: if (m_members != null) {
0390: rv.addAll(m_members);
0391: }
0392: return rv;
0393: }
0394:
0395: /**
0396: * @param members
0397: */
0398: public void addMembers(Collection members) {
0399: if (m_members == null) {
0400: m_members = new LinkedList();
0401: }
0402: m_members.addAll(members);
0403: }
0404:
0405: /**
0406: * @return
0407: */
0408: public boolean canAddItem() {
0409: return m_canAddItem;
0410: }
0411:
0412: /**
0413: * @return
0414: */
0415: public boolean canDelete() {
0416: return m_canDelete;
0417: }
0418:
0419: /**
0420: * @return
0421: */
0422: public boolean canRead() {
0423: return m_canRead;
0424: }
0425:
0426: public boolean canSelect() {
0427: return m_canSelect;
0428: }
0429:
0430: /**
0431: * @return
0432: */
0433: public boolean canRevise() {
0434: return m_canRevise;
0435: }
0436:
0437: /**
0438: * @return
0439: */
0440: public String getId() {
0441: return m_id;
0442: }
0443:
0444: /**
0445: * @return
0446: */
0447: public String getName() {
0448: return m_name;
0449: }
0450:
0451: /**
0452: * @return
0453: */
0454: public int getDepth() {
0455: return m_depth;
0456: }
0457:
0458: /**
0459: * @param depth
0460: */
0461: public void setDepth(int depth) {
0462: m_depth = depth;
0463: }
0464:
0465: /**
0466: * @param canCreate
0467: */
0468: public void setCanAddItem(boolean canAddItem) {
0469: m_canAddItem = canAddItem;
0470: }
0471:
0472: /**
0473: * @param canDelete
0474: */
0475: public void setCanDelete(boolean canDelete) {
0476: m_canDelete = canDelete;
0477: }
0478:
0479: /**
0480: * @param canRead
0481: */
0482: public void setCanRead(boolean canRead) {
0483: m_canRead = canRead;
0484: }
0485:
0486: public void setCanSelect(boolean canSelect) {
0487: m_canSelect = canSelect;
0488: }
0489:
0490: /**
0491: * @param canRevise
0492: */
0493: public void setCanRevise(boolean canRevise) {
0494: m_canRevise = canRevise;
0495: }
0496:
0497: /**
0498: * @return
0499: */
0500: public boolean isFolder() {
0501: return ResourceType.TYPE_FOLDER.equals(m_type);
0502: }
0503:
0504: /**
0505: * @return
0506: */
0507: public String getType() {
0508: return m_type;
0509: }
0510:
0511: /**
0512: * @return
0513: */
0514: public boolean canAddFolder() {
0515: return m_canAddFolder;
0516: }
0517:
0518: /**
0519: * @param b
0520: */
0521: public void setCanAddFolder(boolean canAddFolder) {
0522: m_canAddFolder = canAddFolder;
0523: }
0524:
0525: /**
0526: * @return
0527: */
0528: public boolean canCopy() {
0529: return m_canCopy;
0530: }
0531:
0532: /**
0533: * @param canCopy
0534: */
0535: public void setCanCopy(boolean canCopy) {
0536: m_canCopy = canCopy;
0537: }
0538:
0539: /**
0540: * @return
0541: */
0542: public boolean hasCopyrightAlert() {
0543: return m_copyrightAlert;
0544: }
0545:
0546: /**
0547: * @param copyrightAlert
0548: */
0549: public void setCopyrightAlert(boolean copyrightAlert) {
0550: m_copyrightAlert = copyrightAlert;
0551: }
0552:
0553: /**
0554: * @return
0555: */
0556: public String getUrl() {
0557: return m_url;
0558: }
0559:
0560: /**
0561: * @param url
0562: */
0563: public void setUrl(String url) {
0564: m_url = url;
0565: }
0566:
0567: /**
0568: * @return
0569: */
0570: public boolean isCopied() {
0571: return m_isCopied;
0572: }
0573:
0574: /**
0575: * @param isCopied
0576: */
0577: public void setCopied(boolean isCopied) {
0578: m_isCopied = isCopied;
0579: }
0580:
0581: /**
0582: * @return
0583: */
0584: public boolean isMoved() {
0585: return m_isMoved;
0586: }
0587:
0588: /**
0589: * @param isCopied
0590: */
0591: public void setMoved(boolean isMoved) {
0592: m_isMoved = isMoved;
0593: }
0594:
0595: /**
0596: * @return
0597: */
0598: public String getCreatedBy() {
0599: return m_createdBy;
0600: }
0601:
0602: /**
0603: * @return
0604: */
0605: public String getCreatedTime() {
0606: return m_createdTime;
0607: }
0608:
0609: /**
0610: * @return
0611: */
0612: public String getModifiedBy() {
0613: return m_modifiedBy;
0614: }
0615:
0616: /**
0617: * @return
0618: */
0619: public String getModifiedTime() {
0620: return m_modifiedTime;
0621: }
0622:
0623: /**
0624: * @return
0625: */
0626: public String getSize() {
0627: if (m_size == null) {
0628: m_size = "";
0629: }
0630: return m_size;
0631: }
0632:
0633: /**
0634: * @param creator
0635: */
0636: public void setCreatedBy(String creator) {
0637: m_createdBy = creator;
0638: }
0639:
0640: /**
0641: * @param time
0642: */
0643: public void setCreatedTime(String time) {
0644: m_createdTime = time;
0645: }
0646:
0647: /**
0648: * @param modifier
0649: */
0650: public void setModifiedBy(String modifier) {
0651: m_modifiedBy = modifier;
0652: }
0653:
0654: /**
0655: * @param time
0656: */
0657: public void setModifiedTime(String time) {
0658: m_modifiedTime = time;
0659: }
0660:
0661: /**
0662: * @param size
0663: */
0664: public void setSize(String size) {
0665: m_size = size;
0666: }
0667:
0668: /**
0669: * @return
0670: */
0671: public String getTarget() {
0672: return m_target;
0673: }
0674:
0675: /**
0676: * @param target
0677: */
0678: public void setTarget(String target) {
0679: m_target = target;
0680: }
0681:
0682: /**
0683: * @return
0684: */
0685: public boolean isEmpty() {
0686: return m_isEmpty;
0687: }
0688:
0689: /**
0690: * @param isEmpty
0691: */
0692: public void setIsEmpty(boolean isEmpty) {
0693: m_isEmpty = isEmpty;
0694: }
0695:
0696: /**
0697: * @return
0698: */
0699: public String getContainer() {
0700: return m_container;
0701: }
0702:
0703: /**
0704: * @param container
0705: */
0706: public void setContainer(String container) {
0707: m_container = container;
0708: }
0709:
0710: public void setIsLocal(boolean isLocal) {
0711: m_isLocal = isLocal;
0712: }
0713:
0714: public boolean isLocal() {
0715: return m_isLocal;
0716: }
0717:
0718: /**
0719: * @return Returns the isAttached.
0720: */
0721: public boolean isAttached() {
0722: return m_isAttached;
0723: }
0724:
0725: /**
0726: * @param isAttached The isAttached to set.
0727: */
0728: public void setAttached(boolean isAttached) {
0729: this .m_isAttached = isAttached;
0730: }
0731:
0732: /**
0733: * @return Returns the hasCopyableChildren.
0734: */
0735: public boolean hasCopyableChildren() {
0736: return m_hasCopyableChildren;
0737: }
0738:
0739: /**
0740: * @param hasCopyableChildren The hasCopyableChildren to set.
0741: */
0742: public void setCopyableChildren(boolean hasCopyableChildren) {
0743: this .m_hasCopyableChildren = hasCopyableChildren;
0744: }
0745:
0746: /**
0747: * @return Returns the hasDeletableChildren.
0748: */
0749: public boolean hasDeletableChildren() {
0750: return m_hasDeletableChildren;
0751: }
0752:
0753: /**
0754: * @param hasDeletableChildren The hasDeletableChildren to set.
0755: */
0756: public void seDeletableChildren(boolean hasDeletableChildren) {
0757: this .m_hasDeletableChildren = hasDeletableChildren;
0758: }
0759:
0760: /**
0761: * @return Returns the canUpdate.
0762: */
0763: public boolean canUpdate() {
0764: return m_canUpdate;
0765: }
0766:
0767: /**
0768: * @param canUpdate The canUpdate to set.
0769: */
0770: public void setCanUpdate(boolean canUpdate) {
0771: m_canUpdate = canUpdate;
0772: }
0773:
0774: public void setHighlighted(boolean isHighlighted) {
0775: m_isHighlighted = isHighlighted;
0776: }
0777:
0778: public boolean isHighlighted() {
0779: return m_isHighlighted;
0780: }
0781:
0782: public void setInheritsHighlight(boolean inheritsHighlight) {
0783: m_inheritsHighlight = inheritsHighlight;
0784: }
0785:
0786: public boolean inheritsHighlighted() {
0787: return m_inheritsHighlight;
0788: }
0789:
0790: /**
0791: * Access the access mode for this item.
0792: * @return The access mode.
0793: */
0794: public String getAccess() {
0795: return m_access;
0796: }
0797:
0798: /**
0799: * Access the access mode for this item.
0800: * @return The access mode.
0801: */
0802: public String getInheritedAccess() {
0803: return m_inheritedAccess;
0804: }
0805:
0806: public String getEntityAccess() {
0807: String rv = AccessMode.INHERITED.toString();
0808: boolean sameGroups = true;
0809: if (AccessMode.GROUPED.toString().equals(m_access)) {
0810: Iterator it = getGroups().iterator();
0811: while (sameGroups && it.hasNext()) {
0812: Group g = (Group) it.next();
0813: sameGroups = inheritsGroup(g.getReference());
0814: }
0815: it = getInheritedGroups().iterator();
0816: while (sameGroups && it.hasNext()) {
0817: Group g = (Group) it.next();
0818: sameGroups = hasGroup(g.getReference());
0819: }
0820: if (!sameGroups) {
0821: rv = AccessMode.GROUPED.toString();
0822: }
0823: }
0824: return rv;
0825: }
0826:
0827: public String getEffectiveAccess() {
0828: String rv = this .m_access;
0829: if (AccessMode.INHERITED.toString().equals(rv)) {
0830: rv = this .m_inheritedAccess;
0831: }
0832: if (AccessMode.INHERITED.toString().equals(rv)) {
0833: rv = AccessMode.SITE.toString();
0834: }
0835: return rv;
0836: }
0837:
0838: public String getEffectiveGroups() {
0839: String rv = rb.getString("access.site1");
0840:
0841: if (this .isPubviewInherited()) {
0842: rv = rb.getString("access.public1");
0843: } else if (this .isPubview()) {
0844: rv = rb.getString("access.public1");
0845: } else if (this .isInDropbox()) {
0846: rv = rb.getString("access.dropbox1");
0847: } else if (AccessMode.GROUPED.toString().equals(
0848: getEffectiveAccess())) {
0849: rv = (String) rb.getFormattedMessage("access.group1",
0850: new Object[] { getGroupNames() });
0851: }
0852: return rv;
0853: }
0854:
0855: public Collection getPossibleGroups() {
0856: return m_oldPossibleGroups;
0857: }
0858:
0859: public void setPossibleGroups(Collection groups) {
0860: m_oldPossibleGroups = groups;
0861: }
0862:
0863: public String getGroupNames() {
0864: String rv = "";
0865:
0866: Collection groupRefs = this .m_entityGroupRefs;
0867: if (groupRefs == null || groupRefs.isEmpty()) {
0868: groupRefs = this .m_inheritedGroupRefs;
0869: }
0870: Iterator it = groupRefs.iterator();
0871: while (it.hasNext()) {
0872: String groupRef = (String) it.next();
0873: Group group = (Group) this .m_allSiteGroupsMap.get(groupRef);
0874: if (group != null) {
0875: if (rv.length() == 0) {
0876: rv += group.getTitle();
0877: } else {
0878: rv += ", " + group.getTitle();
0879: }
0880: }
0881: }
0882:
0883: // TODO: After updating getBrowserItems, get rid of this part
0884: if (rv.length() == 0) {
0885: Collection groups = getGroups();
0886: if (groups == null || groups.isEmpty()) {
0887: groups = getInheritedGroups();
0888: }
0889:
0890: Iterator grit = groups.iterator();
0891: while (grit.hasNext()) {
0892: Group g = (Group) grit.next();
0893: rv += g.getTitle();
0894: if (grit.hasNext()) {
0895: rv += ", ";
0896: }
0897: }
0898: }
0899:
0900: return rv;
0901: }
0902:
0903: /**
0904: * Set the access mode for this item.
0905: * @param access
0906: */
0907: public void setAccess(String access) {
0908: m_access = access;
0909: }
0910:
0911: /**
0912: * Set the access mode for this item.
0913: * @param access
0914: */
0915: public void setInheritedAccess(String access) {
0916: m_inheritedAccess = access;
0917: }
0918:
0919: /**
0920: * Access a list of Group objects that can access this item.
0921: * @return Returns the groups.
0922: */
0923: public List getGroups() {
0924: if (m_groups == null) {
0925: m_groups = new Vector();
0926: }
0927: return new Vector(m_groups);
0928: }
0929:
0930: /**
0931: * Access a list of Group objects that can access this item.
0932: * @return Returns the groups.
0933: */
0934: public List getInheritedGroups() {
0935: if (m_oldInheritedGroups == null) {
0936: m_oldInheritedGroups = new Vector();
0937: }
0938: return new Vector(m_oldInheritedGroups);
0939: }
0940:
0941: /**
0942: * Determine whether a group has access to this item.
0943: * @param groupRef The internal reference string that uniquely identifies the group.
0944: * @return true if the group has access, false otherwise.
0945: */
0946: public boolean hasGroup(String groupRef) {
0947: if (m_groups == null) {
0948: m_groups = new Vector();
0949: }
0950: boolean found = false;
0951: Iterator it = m_groups.iterator();
0952: while (it.hasNext() && !found) {
0953: Group gr = (Group) it.next();
0954: found = gr.getReference().equals(groupRef);
0955: }
0956:
0957: return found;
0958: }
0959:
0960: /**
0961: * Determine whether a group has access to this item.
0962: * @param groupRef The internal reference string that uniquely identifies the group.
0963: * @return true if the group has access, false otherwise.
0964: */
0965: public boolean inheritsGroup(String groupRef) {
0966: if (m_oldInheritedGroups == null) {
0967: m_oldInheritedGroups = new Vector();
0968: }
0969: boolean found = false;
0970: Iterator it = m_oldInheritedGroups.iterator();
0971: while (it.hasNext() && !found) {
0972: Group gr = (Group) it.next();
0973: found = gr.getReference().equals(groupRef);
0974: }
0975:
0976: return found;
0977: }
0978:
0979: /**
0980: * Replace the current list of groups with this list of Group objects representing the groups that have access to this item.
0981: * @param groups The groups to set.
0982: */
0983: public void setGroups(Collection groups) {
0984: if (groups == null) {
0985: return;
0986: }
0987: if (m_groups == null) {
0988: m_groups = new Vector();
0989: }
0990: m_groups.clear();
0991: Iterator it = groups.iterator();
0992: while (it.hasNext()) {
0993: Object obj = it.next();
0994: if (obj instanceof Group
0995: && !hasGroup(((Group) obj).getReference())) {
0996: m_groups.add(obj);
0997: } else if (obj instanceof String && !hasGroup((String) obj)) {
0998: addGroup((String) obj);
0999: }
1000: }
1001: }
1002:
1003: /**
1004: * Replace the current list of groups with this list of Group objects representing the groups that have access to this item.
1005: * @param groups The groups to set.
1006: */
1007: public void setInheritedGroups(Collection groups) {
1008: if (groups == null) {
1009: return;
1010: }
1011: if (m_oldInheritedGroups == null) {
1012: m_oldInheritedGroups = new Vector();
1013: }
1014: m_oldInheritedGroups.clear();
1015: Iterator it = groups.iterator();
1016: while (it.hasNext()) {
1017: Object obj = it.next();
1018: if (obj instanceof Group
1019: && !inheritsGroup(((Group) obj).getReference())) {
1020: m_oldInheritedGroups.add(obj);
1021: } else if (obj instanceof String && !hasGroup((String) obj)) {
1022: addInheritedGroup((String) obj);
1023: }
1024: }
1025: }
1026:
1027: /**
1028: * Add a string reference identifying a Group to the list of groups that have access to this item.
1029: * @param groupRef
1030: */
1031: public void addGroup(String groupId) {
1032: if (m_groups == null) {
1033: m_groups = new Vector();
1034: }
1035: if (m_container == null) {
1036: if (m_id == null) {
1037: m_container = ContentHostingService
1038: .getSiteCollection(ToolManager
1039: .getCurrentPlacement().getContext());
1040: } else {
1041: m_container = ContentHostingService
1042: .getContainingCollectionId(m_id);
1043: }
1044: if (m_container == null || m_container.trim() == "") {
1045: m_container = ContentHostingService
1046: .getSiteCollection(ToolManager
1047: .getCurrentPlacement().getContext());
1048: }
1049:
1050: }
1051: boolean found = false;
1052: Collection groups = ContentHostingService
1053: .getGroupsWithReadAccess(m_container);
1054: Iterator it = groups.iterator();
1055: while (it.hasNext() && !found) {
1056: Group group = (Group) it.next();
1057: if (group.getId().equals(groupId)) {
1058: if (!hasGroup(group.getReference())) {
1059: m_groups.add(group);
1060: }
1061: found = true;
1062: }
1063: }
1064:
1065: }
1066:
1067: /**
1068: * Add a Group to the list of groups that have access to this item.
1069: * @param group The Group object to be added
1070: */
1071: public void addGroup(Group group) {
1072: if (m_groups == null) {
1073: m_groups = new Vector();
1074: }
1075: if (!hasGroup(group.getReference())) {
1076: m_groups.add(group);
1077: }
1078: }
1079:
1080: /**
1081: * Add a string reference identifying a Group to the list of groups that have access to this item.
1082: * @param groupRef
1083: */
1084: public void addInheritedGroup(String groupId) {
1085: if (m_oldInheritedGroups == null) {
1086: m_oldInheritedGroups = new Vector();
1087: }
1088: if (m_container == null) {
1089: if (m_id == null) {
1090: m_container = ContentHostingService
1091: .getSiteCollection(ToolManager
1092: .getCurrentPlacement().getContext());
1093: } else {
1094: m_container = ContentHostingService
1095: .getContainingCollectionId(m_id);
1096: }
1097: if (m_container == null || m_container.trim() == "") {
1098: m_container = ContentHostingService
1099: .getSiteCollection(ToolManager
1100: .getCurrentPlacement().getContext());
1101: }
1102:
1103: }
1104: boolean found = false;
1105: Collection groups = ContentHostingService
1106: .getGroupsWithReadAccess(m_container);
1107: Iterator it = groups.iterator();
1108: while (it.hasNext() && !found) {
1109: Group group = (Group) it.next();
1110: String gid = group.getId();
1111: String gref = group.getReference();
1112: if (gid.equals(groupId) || gref.equals(groupId)) {
1113: if (!inheritsGroup(group.getReference())) {
1114: m_oldInheritedGroups.add(group);
1115: }
1116: found = true;
1117: }
1118: }
1119:
1120: }
1121:
1122: /**
1123: * Remove all groups from the item.
1124: */
1125: public void clearGroups() {
1126: if (this .m_groups == null) {
1127: m_groups = new Vector();
1128: }
1129: m_groups.clear();
1130: }
1131:
1132: /**
1133: * Remove all inherited groups from the item.
1134: */
1135: public void clearInheritedGroups() {
1136: if (m_oldInheritedGroups == null) {
1137: m_oldInheritedGroups = new Vector();
1138: }
1139: m_oldInheritedGroups.clear();
1140: }
1141:
1142: /**
1143: * @return Returns the pubview.
1144: */
1145: public boolean isPubview() {
1146: return m_pubview;
1147: }
1148:
1149: /**
1150: * @param pubview The pubview to set.
1151: */
1152: public void setPubview(boolean pubview) {
1153: m_pubview = pubview;
1154: }
1155:
1156: /**
1157: * @param pubview The pubview to set.
1158: */
1159: public void setPubviewPossible(boolean possible) {
1160: m_pubview_possible = possible;
1161: }
1162:
1163: /**
1164: * @return Returns the pubviewset.
1165: */
1166: public boolean isPubviewInherited() {
1167: return m_pubview_inherited;
1168: }
1169:
1170: /**
1171: *
1172: *
1173: */
1174: public boolean isPubviewPossible() {
1175: return m_pubview_possible;
1176: }
1177:
1178: /**
1179: * @param pubviewset The pubviewset to set.
1180: */
1181: public void setPubviewInherited(boolean pubviewset) {
1182: m_pubview_inherited = pubviewset;
1183: }
1184:
1185: /**
1186: * @return Returns the rights.
1187: */
1188: public BasicRightsAssignment getRights() {
1189: return m_rights;
1190: }
1191:
1192: /**
1193: * @param rights The rights to set.
1194: */
1195: public void setRights(BasicRightsAssignment rights) {
1196: this .m_rights = rights;
1197: }
1198:
1199: /**
1200: * @return Returns true if the item is in a dropbox (assuming it's been initialized correctly).
1201: */
1202: public boolean isInDropbox() {
1203: return m_inDropbox;
1204: }
1205:
1206: /**
1207: * @param inDropbox The value for inDropbox to set.
1208: */
1209: public void setInDropbox(boolean inDropbox) {
1210: this .m_inDropbox = inDropbox;
1211: }
1212:
1213: public boolean isSortable() {
1214: return m_sortable;
1215: }
1216:
1217: public void setSortable(boolean sortable) {
1218: m_sortable = sortable;
1219: }
1220:
1221: } // inner class ResourcesBrowseItem
|