KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > web > bean > wizard > BaseActionWizard


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.web.bean.wizard;
18
19 import java.io.Serializable JavaDoc;
20 import java.util.ArrayList JavaDoc;
21 import java.util.HashMap JavaDoc;
22 import java.util.List JavaDoc;
23 import java.util.Map JavaDoc;
24
25 import javax.faces.context.FacesContext;
26 import javax.faces.model.SelectItem;
27
28 import org.alfresco.config.Config;
29 import org.alfresco.config.ConfigElement;
30 import org.alfresco.config.ConfigService;
31 import org.alfresco.model.ContentModel;
32 import org.alfresco.repo.action.executer.AddFeaturesActionExecuter;
33 import org.alfresco.repo.action.executer.CheckInActionExecuter;
34 import org.alfresco.repo.action.executer.CheckOutActionExecuter;
35 import org.alfresco.repo.action.executer.CopyActionExecuter;
36 import org.alfresco.repo.action.executer.ImageTransformActionExecuter;
37 import org.alfresco.repo.action.executer.ImporterActionExecuter;
38 import org.alfresco.repo.action.executer.LinkCategoryActionExecuter;
39 import org.alfresco.repo.action.executer.MailActionExecuter;
40 import org.alfresco.repo.action.executer.MoveActionExecuter;
41 import org.alfresco.repo.action.executer.SimpleWorkflowActionExecuter;
42 import org.alfresco.repo.action.executer.SpecialiseTypeActionExecuter;
43 import org.alfresco.repo.action.executer.TransformActionExecuter;
44 import org.alfresco.service.cmr.action.ActionDefinition;
45 import org.alfresco.service.cmr.action.ActionService;
46 import org.alfresco.service.cmr.dictionary.AspectDefinition;
47 import org.alfresco.service.cmr.dictionary.DictionaryService;
48 import org.alfresco.service.cmr.dictionary.TypeDefinition;
49 import org.alfresco.service.cmr.repository.MimetypeService;
50 import org.alfresco.service.cmr.repository.NodeRef;
51 import org.alfresco.service.namespace.NamespaceService;
52 import org.alfresco.service.namespace.QName;
53 import org.alfresco.web.app.Application;
54 import org.alfresco.web.bean.repository.Node;
55 import org.alfresco.web.bean.repository.Repository;
56 import org.alfresco.web.data.IDataContainer;
57 import org.alfresco.web.data.QuickSort;
58 import org.apache.commons.logging.Log;
59 import org.apache.commons.logging.LogFactory;
60
61 /**
62  * Base handler class containing common code used by the New Space Wizard and New Action Wizard
63  *
64  * @author gavinc kevinr
65  */

