001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/content/tags/sakai_2-4-1/content-tool/tool/src/java/org/sakaiproject/content/tool/ResourcesItem.java $
003: * $Id: ResourcesItem.java 22517 2007-03-13 02:56:22Z jimeng@umich.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2007 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.tool;
021:
022: import java.util.Collection;
023: import java.util.Hashtable;
024: import java.util.List;
025: import java.util.Map;
026: import java.util.Set;
027: import java.util.TreeSet;
028: import java.util.Vector;
029:
030: import org.sakaiproject.content.api.ContentCollection;
031: import org.sakaiproject.content.api.ContentEntity;
032: import org.sakaiproject.content.api.ContentResource;
033: import org.sakaiproject.content.api.ResourceToolActionPipe;
034: import org.sakaiproject.content.api.GroupAwareEntity.AccessMode;
035: import org.sakaiproject.entity.api.EntityPropertyNotDefinedException;
036: import org.sakaiproject.entity.api.EntityPropertyTypeException;
037: import org.sakaiproject.entity.api.ResourceProperties;
038: import org.sakaiproject.exception.ServerOverloadException;
039: import org.sakaiproject.time.api.Time;
040:
041: public class ResourcesItem {
042: protected byte[] content;
043: protected String contentType;
044: protected String resourceType;
045: protected boolean collection = false;
046: protected AccessMode accessMode = AccessMode.INHERITED;
047: protected String createdBy;
048: protected Time createdTime;
049: protected String displayName;
050: protected String entityId;
051: protected String collectionId;
052: protected String siteCollectionId;
053: protected Set groups;
054: protected String modifiedBy;
055: protected Time modifiedTime;
056: protected Map propertyValues = new Hashtable();
057: protected int prioritySortOrder;
058: protected Time retractDate;
059: protected String uuid;
060: protected int version;
061: protected boolean hasPrioritySort = false;
062: protected boolean hidden = false;
063: protected Time releaseDate;
064: protected int notification;
065: protected boolean hasQuota = false;
066: protected boolean canSetQuota = false;
067: protected String quota;
068: protected String description;
069: protected boolean useReleaseDate;
070: protected boolean useRetractDate;
071: protected String copyrightStatus;
072: protected String copyrightInfo;
073: protected boolean copyrightAlert = false;
074:
075: /**
076: * @param entityId
077: * @param collectionId
078: * @param propertyValues
079: * @param resourceType
080: */
081: public ResourcesItem(String entityId, String collectionId,
082: String resourceType, Map propertyValues) {
083: super ();
084: this .entityId = entityId;
085: this .collectionId = collectionId;
086: this .resourceType = resourceType;
087: if (propertyValues != null) {
088: this .propertyValues.putAll(propertyValues);
089: }
090: }
091:
092: public ResourcesItem(ContentEntity entity) {
093: ResourceProperties props = entity.getProperties();
094: this .accessMode = entity.getAccess();
095: //this.canSetQuota =
096: //this.collection =
097: this .collectionId = entity.getContainingCollection().getId();
098: this .createdBy = props
099: .getProperty(ResourceProperties.PROP_CREATOR);
100: this .modifiedBy = props
101: .getProperty(ResourceProperties.PROP_MODIFIED_BY);
102: try {
103: this .createdTime = props
104: .getTimeProperty(ResourceProperties.PROP_CREATION_DATE);
105: this .modifiedTime = props
106: .getTimeProperty(ResourceProperties.PROP_MODIFIED_DATE);
107: } catch (EntityPropertyNotDefinedException e1) {
108: // TODO Auto-generated catch block
109: ResourcesAction.logger
110: .warn("EntityPropertyNotDefinedException for createdTime or modifiedTime of "
111: + this .entityId);
112: } catch (EntityPropertyTypeException e1) {
113: // TODO Auto-generated catch block
114: ResourcesAction.logger
115: .warn("EntityPropertyTypeException for createdTime or modifiedTime of "
116: + this .entityId);
117: }
118: this .displayName = props
119: .getProperty(ResourceProperties.PROP_DISPLAY_NAME);
120: this .description = props
121: .getProperty(ResourceProperties.PROP_DESCRIPTION);
122: this .entityId = entity.getId();
123: this .groups = new TreeSet(entity.getGroupObjects());
124: // this.hasQuota =
125: this .hidden = entity.isHidden();
126: // this.notification = entity.
127: // this.prioritySortOrder = props.getLongProperty()
128: // this.propertyValues = props;
129: // this.quota =
130: this .releaseDate = entity.getReleaseDate();
131: this .retractDate = entity.getRetractDate();
132: this .useReleaseDate = (this .releaseDate != null);
133: this .useRetractDate = (this .retractDate != null);
134: this .resourceType = entity.getResourceType();
135: // this.siteCollectionId =
136: // this.version
137:
138: if (entity.isCollection()) {
139: ContentCollection collection = (ContentCollection) entity;
140: // this.hasPrioritySort = collection.;
141: this .collection = true;
142: } else {
143: this .collection = false;
144: ContentResource resource = (ContentResource) entity;
145: try {
146: this .content = resource.getContent();
147: } catch (ServerOverloadException e) {
148: // TODO Auto-generated catch block
149: ResourcesAction.logger.warn("ServerOverloadException ",
150: e);
151: }
152: this .copyrightStatus = props
153: .getProperty(ResourceProperties.PROP_COPYRIGHT_CHOICE);
154: this .copyrightInfo = props
155: .getProperty(ResourceProperties.PROP_COPYRIGHT);
156: String crAlert = props
157: .getProperty(ResourceProperties.PROP_COPYRIGHT_ALERT);
158: if (crAlert != null
159: && Boolean.TRUE.toString()
160: .equalsIgnoreCase(crAlert)) {
161: this .copyrightAlert = true;
162: } else {
163: this .copyrightAlert = false;
164: }
165:
166: // this.uuid = resource.
167: }
168: }
169:
170: public ResourcesItem(String entityId, String collectionId,
171: String resourceType, ResourceToolActionPipe pipe) {
172: super ();
173: this .entityId = entityId;
174: this .collectionId = collectionId;
175: this .resourceType = resourceType;
176: this .content = pipe.getContent();
177: this .propertyValues.putAll(pipe.getRevisedResourceProperties());
178:
179: if (pipe.getRevisedMimeType() == null) {
180: // this.propertyValues.remove(ResourceProperties.PROP_CONTENT_TYPE);
181: } else {
182: this .propertyValues.put(
183: ResourceProperties.PROP_CONTENT_TYPE, pipe
184: .getRevisedMimeType());
185: }
186: }
187:
188: public void update(ResourceToolActionPipe pipe) {
189: // TODO: update the ResourcesItem based on the pipe
190: }
191:
192: /**
193: * @return the useRetractDate
194: */
195: public boolean useRetractDate() {
196: return this .useRetractDate;
197: }
198:
199: /**
200: * @param useRetractDate the useRetractDate to set
201: */
202: public void setUseRetractDate(boolean useRetractDate) {
203: this .useRetractDate = useRetractDate;
204: }
205:
206: /**
207: * @return the useReleaseDate
208: */
209: public boolean useReleaseDate() {
210: return this .useReleaseDate;
211: }
212:
213: /**
214: * @param useReleaseDate the useReleaseDate to set
215: */
216: public void setUseReleaseDate(boolean useReleaseDate) {
217: this .useReleaseDate = useReleaseDate;
218: }
219:
220: /**
221: * @return the description
222: */
223: public String getDescription() {
224: return this .description;
225: }
226:
227: /**
228: * @param description the description to set
229: */
230: public void setDescription(String description) {
231: this .description = description;
232: }
233:
234: /**
235: * @return the accessMode
236: */
237: public AccessMode getAccessMode() {
238: return this .accessMode;
239: }
240:
241: /**
242: * @param accessMode the accessMode to set
243: */
244: public void setAccessMode(AccessMode accessMode) {
245: this .accessMode = accessMode;
246: }
247:
248: /**
249: * @return the canSetQuota
250: */
251: public boolean isCanSetQuota() {
252: return this .canSetQuota;
253: }
254:
255: /**
256: * @param canSetQuota the canSetQuota to set
257: */
258: public void setCanSetQuota(boolean canSetQuota) {
259: this .canSetQuota = canSetQuota;
260: }
261:
262: /**
263: * @return the collection
264: */
265: public boolean isCollection() {
266: return this .collection;
267: }
268:
269: /**
270: * @param collection the collection to set
271: */
272: public void setCollection(boolean collection) {
273: this .collection = collection;
274: }
275:
276: /**
277: * @return the collectionId
278: */
279: public String getCollectionId() {
280: return this .collectionId;
281: }
282:
283: /**
284: * @param collectionId the collectionId to set
285: */
286: public void setCollectionId(String collectionId) {
287: this .collectionId = collectionId;
288: }
289:
290: /**
291: * @return the content
292: */
293: public byte[] getContent() {
294: return this .content;
295: }
296:
297: /**
298: * @param content the content to set
299: */
300: public void setContent(byte[] content) {
301: this .content = content;
302: }
303:
304: /**
305: * @return the createdBy
306: */
307: public String getCreatedBy() {
308: return this .createdBy;
309: }
310:
311: /**
312: * @param createdBy the createdBy to set
313: */
314: public void setCreatedBy(String createdBy) {
315: this .createdBy = createdBy;
316: }
317:
318: /**
319: * @return the createdTime
320: */
321: public Time getCreatedTime() {
322: return this .createdTime;
323: }
324:
325: /**
326: * @param createdTime the createdTime to set
327: */
328: public void setCreatedTime(Time createdTime) {
329: this .createdTime = createdTime;
330: }
331:
332: /**
333: * @return the displayName
334: */
335: public String getDisplayName() {
336: return this .displayName;
337: }
338:
339: /**
340: * @param displayName the displayName to set
341: */
342: public void setDisplayName(String displayName) {
343: this .displayName = displayName;
344: }
345:
346: /**
347: * @return the entityId
348: */
349: public String getEntityId() {
350: return this .entityId;
351: }
352:
353: /**
354: * @param entityId the entityId to set
355: */
356: public void setEntityId(String entityId) {
357: this .entityId = entityId;
358: }
359:
360: /**
361: * @return the groups
362: */
363: public Set getGroups() {
364: return this .groups;
365: }
366:
367: /**
368: * @param groups the groups to set
369: */
370: public void setGroups(Set groups) {
371: this .groups = groups;
372: }
373:
374: /**
375: * @return the hasPrioritySort
376: */
377: public boolean hasPrioritySort() {
378: return this .hasPrioritySort;
379: }
380:
381: /**
382: * @param hasPrioritySort the hasPrioritySort to set
383: */
384: public void setHasPrioritySort(boolean hasPrioritySort) {
385: this .hasPrioritySort = hasPrioritySort;
386: }
387:
388: /**
389: * @return the hasQuota
390: */
391: public boolean hasQuota() {
392: return this .hasQuota;
393: }
394:
395: /**
396: * @param hasQuota the hasQuota to set
397: */
398: public void setHasQuota(boolean hasQuota) {
399: this .hasQuota = hasQuota;
400: }
401:
402: /**
403: * @return the hidden
404: */
405: public boolean isHidden() {
406: return this .hidden;
407: }
408:
409: /**
410: * @param hidden the hidden to set
411: */
412: public void setHidden(boolean hidden) {
413: this .hidden = hidden;
414: }
415:
416: /**
417: * @return the modifiedBy
418: */
419: public String getModifiedBy() {
420: return this .modifiedBy;
421: }
422:
423: /**
424: * @param modifiedBy the modifiedBy to set
425: */
426: public void setModifiedBy(String modifiedBy) {
427: this .modifiedBy = modifiedBy;
428: }
429:
430: /**
431: * @return the modifiedTime
432: */
433: public Time getModifiedTime() {
434: return this .modifiedTime;
435: }
436:
437: /**
438: * @param modifiedTime the modifiedTime to set
439: */
440: public void setModifiedTime(Time modifiedTime) {
441: this .modifiedTime = modifiedTime;
442: }
443:
444: /**
445: * @return the notification
446: */
447: public int getNotification() {
448: return this .notification;
449: }
450:
451: /**
452: * @param notification the notification to set
453: */
454: public void setNotification(int notification) {
455: this .notification = notification;
456: }
457:
458: /**
459: * @return the prioritySortOrder
460: */
461: public int getPrioritySortOrder() {
462: return this .prioritySortOrder;
463: }
464:
465: /**
466: * @param prioritySortOrder the prioritySortOrder to set
467: */
468: public void setPrioritySortOrder(int prioritySortOrder) {
469: this .prioritySortOrder = prioritySortOrder;
470: }
471:
472: /**
473: * @param name
474: * @return
475: */
476: public String getPropertyValue(String name) {
477: String rv = null;
478: Object value = this .propertyValues.get(name);
479: if (value == null) {
480: // do nothing, return null
481: } else if (value instanceof String) {
482: rv = (String) value;
483: } else if (value instanceof List) {
484: List list = (List) value;
485: if (list.isEmpty()) {
486: // do nothing, return null
487: } else {
488: rv = (String) list.get(0);
489: }
490: }
491: return rv;
492: }
493:
494: /**
495: * @param name
496: * @return
497: */
498: public List getPropertyValues(String name) {
499: List rv = new Vector();
500: Object value = this .propertyValues.get(name);
501: if (value == null) {
502: // do nothing, return empty list
503: } else if (value instanceof String) {
504: rv.add(value);
505: } else if (value instanceof List) {
506: rv.addAll((Collection) value);
507: }
508: return rv;
509: }
510:
511: /**
512: * @param name
513: * @param value
514: */
515: public void setPropertyValue(String name, List value) {
516: this .propertyValues.put(name, value);
517: }
518:
519: /**
520: * @param name
521: * @param index
522: * @param value
523: */
524: public void setPropertyValue(String name, int index, String value) {
525: Object obj = this .propertyValues.get(name);
526: if (obj != null && obj instanceof List) {
527: List list = (List) obj;
528: if (index < 0) {
529: // throw exception??
530: } else if (index < list.size()) {
531: list.add(index, value);
532: } else if (index == list.size()) {
533: list.add(value);
534: } else {
535: // throw exception??
536: }
537: } else {
538: if (index > 0) {
539: // throw exception??
540: } else {
541: List list = new Vector();
542: this .propertyValues.put(name, list);
543: list.add(value);
544: }
545: }
546: }
547:
548: /**
549: * @return the propertyValues
550: */
551: public Map getPropertyValues() {
552: return this .propertyValues;
553: }
554:
555: /**
556: * @param propertyValues the propertyValues to set
557: */
558: public void setPropertyValues(Map propertyValues) {
559: this .propertyValues = propertyValues;
560: }
561:
562: /**
563: * @return the quota
564: */
565: public String getQuota() {
566: return this .quota;
567: }
568:
569: /**
570: * @param quota the quota to set
571: */
572: public void setQuota(String quota) {
573: this .quota = quota;
574: }
575:
576: /**
577: * @return the releaseDate
578: */
579: public Time getReleaseDate() {
580: return this .releaseDate;
581: }
582:
583: /**
584: * @param releaseDate the releaseDate to set
585: */
586: public void setReleaseDate(Time releaseDate) {
587: this .releaseDate = releaseDate;
588: }
589:
590: /**
591: * @return the resourceType
592: */
593: public String getResourceType() {
594: return this .resourceType;
595: }
596:
597: /**
598: * @param resourceType the resourceType to set
599: */
600: public void setResourceType(String resourceType) {
601: this .resourceType = resourceType;
602: }
603:
604: /**
605: * @return the retractDate
606: */
607: public Time getRetractDate() {
608: return this .retractDate;
609: }
610:
611: /**
612: * @param retractDate the retractDate to set
613: */
614: public void setRetractDate(Time retractDate) {
615: this .retractDate = retractDate;
616: }
617:
618: /**
619: * @return the siteCollectionId
620: */
621: public String getSiteCollectionId() {
622: return this .siteCollectionId;
623: }
624:
625: /**
626: * @param siteCollectionId the siteCollectionId to set
627: */
628: public void setSiteCollectionId(String siteCollectionId) {
629: this .siteCollectionId = siteCollectionId;
630: }
631:
632: /**
633: * @return the uuid
634: */
635: public String getUuid() {
636: return this .uuid;
637: }
638:
639: /**
640: * @param uuid the uuid to set
641: */
642: public void setUuid(String uuid) {
643: this .uuid = uuid;
644: }
645:
646: /**
647: * @return the version
648: */
649: public int getVersion() {
650: return this .version;
651: }
652:
653: /**
654: * @param version the version to set
655: */
656: public void setVersion(int version) {
657: this .version = version;
658: }
659:
660: /**
661: * @return the copyrightAlert
662: */
663: public boolean hasCopyrightAlert() {
664: return copyrightAlert;
665: }
666:
667: /**
668: * @param copyrightAlert the copyrightAlert to set
669: */
670: public void setCopyrightAlert(boolean copyrightAlert) {
671: this .copyrightAlert = copyrightAlert;
672: }
673:
674: /**
675: * @return the copyrightInfo
676: */
677: public String getCopyrightInfo() {
678: return copyrightInfo;
679: }
680:
681: /**
682: * @param copyrightInfo the copyrightInfo to set
683: */
684: public void setCopyrightInfo(String copyrightInfo) {
685: this .copyrightInfo = copyrightInfo;
686: }
687:
688: /**
689: * @return the copyrightStatus
690: */
691: public String getCopyrightStatus() {
692: return copyrightStatus;
693: }
694:
695: /**
696: * @param copyrightStatus the copyrightStatus to set
697: */
698: public void setCopyrightStatus(String copyrightStatus) {
699: this .copyrightStatus = copyrightStatus;
700: }
701:
702: /**
703: * @return the contentType
704: */
705: public String getContentType() {
706: return contentType;
707: }
708:
709: /**
710: * @param contentType the contentType to set
711: */
712: public void setContentType(String contentType) {
713: this.contentType = contentType;
714: }
715:
716: }
|