KickJava   Java API By Example, From Geeks To Geeks.

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


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.text.MessageFormat JavaDoc;
21 import java.util.ArrayList JavaDoc;
22 import java.util.HashMap JavaDoc;
23 import java.util.List JavaDoc;
24 import java.util.Map JavaDoc;
25 import java.util.ResourceBundle JavaDoc;
26
27 import javax.faces.application.FacesMessage;
28 import javax.faces.context.FacesContext;
29 import javax.faces.model.SelectItem;
30 import javax.transaction.UserTransaction JavaDoc;
31
32 import org.alfresco.config.Config;
33 import org.alfresco.config.ConfigElement;
34 import org.alfresco.model.ContentModel;
35 import org.alfresco.service.cmr.dictionary.DictionaryService;
36 import org.alfresco.service.cmr.dictionary.TypeDefinition;
37 import org.alfresco.service.cmr.model.FileExistsException;
38 import org.alfresco.service.cmr.model.FileInfo;
39 import org.alfresco.service.cmr.repository.NodeRef;
40 import org.alfresco.service.cmr.search.SearchService;
41 import org.alfresco.service.namespace.DynamicNamespacePrefixResolver;
42 import org.alfresco.service.namespace.NamespaceService;
43 import org.alfresco.service.namespace.QName;
44 import org.alfresco.web.app.Application;
45 import org.alfresco.web.bean.repository.Node;
46 import org.alfresco.web.bean.repository.Repository;
47 import org.alfresco.web.data.IDataContainer;
48 import org.alfresco.web.data.QuickSort;
49 import org.alfresco.web.ui.common.Utils;
50 import org.alfresco.web.ui.common.component.UIListItem;
51 import org.alfresco.web.ui.common.component.description.UIDescription;
52 import org.apache.commons.logging.Log;
53 import org.apache.commons.logging.LogFactory;
54
55 /**
56  * Handler class used by the New Space Wizard
57  *
58  * @author gavinc
59  */