66 public abstract class BaseActionWizard extends AbstractWizardBean
67 {
68    // parameter names for actions
69
public static final String JavaDoc PROP_CATEGORY = "category";
70    public static final String JavaDoc PROP_ASPECT = "aspect";
71    public static final String JavaDoc PROP_DESTINATION = "destinationLocation";
72    public static final String JavaDoc PROP_APPROVE_STEP_NAME = "approveStepName";
73    public static final String JavaDoc PROP_APPROVE_ACTION = "approveAction";
74    public static final String JavaDoc PROP_APPROVE_FOLDER = "approveFolder";
75    public static final String JavaDoc PROP_REJECT_STEP_PRESENT = "rejectStepPresent";
76    public static final String JavaDoc PROP_REJECT_STEP_NAME = "rejectStepName";
77    public static final String JavaDoc PROP_REJECT_ACTION = "rejectAction";
78    public static final String JavaDoc PROP_REJECT_FOLDER = "rejectFolder";
79    public static final String JavaDoc PROP_CHECKIN_DESC = "checkinDescription";
80    public static final String JavaDoc PROP_CHECKIN_MINOR = "checkinMinorChange";
81    public static final String JavaDoc PROP_TRANSFORMER = "transformer";
82    public static final String JavaDoc PROP_IMAGE_TRANSFORMER = "imageTransformer";
83    public static final String JavaDoc PROP_TRANSFORM_OPTIONS = "transformOptions";
84    public static final String JavaDoc PROP_ENCODING = "encoding";
85    public static final String JavaDoc PROP_MESSAGE = "message";
86    public static final String JavaDoc PROP_SUBJECT = "subject";
87    public static final String JavaDoc PROP_TO = "to";
88    public static final String JavaDoc PROP_OBJECT_TYPE = "objecttype";
89    
90    private static final Log logger = LogFactory.getLog(BaseActionWizard.class);
91    private static final String JavaDoc IMPORT_ENCODING = "UTF-8";
92    
93    // new rule/action wizard specific properties
94
protected boolean multiActionMode = false;
95    protected String JavaDoc action;
96    protected ActionService actionService;
97    protected DictionaryService dictionaryService;
98    protected MimetypeService mimetypeService;
99    protected List JavaDoc<SelectItem> actions;
100    protected List JavaDoc<SelectItem> transformers;
101    protected List JavaDoc<SelectItem> imageTransformers;
102    protected List JavaDoc<SelectItem> aspects;
103    protected List JavaDoc<SelectItem> users;
104    protected List JavaDoc<SelectItem> encodings;
105    protected Map JavaDoc<String JavaDoc, String JavaDoc> actionDescriptions;
106    protected Map JavaDoc<String JavaDoc, Serializable JavaDoc> currentActionProperties;
107    protected List JavaDoc<SelectItem> objectTypes;
108    
109    /**
110     * Initialises the wizard
111     */

112    public void init()
113    {
114       super.init();
115       
116       this.action = "add-features";
117       this.users = null;
118       this.actions = null;
119       this.actionDescriptions = null;
120       
121       this.currentActionProperties = new HashMap JavaDoc<String JavaDoc, Serializable JavaDoc>(3);
122       
123       // default the approve and reject actions
124
this.currentActionProperties.put(PROP_APPROVE_ACTION, "move");
125       this.currentActionProperties.put(PROP_REJECT_STEP_PRESENT, "yes");
126       this.currentActionProperties.put(PROP_REJECT_ACTION, "move");
127       
128       // default the checkin minor change
129
this.currentActionProperties.put(PROP_CHECKIN_MINOR, new Boolean JavaDoc(true));
130    }
131    
132    /**
133     * Build the param map for the current Action instance
134     *
135     * @return param map
136     */

137    protected Map JavaDoc<String JavaDoc, Serializable JavaDoc> buildActionParams()
138    {
139       // set up parameters maps for the action
140
Map JavaDoc<String JavaDoc, Serializable JavaDoc> actionParams = new HashMap JavaDoc<String JavaDoc, Serializable JavaDoc>();
141       
142       if (this.action.equals(AddFeaturesActionExecuter.NAME))
143       {
144          QName aspect = Repository.resolveToQName((String JavaDoc)this.currentActionProperties.get(PROP_ASPECT));
145          actionParams.put(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, aspect);
146       }
147       else if (this.action.equals(CopyActionExecuter.NAME))
148       {
149          // add the destination space id to the action properties
150
NodeRef destNodeRef = (NodeRef)this.currentActionProperties.get(PROP_DESTINATION);
151          actionParams.put(CopyActionExecuter.PARAM_DESTINATION_FOLDER, destNodeRef);
152          
153          // add the type and name of the association to create when the copy
154
// is performed
155
actionParams.put(CopyActionExecuter.PARAM_ASSOC_TYPE_QNAME,
156                ContentModel.ASSOC_CONTAINS);
157          actionParams.put(CopyActionExecuter.PARAM_ASSOC_QNAME,
158                QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "copy"));
159       }
160       else if (this.action.equals(MoveActionExecuter.NAME))
161       {
162          // add the destination space id to the action properties
163
NodeRef destNodeRef = (NodeRef)this.currentActionProperties.get(PROP_DESTINATION);
164          actionParams.put(MoveActionExecuter.PARAM_DESTINATION_FOLDER, destNodeRef);
165          
166          // add the type and name of the association to create when the move
167
// is performed
168
actionParams.put(MoveActionExecuter.PARAM_ASSOC_TYPE_QNAME,
169                ContentModel.ASSOC_CONTAINS);
170          actionParams.put(MoveActionExecuter.PARAM_ASSOC_QNAME,
171                QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "move"));
172       }
173       else if (this.action.equals(SimpleWorkflowActionExecuter.NAME))
174       {
175          // add the approve step name
176
actionParams.put(SimpleWorkflowActionExecuter.PARAM_APPROVE_STEP,
177                (String JavaDoc)this.currentActionProperties.get(PROP_APPROVE_STEP_NAME));
178          
179          // add whether the approve step will copy or move the content
180
boolean approveMove = true;
181          String JavaDoc approveAction = (String JavaDoc)this.currentActionProperties.get(PROP_APPROVE_ACTION);
182          if (approveAction != null && approveAction.equals("copy"))
183          {
184             approveMove = false;
185          }
186          
187          actionParams.put(SimpleWorkflowActionExecuter.PARAM_APPROVE_MOVE, Boolean.valueOf(approveMove));
188          
189          // add the destination folder of the content
190
NodeRef approveDestNodeRef = null;
191          Object JavaDoc approveDestNode = this.currentActionProperties.get(PROP_APPROVE_FOLDER);
192          if (approveDestNode instanceof NodeRef)
193          {
194             approveDestNodeRef = (NodeRef)approveDestNode;
195          }
196          else if (approveDestNode instanceof String JavaDoc)
197          {
198             approveDestNodeRef = new NodeRef((String JavaDoc)approveDestNode);
199          }
200          actionParams.put(SimpleWorkflowActionExecuter.PARAM_APPROVE_FOLDER, approveDestNodeRef);
201          
202          // determine whether we have a reject step or not
203
boolean requireReject = true;
204          String JavaDoc rejectStepPresent = (String JavaDoc)this.currentActionProperties.get(PROP_REJECT_STEP_PRESENT);
205          if (rejectStepPresent != null && rejectStepPresent.equals("no"))
206          {
207             requireReject = false;
208          }
209
210          if (requireReject)
211          {
212             // add the reject step name
213
actionParams.put(SimpleWorkflowActionExecuter.PARAM_REJECT_STEP,
214                   (String JavaDoc)this.currentActionProperties.get(PROP_REJECT_STEP_NAME));
215          
216             // add whether the reject step will copy or move the content
217
boolean rejectMove = true;
218             String JavaDoc rejectAction = (String JavaDoc)this.currentActionProperties.get(PROP_REJECT_ACTION);
219             if (rejectAction != null && rejectAction.equals("copy"))
220             {
221                rejectMove = false;
222             }
223             
224             actionParams.put(SimpleWorkflowActionExecuter.PARAM_REJECT_MOVE, Boolean.valueOf(rejectMove));
225             
226             // add the destination folder of the content
227
NodeRef rejectDestNodeRef = null;
228             Object JavaDoc rejectDestNode = this.currentActionProperties.get(PROP_REJECT_FOLDER);
229             if (rejectDestNode instanceof NodeRef)
230             {
231                rejectDestNodeRef = (NodeRef)rejectDestNode;
232             }
233             else if (rejectDestNode instanceof String JavaDoc)
234             {
235                rejectDestNodeRef = new NodeRef((String JavaDoc)rejectDestNode);
236             }
237             actionParams.put(SimpleWorkflowActionExecuter.PARAM_REJECT_FOLDER, rejectDestNodeRef);
238          }
239       }
240       else if (this.action.equals(LinkCategoryActionExecuter.NAME))
241       {
242          // add the classifiable aspect
243
actionParams.put(LinkCategoryActionExecuter.PARAM_CATEGORY_ASPECT,
244                ContentModel.ASPECT_GEN_CLASSIFIABLE);
245          
246          // put the selected category in the action params
247
NodeRef catNodeRef = (NodeRef)this.currentActionProperties.get(PROP_CATEGORY);
248          actionParams.put(LinkCategoryActionExecuter.PARAM_CATEGORY_VALUE,
249                catNodeRef);
250       }
251       else if (this.action.equals(CheckOutActionExecuter.NAME))
252       {
253          // specify the location the checked out working copy should go
254
// add the destination space id to the action properties
255
NodeRef destNodeRef = (NodeRef)this.currentActionProperties.get(PROP_DESTINATION);
256          actionParams.put(CheckOutActionExecuter.PARAM_DESTINATION_FOLDER, destNodeRef);
257          
258          // add the type and name of the association to create when the
259
// check out is performed
260
actionParams.put(CheckOutActionExecuter.PARAM_ASSOC_TYPE_QNAME,
261                ContentModel.ASSOC_CONTAINS);
262          actionParams.put(CheckOutActionExecuter.PARAM_ASSOC_QNAME,
263                QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "checkout"));
264       }
265       else if (this.action.equals(CheckInActionExecuter.NAME))
266       {
267          // add the description for the checkin to the action params
268
actionParams.put(CheckInActionExecuter.PARAM_DESCRIPTION,
269                this.currentActionProperties.get(PROP_CHECKIN_DESC));
270          
271          // add the minor change flag
272
actionParams.put(CheckInActionExecuter.PARAM_MINOR_CHANGE,
273                this.currentActionProperties.get(PROP_CHECKIN_MINOR));
274       }
275       else if (this.action.equals(TransformActionExecuter.NAME))
276       {
277          // add the transformer to use
278
actionParams.put(TransformActionExecuter.PARAM_MIME_TYPE,
279                this.currentActionProperties.get(PROP_TRANSFORMER));
280          
281          // add the destination space id to the action properties
282
NodeRef destNodeRef = (NodeRef)this.currentActionProperties.get(PROP_DESTINATION);
283          actionParams.put(TransformActionExecuter.PARAM_DESTINATION_FOLDER, destNodeRef);
284          
285          // add the type and name of the association to create when the copy
286
// is performed
287
actionParams.put(TransformActionExecuter.PARAM_ASSOC_TYPE_QNAME,
288                ContentModel.ASSOC_CONTAINS);
289          actionParams.put(TransformActionExecuter.PARAM_ASSOC_QNAME,
290                QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "copy"));
291       }
292       else if (this.action.equals(ImageTransformActionExecuter.NAME))
293       {
294          // add the transformer to use
295
actionParams.put(ImageTransformActionExecuter.PARAM_MIME_TYPE,
296                this.currentActionProperties.get(PROP_IMAGE_TRANSFORMER));
297          
298          // add the options
299
actionParams.put(ImageTransformActionExecuter.PARAM_CONVERT_COMMAND,
300                this.currentActionProperties.get(PROP_TRANSFORM_OPTIONS));
301          
302          // add the destination space id to the action properties
303
NodeRef destNodeRef = (NodeRef)this.currentActionProperties.get(PROP_DESTINATION);
304          actionParams.put(TransformActionExecuter.PARAM_DESTINATION_FOLDER, destNodeRef);
305          
306          // add the type and name of the association to create when the copy
307
// is performed
308
actionParams.put(TransformActionExecuter.PARAM_ASSOC_TYPE_QNAME,
309                ContentModel.ASSOC_CONTAINS);
310          actionParams.put(TransformActionExecuter.PARAM_ASSOC_QNAME,
311                QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "copy"));
312       }
313       else if (this.action.equals(MailActionExecuter.NAME))
314       {
315          // add the actual email text to send
316
actionParams.put(MailActionExecuter.PARAM_TEXT,
317                this.currentActionProperties.get(PROP_MESSAGE));
318             
319          // add the person it's going to
320
actionParams.put(MailActionExecuter.PARAM_TO,
321                this.currentActionProperties.get(PROP_TO));
322          
323          // add the subject for the email
324
actionParams.put(MailActionExecuter.PARAM_SUBJECT,
325                this.currentActionProperties.get(PROP_SUBJECT));
326       }
327       else if (this.action.equals(ImporterActionExecuter.NAME))
328       {
329          // add the encoding
330
actionParams.put(ImporterActionExecuter.PARAM_ENCODING, IMPORT_ENCODING);
331          
332          // add the destination for the import
333
NodeRef destNodeRef = (NodeRef)this.currentActionProperties.get(PROP_DESTINATION);
334          actionParams.put(ImporterActionExecuter.PARAM_DESTINATION_FOLDER, destNodeRef);
335       }
336       else if (this.action.equals(SpecialiseTypeActionExecuter.NAME) == true)
337       {
338           // add the specialisation type
339
String JavaDoc objectType = (String JavaDoc)this.currentActionProperties.get(PROP_OBJECT_TYPE);
340           actionParams.put(SpecialiseTypeActionExecuter.PARAM_TYPE_NAME, QName.createQName(objectType));
341       }
342       
343       return actionParams;
344    }
345    
346    /**
347     * Populate the actionProperties member variable with correct props for the current action
348     * using the supplied property map.
349     *
350     * @param actionProps Map to retrieve props appropriate to the current action from
351     */

