View Javadoc
1   /*
2    * Copyright (C) 2003-2008 eXo Platform SAS.
3    *
4    * This program is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Affero General Public License
6    * as published by the Free Software Foundation; either version 3
7    * of the License, or (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program; if not, see<http://www.gnu.org/licenses/>.
16   */
17  package org.exoplatform.wcm.webui.dialog;
18  
19  import java.security.AccessControlException;
20  import java.util.ArrayList;
21  import java.util.HashMap;
22  import java.util.List;
23  import java.util.Map;
24  
25  import javax.jcr.AccessDeniedException;
26  import javax.jcr.ItemExistsException;
27  import javax.jcr.ItemNotFoundException;
28  import javax.jcr.Node;
29  import javax.jcr.NodeIterator;
30  import javax.jcr.RepositoryException;
31  import javax.jcr.Session;
32  import javax.jcr.Value;
33  import javax.jcr.lock.LockException;
34  import javax.jcr.version.VersionException;
35  import javax.portlet.PortletMode;
36  
37  import org.exoplatform.ecm.resolver.JCRResourceResolver;
38  import org.exoplatform.ecm.webui.form.UIDialogForm;
39  import org.exoplatform.ecm.webui.selector.UISelectable;
40  import org.exoplatform.ecm.webui.tree.selectone.UIOneTaxonomySelector;
41  import org.exoplatform.ecm.webui.utils.DialogFormUtil;
42  import org.exoplatform.webui.form.UIFormMultiValueInputSet;
43  import org.exoplatform.portal.webui.util.Util;
44  import org.exoplatform.portal.webui.workspace.UIPortalApplication;
45  import org.exoplatform.resolver.ResourceResolver;
46  import org.exoplatform.services.cms.BasePath;
47  import org.exoplatform.services.cms.CmsService;
48  import org.exoplatform.services.cms.JcrInputProperty;
49  import org.exoplatform.services.cms.impl.DMSConfiguration;
50  import org.exoplatform.services.cms.impl.DMSRepositoryConfiguration;
51  import org.exoplatform.services.cms.link.LinkManager;
52  import org.exoplatform.services.cms.taxonomy.TaxonomyService;
53  import org.exoplatform.services.cms.templates.TemplateService;
54  import org.exoplatform.services.ecm.publication.PublicationPlugin;
55  import org.exoplatform.services.ecm.publication.PublicationService;
56  import org.exoplatform.services.jcr.RepositoryService;
57  import org.exoplatform.services.jcr.core.ManageableRepository;
58  import org.exoplatform.services.jcr.ext.hierarchy.NodeHierarchyCreator;
59  import org.exoplatform.services.log.ExoLogger;
60  import org.exoplatform.services.log.Log;
61  import org.exoplatform.services.wcm.core.NodeLocation;
62  import org.exoplatform.services.wcm.publication.PublicationDefaultStates;
63  import org.exoplatform.services.wcm.utils.WCMCoreUtils;
64  import org.exoplatform.wcm.webui.Utils;
65  import org.exoplatform.web.application.ApplicationMessage;
66  import org.exoplatform.webui.application.WebuiRequestContext;
67  import org.exoplatform.webui.application.portlet.PortletRequestContext;
68  import org.exoplatform.webui.config.annotation.ComponentConfig;
69  import org.exoplatform.webui.config.annotation.EventConfig;
70  import org.exoplatform.webui.core.UIApplication;
71  import org.exoplatform.webui.core.UIComponent;
72  import org.exoplatform.webui.core.UIPopupComponent;
73  import org.exoplatform.webui.core.UIPopupContainer;
74  import org.exoplatform.webui.core.lifecycle.UIFormLifecycle;
75  import org.exoplatform.webui.event.Event;
76  import org.exoplatform.webui.event.EventListener;
77  import org.exoplatform.webui.event.Event.Phase;
78  import org.exoplatform.webui.form.UIFormInput;
79  import org.exoplatform.webui.form.UIFormInputBase;
80  import org.exoplatform.webui.form.UIFormStringInput;
81  import org.exoplatform.ecm.webui.form.DialogFormActionListeners;
82  
83  /**
84   * Created by The eXo Platform SAS
85   * Author : Phan Le Thanh Chuong
86   * chuong.phan@exoplatform.com, phan.le.thanh.chuong@gmail.com
87   * Oct 29, 2009
88   */
89  @ComponentConfig (
90      lifecycle = UIFormLifecycle.class,
91      events = {
92        @EventConfig(listeners = UIContentDialogForm.AddActionListener.class, phase = Phase.DECODE),
93        @EventConfig(listeners = UIContentDialogForm.RemoveReferenceActionListener.class,
94                     confirm = "DialogFormField.msg.confirm-delete", phase = Phase.DECODE),
95        @EventConfig(listeners = UIContentDialogForm.SaveDraftActionListener.class),
96        @EventConfig(listeners = UIContentDialogForm.FastPublishActionListener.class),
97        @EventConfig(listeners = UIContentDialogForm.PreferencesActionListener.class),
98        @EventConfig(listeners = UIContentDialogForm.CloseActionListener.class),
99        @EventConfig(listeners = DialogFormActionListeners.RemoveDataActionListener.class, phase = Phase.DECODE),
100       @EventConfig(listeners = DialogFormActionListeners.ChangeTabActionListener.class, phase = Phase.DECODE)
101     }
102 )
103 public class UIContentDialogForm extends UIDialogForm  implements UIPopupComponent, UISelectable {
104 
105   /** The Constant CONTENT_DIALOG_FORM_POPUP_WINDOW. */
106   public static final String CONTENT_DIALOG_FORM_POPUP_WINDOW = "UIContentDialogFormPopupWindow";
107 
108   /** The Constant FIELD_TAXONOMY. */
109   public static final String FIELD_TAXONOMY = "categories";
110 
111   /** The Constant TAXONOMY_CONTENT_POPUP_WINDOW. */
112   public static final String TAXONOMY_CONTENT_POPUP_WINDOW = "UIContentPopupWindow";
113 
114   /** The Log **/
115   private static final Log LOG  = ExoLogger.getLogger(UIContentDialogForm.class.getName());
116 
117   /** The webcontent node location. */
118   private NodeLocation webcontentNodeLocation;
119 
120   /** The list taxonomy. */
121   private List<String> listTaxonomy = new ArrayList<String>();
122 
123   /** The list taxonomy name. */
124   private List<String> listTaxonomyName = new ArrayList<String>();
125 
126   /** The template. */
127   private String template;
128 
129 
130   /**
131    * Gets the list taxonomy.
132    *
133    * @return the list taxonomy
134    */
135   public List<String> getListTaxonomy() {
136     return listTaxonomy;
137   }
138 
139   /**
140    * Gets the list taxonomy name.
141    *
142    * @return the list taxonomy name
143    */
144   public List<String> getlistTaxonomyName() {
145     return listTaxonomyName;
146   }
147 
148   /**
149    * Sets the list taxonomy.
150    *
151    * @param listTaxonomyNew the new list taxonomy
152    */
153   public void setListTaxonomy(List<String> listTaxonomyNew) {
154     listTaxonomy = listTaxonomyNew;
155   }
156 
157   /**
158    * Sets the list taxonomy name.
159    *
160    * @param listTaxonomyNameNew the new list taxonomy name
161    */
162   public void setListTaxonomyName(List<String> listTaxonomyNameNew) {
163     listTaxonomyName = listTaxonomyNameNew;
164   }
165 
166   /** The preference component. */
167   private Class<? extends UIContentDialogPreference> preferenceComponent;
168 
169   /**
170    * Gets the webcontent node location.
171    *
172    * @return the webcontent node location
173    */
174   public NodeLocation getWebcontentNodeLocation() {
175     return webcontentNodeLocation;
176   }
177 
178   /**
179    * Sets the webcontent node location.
180    *
181    * @param webcontentNodeLocation the new webcontent node location
182    */
183   public void setWebcontentNodeLocation(NodeLocation webcontentNodeLocation) {
184     this.webcontentNodeLocation = webcontentNodeLocation;
185   }
186 
187   /**
188    * Gets the preference component.
189    *
190    * @return the preference component
191    */
192   public Class<? extends UIContentDialogPreference> getPreferenceComponent() {
193     return preferenceComponent;
194   }
195 
196   /**
197    * Sets the preference component.
198    *
199    * @param preferenceComponent the new preference component
200    */
201   public void setPreferenceComponent(Class<? extends UIContentDialogPreference> preferenceComponent) {
202     this.preferenceComponent = preferenceComponent;
203   }
204 
205   /**
206    * Instantiates a new uI content dialog form.
207    *
208    * @throws Exception the exception
209    */
210   public UIContentDialogForm() throws Exception {
211     setActions(new String [] {"SaveDraft", "FastPublish", "Preferences", "Close"});
212   }
213 
214   /**
215    * Inits the.
216    *
217    * @param webcontent the webcontent
218    * @param isAddNew the is add new
219    *
220    * @throws Exception the exception
221    */
222   public void init(Node webcontent, boolean isAddNew) throws Exception {
223     NodeLocation webcontentNodeLocation = null;
224     if(webcontent.isNodeType("exo:symlink")) {
225       LinkManager linkManager = getApplicationComponent(LinkManager.class);
226       Node realNode = linkManager.getTarget(webcontent);
227       webcontentNodeLocation = NodeLocation.getNodeLocationByNode(realNode);
228       this.contentType = realNode.getPrimaryNodeType().getName();
229       this.nodePath = realNode.getPath();
230       setStoredPath(getParentPath(realNode));
231     } else {
232       webcontentNodeLocation = NodeLocation.getNodeLocationByNode(webcontent);
233       this.contentType = webcontent.getPrimaryNodeType().getName();
234       this.nodePath = webcontent.getPath();
235       setStoredPath(getParentPath(webcontent));
236     }
237     this.webcontentNodeLocation = webcontentNodeLocation;
238     this.repositoryName = webcontentNodeLocation.getRepository();
239     this.workspaceName = webcontentNodeLocation.getWorkspace();
240     this.isAddNew = isAddNew;
241     resetProperties();
242     TemplateService templateService = getApplicationComponent(TemplateService.class) ;
243     String userName = Util.getPortalRequestContext().getRemoteUser();
244     this.template = templateService.getTemplatePathByUser(true, contentType, userName);
245     initFieldInput();
246   }
247 
248   private String getParentPath(Node node) throws RepositoryException {
249     return node.getPath().substring(0, node.getPath().lastIndexOf('/'));
250   }
251 
252   /**
253    * Inits the field input.
254    *
255    * @throws Exception the exception
256    */
257   private void initFieldInput() throws Exception {
258     TemplateService tservice = this.getApplicationComponent(TemplateService.class);
259     List<String> documentNodeType = tservice.getDocumentTemplates();
260     if(!documentNodeType.contains(this.contentType)){
261       return;
262     }
263     if (!isAddNew) {
264       TaxonomyService taxonomyService = getApplicationComponent(TaxonomyService.class);
265       Node currentNode = getCurrentNode();
266       List<Node> listCategories = taxonomyService.getAllCategories(currentNode);
267       for (Node itemNode : listCategories) {
268         String categoryPath = itemNode.getPath().replaceAll(getPathTaxonomy() + "/", "");
269         if (!listTaxonomy.contains(categoryPath)) {
270           listTaxonomy.add(categoryPath);
271           listTaxonomyName.add(categoryPath);
272         }
273       }
274     }
275     if(listTaxonomyName == null || listTaxonomyName.size() == 0) return;
276     UIFormMultiValueInputSet uiFormMultiValue = createUIComponent(UIFormMultiValueInputSet.class, null, null);
277     uiFormMultiValue.setId(FIELD_TAXONOMY);
278     uiFormMultiValue.setName(FIELD_TAXONOMY);
279     uiFormMultiValue.setType(UIFormStringInput.class);
280     uiFormMultiValue.setValue(listTaxonomyName);
281     addUIFormInput(uiFormMultiValue);
282   }
283 
284   /**
285    * Gets the current node.
286    *
287    * @return the current node
288    */
289   public Node getCurrentNode() {
290     return NodeLocation.getNodeByLocation(webcontentNodeLocation);
291   }
292 
293   /* (non-Javadoc)
294    * @see org.exoplatform.ecm.webui.form.UIDialogForm#getTemplate()
295    */
296   public String getTemplate() {
297     return template;
298   }
299 
300   /*
301    * (non-Javadoc)
302    * @see
303    * org.exoplatform.webui.core.UIComponent#getTemplateResourceResolver(org.
304    * exoplatform.webui.application.WebuiRequestContext, java.lang.String)
305    */
306   public ResourceResolver getTemplateResourceResolver(WebuiRequestContext context, String template) {
307     DMSConfiguration dmsConfiguration = getApplicationComponent(DMSConfiguration.class);
308     String workspace = dmsConfiguration.getConfig().getSystemWorkspace();
309     return new JCRResourceResolver(workspace);
310   }
311 
312   /**
313    * The listener interface for receiving closeAction events.
314    * The class that is interested in processing a cancelAction
315    * event implements this interface, and the object created
316    * with that class is registered with a component using the
317    * component's <code>addCloseActionListener</code> method. When
318    * the cancelAction event occurs, that object's appropriate
319    * method is invoked.
320    */
321   static public class CloseActionListener extends EventListener<UIContentDialogForm> {
322 
323     /* (non-Javadoc)
324      * @see org.exoplatform.webui.event.EventListener#execute(org.exoplatform.webui.event.Event)
325      */
326     public void execute(Event<UIContentDialogForm> event) throws Exception {
327       UIContentDialogForm contentDialogForm = event.getSource();
328       if (Util.getUIPortalApplication().getModeState() == UIPortalApplication.NORMAL_MODE)
329         ((PortletRequestContext)event.getRequestContext()).setApplicationMode(PortletMode.VIEW);
330       Utils.closePopupWindow(contentDialogForm, CONTENT_DIALOG_FORM_POPUP_WINDOW);
331     }
332   }
333 
334   /**
335    * The listener interface for receiving preferencesAction events.
336    * The class that is interested in processing a preferencesAction
337    * event implements this interface, and the object created
338    * with that class is registered with a component using the
339    * component's <code>addPreferencesActionListener</code> method. When
340    * the PreferencesAction event occurs, that object's appropriate
341    * method is invoked.
342    */
343   static public class PreferencesActionListener extends EventListener<UIContentDialogForm> {
344 
345     /* (non-Javadoc)
346      * @see org.exoplatform.webui.event.EventListener#execute(org.exoplatform.webui.event.Event)
347      */
348     public void execute(Event<UIContentDialogForm> event) throws Exception {
349       UIContentDialogForm contentDialogForm = event.getSource();
350       UIPopupContainer popupContainer = Utils.getPopupContainer(contentDialogForm);
351       popupContainer.addChild(contentDialogForm);
352       contentDialogForm.setParent(popupContainer);
353       UIContentDialogPreference contentDialogPreference = null;
354       if (contentDialogForm.getPreferenceComponent() != null)
355         contentDialogPreference = contentDialogForm.createUIComponent(contentDialogForm.getPreferenceComponent(),
356                                                                       null,
357                                                                       null);
358       else
359         contentDialogPreference = contentDialogForm.createUIComponent(UIContentDialogPreference.class,
360                                                                       null,
361                                                                       null);
362 
363       Utils.updatePopupWindow(contentDialogForm, contentDialogPreference, CONTENT_DIALOG_FORM_POPUP_WINDOW);
364       contentDialogPreference.init();
365     }
366   }
367 
368   /**
369    * The listener interface for receiving saveAction events.
370    * The class that is interested in processing a saveAction
371    * event implements this interface, and the object created
372    * with that class is registered with a component using the
373    * component's <code>addSaveDraftActionListener</code> method. When
374    * the saveAction event occurs, that object's appropriate
375    * method is invoked.
376    */
377   public static class SaveDraftActionListener extends EventListener<UIContentDialogForm> {
378 
379     /* (non-Javadoc)
380      * @see org.exoplatform.webui.event.EventListener#execute(org.exoplatform.webui.event.Event)
381      */
382     public void execute(Event<UIContentDialogForm> event) throws Exception {
383       UIContentDialogForm contentDialogForm = event.getSource();
384       try {
385         Node webContentNode = contentDialogForm.getNode();
386         if (!webContentNode.isCheckedOut()) {
387           webContentNode.checkout();
388         }
389         List<UIComponent> inputs = contentDialogForm.getChildren();
390         if (contentDialogForm.checkCategories(contentDialogForm)) {
391           Utils.createPopupMessage(contentDialogForm,
392                                    "UIContentDialogForm.msg.non-categories",
393                                    null,
394                                    ApplicationMessage.WARNING);
395           return;
396         }
397         Map<String, JcrInputProperty> inputProperties = DialogFormUtil.prepareMap(inputs,
398                                                                                   contentDialogForm.getInputProperties(),
399                                                                                   contentDialogForm.getInputOptions());
400         CmsService cmsService = contentDialogForm.getApplicationComponent(CmsService.class);
401         if (WCMCoreUtils.canAccessParentNode(webContentNode)) {
402           cmsService.storeNode(contentDialogForm.contentType,
403                                webContentNode.getParent(),
404                                inputProperties,
405                                contentDialogForm.isAddNew);
406         } else {
407           cmsService.storeEditedNode(contentDialogForm.contentType,
408                                      webContentNode,
409                                      inputProperties,
410                                      contentDialogForm.isAddNew);
411         }
412 
413         if (Util.getUIPortalApplication().getModeState() == UIPortalApplication.NORMAL_MODE) {
414           ((PortletRequestContext) event.getRequestContext()).setApplicationMode(PortletMode.VIEW);
415         }
416         Utils.closePopupWindow(contentDialogForm, CONTENT_DIALOG_FORM_POPUP_WINDOW);
417 
418       } catch(LockException le) {
419         Object[] args = {contentDialogForm.getNode().getPath()};
420         Utils.createPopupMessage(contentDialogForm, "UIContentDialogForm.msg.node-locked", args, ApplicationMessage.WARNING);
421       } catch(AccessControlException ace) {
422         if (LOG.isWarnEnabled()) {
423           LOG.warn(ace.getMessage());
424         }
425       } catch (AccessDeniedException ade) {
426         Utils.createPopupMessage(contentDialogForm,
427                                  "UIDocumentInfo.msg.access-denied-exception",
428                                  null,
429                                  ApplicationMessage.WARNING);
430       } catch(VersionException ve) {
431         Utils.createPopupMessage(contentDialogForm, "UIDocumentForm.msg.in-versioning", null, ApplicationMessage.WARNING);
432       } catch(ItemNotFoundException item) {
433         Utils.createPopupMessage(contentDialogForm, "UIDocumentForm.msg.item-not-found", null, ApplicationMessage.WARNING);
434       } catch(RepositoryException repo) {
435         String key = "UIDocumentForm.msg.repository-exception";
436         if (ItemExistsException.class.isInstance(repo)) key = "UIDocumentForm.msg.not-allowed-same-name-sibling";
437         Utils.createPopupMessage(contentDialogForm, key, null, ApplicationMessage.WARNING);
438       } catch (NumberFormatException nfe) {
439         Utils.createPopupMessage(contentDialogForm,
440                                  "UIDocumentForm.msg.numberformat-exception",
441                                  null,
442                                  ApplicationMessage.WARNING);
443       } catch (Exception e) {
444         Utils.createPopupMessage(contentDialogForm,
445                                  "UIDocumentForm.msg.cannot-save",
446                                  null,
447                                  ApplicationMessage.WARNING);
448       }
449     }
450 
451   }
452 
453   /**
454    * Check categories.
455    *
456    * @param contentDialogForm the content dialog form
457    *
458    * @return true, if successful
459    */
460   private boolean checkCategories(UIContentDialogForm contentDialogForm) {
461     String[] categoriesPathList = null;
462     int index = 0;
463     if (contentDialogForm.isReference) {
464       UIFormMultiValueInputSet uiSet = contentDialogForm.getChild(UIFormMultiValueInputSet.class);
465       if ((uiSet != null) && (uiSet.getName() != null) && uiSet.getName().equals(FIELD_TAXONOMY)) {
466         List<UIComponent> listChildren = uiSet.getChildren();
467         StringBuffer sb = new StringBuffer();
468         for (UIComponent component : listChildren) {
469           UIFormStringInput uiStringInput = (UIFormStringInput) component;
470           if (uiStringInput.getValue() != null) {
471             String value = uiStringInput.getValue().trim();
472             sb.append(value).append(",");
473           }
474         }
475         String categoriesPath = sb.toString();
476         if (categoriesPath != null && categoriesPath.length() > 0) {
477           try {
478             if (categoriesPath.endsWith(",")) {
479               categoriesPath = categoriesPath.substring(0, categoriesPath.length() - 1).trim();
480               if (categoriesPath.trim().length() == 0) {
481                 return true;
482               }
483             }
484             categoriesPathList = categoriesPath.split(",");
485             if ((categoriesPathList == null) || (categoriesPathList.length == 0)) {
486               return true;
487             }
488             for (String categoryPath : categoriesPathList) {
489               index = categoryPath.indexOf("/");
490               if (index < 0) {
491                 return true;
492               }
493             }
494           } catch (Exception e) {
495             return true;
496           }
497         }
498       }
499     }
500     return false;
501   }
502 
503   /**
504    * The listener interface for receiving fastPublishAction events.
505    * The class that is interested in processing a cancelAction
506    * event implements this interface, and the object created
507    * with that class is registered with a component using the
508    * component's <code>addFastPublishActionListener</code> method. When
509    * the cancelAction event occurs, that object's appropriate
510    * method is invoked.
511    */
512   public static class FastPublishActionListener extends EventListener<UIContentDialogForm> {
513 
514     /* (non-Javadoc)
515      * @see org.exoplatform.webui.event.EventListener#execute(org.exoplatform.webui.event.Event)
516      */
517     public void execute(Event<UIContentDialogForm> event) throws Exception {
518       UIContentDialogForm contentDialogForm = event.getSource();
519       try{
520         Node webContentNode = contentDialogForm.getNode();
521         if (!webContentNode.isCheckedOut()) {
522           webContentNode.checkout();
523         }
524         List<UIComponent> inputs = contentDialogForm.getChildren();
525         if (contentDialogForm.checkCategories(contentDialogForm)) {
526           Utils.createPopupMessage(contentDialogForm,
527                                    "UIContentDialogForm.msg.non-categories",
528                                    null,
529                                    ApplicationMessage.WARNING);
530           return;
531         }
532         Map<String, JcrInputProperty> inputProperties = DialogFormUtil.prepareMap(inputs,
533                                                                                   contentDialogForm.getInputProperties(),
534                                                                                   contentDialogForm.getInputOptions());
535         CmsService cmsService = contentDialogForm.getApplicationComponent(CmsService.class);
536         cmsService.storeNode(contentDialogForm.contentType,
537                              contentDialogForm.getNode().getParent(),
538                              inputProperties,
539                              contentDialogForm.isAddNew);
540 
541         PublicationService publicationService = contentDialogForm.getApplicationComponent(PublicationService.class);
542         PublicationPlugin publicationPlugin = publicationService.getPublicationPlugins()
543                                                                 .get(publicationService.getNodeLifecycleName(webContentNode));
544         HashMap<String, String> context = new HashMap<String, String>();
545         if(webContentNode != null) {
546           context.put("Publication.context.currentVersion", webContentNode.getName());
547         }
548         publicationPlugin.changeState(webContentNode, PublicationDefaultStates.PUBLISHED, context);
549 
550         if (Util.getUIPortalApplication().getModeState() == UIPortalApplication.NORMAL_MODE) {
551             ((PortletRequestContext)event.getRequestContext()).setApplicationMode(PortletMode.VIEW);
552         }
553         Utils.closePopupWindow(contentDialogForm, CONTENT_DIALOG_FORM_POPUP_WINDOW);
554 
555       } catch(LockException le) {
556         Object[] args = {contentDialogForm.getNode().getPath()};
557         Utils.createPopupMessage(contentDialogForm,
558                                  "UIContentDialogForm.msg.node-locked",
559                                  args,
560                                  ApplicationMessage.WARNING);
561       } catch (AccessControlException ace) {
562         if (LOG.isWarnEnabled()) {
563           LOG.warn(ace.getMessage());
564         }
565       } catch (AccessDeniedException ade) {
566         Utils.createPopupMessage(contentDialogForm,
567                                  "UIDocumentInfo.msg.access-denied-exception",
568                                  null,
569                                  ApplicationMessage.WARNING);
570       } catch (VersionException ve) {
571         Utils.createPopupMessage(contentDialogForm,
572                                  "UIDocumentForm.msg.in-versioning",
573                                  null,
574                                  ApplicationMessage.WARNING);
575       } catch (ItemNotFoundException item) {
576         Utils.createPopupMessage(contentDialogForm,
577                                  "UIDocumentForm.msg.item-not-found",
578                                  null,
579                                  ApplicationMessage.WARNING);
580       } catch (RepositoryException repo) {
581         String key = "UIDocumentForm.msg.repository-exception";
582         if (ItemExistsException.class.isInstance(repo))
583           key = "UIDocumentForm.msg.not-allowed-same-name-sibling";
584         Utils.createPopupMessage(contentDialogForm, key, null, ApplicationMessage.WARNING);
585       } catch (NumberFormatException nfe) {
586         Utils.createPopupMessage(contentDialogForm,
587                                  "UIDocumentForm.msg.numberformat-exception",
588                                  null,
589                                  ApplicationMessage.WARNING);
590       } catch (Exception e) {
591         Utils.createPopupMessage(contentDialogForm,
592                                  "UIDocumentForm.msg.cannot-save",
593                                  null,
594                                  ApplicationMessage.WARNING);
595       }
596     }
597   }
598 
599   /**
600    * The listener interface for receiving addAction events. The class that is
601    * interested in processing a addAction event implements this interface, and
602    * the object created with that class is registered with a component using the
603    * component's <code>addAddActionListener</code> method. When
604    * the addAction event occurs, that object's appropriate
605    * method is invoked.
606    */
607   static public class AddActionListener extends EventListener<UIContentDialogForm> {
608 
609     /*
610      * (non-Javadoc)
611      * @see
612      * org.exoplatform.webui.event.EventListener#execute(org.exoplatform.webui
613      * .event.Event)
614      */
615     public void execute(Event<UIContentDialogForm> event) throws Exception {
616       UIContentDialogForm contentDialogForm = event.getSource();
617       String clickedField = event.getRequestContext().getRequestParameter(OBJECTID);
618       if (contentDialogForm.isReference) {
619         UIApplication uiApp = contentDialogForm.getAncestorOfType(UIApplication.class);
620         try {
621           UIFormMultiValueInputSet uiSet = contentDialogForm.getChildById(FIELD_TAXONOMY);
622           if ((uiSet != null) && (uiSet.getName() != null)
623               && uiSet.getName().equals(FIELD_TAXONOMY)) {
624             if ((clickedField != null) && (clickedField.equals(FIELD_TAXONOMY))) {
625               NodeHierarchyCreator nodeHierarchyCreator = contentDialogForm.getApplicationComponent(NodeHierarchyCreator.class);
626               String repository = contentDialogForm.repositoryName;
627               DMSConfiguration dmsConfiguration = contentDialogForm.getApplicationComponent(DMSConfiguration.class);
628               DMSRepositoryConfiguration repositoryConfiguration = dmsConfiguration.getConfig();
629               String workspaceName = repositoryConfiguration.getSystemWorkspace();
630               UIOneTaxonomySelector uiOneTaxonomySelector = contentDialogForm.createUIComponent(UIOneTaxonomySelector.class,
631                                                                                                 null,
632                                                                                                 null);
633               if (uiSet.getValue().size() == 0)
634                 uiSet.setValue(new ArrayList<Value>());
635               String rootTreePath = nodeHierarchyCreator.getJcrPath(BasePath.TAXONOMIES_TREE_STORAGE_PATH);
636               RepositoryService repositoryService = (RepositoryService) contentDialogForm.
637                   getApplicationComponent(RepositoryService.class);
638               ManageableRepository manageableRepository = repositoryService.getCurrentRepository();
639               Session session = WCMCoreUtils.getUserSessionProvider()
640                                             .getSession(workspaceName, manageableRepository);
641               Node rootTree = (Node) session.getItem(rootTreePath);
642               NodeIterator childrenIterator = rootTree.getNodes();
643               while (childrenIterator.hasNext()) {
644                 Node childNode = childrenIterator.nextNode();
645                 rootTreePath = childNode.getPath();
646                 break;
647               }
648               uiOneTaxonomySelector.setRootNodeLocation(repository, workspaceName, rootTreePath);
649               uiOneTaxonomySelector.setExceptedNodeTypesInPathPanel(new String[] { "exo:symlink" });
650               uiOneTaxonomySelector.init(WCMCoreUtils.getUserSessionProvider());
651               String param = "returnField=" + FIELD_TAXONOMY;
652               uiOneTaxonomySelector.setSourceComponent(contentDialogForm, new String[] { param });
653               Utils.createPopupWindow(contentDialogForm,
654                                       uiOneTaxonomySelector,
655                                       TAXONOMY_CONTENT_POPUP_WINDOW,
656                                       700);
657             }
658           }
659         } catch (AccessDeniedException accessDeniedException) {
660           uiApp.addMessage(new ApplicationMessage("UIContentDialogForm.msg.access-denied",
661                                                   null,
662                                                   ApplicationMessage.WARNING));
663           return;
664         } catch (Exception e) {
665           uiApp.addMessage(new ApplicationMessage("UIContentDialogForm.msg.exception",
666                                                   null,
667                                                   ApplicationMessage.WARNING));
668           return;
669         }
670       } else {
671         event.getRequestContext().addUIComponentToUpdateByAjax(contentDialogForm);
672       }
673     }
674   }
675 
676   /* (non-Javadoc)
677    * @see org.exoplatform.webui.core.UIPopupComponent#activate()
678    */
679   public void activate() {
680   }
681 
682   /* (non-Javadoc)
683    * @see org.exoplatform.webui.core.UIPopupComponent#deActivate()
684    */
685   public void deActivate() {
686   }
687 
688   /* (non-Javadoc)
689    * @see org.exoplatform.ecm.webui.selector.UISelectable#doSelect(java.lang.String, java.lang.Object)
690    */
691   @SuppressWarnings("unchecked")
692   public void doSelect(String selectField, Object value) throws Exception {
693     isUpdateSelect = true;
694     UIFormInput formInput = getUIInput(selectField);
695     if(formInput instanceof UIFormInputBase) {
696       ((UIFormInputBase)formInput).setValue(value.toString());
697     }else if(formInput instanceof UIFormMultiValueInputSet) {
698       UIFormMultiValueInputSet  inputSet = (UIFormMultiValueInputSet) formInput;
699       String valueTaxonomy = String.valueOf(value).trim();
700       List taxonomylist = inputSet.getValue();
701       if (!taxonomylist.contains(valueTaxonomy)) {
702         listTaxonomy.add(valueTaxonomy);
703         listTaxonomyName.add(valueTaxonomy);
704         taxonomylist.add(valueTaxonomy);
705       }
706       inputSet.setValue(taxonomylist);
707     }
708   }
709 
710   /**
711    * The listener interface for receiving removeReferenceAction events.
712    * The class that is interested in processing a removeReferenceAction
713    * event implements this interface, and the object created
714    * with that class is registered with a component using the
715    * component's <code>addRemoveReferenceActionListener</code> method. When
716    * the removeReferenceAction event occurs, that object's appropriate
717    * method is invoked.
718    */
719   static public class RemoveReferenceActionListener extends EventListener<UIContentDialogForm> {
720 
721     /* (non-Javadoc)
722      * @see org.exoplatform.webui.event.EventListener#execute(org.exoplatform.webui.event.Event)
723      */
724     public void execute(Event<UIContentDialogForm> event) throws Exception {
725       UIContentDialogForm contentDialogForm = event.getSource();
726       contentDialogForm.isRemovePreference = true;
727       String fieldName = event.getRequestContext().getRequestParameter(OBJECTID);
728       contentDialogForm.getUIStringInput(fieldName).setValue(null);
729       event.getRequestContext().addUIComponentToUpdateByAjax(contentDialogForm);
730     }
731   }
732 }