001: /**********************************************************************************
002: * $URL: $
003: * $Id: $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2006, 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.types;
021:
022: import java.util.EnumMap;
023: import java.util.Hashtable;
024: import java.util.Iterator;
025: import java.util.List;
026: import java.util.Map;
027: import java.util.Set;
028: import java.util.Vector;
029:
030: import javax.servlet.http.HttpServletRequest;
031:
032: import org.sakaiproject.component.cover.ComponentManager;
033: import org.sakaiproject.content.api.ContentEntity;
034: import org.sakaiproject.content.api.InteractionAction;
035: import org.sakaiproject.content.api.ResourceToolAction;
036: import org.sakaiproject.content.api.ResourceToolActionPipe;
037: import org.sakaiproject.content.api.ResourceType;
038: import org.sakaiproject.content.api.ServiceLevelAction;
039: import org.sakaiproject.content.api.ResourceToolAction.ActionType;
040: import org.sakaiproject.content.util.BaseResourceType;
041: import org.sakaiproject.content.types.FileUploadType.FileUploadAccessAction;
042: import org.sakaiproject.content.types.FileUploadType.FileUploadCopyAction;
043: import org.sakaiproject.content.types.FileUploadType.FileUploadCreateAction;
044: import org.sakaiproject.content.types.FileUploadType.FileUploadDeleteAction;
045: import org.sakaiproject.content.types.FileUploadType.FileUploadDuplicateAction;
046: import org.sakaiproject.content.types.FileUploadType.FileUploadMoveAction;
047: import org.sakaiproject.content.types.FileUploadType.FileUploadReviseAction;
048: import org.sakaiproject.entity.api.Reference;
049: import org.sakaiproject.entity.api.ResourceProperties;
050: import org.sakaiproject.user.api.User;
051: import org.sakaiproject.user.api.UserDirectoryService;
052: import org.sakaiproject.util.ResourceLoader;
053:
054: public class HtmlDocumentType extends BaseResourceType {
055: /** Resource bundle using current language locale */
056: private static ResourceLoader rb = new ResourceLoader("types");
057:
058: protected EnumMap<ResourceToolAction.ActionType, List<ResourceToolAction>> actionMap = new EnumMap<ResourceToolAction.ActionType, List<ResourceToolAction>>(
059: ResourceToolAction.ActionType.class);
060:
061: protected Map<String, ResourceToolAction> actions = new Hashtable<String, ResourceToolAction>();
062: protected UserDirectoryService userDirectoryService;
063:
064: protected String typeId = ResourceType.TYPE_HTML;
065: protected String helperId = "sakai.resource.type.helper";
066:
067: public class HtmlDocumentReplaceAction implements InteractionAction {
068: public boolean available(ContentEntity entity) {
069: return true;
070: }
071:
072: public ActionType getActionType() {
073: return ResourceToolAction.ActionType.REPLACE_CONTENT;
074: }
075:
076: public String getId() {
077: return ResourceToolAction.REPLACE_CONTENT;
078: }
079:
080: public String getLabel() {
081: return rb.getString("action.replace");
082: }
083:
084: public String getTypeId() {
085: return typeId;
086: }
087:
088: public void cancelAction(Reference reference,
089: String initializationId) {
090:
091: }
092:
093: public void finalizeAction(Reference reference,
094: String initializationId) {
095:
096: }
097:
098: public String getHelperId() {
099: return helperId;
100: }
101:
102: public List getRequiredPropertyKeys() {
103: List<String> rv = new Vector<String>();
104: rv.add(ResourceProperties.PROP_CONTENT_ENCODING);
105: return rv;
106: }
107:
108: public String initializeAction(Reference reference) {
109: return null;
110: }
111: }
112:
113: public class HtmlDocumentPropertiesAction implements
114: ServiceLevelAction {
115: /* (non-Javadoc)
116: * @see org.sakaiproject.content.api.ResourceToolAction#available(java.lang.String)
117: */
118: public boolean available(ContentEntity entity) {
119: return true;
120: }
121:
122: /* (non-Javadoc)
123: * @see org.sakaiproject.content.api.ServiceLevelAction#cancelAction(org.sakaiproject.entity.api.Reference)
124: */
125: public void cancelAction(Reference reference) {
126: // TODO Auto-generated method stub
127:
128: }
129:
130: /* (non-Javadoc)
131: * @see org.sakaiproject.content.api.ServiceLevelAction#finalizeAction(org.sakaiproject.entity.api.Reference)
132: */
133: public void finalizeAction(Reference reference) {
134: // TODO Auto-generated method stub
135:
136: }
137:
138: /* (non-Javadoc)
139: * @see org.sakaiproject.content.api.ServiceLevelAction#initializeAction(org.sakaiproject.entity.api.Reference)
140: */
141: public void initializeAction(Reference reference) {
142: // TODO Auto-generated method stub
143:
144: }
145:
146: /* (non-Javadoc)
147: * @see org.sakaiproject.content.api.ServiceLevelAction#isMultipleItemAction()
148: */
149: public boolean isMultipleItemAction() {
150: // TODO Auto-generated method stub
151: return false;
152: }
153:
154: /* (non-Javadoc)
155: * @see org.sakaiproject.content.api.ResourceToolAction#getActionType()
156: */
157: public ActionType getActionType() {
158: // TODO Auto-generated method stub
159: return ResourceToolAction.ActionType.REVISE_METADATA;
160: }
161:
162: /* (non-Javadoc)
163: * @see org.sakaiproject.content.api.ResourceToolAction#getId()
164: */
165: public String getId() {
166: // TODO Auto-generated method stub
167: return ResourceToolAction.REVISE_METADATA;
168: }
169:
170: /* (non-Javadoc)
171: * @see org.sakaiproject.content.api.ResourceToolAction#getLabel()
172: */
173: public String getLabel() {
174: // TODO Auto-generated method stub
175: return rb.getString("action.props");
176: }
177:
178: /* (non-Javadoc)
179: * @see org.sakaiproject.content.api.ResourceToolAction#getTypeId()
180: */
181: public String getTypeId() {
182: // TODO Auto-generated method stub
183: return typeId;
184: }
185:
186: }
187:
188: public class HtmlDocumentCopyAction implements ServiceLevelAction {
189: /* (non-Javadoc)
190: * @see org.sakaiproject.content.api.ResourceToolAction#available(java.lang.String)
191: */
192: public boolean available(ContentEntity entity) {
193: return true;
194: }
195:
196: /* (non-Javadoc)
197: * @see org.sakaiproject.content.api.ResourceToolAction#getActionType()
198: */
199: public ActionType getActionType() {
200: return ResourceToolAction.ActionType.COPY;
201: }
202:
203: public String getId() {
204: return ResourceToolAction.COPY;
205: }
206:
207: public String getLabel() {
208: return rb.getString("action.copy");
209: }
210:
211: public boolean isMultipleItemAction() {
212: return true;
213: }
214:
215: public String getTypeId() {
216: return typeId;
217: }
218:
219: /* (non-Javadoc)
220: * @see org.sakaiproject.content.api.ServiceLevelAction#cancelAction(org.sakaiproject.entity.api.Reference)
221: */
222: public void cancelAction(Reference reference) {
223: // TODO Auto-generated method stub
224:
225: }
226:
227: /* (non-Javadoc)
228: * @see org.sakaiproject.content.api.ServiceLevelAction#finalizeAction(org.sakaiproject.entity.api.Reference)
229: */
230: public void finalizeAction(Reference reference) {
231: // TODO Auto-generated method stub
232:
233: }
234:
235: /* (non-Javadoc)
236: * @see org.sakaiproject.content.api.ServiceLevelAction#initializeAction(org.sakaiproject.entity.api.Reference)
237: */
238: public void initializeAction(Reference reference) {
239: // TODO Auto-generated method stub
240:
241: }
242:
243: }
244:
245: public class HtmlDocumentCreateAction implements InteractionAction {
246: /* (non-Javadoc)
247: * @see org.sakaiproject.content.api.ResourceToolAction#available(java.lang.String)
248: */
249: public boolean available(ContentEntity entity) {
250: return true;
251: }
252:
253: public String initializeAction(Reference reference) {
254: return null;
255: }
256:
257: public void cancelAction(Reference reference,
258: String initializationId) {
259: // TODO Auto-generated method stub
260:
261: }
262:
263: public void finalizeAction(Reference reference,
264: String initializationId) {
265: // TODO Auto-generated method stub
266:
267: }
268:
269: /* (non-Javadoc)
270: * @see org.sakaiproject.content.api.ResourceToolAction#getActionType()
271: */
272: public ActionType getActionType() {
273: return ResourceToolAction.ActionType.CREATE;
274: }
275:
276: public String getId() {
277: return ResourceToolAction.CREATE;
278: }
279:
280: public String getLabel() {
281: return rb.getString("create.html");
282: }
283:
284: public String getTypeId() {
285: return typeId;
286: }
287:
288: public String getHelperId() {
289: return helperId;
290: }
291:
292: public List getRequiredPropertyKeys() {
293: List<String> rv = new Vector<String>();
294: rv.add(ResourceProperties.PROP_CONTENT_ENCODING);
295: return rv;
296: }
297:
298: }
299:
300: public class HtmlDocumentDeleteAction implements ServiceLevelAction {
301: /* (non-Javadoc)
302: * @see org.sakaiproject.content.api.ResourceToolAction#available(java.lang.String)
303: */
304: public boolean available(ContentEntity entity) {
305: return true;
306: }
307:
308: /* (non-Javadoc)
309: * @see org.sakaiproject.content.api.ResourceToolAction#getActionType()
310: */
311: public ActionType getActionType() {
312: return ResourceToolAction.ActionType.DELETE;
313: }
314:
315: public String getId() {
316: return ResourceToolAction.DELETE;
317: }
318:
319: public String getLabel() {
320: return rb.getString("action.delete");
321: }
322:
323: public boolean isMultipleItemAction() {
324: return true;
325: }
326:
327: public String getTypeId() {
328: return typeId;
329: }
330:
331: /* (non-Javadoc)
332: * @see org.sakaiproject.content.api.ServiceLevelAction#cancelAction(org.sakaiproject.entity.api.Reference)
333: */
334: public void cancelAction(Reference reference) {
335: // TODO Auto-generated method stub
336:
337: }
338:
339: /* (non-Javadoc)
340: * @see org.sakaiproject.content.api.ServiceLevelAction#finalizeAction(org.sakaiproject.entity.api.Reference)
341: */
342: public void finalizeAction(Reference reference) {
343: // TODO Auto-generated method stub
344:
345: }
346:
347: /* (non-Javadoc)
348: * @see org.sakaiproject.content.api.ServiceLevelAction#initializeAction(org.sakaiproject.entity.api.Reference)
349: */
350: public void initializeAction(Reference reference) {
351: // TODO Auto-generated method stub
352:
353: }
354:
355: }
356:
357: public class HtmlDocumentDuplicateAction implements
358: ServiceLevelAction {
359: /* (non-Javadoc)
360: * @see org.sakaiproject.content.api.ResourceToolAction#available(java.lang.String)
361: */
362: public boolean available(ContentEntity entity) {
363: return true;
364: }
365:
366: /* (non-Javadoc)
367: * @see org.sakaiproject.content.api.ResourceToolAction#getActionType()
368: */
369: public ActionType getActionType() {
370: return ResourceToolAction.ActionType.DUPLICATE;
371: }
372:
373: public String getId() {
374: return ResourceToolAction.DUPLICATE;
375: }
376:
377: public String getLabel() {
378: return rb.getString("action.duplicate");
379: }
380:
381: public boolean isMultipleItemAction() {
382: // TODO Auto-generated method stub
383: return false;
384: }
385:
386: public String getTypeId() {
387: return typeId;
388: }
389:
390: /* (non-Javadoc)
391: * @see org.sakaiproject.content.api.ServiceLevelAction#cancelAction(org.sakaiproject.entity.api.Reference)
392: */
393: public void cancelAction(Reference reference) {
394: // TODO Auto-generated method stub
395:
396: }
397:
398: /* (non-Javadoc)
399: * @see org.sakaiproject.content.api.ServiceLevelAction#finalizeAction(org.sakaiproject.entity.api.Reference)
400: */
401: public void finalizeAction(Reference reference) {
402: // TODO Auto-generated method stub
403:
404: }
405:
406: /* (non-Javadoc)
407: * @see org.sakaiproject.content.api.ServiceLevelAction#initializeAction(org.sakaiproject.entity.api.Reference)
408: */
409: public void initializeAction(Reference reference) {
410: // TODO Auto-generated method stub
411:
412: }
413:
414: }
415:
416: public class HtmlDocumentMoveAction implements ServiceLevelAction {
417: /* (non-Javadoc)
418: * @see org.sakaiproject.content.api.ResourceToolAction#available(java.lang.String)
419: */
420: public boolean available(ContentEntity entity) {
421: return true;
422: }
423:
424: /* (non-Javadoc)
425: * @see org.sakaiproject.content.api.ResourceToolAction#getActionType()
426: */
427: public ActionType getActionType() {
428: return ResourceToolAction.ActionType.MOVE;
429: }
430:
431: public String getId() {
432: return ResourceToolAction.MOVE;
433: }
434:
435: public String getLabel() {
436: return rb.getString("action.move");
437: }
438:
439: public boolean isMultipleItemAction() {
440: return true;
441: }
442:
443: public String getTypeId() {
444: return typeId;
445: }
446:
447: /* (non-Javadoc)
448: * @see org.sakaiproject.content.api.ServiceLevelAction#cancelAction(org.sakaiproject.entity.api.Reference)
449: */
450: public void cancelAction(Reference reference) {
451: // TODO Auto-generated method stub
452:
453: }
454:
455: /* (non-Javadoc)
456: * @see org.sakaiproject.content.api.ServiceLevelAction#finalizeAction(org.sakaiproject.entity.api.Reference)
457: */
458: public void finalizeAction(Reference reference) {
459: // TODO Auto-generated method stub
460:
461: }
462:
463: /* (non-Javadoc)
464: * @see org.sakaiproject.content.api.ServiceLevelAction#initializeAction(org.sakaiproject.entity.api.Reference)
465: */
466: public void initializeAction(Reference reference) {
467: // TODO Auto-generated method stub
468:
469: }
470:
471: }
472:
473: public class HtmlDocumentReviseAction implements InteractionAction {
474: /* (non-Javadoc)
475: * @see org.sakaiproject.content.api.ResourceToolAction#available(java.lang.String)
476: */
477: public boolean available(ContentEntity entity) {
478: return true;
479: }
480:
481: public String initializeAction(Reference reference) {
482: return null;
483: }
484:
485: public void cancelAction(Reference reference,
486: String initializationId) {
487: // TODO Auto-generated method stub
488:
489: }
490:
491: public void finalizeAction(Reference reference,
492: String initializationId) {
493: // TODO Auto-generated method stub
494:
495: }
496:
497: /* (non-Javadoc)
498: * @see org.sakaiproject.content.api.ResourceToolAction#getActionType()
499: */
500: public ActionType getActionType() {
501: return ResourceToolAction.ActionType.REVISE_CONTENT;
502: }
503:
504: public String getId() {
505: return ResourceToolAction.REVISE_CONTENT;
506: }
507:
508: public String getLabel() {
509: return rb.getString("action.revise");
510: }
511:
512: public String getTypeId() {
513: return typeId;
514: }
515:
516: public String getHelperId() {
517: return helperId;
518: }
519:
520: public List getRequiredPropertyKeys() {
521: List<String> rv = new Vector<String>();
522: rv.add(ResourceProperties.PROP_CONTENT_ENCODING);
523: return rv;
524: }
525:
526: }
527:
528: public class HtmlDocumentAccessAction implements InteractionAction {
529: /* (non-Javadoc)
530: * @see org.sakaiproject.content.api.ResourceToolAction#available(java.lang.String)
531: */
532: public boolean available(ContentEntity entity) {
533: return true;
534: }
535:
536: public String initializeAction(Reference reference) {
537: return null;
538: }
539:
540: public void cancelAction(Reference reference,
541: String initializationId) {
542: // TODO Auto-generated method stub
543:
544: }
545:
546: public void finalizeAction(Reference reference,
547: String initializationId) {
548: // TODO Auto-generated method stub
549:
550: }
551:
552: /* (non-Javadoc)
553: * @see org.sakaiproject.content.api.ResourceToolAction#getActionType()
554: */
555: public ActionType getActionType() {
556: return ResourceToolAction.ActionType.VIEW_CONTENT;
557: }
558:
559: public String getId() {
560: return ResourceToolAction.ACCESS_CONTENT;
561: }
562:
563: public String getLabel() {
564: return rb.getString("action.access");
565: }
566:
567: public String getTypeId() {
568: return typeId;
569: }
570:
571: public String getHelperId() {
572: return helperId;
573: }
574:
575: public List getRequiredPropertyKeys() {
576: return null;
577: }
578:
579: }
580:
581: public HtmlDocumentType() {
582: this .userDirectoryService = (UserDirectoryService) ComponentManager
583: .get("org.sakaiproject.user.api.UserDirectoryService");
584:
585: actions.put(ResourceToolAction.CREATE,
586: new HtmlDocumentCreateAction());
587: //actions.put(ResourceToolAction.ACCESS_CONTENT, new HtmlDocumentAccessAction());
588: actions.put(ResourceToolAction.REVISE_CONTENT,
589: new HtmlDocumentReviseAction());
590: actions.put(ResourceToolAction.REPLACE_CONTENT,
591: new HtmlDocumentReplaceAction());
592: actions.put(ResourceToolAction.REVISE_METADATA,
593: new HtmlDocumentPropertiesAction());
594: actions.put(ResourceToolAction.DUPLICATE,
595: new HtmlDocumentDuplicateAction());
596: actions.put(ResourceToolAction.COPY,
597: new HtmlDocumentCopyAction());
598: actions.put(ResourceToolAction.MOVE,
599: new HtmlDocumentMoveAction());
600: actions.put(ResourceToolAction.DELETE,
601: new HtmlDocumentDeleteAction());
602:
603: // initialize actionMap with an empty List for each ActionType
604: for (ResourceToolAction.ActionType type : ResourceToolAction.ActionType
605: .values()) {
606: actionMap.put(type, new Vector<ResourceToolAction>());
607: }
608:
609: // for each action in actions, add a link in actionMap
610: Iterator<String> it = actions.keySet().iterator();
611: while (it.hasNext()) {
612: String id = it.next();
613: ResourceToolAction action = actions.get(id);
614: List<ResourceToolAction> list = actionMap.get(action
615: .getActionType());
616: if (list == null) {
617: list = new Vector<ResourceToolAction>();
618: actionMap.put(action.getActionType(), list);
619: }
620: list.add(action);
621: }
622:
623: }
624:
625: public ResourceToolAction getAction(String actionId) {
626: return (ResourceToolAction) actions.get(actionId);
627: }
628:
629: public String getIconLocation(ContentEntity entity) {
630: return null;
631: }
632:
633: public String getId() {
634: return typeId;
635: }
636:
637: public String getLabel() {
638: return rb.getString("type.html");
639: }
640:
641: /* (non-Javadoc)
642: * @see org.sakaiproject.content.api.ResourceType#getLocalizedHoverText(org.sakaiproject.entity.api.Reference)
643: */
644: public String getLocalizedHoverText(ContentEntity member) {
645: return rb.getString("type.html");
646: }
647:
648: /* (non-Javadoc)
649: * @see org.sakaiproject.content.api.ResourceType#getActions(org.sakaiproject.content.api.ResourceType.ActionType)
650: */
651: public List<ResourceToolAction> getActions(ActionType type) {
652: List<ResourceToolAction> list = actionMap.get(type);
653: if (list == null) {
654: list = new Vector<ResourceToolAction>();
655: actionMap.put(type, list);
656: }
657: return new Vector<ResourceToolAction>(list);
658: }
659:
660: /* (non-Javadoc)
661: * @see org.sakaiproject.content.api.ResourceType#getActions(java.util.List)
662: */
663: public List<ResourceToolAction> getActions(List<ActionType> types) {
664: List<ResourceToolAction> list = new Vector<ResourceToolAction>();
665: if (types != null) {
666: Iterator<ActionType> it = types.iterator();
667: while (it.hasNext()) {
668: ActionType type = it.next();
669: List<ResourceToolAction> sublist = actionMap.get(type);
670: if (sublist == null) {
671: sublist = new Vector<ResourceToolAction>();
672: actionMap.put(type, sublist);
673: }
674: list.addAll(sublist);
675: }
676: }
677: return list;
678: }
679:
680: }
|