352    protected void populateActionFromProperties(Map JavaDoc<String JavaDoc, Serializable JavaDoc> actionProps)
353    {
354       if (this.action.equals(AddFeaturesActionExecuter.NAME))
355       {
356          QName aspect = (QName)actionProps.get(AddFeaturesActionExecuter.PARAM_ASPECT_NAME);
357          this.currentActionProperties.put(PROP_ASPECT, aspect.toString());
358       }
359       else if (this.action.equals(CopyActionExecuter.NAME))
360       {
361          NodeRef destNodeRef = (NodeRef)actionProps.get(CopyActionExecuter.PARAM_DESTINATION_FOLDER);
362          this.currentActionProperties.put(PROP_DESTINATION, destNodeRef);
363       }
364       else if (this.action.equals(MoveActionExecuter.NAME))
365       {
366          NodeRef destNodeRef = (NodeRef)actionProps.get(MoveActionExecuter.PARAM_DESTINATION_FOLDER);
367          this.currentActionProperties.put(PROP_DESTINATION, destNodeRef);
368       }
369       else if (this.action.equals(SimpleWorkflowActionExecuter.NAME))
370       {
371          String JavaDoc approveStep = (String JavaDoc)actionProps.get(SimpleWorkflowActionExecuter.PARAM_APPROVE_STEP);
372          Boolean JavaDoc approveMove = (Boolean JavaDoc)actionProps.get(SimpleWorkflowActionExecuter.PARAM_APPROVE_MOVE);
373          NodeRef approveFolderNode = (NodeRef)actionProps.get(
374                SimpleWorkflowActionExecuter.PARAM_APPROVE_FOLDER);
375          
376          String JavaDoc rejectStep = (String JavaDoc)actionProps.get(SimpleWorkflowActionExecuter.PARAM_REJECT_STEP);
377          Boolean JavaDoc rejectMove = (Boolean JavaDoc)actionProps.get(SimpleWorkflowActionExecuter.PARAM_REJECT_MOVE);
378          NodeRef rejectFolderNode = (NodeRef)actionProps.get(
379                SimpleWorkflowActionExecuter.PARAM_REJECT_FOLDER);
380          
381          this.currentActionProperties.put(PROP_APPROVE_STEP_NAME, approveStep);
382          this.currentActionProperties.put(PROP_APPROVE_ACTION, approveMove ? "move" : "copy");
383          this.currentActionProperties.put(PROP_APPROVE_FOLDER, approveFolderNode);
384          
385          if (rejectStep == null && rejectMove == null && rejectFolderNode == null)
386          {
387             this.currentActionProperties.put(PROP_REJECT_STEP_PRESENT, "no");
388          }
389          else
390          {
391             this.currentActionProperties.put(PROP_REJECT_STEP_PRESENT, "yes");
392             this.currentActionProperties.put(PROP_REJECT_STEP_NAME, rejectStep);
393             this.currentActionProperties.put(PROP_REJECT_ACTION, rejectMove ? "move" : "copy");
394             this.currentActionProperties.put(PROP_REJECT_FOLDER, rejectFolderNode);
395          }
396       }
397       else if (this.action.equals(LinkCategoryActionExecuter.NAME))
398       {
399          NodeRef catNodeRef = (NodeRef)actionProps.get(LinkCategoryActionExecuter.PARAM_CATEGORY_VALUE);
400          this.currentActionProperties.put(PROP_CATEGORY, catNodeRef);
401       }
402       else if (this.action.equals(CheckOutActionExecuter.NAME))
403       {
404          NodeRef destNodeRef = (NodeRef)actionProps.get(CheckOutActionExecuter.PARAM_DESTINATION_FOLDER);
405          this.currentActionProperties.put(PROP_DESTINATION, destNodeRef);
406       }
407       else if (this.action.equals(CheckInActionExecuter.NAME))
408       {
409          String JavaDoc checkDesc = (String JavaDoc)actionProps.get(CheckInActionExecuter.PARAM_DESCRIPTION);
410          this.currentActionProperties.put(PROP_CHECKIN_DESC, checkDesc);
411          
412          Boolean JavaDoc minorChange = (Boolean JavaDoc)actionProps.get(CheckInActionExecuter.PARAM_MINOR_CHANGE);
413          this.currentActionProperties.put(PROP_CHECKIN_MINOR, minorChange);
414       }
415       else if (this.action.equals(TransformActionExecuter.NAME))
416       {
417          String JavaDoc transformer = (String JavaDoc)actionProps.get(TransformActionExecuter.PARAM_MIME_TYPE);
418          this.currentActionProperties.put(PROP_TRANSFORMER, transformer);
419          
420          NodeRef destNodeRef = (NodeRef)actionProps.get(CopyActionExecuter.PARAM_DESTINATION_FOLDER);
421          this.currentActionProperties.put(PROP_DESTINATION, destNodeRef);
422       }
423       else if (this.action.equals(ImageTransformActionExecuter.NAME))
424       {
425          String JavaDoc transformer = (String JavaDoc)actionProps.get(TransformActionExecuter.PARAM_MIME_TYPE);
426          this.currentActionProperties.put(PROP_IMAGE_TRANSFORMER, transformer);
427          
428          String JavaDoc options = (String JavaDoc)actionProps.get(ImageTransformActionExecuter.PARAM_CONVERT_COMMAND);
429          this.currentActionProperties.put(PROP_TRANSFORM_OPTIONS, options != null ? options : "");
430          
431          NodeRef destNodeRef = (NodeRef)actionProps.get(CopyActionExecuter.PARAM_DESTINATION_FOLDER);
432          this.currentActionProperties.put(PROP_DESTINATION, destNodeRef);
433       }
434       else if (this.action.equals(MailActionExecuter.NAME))
435       {
436          String JavaDoc subject = (String JavaDoc)actionProps.get(MailActionExecuter.PARAM_SUBJECT);
437          this.currentActionProperties.put(PROP_SUBJECT, subject);
438          
439          String JavaDoc message = (String JavaDoc)actionProps.get(MailActionExecuter.PARAM_TEXT);
440          this.currentActionProperties.put(PROP_MESSAGE, message);
441          
442          String JavaDoc to = (String JavaDoc)actionProps.get(MailActionExecuter.PARAM_TO);
443          this.currentActionProperties.put(PROP_TO, to);
444       }
445       else if (this.action.equals(ImporterActionExecuter.NAME))
446       {
447          NodeRef destNodeRef = (NodeRef)actionProps.get(ImporterActionExecuter.PARAM_DESTINATION_FOLDER);
448          this.currentActionProperties.put(PROP_DESTINATION, destNodeRef);
449       }
450       else if (this.action.equals(SpecialiseTypeActionExecuter.NAME) == true)
451       {
452           QName specialiseType = (QName)actionProps.get(SpecialiseTypeActionExecuter.PARAM_TYPE_NAME);
453           this.currentActionProperties.put(PROP_OBJECT_TYPE, specialiseType.toString());
454       }
455    }
456
457    /**
458     * @return Returns the selected action
459     */

