001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/content/tags/sakai_2-4-1/content-util/util/src/java/org/sakaiproject/content/util/BasicResourceType.java $
003: * $Id: BasicResourceType.java 23027 2007-03-20 01:20:25Z ggolden@umich.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 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.content.util;
021:
022: import java.util.HashMap;
023: import java.util.Iterator;
024: import java.util.List;
025: import java.util.Map;
026: import java.util.Vector;
027:
028: import org.sakaiproject.content.api.ContentEntity;
029: import org.sakaiproject.content.api.ResourceToolAction;
030: import org.sakaiproject.content.api.ResourceType;
031: import org.sakaiproject.content.api.ResourceToolAction.ActionType;
032:
033: /**
034: *
035: *
036: */
037: public class BasicResourceType implements ResourceType {
038: /**
039: * Localizer provides a way for the registrant to take charge of localizing labels
040: * without extending BasicResourceType. In defining types, a registrant can create
041: * instances of BasicResourceType, implement the Localizer interface with methods
042: * that provide localized strings, and set the localizer. Subsequent invocation of
043: * BasicResourceType.getLabel() and BasicResourceType.getLocalizedHoverText(entity)
044: * will use the Localizer to supply labels.
045: */
046: public interface Localizer {
047: /**
048: *
049: * @return
050: */
051: public String getLabel();
052:
053: /**
054: *
055: * @param member
056: * @return
057: */
058: public String getLocalizedHoverText(ContentEntity entity);
059: }
060:
061: protected Map<ActionType, List<ResourceToolAction>> actionTypeMap = new HashMap<ActionType, List<ResourceToolAction>>();
062:
063: protected Map<String, ResourceToolAction> actionIdMap = new HashMap<String, ResourceToolAction>();
064:
065: protected String id;
066:
067: protected String iconLocation;
068:
069: protected Localizer localizer = null;
070:
071: protected boolean hasRightsDialog = true;
072: protected boolean hasPublicDialog = true;
073: protected boolean hasOptionalPropertiesDialog = true;
074: protected boolean hasNotificationDialog = true;
075: protected boolean hasGroupsDialog = true;
076: protected boolean hasDescription = true;
077: protected boolean hasAvailabilityDialog = true;
078:
079: /**
080: *
081: */
082: public BasicResourceType(String id) {
083: this .id = id;
084: }
085:
086: /**
087: *
088: * @param action
089: */
090: public void addAction(ResourceToolAction action) {
091: this .actionIdMap.put(action.getId(), action);
092: List<ResourceToolAction> actionList = this .actionTypeMap
093: .get(action.getActionType());
094: if (actionList == null) {
095: actionList = new Vector<ResourceToolAction>();
096: this .actionTypeMap.put(action.getActionType(), actionList);
097: }
098: actionList.add(action);
099: }
100:
101: /* (non-Javadoc)
102: * @see org.sakaiproject.content.api.ResourceType#getAction(java.lang.String)
103: */
104: public ResourceToolAction getAction(String actionId) {
105: return this .actionIdMap.get(actionId);
106: }
107:
108: /* (non-Javadoc)
109: * @see org.sakaiproject.content.api.ResourceType#getActions(org.sakaiproject.content.api.ResourceToolAction.ActionType)
110: */
111: public List<ResourceToolAction> getActions(ActionType type) {
112: List<ResourceToolAction> rv = new Vector<ResourceToolAction>();
113: if (this .actionTypeMap.get(type) != null) {
114: rv.addAll(this .actionTypeMap.get(type));
115: }
116: return rv;
117: }
118:
119: /* (non-Javadoc)
120: * @see org.sakaiproject.content.api.ResourceType#getActions(java.util.List)
121: */
122: public List<ResourceToolAction> getActions(List<ActionType> types) {
123: List<ResourceToolAction> rv = new Vector<ResourceToolAction>();
124: if (types == null) {
125: return rv;
126: }
127: Iterator<ActionType> typeIt = types.iterator();
128: while (typeIt.hasNext()) {
129: ActionType type = typeIt.next();
130: rv.addAll(getActions(type));
131:
132: }
133: return rv;
134: }
135:
136: /* (non-Javadoc)
137: * @see org.sakaiproject.content.api.ResourceType#getIconLocation()
138: */
139: public String getIconLocation(ContentEntity entity) {
140: return iconLocation;
141: }
142:
143: /* (non-Javadoc)
144: * @see org.sakaiproject.content.api.ResourceType#getId()
145: */
146: public String getId() {
147: return id;
148: }
149:
150: /* (non-Javadoc)
151: * @see org.sakaiproject.content.api.ResourceType#getLabel()
152: */
153: public String getLabel() {
154: String rv = null;
155: if (this .localizer != null) {
156: rv = this .localizer.getLabel();
157: }
158: return rv;
159: }
160:
161: /* (non-Javadoc)
162: * @see org.sakaiproject.content.api.ResourceType#getLocalizedHoverText(org.sakaiproject.content.api.ContentEntity)
163: */
164: public String getLocalizedHoverText(ContentEntity entity) {
165: String rv = null;
166: if (this .localizer != null) {
167: rv = this .localizer.getLocalizedHoverText(entity);
168: }
169: return rv;
170: }
171:
172: /* (non-Javadoc)
173: * @see org.sakaiproject.content.api.ResourceType#hasAvailabilityDialog()
174: */
175: public boolean hasAvailabilityDialog() {
176: return hasAvailabilityDialog;
177: }
178:
179: /* (non-Javadoc)
180: * @see org.sakaiproject.content.api.ResourceType#hasDescription()
181: */
182: public boolean hasDescription() {
183: return hasDescription;
184: }
185:
186: /* (non-Javadoc)
187: * @see org.sakaiproject.content.api.ResourceType#hasGroupsDialog()
188: */
189: public boolean hasGroupsDialog() {
190: return hasGroupsDialog;
191: }
192:
193: /* (non-Javadoc)
194: * @see org.sakaiproject.content.api.ResourceType#hasNotificationDialog()
195: */
196: public boolean hasNotificationDialog() {
197: return hasNotificationDialog;
198: }
199:
200: /* (non-Javadoc)
201: * @see org.sakaiproject.content.api.ResourceType#hasOptionalPropertiesDialog()
202: */
203: public boolean hasOptionalPropertiesDialog() {
204: return hasOptionalPropertiesDialog;
205: }
206:
207: /* (non-Javadoc)
208: * @see org.sakaiproject.content.api.ResourceType#hasPublicDialog()
209: */
210: public boolean hasPublicDialog() {
211: return hasPublicDialog;
212: }
213:
214: /* (non-Javadoc)
215: * @see org.sakaiproject.content.api.ResourceType#hasRightsDialog()
216: */
217: public boolean hasRightsDialog() {
218: return hasRightsDialog;
219: }
220:
221: /**
222: * @param hasAvailabilityDialog the hasAvailabilityDialog to set
223: */
224: public void setHasAvailabilityDialog(boolean hasAvailabilityDialog) {
225: this .hasAvailabilityDialog = hasAvailabilityDialog;
226: }
227:
228: /**
229: * @param hasDescription the hasDescription to set
230: */
231: public void setHasDescription(boolean hasDescription) {
232: this .hasDescription = hasDescription;
233: }
234:
235: /**
236: * @param hasGroupsDialog the hasGroupsDialog to set
237: */
238: public void setHasGroupsDialog(boolean hasGroupsDialog) {
239: this .hasGroupsDialog = hasGroupsDialog;
240: }
241:
242: /**
243: * @param hasNotificationDialog the hasNotificationDialog to set
244: */
245: public void setHasNotificationDialog(boolean hasNotificationDialog) {
246: this .hasNotificationDialog = hasNotificationDialog;
247: }
248:
249: /**
250: * @param hasOptionalPropertiesDialog the hasOptionalPropertiesDialog to set
251: */
252: public void setHasOptionalPropertiesDialog(
253: boolean hasOptionalPropertiesDialog) {
254: this .hasOptionalPropertiesDialog = hasOptionalPropertiesDialog;
255: }
256:
257: /**
258: * @param hasPublicDialog the hasPublicDialog to set
259: */
260: public void setHasPublicDialog(boolean hasPublicDialog) {
261: this .hasPublicDialog = hasPublicDialog;
262: }
263:
264: /**
265: * @param hasRightsDialog the hasRightsDialog to set
266: */
267: public void setHasRightsDialog(boolean hasRightsDialog) {
268: this .hasRightsDialog = hasRightsDialog;
269: }
270:
271: /**
272: * @param iconLocation the iconLocation to set
273: */
274: public void setIconLocation(String iconLocation) {
275: this .iconLocation = iconLocation;
276: }
277:
278: /**
279: * @param id the id to set
280: */
281: public void setId(String id) {
282: this .id = id;
283: }
284:
285: /**
286: * @param localizer the localizer to set
287: */
288: public void setLocalizer(Localizer localizer) {
289: this.localizer = localizer;
290: }
291:
292: }
|