001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/calendar/tags/sakai_2-4-1/mergedlist-util/util/src/java/org/sakaiproject/util/MergedListEntryProviderBase.java $
003: * $Id: MergedListEntryProviderBase.java 8050 2006-04-20 17:39:55Z ggolden@umich.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2003, 2004, 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.util;
021:
022: import java.util.ArrayList;
023: import java.util.Iterator;
024: import java.util.List;
025:
026: import org.sakaiproject.exception.IdUnusedException;
027: import org.sakaiproject.site.api.Site;
028: import org.sakaiproject.site.cover.SiteService;
029:
030: /**
031: * Collects common functionality between MergedListEntry providers.
032: */
033: public abstract class MergedListEntryProviderBase implements
034: MergedList.EntryProvider {
035: /* (non-Javadoc)
036: * @see org.sakaiproject.util.MergedList.EntryProvider#isUserChannel(java.lang.Object)
037: */
038: public boolean isUserChannel(Object channel) {
039: String context = getContext(channel);
040:
041: return (context == null ? false : SiteService
042: .isUserSite(context));
043: }
044:
045: /* (non-Javadoc)
046: * @see org.sakaiproject.util.MergedList.EntryProvider#isSpecialSite(java.lang.Object)
047: */
048: public boolean isSpecialSite(Object channel) {
049: String context = getContext(channel);
050:
051: return (context == null ? true : SiteService
052: .isSpecialSite(context));
053: }
054:
055: /* (non-Javadoc)
056: * @see org.sakaiproject.util.MergedList.EntryProvider#getSiteUserId(java.lang.Object)
057: */
058: public String getSiteUserId(Object channel) {
059: String context = getContext(channel);
060:
061: return (context == null ? "" : SiteService
062: .getSiteUserId(context));
063: }
064:
065: /* (non-Javadoc)
066: * @see org.sakaiproject.util.MergedList.EntryProvider#getSite(java.lang.Object)
067: */
068: public Site getSite(Object channel) {
069: try {
070: String context = getContext(channel);
071:
072: return (context == null ? null : SiteService
073: .getSite(context));
074: }
075:
076: catch (IdUnusedException e) {
077: return null;
078: }
079: }
080:
081: /* (non-Javadoc)
082: * @see org.chefproject.actions.MergedEntryList.EntryProvider#getIterator()
083: */
084: public Iterator getIterator() {
085: List siteList = SiteService
086: .getSites(
087: org.sakaiproject.site.api.SiteService.SelectionType.ACCESS,
088: null,
089: null,
090: null,
091: org.sakaiproject.site.api.SiteService.SortType.TITLE_ASC,
092: null);
093:
094: List objectList = new ArrayList();
095:
096: Iterator it = siteList.iterator();
097:
098: while (it.hasNext()) {
099: Site curSite = (Site) it.next();
100:
101: if (curSite != null) {
102: Object object = makeObjectFromSiteId(curSite.getId());
103:
104: if (object != null) {
105: objectList.add(object);
106: }
107: }
108: }
109:
110: return objectList.iterator();
111: }
112:
113: /**
114: * Make a channel/calendar/etc. in an generic way.
115: */
116: public abstract Object makeObjectFromSiteId(String siteId);
117: }
|