460    public String JavaDoc getAction()
461    {
462       return this.action;
463    }
464
465    /**
466     * @param action Sets the selected action
467     */

468    public void setAction(String JavaDoc action)
469    {
470       this.action = action;
471    }
472
473    /**
474     * Sets the action service
475     *
476     * @param actionRegistration the action service
477     */

478    public void setActionService(ActionService actionService)
479    {
480       this.actionService = actionService;
481    }
482    
483    /**
484     * Sets the dictionary service
485     *
486     * @param dictionaryService the dictionary service
487     */

488    public void setDictionaryService(DictionaryService dictionaryService)
489    {
490       this.dictionaryService = dictionaryService;
491    }
492    
493    /**
494     * Sets the mimetype service
495     *
496     * @param mimetypeService The mimetype service
497     */

498    public void setMimetypeService(MimetypeService mimetypeService)
499    {
500       this.mimetypeService = mimetypeService;
501    }
502
503    /**
504     * @return Returns the list of selectable actions
505     */

506    public List JavaDoc<SelectItem> getActions()
507    {
508       if (this.actions == null)
509       {
510          List JavaDoc<ActionDefinition> ruleActions = this.actionService.getActionDefinitions();
511          this.actions = new ArrayList JavaDoc<SelectItem>();
512          for (ActionDefinition ruleActionDef : ruleActions)
513          {
514             this.actions.add(new SelectItem(ruleActionDef.getName(), ruleActionDef.getTitle()));
515          }
516          
517          // make sure the list is sorted by the label
518
QuickSort sorter = new QuickSort(this.actions, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
519          sorter.sort();
520       }
521       
522       return this.actions;
523    }
524    
525    /**
526     * @return Returns a map of all the action descriptions
527     */

528    public Map JavaDoc<String JavaDoc, String JavaDoc> getActionDescriptions()
529    {
530       if (this.actionDescriptions == null)
531       {
532          List JavaDoc<ActionDefinition> ruleActions = this.actionService.getActionDefinitions();
533          this.actionDescriptions = new HashMap JavaDoc<String JavaDoc, String JavaDoc>();
534          for (ActionDefinition ruleActionDef : ruleActions)
535          {
536             this.actionDescriptions.put(ruleActionDef.getName(), ruleActionDef.getDescription());
537          }
538       }
539       
540       return this.actionDescriptions;
541    }
542
543    /**
544     * @return Gets the action settings
545     */

546    public Map JavaDoc<String JavaDoc, Serializable JavaDoc> getActionProperties()
547    {
548       return this.currentActionProperties;
549    }
550    
551    /**
552     * Returns a list of encodings the import and export actions can use
553     *
554     * @return List of SelectItem objects representing the available encodings
555     */

556    public List JavaDoc<SelectItem> getEncodings()
557    {
558       if (this.encodings == null)
559       {
560          ConfigService svc = Application.getConfigService(FacesContext.getCurrentInstance());
561          Config wizardCfg = svc.getConfig("Action Wizards");
562          if (wizardCfg != null)
563          {
564             ConfigElement encodingsCfg = wizardCfg.getConfigElement("encodings");
565             if (encodingsCfg != null)
566             {
567                FacesContext context = FacesContext.getCurrentInstance();
568                this.encodings = new ArrayList JavaDoc<SelectItem>();
569                for (ConfigElement child : encodingsCfg.getChildren())
570                {
571                   String JavaDoc id = child.getAttribute("name");
572                   
573                   // look for a client localized string
574
String JavaDoc label = null;
575                   String JavaDoc msgId = child.getAttribute("displayLabelId");
576                   if (msgId != null)
577                   {
578                      label = Application.getMessage(context, msgId);
579                   }
580                   
581                   // if there wasn't an externalized string look for one in the config
582
if (label == null)
583                   {
584                      label = child.getAttribute("displayLabel");
585                   }
586                   
587                   this.encodings.add(new SelectItem(id, label));
588                }
589                
590                // make sure the list is sorted by the label
591
QuickSort sorter = new QuickSort(this.encodings, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
592                sorter.sort();
593             }
594             else
595             {
596                logger.warn("Could not find encodings configuration element");
597             }
598          }
599          else
600          {
601             logger.warn("Could not find Action Wizards configuration section");
602          }
603       }
604       
605       return this.encodings;
606    }
607    
608    /**
609     * Returns the transformers that are available
610     *
611     * @return List of SelectItem objects representing the available transformers
612     */

613    public List JavaDoc<SelectItem> getTransformers()
614    {
615       if (this.transformers == null)
616       {
617          ConfigService svc = Application.getConfigService(FacesContext.getCurrentInstance());
618          Config wizardCfg = svc.getConfig("Action Wizards");
619          if (wizardCfg != null)
620          {
621             ConfigElement transformersCfg = wizardCfg.getConfigElement("transformers");
622             if (transformersCfg != null)
623             {
624                FacesContext context = FacesContext.getCurrentInstance();
625                Map JavaDoc<String JavaDoc, String JavaDoc> mimeTypes = this.mimetypeService.getDisplaysByMimetype();
626                this.transformers = new ArrayList JavaDoc<SelectItem>();
627                for (ConfigElement child : transformersCfg.getChildren())
628                {
629                   String JavaDoc id = child.getAttribute("name");
630                   
631                   // look for a client localized string
632
String JavaDoc label = null;
633                   String JavaDoc msgId = child.getAttribute("displayLabelId");
634                   if (msgId != null)
635                   {
636                      label = Application.getMessage(context, msgId);
637                   }
638                   
639                   // if there wasn't an externalized string look for one in the config
640
if (label == null)
641                   {
642                      label = child.getAttribute("displayLabel");
643                   }
644
645                   // if there wasn't a client based label get it from the mime type service
646
if (label == null)
647                   {
648                      label = mimeTypes.get(id);
649                   }
650                   
651                   this.transformers.add(new SelectItem(id, label));
652                }
653                
654                // make sure the list is sorted by the label
655
QuickSort sorter = new QuickSort(this.transformers, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
656                sorter.sort();
657             }
658             else
659             {
660                logger.warn("Could not find transformers configuration element");
661             }
662          }
663          else
664          {
665             logger.warn("Could not find Action Wizards configuration section");
666          }
667       }
668       
669       return this.transformers;
670    }
671    
672    /**
673     * Returns the image transformers that are available
674     *
675     * @return List of SelectItem objects representing the available image transformers
676     */

677    public List JavaDoc<SelectItem> getImageTransformers()
678    {
679       if (this.imageTransformers == null)
680       {
681          ConfigService svc = Application.getConfigService(FacesContext.getCurrentInstance());
682          Config wizardCfg = svc.getConfig("Action Wizards");
683          if (wizardCfg != null)
684          {
685             ConfigElement transformersCfg = wizardCfg.getConfigElement("image-transformers");
686             if (transformersCfg != null)
687             {
688                FacesContext context = FacesContext.getCurrentInstance();
689                Map JavaDoc<String JavaDoc, String JavaDoc> mimeTypes = this.mimetypeService.getDisplaysByMimetype();
690                this.imageTransformers = new ArrayList JavaDoc<SelectItem>();
691                for (ConfigElement child : transformersCfg.getChildren())
692                {
693                   String JavaDoc id = child.getAttribute("name");
694                   
695                   // look for a client localized string
696
String JavaDoc label = null;
697                   String JavaDoc msgId = child.getAttribute("displayLabelId");
698                   if (msgId != null)
699                   {
700                      label = Application.getMessage(context, msgId);
701                   }
702                   
703                   // if there wasn't an externalized string look for one in the config
704
if (label == null)
705                   {
706                      label = child.getAttribute("displayLabel");
707                   }
708
709                   // if there wasn't a client based label get it from the mime type service
710
if (label == null)
711                   {
712                      label = mimeTypes.get(id);
713                   }
714
715                   this.imageTransformers.add(new SelectItem(id, label));
716                }
717                
718                // make sure the list is sorted by the label
719
QuickSort sorter = new QuickSort(this.imageTransformers, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
720                sorter.sort();
721             }
722             else
723             {
724                logger.warn("Could not find image-transformers configuration element");
725             }
726          }
727          else
728          {
729             logger.warn("Could not find Action Wizards configuration section");
730          }
731       }
732       
733       return this.imageTransformers;
734    }
735    
736    /**
737     * Returns the aspects that are available
738     *
739     * @return List of SelectItem objects representing the available aspects
740     */

741    public List JavaDoc<SelectItem> getAspects()
742    {
743       if (this.aspects == null)
744       {
745          ConfigService svc = Application.getConfigService(FacesContext.getCurrentInstance());
746          Config wizardCfg = svc.getConfig("Action Wizards");
747          if (wizardCfg != null)
748          {
749             ConfigElement aspectsCfg = wizardCfg.getConfigElement("aspects");
750             if (aspectsCfg != null)
751             {
752                FacesContext context = FacesContext.getCurrentInstance();
753                this.aspects = new ArrayList JavaDoc<SelectItem>();
754                for (ConfigElement child : aspectsCfg.getChildren())
755                {
756                   QName idQName = Repository.resolveToQName(child.getAttribute("name"));
757
758                   // look for a client localized string
759
String JavaDoc label = null;
760                   String JavaDoc msgId = child.getAttribute("displayLabelId");
761                   if (msgId != null)
762                   {
763                      label = Application.getMessage(context, msgId);
764                   }
765                   
766                   // if there wasn't an externalized string look for one in the config
767
if (label == null)
768                   {
769                      label = child.getAttribute("displayLabel");
770                   }
771
772                   // if there wasn't a client based label try and get it from the dictionary
773
if (label == null)
774                   {
775                      AspectDefinition aspectDef = this.dictionaryService.getAspect(idQName);
776                      if (aspectDef != null)
777                      {
778                         label = aspectDef.getTitle();
779                      }
780                      else
781                      {
782                         label = idQName.getLocalName();
783                      }
784                   }
785                   
786                   this.aspects.add(new SelectItem(idQName.toString(), label));
787                }
788                
789                // make sure the list is sorted by the label
790
QuickSort sorter = new QuickSort(this.aspects, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
791                sorter.sort();
792             }
793             else
794             {
795                logger.warn("Could not find aspects configuration element");
796             }
797          }
798          else
799          {
800             logger.warn("Could not find Action Wizards configuration section");
801          }
802       }
803       
804       return this.aspects;
805    }
806    
807    /**
808     * @return Returns a list of object types to allow the user to select from
809     */

810    public List JavaDoc<SelectItem> getObjectTypes()
811    {
812       if (this.objectTypes == null)
813       {
814          FacesContext context = FacesContext.getCurrentInstance();
815          
816          // add the well known object type to start with
817
this.objectTypes = new ArrayList JavaDoc<SelectItem>(5);
818          this.objectTypes.add(new SelectItem(ContentModel.TYPE_CONTENT.toString(),
819                Application.getMessage(context, "content")));
820          
821          // add any configured content sub-types to the list
822
ConfigService svc = Application.getConfigService(FacesContext.getCurrentInstance());
823          Config wizardCfg = svc.getConfig("Custom Content Types");
824          if (wizardCfg != null)
825          {
826             ConfigElement typesCfg = wizardCfg.getConfigElement("content-types");
827             if (typesCfg != null)
828             {
829                for (ConfigElement child : typesCfg.getChildren())
830                {
831                   QName idQName = Repository.resolveToQName(child.getAttribute("name"));
832                   TypeDefinition typeDef = this.dictionaryService.getType(idQName);
833                   
834                   if (typeDef != null &&
835                       this.dictionaryService.isSubClass(typeDef.getName(), ContentModel.TYPE_CONTENT))
836                   {
837                      // look for a client localized string
838
String JavaDoc label = null;
839                      String JavaDoc msgId = child.getAttribute("displayLabelId");
840                      if (msgId != null)
841                      {
842                         label = Application.getMessage(context, msgId);
843                      }
844                      
845                      // if there wasn't an externalized string look for one in the config
846
if (label == null)
847                      {
848                         label = child.getAttribute("displayLabel");
849                      }
850    
851                      // if there wasn't a client based label try and get it from the dictionary
852
if (label == null)
853                      {
854                         label = typeDef.getTitle();
855                      }
856                      
857                      // finally, just use the localname
858
if (label == null)
859                      {
860                         label = idQName.getLocalName();
861                      }
862                      
863                      this.objectTypes.add(new SelectItem(idQName.toString(), label));
864                   }
865                }
866                
867                // make sure the list is sorted by the label
868
QuickSort sorter = new QuickSort(this.objectTypes, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
869                sorter.sort();
870             }
871             else
872             {
873                logger.warn("Could not find 'content-types' configuration element");
874             }
875          }
876          else
877          {
878             logger.warn("Could not find 'Custom Content Types' configuration section");
879          }
880          
881       }
882       
883       return this.objectTypes;
884    }
885    
886    /**
887     * @return the List of users in the system wrapped in SelectItem objects
888     */

889    public List JavaDoc<SelectItem> getUsers()
890    {
891       if (this.users == null)
892       {
893          List JavaDoc<Node> userNodes = Repository.getUsers(
894                FacesContext.getCurrentInstance(),
895                this.nodeService,
896                this.searchService);
897          this.users = new ArrayList JavaDoc<SelectItem>();
898          for (Node user : userNodes)
899          {
900             String JavaDoc email = (String JavaDoc)user.getProperties().get("email");
901             if (email != null && email.length() > 0)
902             {
903                this.users.add(new SelectItem(email, (String JavaDoc)user.getProperties().get("fullName")));
904             }
905          }
906          
907          // make sure the list is sorted by the label
908
QuickSort sorter = new QuickSort(this.users, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
909          sorter.sort();
910       }
911       
912       return this.users;
913    }
914 }
915
Popular Tags