60 public class NewSpaceWizard extends AbstractWizardBean
61 {
62    public static final String JavaDoc SPACE_ICON_DEFAULT = "space-icon-default";
63
64    private static Log logger = LogFactory.getLog(NewSpaceWizard.class);
65    
66    // TODO: retrieve these from the config service
67
private static final String JavaDoc WIZARD_TITLE_ID = "new_space_title";
68    private static final String JavaDoc WIZARD_DESC_ID = "new_space_desc";
69    private static final String JavaDoc STEP1_TITLE_ID = "new_space_step1_title";
70    private static final String JavaDoc STEP1_DESCRIPTION_ID = "new_space_step1_desc";
71    private static final String JavaDoc STEP2_TITLE_ID = "new_space_step2_title";
72    private static final String JavaDoc STEP2_DESCRIPTION_ID = "new_space_step2_desc";
73    private static final String JavaDoc STEP3_TITLE_ID = "new_space_step3_title";
74    private static final String JavaDoc STEP3_DESCRIPTION_ID = "new_space_step3_desc";
75    private static final String JavaDoc FINISH_INSTRUCTION_ID = "new_space_finish_instruction";
76    
77    private static final String JavaDoc ERROR = "error_space";
78    private static final String JavaDoc DEFAULT_SPACE_TYPE_ICON = "/images/icons/space.gif";
79    private static final String JavaDoc ICONS_LOOKUP_KEY = " icons";
80
81    // new space wizard specific properties
82
protected SearchService searchService;
83    protected NamespaceService namespaceService;
84    protected DictionaryService dictionaryService;
85    
86    protected String JavaDoc spaceType;
87    protected String JavaDoc icon;
88    protected String JavaDoc createFrom;
89    protected NodeRef existingSpaceId;
90    protected String JavaDoc templateSpaceId;
91    protected String JavaDoc copyPolicy;
92    protected String JavaDoc name;
93    protected String JavaDoc description;
94    protected String JavaDoc templateName;
95    protected boolean saveAsTemplate;
96    protected List JavaDoc<SelectItem> templates;
97    protected List JavaDoc<UIListItem> folderTypes;
98    protected List JavaDoc<UIDescription> folderTypeDescriptions;
99    
100    // the NodeRef of the node created during finish
101
protected NodeRef createdNode;
102    
103    /**
104     * Deals with the finish button being pressed
105     *
106     * @return outcome
107     */

108    public String JavaDoc finish()
109    {
110       String JavaDoc outcome = FINISH_OUTCOME;
111       
112       UserTransaction JavaDoc tx = null;
113    
114       try
115       {
116          FacesContext context = FacesContext.getCurrentInstance();
117          tx = Repository.getUserTransaction(FacesContext.getCurrentInstance());
118          tx.begin();
119
120          if (this.editMode)
121          {
122             // update the existing node in the repository
123
Node currentSpace = this.browseBean.getActionSpace();
124             NodeRef nodeRef = currentSpace.getNodeRef();
125             
126             // rename if necessary
127
fileFolderService.rename(nodeRef, this.name);
128             
129             // update the properties
130
Map JavaDoc<QName, Serializable JavaDoc> properties = this.nodeService.getProperties(nodeRef);
131             properties.put(ContentModel.PROP_NAME, this.name);
132             properties.put(ContentModel.PROP_ICON, this.icon);
133             properties.put(ContentModel.PROP_DESCRIPTION, this.description);
134             
135             // apply properties
136
this.nodeService.setProperties(nodeRef, properties);
137          }
138          else
139          {
140             String JavaDoc newSpaceId = null;
141             
142             if (this.createFrom.equals("scratch"))
143             {
144                // create the space (just create a folder for now)
145
NodeRef parentNodeRef;
146                String JavaDoc nodeId = getNavigator().getCurrentNodeId();
147                if (nodeId == null)
148                {
149                   parentNodeRef = this.nodeService.getRootNode(Repository.getStoreRef());
150                }
151                else
152                {
153                   parentNodeRef = new NodeRef(Repository.getStoreRef(), nodeId);
154                }
155                
156                FileInfo fileInfo = fileFolderService.create(
157                      parentNodeRef,
158                      this.name,
159                      Repository.resolveToQName(this.spaceType));
160                NodeRef nodeRef = fileInfo.getNodeRef();
161                newSpaceId = nodeRef.getId();
162                
163                if (logger.isDebugEnabled())
164                   logger.debug("Created folder node with name: " + this.name);
165
166                // apply the uifacets aspect - icon, title and description props
167
Map JavaDoc<QName, Serializable JavaDoc> uiFacetsProps = new HashMap JavaDoc<QName, Serializable JavaDoc>(5);
168                uiFacetsProps.put(ContentModel.PROP_ICON, this.icon);
169                uiFacetsProps.put(ContentModel.PROP_TITLE, this.name);
170                uiFacetsProps.put(ContentModel.PROP_DESCRIPTION, this.description);
171                this.nodeService.addAspect(nodeRef, ContentModel.ASPECT_UIFACETS, uiFacetsProps);
172                
173                if (logger.isDebugEnabled())
174                   logger.debug("Added uifacets aspect with properties: " + uiFacetsProps);
175                
176                // remember the created node
177
this.createdNode = nodeRef;
178             }
179             else if (this.createFrom.equals("existing"))
180             {
181                // copy the selected space and update the name, description and icon
182
NodeRef sourceNode = this.existingSpaceId;
183                NodeRef parentSpace = new NodeRef(Repository.getStoreRef(), getNavigator().getCurrentNodeId());
184                
185                // copy from existing
186
NodeRef copiedNode = this.fileFolderService.copy(sourceNode, parentSpace, this.name).getNodeRef();
187                
188                // also need to set the new description and icon properties
189
this.nodeService.setProperty(copiedNode, ContentModel.PROP_DESCRIPTION, this.description);
190                this.nodeService.setProperty(copiedNode, ContentModel.PROP_ICON, this.icon);
191                
192                newSpaceId = copiedNode.getId();
193                   
194                if (logger.isDebugEnabled())
195                   logger.debug("Copied space with id of " + sourceNode.getId() + " to " + this.name);
196                
197                // remember the created node
198
this.createdNode = copiedNode;
199             }
200             else if (this.createFrom.equals("template"))
201             {
202                // copy the selected space and update the name, description and icon
203
NodeRef sourceNode = new NodeRef(Repository.getStoreRef(), this.templateSpaceId);
204                NodeRef parentSpace = new NodeRef(Repository.getStoreRef(), getNavigator().getCurrentNodeId());
205                // copy from the template
206
NodeRef copiedNode = this.fileFolderService.copy(sourceNode, parentSpace, this.name).getNodeRef();
207                // also need to set the new description and icon properties
208
this.nodeService.setProperty(copiedNode, ContentModel.PROP_DESCRIPTION, this.description);
209                this.nodeService.setProperty(copiedNode, ContentModel.PROP_ICON, this.icon);
210                
211                newSpaceId = copiedNode.getId();
212                
213                if (logger.isDebugEnabled())
214                   logger.debug("Copied template space with id of " + sourceNode.getId() + " to " + this.name);
215                
216                // remember the created node
217
this.createdNode = copiedNode;
218             }
219             
220             // if the user selected to save the space as a template space copy the new
221
// space to the templates folder
222
if (this.saveAsTemplate)
223             {
224                // get hold of the Templates node
225
DynamicNamespacePrefixResolver namespacePrefixResolver = new DynamicNamespacePrefixResolver(null);
226                namespacePrefixResolver.registerNamespace(NamespaceService.APP_MODEL_PREFIX, NamespaceService.APP_MODEL_1_0_URI);
227                
228                String JavaDoc xpath = Application.getRootPath(FacesContext.getCurrentInstance()) + "/" +
229                      Application.getGlossaryFolderName(FacesContext.getCurrentInstance()) + "/" +
230                      Application.getSpaceTemplatesFolderName(FacesContext.getCurrentInstance());
231                
232                NodeRef rootNodeRef = this.nodeService.getRootNode(Repository.getStoreRef());
233                List JavaDoc<NodeRef> templateNodeList = this.searchService.selectNodes(
234                      rootNodeRef,
235                      xpath, null, namespacePrefixResolver, false);
236                if (templateNodeList.size() == 1)
237                {
238                   // get the first item in the list as we from test above there is only one!
239
NodeRef templateNode = templateNodeList.get(0);
240                   NodeRef sourceNode = new NodeRef(Repository.getStoreRef(), newSpaceId);
241                   // copy this to the template location
242
fileFolderService.copy(sourceNode, templateNode, this.templateName);
243                }
244             }
245          }
246          
247          // give subclasses a chance to perform custom processing before committing
248
performCustomProcessing(context);
249          
250          // commit the transaction
251
tx.commit();
252          
253          // now we know the new details are in the repository, reset the
254
// client side node representation so the new details are retrieved
255
String JavaDoc statusMsg = null;
256          if (this.editMode)
257          {
258             this.browseBean.getActionSpace().reset();
259             statusMsg = MessageFormat.format(Application.getMessage(context, "status_space_updated"),
260                   new Object JavaDoc[]{this.name});
261          }
262          else
263          {
264             // add a message to inform the user that the creation was OK
265
statusMsg = MessageFormat.format(Application.getMessage(context, "status_space_created"),
266                   new Object JavaDoc[]{this.name});
267          }
268          
269          // add the status message
270
Utils.addStatusMessage(FacesMessage.SEVERITY_INFO, statusMsg);
271       }
272       catch (FileExistsException e)
273       {
274          // rollback the transaction
275
try { if (tx != null) {tx.rollback();} } catch (Exception JavaDoc ex) {}
276          // print status message
277
String JavaDoc statusMsg = MessageFormat.format(
278                Application.getMessage(
279                      FacesContext.getCurrentInstance(), "error_exists"),
280                      e.getExisting().getName());
281          Utils.addErrorMessage(statusMsg);
282          // no outcome
283
outcome = null;
284       }
285       catch (Throwable JavaDoc e)
286       {
287          // rollback the transaction
288
try { if (tx != null) {tx.rollback();} } catch (Exception JavaDoc ex) {}
289          Utils.addErrorMessage(MessageFormat.format(Application.getMessage(
290                FacesContext.getCurrentInstance(), ERROR), e.getMessage()), e);
291          outcome = null;
292       }
293       
294       return outcome;
295    }
296    
297    /**
298     * @see org.alfresco.web.bean.wizard.AbstractWizardBean#getWizardDescription()
299     */

300    public String JavaDoc getWizardDescription()
301    {
302       return Application.getMessage(FacesContext.getCurrentInstance(), WIZARD_DESC_ID);
303    }
304
305    /**
306     * @see org.alfresco.web.bean.wizard.AbstractWizardBean#getWizardTitle()
307     */

308    public String JavaDoc getWizardTitle()
309    {
310       return Application.getMessage(FacesContext.getCurrentInstance(), WIZARD_TITLE_ID);
311    }
312    
313    /**
314     * @see org.alfresco.web.bean.wizard.AbstractWizardBean#getStepDescription()
315     */

316    public String JavaDoc getStepDescription()
317    {
318       String JavaDoc stepDesc = null;
319       
320       switch (this.currentStep)
321       {
322          case 1:
323          {
324             stepDesc = Application.getMessage(FacesContext.getCurrentInstance(), STEP1_DESCRIPTION_ID);
325             break;
326          }
327          case 2:
328          {
329             stepDesc = Application.getMessage(FacesContext.getCurrentInstance(), STEP2_DESCRIPTION_ID);
330             break;
331          }
332          case 3:
333          {
334             stepDesc = Application.getMessage(FacesContext.getCurrentInstance(), STEP3_DESCRIPTION_ID);
335             break;
336          }
337          case 4:
338          {
339             stepDesc = Application.getMessage(FacesContext.getCurrentInstance(), SUMMARY_DESCRIPTION_ID);
340             break;
341          }
342          default:
343          {
344             stepDesc = "";
345          }
346       }
347       
348       return stepDesc;
349    }
350
351    /**
352     * @see org.alfresco.web.bean.wizard.AbstractWizardBean#getStepTitle()
353     */

354    public String JavaDoc getStepTitle()
355    {
356       String JavaDoc stepTitle = null;
357       
358       switch (this.currentStep)
359       {
360          case 1:
361          {
362             stepTitle = Application.getMessage(FacesContext.getCurrentInstance(), STEP1_TITLE_ID);
363             break;
364          }
365          case 2:
366          {
367             stepTitle = Application.getMessage(FacesContext.getCurrentInstance(), STEP2_TITLE_ID);
368             break;
369          }
370          case 3:
371          {
372             stepTitle = Application.getMessage(FacesContext.getCurrentInstance(), STEP3_TITLE_ID);
373             break;
374          }
375          case 4:
376          {
377             stepTitle = Application.getMessage(FacesContext.getCurrentInstance(), SUMMARY_TITLE_ID);
378             break;
379          }
380          default:
381          {
382             stepTitle = "";
383          }
384       }
385       
386       return stepTitle;
387    }
388    
389    /**
390     * @see org.alfresco.web.bean.wizard.AbstractWizardBean#getStepInstructions()
391     */

392    public String JavaDoc getStepInstructions()
393    {
394       String JavaDoc stepInstruction = null;
395       
396       switch (this.currentStep)
397       {
398          case 4:
399          {
400             stepInstruction = Application.getMessage(FacesContext.getCurrentInstance(), FINISH_INSTRUCTION_ID);
401             break;
402          }
403          default:
404          {
405             stepInstruction = Application.getMessage(FacesContext.getCurrentInstance(), DEFAULT_INSTRUCTION_ID);
406          }
407       }
408       
409       return stepInstruction;
410    }
411    
412    /**
413     * Initialises the wizard
414     */

415    public void init()
416    {
417       super.init();
418       
419       // clear the cached query results
420
if (this.templates != null)
421       {
422          this.templates.clear();
423          this.templates = null;
424       }
425       
426       // reset all variables
427
this.createFrom = "scratch";
428       this.spaceType = ContentModel.TYPE_FOLDER.toString();
429       this.icon = null;
430       this.copyPolicy = "contents";
431       this.existingSpaceId = null;
432       this.templateSpaceId = null;
433       this.name = null;
434       this.description = "";
435       this.templateName = null;
436       this.saveAsTemplate = false;
437    }
438
439    /**
440     * @see org.alfresco.web.bean.wizard.AbstractWizardBean#populate()
441     */

442    public void populate()
443    {
444       // get hold of the current node and populate the appropriate values
445
Node currentSpace = browseBean.getActionSpace();
446       Map JavaDoc<String JavaDoc, Object JavaDoc> props = currentSpace.getProperties();
447       
448       this.name = (String JavaDoc)props.get("name");
449       this.description = (String JavaDoc)props.get("description");
450       this.icon = (String JavaDoc)props.get("app:icon");
451    }
452
453    /**
454     * @return Returns the summary data for the wizard.
455     */

456    public String JavaDoc getSummary()
457    {
458       String JavaDoc summaryCreateType = null;
459       ResourceBundle JavaDoc bundle = Application.getBundle(FacesContext.getCurrentInstance());
460       
461       if (this.createFrom.equals("scratch"))
462       {
463          summaryCreateType = bundle.getString("scratch");
464       }
465       else if (this.createFrom.equals("existing"))
466       {
467          summaryCreateType = bundle.getString("an_existing_space");
468       }
469       else if (this.createFrom.equals("template"))
470       {
471          summaryCreateType = bundle.getString("a_template");
472       }
473       
474 // String summarySaveAsTemplate = this.saveAsTemplate ? bundle.getString("yes") : bundle.getString("no");
475
// bundle.getString("save_as_template"), bundle.getString("template_name")},
476
// summarySaveAsTemplate, this.templateName
477

478       String JavaDoc spaceTypeLabel = null;
479       for (UIListItem item : this.getFolderTypes())
480       {
481          if (item.getValue().equals(this.spaceType))
482          {
483             spaceTypeLabel = item.getLabel();
484             break;
485          }
486       }
487       
488       return buildSummary(
489             new String JavaDoc[] {bundle.getString("space_type"), bundle.getString("name"),
490                           bundle.getString("description"), bundle.getString("creating_from")},
491             new String JavaDoc[] {spaceTypeLabel, this.name, this.description, summaryCreateType});
492    }
493    
494    /**
495     * @return Returns a list of template spaces currently in the system
496     */

497    public List JavaDoc<SelectItem> getTemplateSpaces()
498    {
499       if (this.templates == null)
500       {
501          this.templates = new ArrayList JavaDoc<SelectItem>();
502          
503          FacesContext context = FacesContext.getCurrentInstance();
504          String JavaDoc xpath = Application.getRootPath(context) + "/" + Application.getGlossaryFolderName(context) +
505                "/" + Application.getSpaceTemplatesFolderName(context) + "/*";
506          NodeRef rootNodeRef = this.nodeService.getRootNode(Repository.getStoreRef());
507          NamespaceService resolver = Repository.getServiceRegistry(context).getNamespaceService();
508          List JavaDoc<NodeRef> results = this.searchService.selectNodes(rootNodeRef, xpath, null, resolver, false);
509          
510          if (results.size() > 0)
511          {
512             for (NodeRef assocRef : results)
513             {
514                Node childNode = new Node(assocRef);
515                this.templates.add(new SelectItem(childNode.getId(), childNode.getName()));
516             }
517             
518             // make sure the list is sorted by the label
519
QuickSort sorter = new QuickSort(this.templates, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
520             sorter.sort();
521          }
522          
523          // add an entry (at the start) to instruct the user to select a template
524
this.templates.add(0, new SelectItem("none", Application.getMessage(FacesContext.getCurrentInstance(), "select_a_template")));
525       }
526       
527       return this.templates;
528    }
529
530    /**
531     * Returns a list of UIListItem objects representing the folder types
532     * and also constructs the list of descriptions for each type
533     *
534     * @return List of UIListItem components
535     */

536    @SuppressWarnings JavaDoc("unchecked")
537    public List JavaDoc<UIListItem> getFolderTypes()
538    {
539       if (this.folderTypes == null)
540       {
541          FacesContext context = FacesContext.getCurrentInstance();
542          this.folderTypes = new ArrayList JavaDoc<UIListItem>(2);
543          this.folderTypeDescriptions = new ArrayList JavaDoc<UIDescription>(2);
544          
545          // add the well known 'container space' type to start with
546
UIListItem defaultItem = new UIListItem();
547          String JavaDoc defaultLabel = Application.getMessage(context, "container");
548          defaultItem.setValue(ContentModel.TYPE_FOLDER.toString());
549          defaultItem.setLabel(defaultLabel);
550          defaultItem.setTooltip(defaultLabel);
551          defaultItem.getAttributes().put("image", DEFAULT_SPACE_TYPE_ICON);
552          this.folderTypes.add(defaultItem);
553          
554          UIDescription defaultDesc = new UIDescription();
555          defaultDesc.setControlValue(ContentModel.TYPE_FOLDER.toString());
556          defaultDesc.setText(Application.getMessage(context, "container_desc"));
557          this.folderTypeDescriptions.add(defaultDesc);
558          
559          // add any configured content sub-types to the list
560
Config wizardCfg = Application.getConfigService(FacesContext.getCurrentInstance()).
561                getConfig("Custom Folder Types");
562          if (wizardCfg != null)
563          {
564             ConfigElement typesCfg = wizardCfg.getConfigElement("folder-types");
565             if (typesCfg != null)
566             {
567                for (ConfigElement child : typesCfg.getChildren())
568                {
569                   QName idQName = Repository.resolveToQName(child.getAttribute("name"));
570                   TypeDefinition typeDef = this.dictionaryService.getType(idQName);
571                   
572                   if (typeDef != null &&
573                       this.dictionaryService.isSubClass(typeDef.getName(), ContentModel.TYPE_FOLDER))
574                   {
575                      // look for a client localized string
576
String JavaDoc label = null;
577                      String JavaDoc msgId = child.getAttribute("displayLabelId");
578                      if (msgId != null)
579                      {
580                         label = Application.getMessage(context, msgId);
581                      }
582                      
583                      // if there wasn't an externalized string look for one in the config
584
if (label == null)
585                      {
586                         label = child.getAttribute("displayLabel");
587                      }
588    
589                      // if there wasn't a client based label try and get it from the dictionary
590
if (label == null)
591                      {
592                         label = typeDef.getTitle();
593                      }
594                      
595                      // finally use the localname if we still haven't found a label
596
if (label == null)
597                      {
598                         label = idQName.getLocalName();
599                      }
600                      
601                      // resolve a description string for the type
602
String JavaDoc description = null;
603                      msgId = child.getAttribute("descriptionMsgId");
604                      if (msgId != null)
605                      {
606                         description = Application.getMessage(context, msgId);
607                      }
608                      
609                      if (description == null)
610                      {
611                         description = child.getAttribute("description");
612                      }
613                      
614                      // if we don't have a local description just use the label
615
if (description == null)
616                      {
617                         description = label;
618                      }
619                      
620                      // extract the icon to use from the config
621
String JavaDoc icon = child.getAttribute("icon");
622                      if (icon == null || icon.length() == 0)
623                      {
624                         icon = DEFAULT_SPACE_TYPE_ICON;
625                      }
626                      
627                      UIListItem item = new UIListItem();
628                      item.getAttributes().put("value", idQName.toString());
629                      item.getAttributes().put("label", label);
630                      item.getAttributes().put("tooltip", label);
631                      item.getAttributes().put("image", icon);
632                      this.folderTypes.add(item);
633                      
634                      UIDescription desc = new UIDescription();
635                      desc.setControlValue(idQName.toString());
636                      desc.setText(description);
637                      this.folderTypeDescriptions.add(desc);
638                   }
639                }
640             }
641             else
642             {
643                logger.warn("Could not find 'folder-types' configuration element");
644             }
645          }
646          else
647          {
648             logger.warn("Could not find 'Custom Folder Types' configuration section");
649          }
650          
651       }
652       
653       return this.folderTypes;
654    }
655    
656    /**
657     * Returns a list of UIDescription objects for the folder types
658     *
659     * @return A list of UIDescription objects
660     */

661    public List JavaDoc<UIDescription> getFolderTypeDescriptions()
662    {
663       if (this.folderTypeDescriptions == null)
664       {
665          // call the getFolderType method to construct the list
666
getFolderTypes();
667       }
668       
669       return this.folderTypeDescriptions;
670    }
671    
672    /**
673     * Returns a list of icons to allow the user to select from.
674     * The list can change according to the type of space being created.
675     *
676     * @return A list of icons
677     */

678    @SuppressWarnings JavaDoc("unchecked")
679    public List JavaDoc<UIListItem> getIcons()
680    {
681       // NOTE: we can't cache this list as it depends on the space type
682
// which the user can change during the advanced space wizard
683

684       List JavaDoc<UIListItem> icons = null;
685       
686       QName type = QName.createQName(this.spaceType);
687       String JavaDoc typePrefixForm = type.toPrefixString(this.namespaceService);
688       
689       Config config = Application.getConfigService(FacesContext.getCurrentInstance()).
690             getConfig(typePrefixForm + ICONS_LOOKUP_KEY);
691       if (config != null)
692       {
693          ConfigElement iconsCfg = config.getConfigElement("icons");
694          if (iconsCfg != null)
695          {
696             boolean first = true;
697             for (ConfigElement icon : iconsCfg.getChildren())
698             {
699                String JavaDoc iconName = icon.getAttribute("name");
700                String JavaDoc iconPath = icon.getAttribute("path");
701                
702                if (iconName != null && iconPath != null)
703                {
704                   if (first)
705                   {
706                      // if this is the first icon create the list and make
707
// the first icon in the list the default
708

709                      icons = new ArrayList JavaDoc<UIListItem>(iconsCfg.getChildCount());
710                      if (this.icon == null)
711                      {
712                         // set the default if it is not already
713
this.icon = iconName;
714                      }
715                      first = false;
716                   }
717                   
718                   UIListItem item = new UIListItem();
719                   item.setValue(iconName);
720                   item.getAttributes().put("image", iconPath);
721                   icons.add(item);
722                }
723             }
724          }
725       }
726       
727       // if we didn't find any icons display one default choice
728
if (icons == null)
729       {
730          icons = new ArrayList JavaDoc<UIListItem>(1);
731          this.icon = SPACE_ICON_DEFAULT;
732          
733          UIListItem item = new UIListItem();
734          item.setValue("space-icon-default");
735          item.getAttributes().put("image", "/images/icons/space-icon-default.gif");
736          icons.add(item);
737       }
738       
739       return icons;
740    }
741    
742    /**
743     * @return Returns the searchService.
744     */

745    public SearchService getSearchService()
746    {
747       return searchService;
748    }
749
750    /**
751     * @param searchService The searchService to set.
752     */

753    public void setSearchService(SearchService searchService)
754    {
755       this.searchService = searchService;
756    }
757    
758    /**
759     * @param namespaceService The NamespaceService
760     */

761    public void setNamespaceService(NamespaceService namespaceService)
762    {
763       this.namespaceService = namespaceService;
764    }
765
766    /**
767     * Sets the dictionary service
768     *
769     * @param dictionaryService the dictionary service
770     */

771    public void setDictionaryService(DictionaryService dictionaryService)
772    {
773       this.dictionaryService = dictionaryService;
774    }
775
776    /**
777     * @return Returns the copyPolicy.
778     */

779    public String JavaDoc getCopyPolicy()
780    {
781       return copyPolicy;
782    }
783
784    /**
785     * @param copyPolicy The copyPolicy to set.
786     */

787    public void setCopyPolicy(String JavaDoc copyPolicy)
788    {
789       this.copyPolicy = copyPolicy;
790    }
791    
792    /**
793     * @return Returns the createFrom.
794     */

795    public String JavaDoc getCreateFrom()
796    {
797       return createFrom;
798    }
799
800    /**
801     * @param createFrom The createFrom to set.
802     */

803    public void setCreateFrom(String JavaDoc createFrom)
804    {
805       this.createFrom = createFrom;
806    }
807
808    /**
809     * @return Returns the description.
810     */

811    public String JavaDoc getDescription()
812    {
813       return description;
814    }
815    
816    /**
817     * @param description The description to set.
818     */

819    public void setDescription(String JavaDoc description)
820    {
821       this.description = description;
822    }
823
824    /**
825     * @return Returns the existingSpaceId.
826     */

827    public NodeRef getExistingSpaceId()
828    {
829       return existingSpaceId;
830    }
831    
832    /**
833     * @param existingSpaceId The existingSpaceId to set.
834     */

835    public void setExistingSpaceId(NodeRef existingSpaceId)
836    {
837       this.existingSpaceId = existingSpaceId;
838    }
839    
840    /**
841     * @return Returns the icon.
842     */

843    public String JavaDoc getIcon()
844    {
845       return icon;
846    }
847    
848    /**
849     * @param icon The icon to set.
850     */

851    public void setIcon(String JavaDoc icon)
852    {
853       this.icon = icon;
854    }
855    
856    /**
857     * @return Returns the name.
858     */

859    public String JavaDoc getName()
860    {
861       return name;
862    }
863    
864    /**
865     * @param name The name to set.
866     */

867    public void setName(String JavaDoc name)
868    {
869       this.name = name;
870    }
871    
872    /**
873     * @return Returns the saveAsTemplate.
874     */

875    public boolean isSaveAsTemplate()
876    {
877       return saveAsTemplate;
878    }
879    
880    /**
881     * @param saveAsTemplate The saveAsTemplate to set.
882     */

883    public void setSaveAsTemplate(boolean saveAsTemplate)
884    {
885       this.saveAsTemplate = saveAsTemplate;
886    }
887
888    /**
889     * @return Returns the spaceType.
890     */

891    public String JavaDoc getSpaceType()
892    {
893       return spaceType;
894    }
895    
896    /**
897     * @param spaceType The spaceType to set.
898     */

899    public void setSpaceType(String JavaDoc spaceType)
900    {
901       this.spaceType = spaceType;
902    }
903    
904    /**
905     * @return Returns the templateName.
906     */

907    public String JavaDoc getTemplateName()
908    {
909       return templateName;
910    }
911    
912    /**
913     * @param templateName The templateName to set.
914     */

915    public void setTemplateName(String JavaDoc templateName)
916    {
917       this.templateName = templateName;
918    }
919    
920    /**
921     * @return Returns the templateSpaceId.
922     */

923    public String JavaDoc getTemplateSpaceId()
924    {
925       return templateSpaceId;
926    }
927    
928    /**
929     * @param templateSpaceId The templateSpaceId to set.
930     */

931    public void setTemplateSpaceId(String JavaDoc templateSpaceId)
932    {
933       this.templateSpaceId = templateSpaceId;
934    }
935    
936    /**
937     * @see org.alfresco.web.bean.wizard.AbstractWizardBean#determineOutcomeForStep(int)
938     */

939    protected String JavaDoc determineOutcomeForStep(int step)
940    {
941       String JavaDoc outcome = null;
942       
943       switch(step)
944       {
945          case 1:
946          {
947             outcome = "create-from";
948             break;
949          }
950          case 2:
951          {
952             if (createFrom.equalsIgnoreCase("scratch"))
953             {
954                outcome = "from-scratch";
955             }
956             else if (createFrom.equalsIgnoreCase("existing"))
957             {
958                outcome = "from-existing";
959             }
960             else if (createFrom.equalsIgnoreCase("template"))
961             {
962                outcome = "from-template";
963             }
964             
965             break;
966          }
967          case 3:
968          {
969             outcome = "details";
970             break;
971          }
972          case 4:
973          {
974             outcome = "summary";
975             break;
976          }
977          default:
978          {
979             outcome = CANCEL_OUTCOME;
980          }
981       }
982       
983       return outcome;
984    }
985    
986    /**
987     * Performs any processing sub classes may wish to do before commit is called
988     *
989     * @param context Faces context
990     */

991    protected void performCustomProcessing(FacesContext context) throws Exception JavaDoc
992    {
993       // used by subclasses if necessary
994
}
995 }
996
Popular Tags