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.clv;
18  
19  import java.util.ArrayList;
20  import java.util.Arrays;
21  import java.util.Collections;
22  import java.util.Comparator;
23  import java.util.List;
24  
25  import javax.jcr.Node;
26  import javax.jcr.PathNotFoundException;
27  import javax.jcr.RepositoryException;
28  import javax.portlet.PortletPreferences;
29  
30  import org.exoplatform.ecm.utils.text.Text;
31  import org.exoplatform.ecm.webui.selector.UISelectable;
32  import org.exoplatform.services.cms.drives.DriveData;
33  import org.exoplatform.services.cms.drives.ManageDriveService;
34  import org.exoplatform.services.cms.views.ApplicationTemplateManagerService;
35  import org.exoplatform.services.log.ExoLogger;
36  import org.exoplatform.services.log.Log;
37  import org.exoplatform.services.wcm.core.NodetypeConstant;
38  import org.exoplatform.services.wcm.utils.WCMCoreUtils;
39  import org.exoplatform.wcm.webui.Utils;
40  import org.exoplatform.wcm.webui.reader.ContentReader;
41  import org.exoplatform.wcm.webui.selector.content.UIContentSelector;
42  import org.exoplatform.wcm.webui.selector.content.folder.UIContentBrowsePanelFolder;
43  import org.exoplatform.wcm.webui.selector.content.folder.UIContentSelectorFolder;
44  import org.exoplatform.wcm.webui.selector.content.multi.UIContentBrowsePanelMulti;
45  import org.exoplatform.wcm.webui.selector.content.multi.UIContentSelectorMulti;
46  import org.exoplatform.wcm.webui.selector.page.UIPageSelector;
47  import org.exoplatform.wcm.webui.validator.ZeroNumberValidator;
48  import org.exoplatform.web.application.ApplicationMessage;
49  import org.exoplatform.webui.application.WebuiRequestContext;
50  import org.exoplatform.webui.application.portlet.PortletRequestContext;
51  import org.exoplatform.webui.config.annotation.ComponentConfig;
52  import org.exoplatform.webui.config.annotation.EventConfig;
53  import org.exoplatform.webui.core.UIComponent;
54  import org.exoplatform.webui.core.lifecycle.UIFormLifecycle;
55  import org.exoplatform.webui.core.model.SelectItemOption;
56  import org.exoplatform.webui.event.Event;
57  import org.exoplatform.webui.event.Event.Phase;
58  import org.exoplatform.webui.event.EventListener;
59  import org.exoplatform.webui.form.UIFormInputSet;
60  import org.exoplatform.webui.form.UIFormRadioBoxInput;
61  import org.exoplatform.webui.form.UIFormSelectBox;
62  import org.exoplatform.webui.form.UIFormStringInput;
63  import org.exoplatform.webui.form.UIFormTabPane;
64  import org.exoplatform.webui.form.UIFormTextAreaInput;
65  import org.exoplatform.webui.form.ext.UIFormInputSetWithAction;
66  import org.exoplatform.webui.form.input.UICheckBoxInput;
67  import org.exoplatform.webui.form.validator.MandatoryValidator;
68  import org.exoplatform.webui.form.validator.PositiveNumberFormatValidator;
69  
70  /*
71   * Created by The eXo Platform SAS Author : Anh Do Ngoc anh.do@exoplatform.com
72   * Oct 15, 2008
73   */
74  /**
75   * The Class UICLVConfig.
76   */
77  @ComponentConfig(
78                   lifecycle = UIFormLifecycle.class,
79                   template = "system:/groovy/ContentListViewer/UICLVConfig.gtmpl",  
80                   events = {
81                     @EventConfig(listeners = UICLVConfig.SaveActionListener.class),
82                     @EventConfig(listeners = UICLVConfig.CancelActionListener.class, phase = Phase.DECODE),
83                     @EventConfig(listeners = UICLVConfig.AddPathActionListener.class, phase = Phase.DECODE),
84                     @EventConfig(listeners = UICLVConfig.IncreaseActionListener.class, phase = Phase.DECODE),
85                     @EventConfig(listeners = UICLVConfig.DecreaseActionListener.class, phase = Phase.DECODE),
86                     @EventConfig(listeners = UICLVConfig.SelectTargetPageActionListener.class, phase = Phase.DECODE),
87  	                 @EventConfig(listeners = UICLVConfig.SelectTabActionListener.class, phase = Phase.DECODE),
88                     @EventConfig(listeners = UICLVConfig.ShowAdvancedBlockActionListener.class, phase = Phase.DECODE)
89                   }
90      )
91  public class UICLVConfig extends UIFormTabPane  implements UISelectable {
92  
93    final static public String CONTENT_TAB = "clvContentTab" ;
94    final static public String DISPLAY_TAB = "clvDisplayTab" ;
95    final static public String ADVANCED_TAB = "clvAdvancedTab" ;
96    
97    private static final Log         LOG             = ExoLogger.getLogger(UICLVConfig.class.getName());
98  
99    /** The Constant DISPLAY_MODE_FORM_RADIO_BOX_INPUT. */
100   public static final String DISPLAY_MODE_FORM_RADIO_BOX_INPUT       = "UICLVConfigDisplayModeFormRadioBoxInput";
101 
102   /** The Constant ITEM_PATH_FORM_INPUT_SET. */
103   public final static String ITEM_PATH_FORM_INPUT_SET                = "UICLVConfigItemPathFormInputSet";
104 
105   /** The Constant ITEM_PATH_FORM_STRING_INPUT. */
106   public final static String ITEM_PATH_FORM_STRING_INPUT             = "UICLVConfigItemPathFormStringInput";
107 
108   /** The Constant ORDER_BY_FORM_SELECT_BOX. */
109   public static final String ORDER_BY_FORM_SELECT_BOX                = "UICLVConfigOrderByFormSelectBox";
110 
111   /** The Constant ORDER_BY_FORM_SELECT_BOX. */
112   public static final String ORDER_TYPE_FORM_SELECT_BOX              = "UICLVConfigOrderTypeFormSelectBox";
113 
114   /** The Constant ORDER_TYPE_FORM_RADIO_BOX_INPUT. */
115   public static final String ORDER_TYPE_FORM_RADIO_BOX_INPUT         = "UICLVConfigOrderTypeFormRadioBoxInput";
116 
117   /** The Constant HEADER_FORM_STRING_INPUT. */
118   public final static String HEADER_FORM_STRING_INPUT                = "UICLVConfigHeaderFormStringInput";
119 
120   /** The Constant SHOW_AUTOMATIC_DETECTION_CHECKBOX_INPUT. */
121   public static final String SHOW_AUTOMATIC_DETECTION_CHECKBOX_INPUT = "UICLVConfigShowAutomaticDetectionCheckboxInput";
122 
123   /** The Constant DISPLAY_TEMPLATE_FORM_SELECT_BOX. */
124   public final static String DISPLAY_TEMPLATE_FORM_SELECT_BOX        = "UICLVConfigDisplayTemplateFormSelectBox";
125 
126   /** The Constant PAGINATOR_TEMPLATE_FORM_SELECT_BOX. */
127   public final static String PAGINATOR_TEMPLATE_FORM_SELECT_BOX      = "UICLVConfigPaginatorTemplateFormSelectBox";
128 
129   /** The Constant ITEMS_PER_PAGE_FORM_STRING_INPUT. */
130   public final static String ITEMS_PER_PAGE_FORM_STRING_INPUT        = "UICLVConfigItemsPerPageFormStringInput";
131 
132   /** The Constant SHOW_TITLE_FORM_CHECKBOX_INPUT. */
133   public static final String SHOW_TITLE_FORM_CHECKBOX_INPUT          = "UICLVConfigShowTitleFormCheckboxInput";
134 
135   /** The Constant SHOW_HEADER_FORM_CHECKBOX_INPUT. */
136   public static final String SHOW_HEADER_FORM_CHECKBOX_INPUT         = "UICLVConfigShowHeaderFormCheckboxInput";
137 
138   /** The Constant SHOW_REFRESH_FORM_CHECKBOX_INPUT. */
139   public final static String SHOW_REFRESH_FORM_CHECKBOX_INPUT        = "UICLVConfigShowRefreshFormCheckboxInput";
140 
141   /** The Constant SHOW_ILLUSTRATION_FORM_CHECKBOX_INPUT. */
142   /** The Constant SHOW_IMAGE_FORM_CHECKBOX_INPUT. */
143   public static final String SHOW_ILLUSTRATION_FORM_CHECKBOX_INPUT   = "UICLVConfigShowIllustrationFormCheckboxInput";
144 
145   // public static final String SHOW_IMAGE_FORM_CHECKBOX_INPUT =
146   // "UICLVConfigShowImageFormCheckboxInput";
147 
148   /** The Constant SHOW_DATE_CREATED_FORM_CHECKBOX_INPUT. */
149   public static final String SHOW_DATE_CREATED_FORM_CHECKBOX_INPUT   = "UICLVConfigShowDateCreatedFormCheckboxInput";
150 
151   /** The Constant SHOW_MORE_LINK_FORM_CHECKBOX_INPUT. */
152   public final static String SHOW_READMORE_FORM_CHECKBOX_INPUT       = "UICLVConfigShowReadmoreFormCheckboxInput";
153 
154   // public static final String SHOW_MORE_LINK_FORM_CHECKBOX_INPUT =
155   // "UICLVConfigShowMoreLinkCheckedboxInput";
156 
157   /** The Constant SHOW_SUMMARY_FORM_CHECKBOX_INPUT. */
158   public static final String SHOW_SUMMARY_FORM_CHECKBOX_INPUT        = "UICLVConfigShowSummaryFormCheckboxInput";
159 
160   /** The Constant SHOW_LINK_FORM_CHECKBOX_INPUT. */
161   public static final String SHOW_LINK_FORM_CHECKBOX_INPUT           = "UICLVConfigShowLinkFormCheckboxInput";
162 
163   /** The Constant SHOW_RSSLINK_FORM_CHECKBOX_INPUT. */
164   public static final String SHOW_RSSLINK_FORM_CHECKBOX_INPUT        = "UICLVConfigShowRssLinkFormCheckboxInput";
165 
166   /** The Constant TARGET_PAGE_FORM_INPUT_SET. */
167   public final static String TARGET_PAGE_FORM_INPUT_SET              = "UICLVConfigTargetPageFormInputSet";
168 
169   /** The Constant TARGET_PAGE_FORM_STRING_INPUT. */
170   public final static String TARGET_PAGE_FORM_STRING_INPUT           = "UICLVConfigTargetPageFormStringInput";
171 
172   /** The Constant TARGET_PAGE_SELECTOR_POPUP_WINDOW. */
173   public final static String TARGET_PAGE_SELECTOR_POPUP_WINDOW       = "UICLVConfigTargetPageSelectorPopupWindow";
174 
175   /** The Constant DYNAMIC_NAVIGATION_LABEL. */
176   public static final String DYNAMIC_NAVIGATION_LABEL                = "UICLVConfigDynamicNavigationLabel";
177 
178   /** The Constant CONTEXTUAL_FOLDER_RADIOBOX_INPUT. */
179   public static final String CONTEXTUAL_FOLDER_RADIOBOX_INPUT        = "UICLVConfigContextualFolderRadioBoxInput";
180 
181   /** The Constant SHOW_CLV_BY_STRING_INPUT. */
182   public static final String SHOW_CLV_BY_STRING_INPUT                = "UICLVConfigShowCLVByStringInput";
183 
184   /** The Constant SHOW_SCV_WITH_STRING_INPUT. */
185   public static final String SHOW_SCV_WITH_STRING_INPUT              = "UICLVConfigshowSCVWithStringInput";
186 
187   /** The Constant PAGINATOR_TEMPLATE_CATEGORY. */
188   public final static String PAGINATOR_TEMPLATE_CATEGORY             = "paginators";
189 
190   /** The Constant CACHE_ENABLE_RADIOBOX_INPUT */
191   public static final String CACHE_ENABLE_RADIOBOX_INPUT             = "UICLVConfigCacheEnableRadioBoxInput";
192 
193   /** The Constant CONTENT_BY_QUERY_TEXT_AREA */
194   public static final String CONTENT_BY_QUERY_TEXT_AREA              = "UICLVConfigContentByQueryTextArea";
195 
196   /** The Constant WORKSPACE_FORM_SELECT_BOX. */
197   public final static String WORKSPACE_FORM_SELECT_BOX               = "UICLVConfigWorkspaceFormSelectBox";
198 
199   /** The Constant CACHE_MANAGEMENT_LABEL */
200   public static final String CACHE_MANAGEMENT_LABEL                  = "UICLVConfigCacheManagementLabel";
201 
202   /** The Constant CONTENT_BY_QUERY_LABEL */
203   public static final String CONTENT_BY_QUERY_LABEL                  = "UICLVContentByQueryLabel";
204 
205   /** The Constant DISPLAY_TEMPLATE_CATEGORY. */
206   public final static String DISPLAY_TEMPLATE_CATEGORY               = "navigation";
207 
208   public final static String DISPLAY_TEMPLATE_LIST                   = "list";
209 
210   public final static String TEMPLATE_STORAGE_FOLDER                 = "content-list-viewer";
211 
212   public final static String CONTENT_LIST_TYPE                       = "ContentList";
213 
214   public final static String CATEGORIES_CONTENT_TYPE                 = "CategoryContents";
215 
216   public final static String CATOGORIES_NAVIGATION_TYPE              = "CategoryNavigation";
217 
218   /** The constant values for cache */
219   public static final String ENABLE_CACHE                            = "ENABLE";
220   public static final String DISABLE_CACHE                           = "DISABLE";
221 
222   /** The popup id. */
223   private String popupId;
224 
225   /** The items. */
226   private List<String> items;
227 
228   private String savedPath;
229   private boolean isShowAdvancedBlock_;
230   private String appType;
231   private String driveName_;
232 
233   public void setSavedPath(String value) {
234     savedPath = value;
235   }
236   public String getSavedPath () {
237     return savedPath;
238   }
239 
240   /**
241    * check if the content in the path is alive and return only alive content
242    * 
243    * @return
244    */
245   public String getAliveSavedPath () {
246     //check if the path is alive
247     if(savedPath != null && !savedPath.isEmpty()){
248       List<String> tmpItems = new ArrayList<String>();
249       StringBuffer itemsBuffer = new StringBuffer();
250       if(savedPath.contains(";")){
251         tmpItems = Arrays.asList(savedPath.split(";"));
252       } else {
253         tmpItems.add(savedPath);
254       }
255 	    //only add exist Node
256       for(String item:tmpItems) {
257         try{
258           if(getRealNode(item) != null){
259             itemsBuffer.append(item).append(";");
260           }
261         }catch(RepositoryException e){
262           if(LOG.isDebugEnabled()){
263             LOG.debug(e.getMessage());
264           }
265         }
266       }
267       return itemsBuffer.toString();
268     }
269     return savedPath;
270   }
271   
272   /**
273    * Gets the popup id.
274    *
275    * @return the popup id
276    */
277   public String getPopupId() {
278     return popupId;
279   }
280 
281   /**
282    * Sets the popup id.
283    *
284    * @param popupId the new popup id
285    */
286   public void setPopupId(String popupId) {
287     this.popupId = popupId;
288   }
289 
290   public void setDriveName(String value) { this.driveName_ = value; }
291   public String getDriveName() { return this.driveName_; }
292 
293   /**
294    * Gets the items.
295    *
296    * @return the items
297    */
298   public List<String> getItems() {
299     String displayMode = ((UIFormRadioBoxInput) findComponentById(UICLVConfig.DISPLAY_MODE_FORM_RADIO_BOX_INPUT)).getValue();
300     String itemPath = Utils.getPortletPreference(UICLVPortlet.PREFERENCE_ITEM_PATH);
301     if (items == null && UICLVPortlet.DISPLAY_MODE_MANUAL.equals(displayMode) && itemPath != null) {
302       if(itemPath.contains(";")) {
303         List<String> tmpItems = Arrays.asList(itemPath.split(";"));
304         items = new ArrayList<String>();
305         //only add exist Node
306         for(String item:tmpItems) {
307           try{
308             Node realNode=getRealNode(item);
309             if(realNode != null){
310               items.add(item);
311             }
312           }catch(RepositoryException e){
313             if(LOG.isDebugEnabled()){
314               LOG.debug(e.getMessage());
315             }
316           }
317           
318         }
319       }
320     }
321     return items;
322   }
323 
324   /**
325    * Sets the items.
326    *
327    * @param items the new items
328    */
329   public void setItems(List<String> items) {
330     this.items = items;
331   }
332 
333   public boolean isShowAdvancedBlock() { return isShowAdvancedBlock_; }
334 
335   public void setIsShowAdvancedBlock(boolean value) { isShowAdvancedBlock_ = value; }
336 
337   /**
338    * Instantiates a new uICLV config.
339    *
340    * @throws Exception the exception
341    */
342   public UICLVConfig() throws Exception {
343     super("UICLVConfig");
344     PortletPreferences portletPreferences = ((PortletRequestContext) WebuiRequestContext.getCurrentInstance()).getRequest()
345         .getPreferences();
346     appType = portletPreferences.getValue(UICLVPortlet.PREFERENCE_APPLICATION_TYPE, null);
347     String displayMode = portletPreferences.getValue(UICLVPortlet.PREFERENCE_DISPLAY_MODE, null);
348     String itemPath = portletPreferences.getValue(UICLVPortlet.PREFERENCE_ITEM_PATH, null);
349     savedPath = itemPath;
350     itemPath = getTitles(savedPath);
351     this.setDriveName(portletPreferences.getValue(UICLVPortlet.PREFERENCE_ITEM_DRIVE, null));
352     String orderBy = portletPreferences.getValue(UICLVPortlet.PREFERENCE_ORDER_BY, null);
353     String orderType = portletPreferences.getValue(UICLVPortlet.PREFERENCE_ORDER_TYPE, null);
354 
355     String header = portletPreferences.getValue(UICLVPortlet.PREFERENCE_HEADER, null);
356     String displayTemplate = portletPreferences.getValue(UICLVPortlet.PREFERENCE_DISPLAY_TEMPLATE, null);
357     String paginatorTemplate = portletPreferences.getValue(UICLVPortlet.PREFERENCE_PAGINATOR_TEMPLATE, null);
358     String itemsPerPage = portletPreferences.getValue(UICLVPortlet.PREFERENCE_ITEMS_PER_PAGE, null);
359 
360     String contextualFolderMode = portletPreferences.getValue(UICLVPortlet.PREFERENCE_CONTEXTUAL_FOLDER, null);
361 
362     String showClvBy = portletPreferences.getValue(UICLVPortlet.PREFERENCE_SHOW_CLV_BY, null);
363     String targetPage = portletPreferences.getValue(UICLVPortlet.PREFERENCE_TARGET_PAGE, null);
364     String showScvWith = portletPreferences.getValue(UICLVPortlet.PREFERENCE_SHOW_SCV_WITH, null);
365     String isCacheEnabled = portletPreferences.getValue(UICLVPortlet.PREFERENCE_CACHE_ENABLED, null);
366     String workspace = portletPreferences.getValue(UICLVPortlet.PREFERENCE_WORKSPACE, null);
367     String contentByQuery = portletPreferences.getValue(UICLVPortlet.PREFERENCE_CONTENTS_BY_QUERY, null);
368 
369     boolean showAutomaticDetection = Boolean.parseBoolean(portletPreferences.getValue(
370                                                                                       UICLVPortlet.PREFERENCE_AUTOMATIC_DETECTION,null));
371     boolean showTitle  = Boolean.parseBoolean(portletPreferences.getValue(UICLVPortlet.PREFERENCE_SHOW_TITLE, null));
372     boolean showHeader  = Boolean.parseBoolean(portletPreferences.getValue(UICLVPortlet.PREFERENCE_SHOW_HEADER, null));
373     boolean showRefresh  = Boolean.parseBoolean(portletPreferences.getValue(UICLVPortlet.PREFERENCE_SHOW_REFRESH_BUTTON, null));
374 
375     boolean showImage = Boolean.parseBoolean(portletPreferences.getValue(UICLVPortlet.PREFERENCE_SHOW_ILLUSTRATION, null));
376     boolean showDateCreated = Boolean.parseBoolean(portletPreferences.getValue(UICLVPortlet.PREFERENCE_SHOW_DATE_CREATED,
377                                                                                null));
378     boolean showReadmore  = Boolean.parseBoolean(portletPreferences.getValue(UICLVPortlet.PREFERENCE_SHOW_READMORE, null));
379 
380     boolean showSummary  = Boolean.parseBoolean(portletPreferences.getValue(UICLVPortlet.PREFERENCE_SHOW_SUMMARY, null));
381     boolean showLink = Boolean.parseBoolean(portletPreferences.getValue(UICLVPortlet.PREFERENCE_SHOW_LINK, null));
382     boolean showRssLink = Boolean.parseBoolean(portletPreferences.getValue(UICLVPortlet.PREFERENCE_SHOW_RSSLINK, null));
383 
384     /** DISPLAY MODE */
385     List<SelectItemOption<String>> displayModeOptions = new ArrayList<SelectItemOption<String>>();
386     displayModeOptions.add(new SelectItemOption<String>(UICLVPortlet.DISPLAY_MODE_AUTOMATIC,
387         UICLVPortlet.DISPLAY_MODE_AUTOMATIC));
388     displayModeOptions.add(new SelectItemOption<String>(UICLVPortlet.DISPLAY_MODE_MANUAL,
389         UICLVPortlet.DISPLAY_MODE_MANUAL));
390     UIFormRadioBoxInput displayModeRadioBoxInput = new UIFormRadioBoxInput(DISPLAY_MODE_FORM_RADIO_BOX_INPUT,
391                                                                            DISPLAY_MODE_FORM_RADIO_BOX_INPUT,
392                                                                            displayModeOptions);
393     displayModeRadioBoxInput.setValue(displayMode);
394 
395     /** ITEM PATH */
396     UIFormStringInput itemPathInput =
397         new UIFormStringInput(ITEM_PATH_FORM_STRING_INPUT, ITEM_PATH_FORM_STRING_INPUT, itemPath);
398     itemPathInput.setReadOnly(true);
399     itemPathInput.addValidator(MandatoryValidator.class);
400 
401     UIFormInputSetWithAction itemPathInputSet = new UIFormInputSetWithAction(ITEM_PATH_FORM_INPUT_SET);
402     itemPathInputSet.setActionInfo(ITEM_PATH_FORM_STRING_INPUT, new String[] { "AddPath" }) ;
403     itemPathInputSet.addUIFormInput(itemPathInput);
404 
405     /** ORDER BY */
406     List<SelectItemOption<String>> orderByOptions = new ArrayList<SelectItemOption<String>>();
407     orderByOptions.add(new SelectItemOption<String>(UICLVPortlet.ORDER_BY_TITLE, NodetypeConstant.EXO_TITLE));
408     orderByOptions.add(new SelectItemOption<String>(UICLVPortlet.ORDER_BY_DATE_CREATED, NodetypeConstant.EXO_DATE_CREATED));
409     orderByOptions.add(new SelectItemOption<String>(UICLVPortlet.ORDER_BY_DATE_MODIFIED, 
410         NodetypeConstant.EXO_LAST_MODIFIED_DATE));
411     orderByOptions.add(new SelectItemOption<String>(UICLVPortlet.ORDER_BY_DATE_PUBLISHED, 
412         NodetypeConstant.PUBLICATION_LIVE_DATE));
413     orderByOptions.add(new SelectItemOption<String>(UICLVPortlet.ORDER_BY_DATE_START_EVENT, NodetypeConstant.EXO_START_EVENT));
414     orderByOptions.add(new SelectItemOption<String>(UICLVPortlet.ORDER_BY_INDEX, NodetypeConstant.EXO_INDEX));
415     UIFormSelectBox orderBySelectBox = new UIFormSelectBox(ORDER_BY_FORM_SELECT_BOX, ORDER_BY_FORM_SELECT_BOX, orderByOptions);
416     orderBySelectBox.setValue(orderBy);
417 
418     /** ORDER TYPE */
419     List<SelectItemOption<String>> orderTypeOptions = new ArrayList<SelectItemOption<String>>();
420     orderTypeOptions.add(new SelectItemOption<String>(UICLVPortlet.ORDER_TYPE_DESCENDENT, "DESC"));    
421     orderTypeOptions.add(new SelectItemOption<String>(UICLVPortlet.ORDER_TYPE_ASCENDENT, "ASC"));
422     UIFormRadioBoxInput orderTypeRadioBoxInput = new UIFormRadioBoxInput(ORDER_TYPE_FORM_RADIO_BOX_INPUT,
423                                                                          ORDER_TYPE_FORM_RADIO_BOX_INPUT,
424                                                                          orderTypeOptions);
425 
426     UIFormSelectBox orderTypeSelectBox = new UIFormSelectBox(ORDER_TYPE_FORM_SELECT_BOX, ORDER_TYPE_FORM_SELECT_BOX, 
427                                                              orderTypeOptions);
428     orderTypeSelectBox.setValue(orderType);
429     //orderTypeRadioBoxInput.setValue(orderType);
430 
431     /** HEADER */
432     UIFormStringInput headerInput = new UIFormStringInput(HEADER_FORM_STRING_INPUT, HEADER_FORM_STRING_INPUT, header);
433 
434     /** AUTOMATIC DETECTION */
435     UICheckBoxInput showAutomaticDetectionCheckBox = new UICheckBoxInput(SHOW_AUTOMATIC_DETECTION_CHECKBOX_INPUT,
436                                                                          SHOW_AUTOMATIC_DETECTION_CHECKBOX_INPUT, null);
437     showAutomaticDetectionCheckBox.setChecked(showAutomaticDetection);
438 
439     List<SelectItemOption<String>> formViewerTemplateList = new ArrayList<SelectItemOption<String>>();
440 
441     /** DISPLAY TEMPLATE */
442     List<SelectItemOption<String>> viewerTemplateList = new ArrayList<SelectItemOption<String>>();
443     if (appType.equals(CONTENT_LIST_TYPE) || appType.equals(CATEGORIES_CONTENT_TYPE)
444         || appType.equals(UICLVPortlet.APPLICATION_CLV_BY_QUERY)) {
445       viewerTemplateList.addAll(getTemplateList(TEMPLATE_STORAGE_FOLDER, DISPLAY_TEMPLATE_LIST));
446     }
447     if (appType.equals(CONTENT_LIST_TYPE) || appType.equals(CATOGORIES_NAVIGATION_TYPE)) {
448       viewerTemplateList.addAll(getTemplateList(TEMPLATE_STORAGE_FOLDER,
449                                                 DISPLAY_TEMPLATE_CATEGORY));
450     }
451     Collections.sort(viewerTemplateList, new TemplateNameComparator());
452     formViewerTemplateList.addAll(viewerTemplateList);
453 
454     UIFormSelectBox formViewTemplateSelector = new UIFormSelectBox(DISPLAY_TEMPLATE_FORM_SELECT_BOX,
455                                                                    DISPLAY_TEMPLATE_FORM_SELECT_BOX,
456                                                                    formViewerTemplateList);
457     formViewTemplateSelector.setValue(displayTemplate);
458 
459     /** PAGINATOR TEMPLATE */
460     List<SelectItemOption<String>> paginatorTemplateList = getTemplateList(TEMPLATE_STORAGE_FOLDER, PAGINATOR_TEMPLATE_CATEGORY);
461     Collections.sort(paginatorTemplateList, new TemplateNameComparator());
462     UIFormSelectBox paginatorTemplateSelector = new UIFormSelectBox(PAGINATOR_TEMPLATE_FORM_SELECT_BOX,
463                                                                     PAGINATOR_TEMPLATE_FORM_SELECT_BOX,
464                                                                     paginatorTemplateList);
465     paginatorTemplateSelector.setValue(paginatorTemplate);
466 
467     /** ITEMS PER PAGE */
468     UIFormStringInput itemsPerPageStringInput = new UIFormStringInput(ITEMS_PER_PAGE_FORM_STRING_INPUT,
469                                                                       ITEMS_PER_PAGE_FORM_STRING_INPUT,
470                                                                       itemsPerPage);
471     itemsPerPageStringInput.addValidator(MandatoryValidator.class);
472     itemsPerPageStringInput.addValidator(ZeroNumberValidator.class);
473     itemsPerPageStringInput.addValidator(PositiveNumberFormatValidator.class);
474     itemsPerPageStringInput.setMaxLength(3);
475 
476     /** SHOW TITLE */
477     UICheckBoxInput showTitleCheckbox = new UICheckBoxInput(SHOW_TITLE_FORM_CHECKBOX_INPUT,
478                                                             SHOW_TITLE_FORM_CHECKBOX_INPUT, null);
479     showTitleCheckbox.setChecked(showTitle);
480 
481     /** SHOW HEADER */
482     UICheckBoxInput showHeaderCheckBox = new UICheckBoxInput(SHOW_HEADER_FORM_CHECKBOX_INPUT,
483                                                              SHOW_HEADER_FORM_CHECKBOX_INPUT, null);
484     showHeaderCheckBox.setChecked(showHeader);
485 
486     /** SHOW REFRESH */
487     UICheckBoxInput showRefreshCheckbox = new UICheckBoxInput(SHOW_REFRESH_FORM_CHECKBOX_INPUT,
488                                                               SHOW_REFRESH_FORM_CHECKBOX_INPUT, null);
489     showRefreshCheckbox.setChecked(showRefresh);
490 
491     /** SHOW_IMAGE */
492     UICheckBoxInput showImageCheckbox = new UICheckBoxInput(SHOW_ILLUSTRATION_FORM_CHECKBOX_INPUT,
493                                                             SHOW_ILLUSTRATION_FORM_CHECKBOX_INPUT, null);
494     showImageCheckbox.setChecked(showImage);
495 
496     /** SHOW DATE CREATED */
497     UICheckBoxInput showDateCreatedCheckbox = new UICheckBoxInput(SHOW_DATE_CREATED_FORM_CHECKBOX_INPUT,
498                                                                   SHOW_DATE_CREATED_FORM_CHECKBOX_INPUT, null);
499     showDateCreatedCheckbox.setChecked(showDateCreated);
500 
501     /** SHOW MORE LINK */
502     UICheckBoxInput showMoreLinkCheckbox = new UICheckBoxInput(SHOW_READMORE_FORM_CHECKBOX_INPUT,
503                                                                SHOW_READMORE_FORM_CHECKBOX_INPUT, null);
504     showMoreLinkCheckbox.setChecked(showReadmore);
505 
506     /** SHOW SUMMARY */
507     UICheckBoxInput showSummaryCheckbox = new UICheckBoxInput(SHOW_SUMMARY_FORM_CHECKBOX_INPUT,
508                                                               SHOW_SUMMARY_FORM_CHECKBOX_INPUT, null);
509     showSummaryCheckbox.setChecked(showSummary);
510 
511     /** SHOW LINK */
512     UICheckBoxInput showLinkCheckbox = new UICheckBoxInput(SHOW_LINK_FORM_CHECKBOX_INPUT,
513                                                            SHOW_LINK_FORM_CHECKBOX_INPUT, null);
514     showLinkCheckbox.setChecked(showLink);
515 
516     /** SHOW RSS LINK */
517     UICheckBoxInput showRssLinkCheckbox = new UICheckBoxInput(SHOW_RSSLINK_FORM_CHECKBOX_INPUT,
518                                                               SHOW_RSSLINK_FORM_CHECKBOX_INPUT, null);
519     showRssLinkCheckbox.setChecked(showRssLink);
520 
521     /** CONTEXTUAL FOLDER */
522     List<SelectItemOption<String>> contextualFolderOptions = new ArrayList<SelectItemOption<String>>();
523     contextualFolderOptions.add(new SelectItemOption<String>(UICLVPortlet.PREFERENCE_CONTEXTUAL_FOLDER_ENABLE,
524         UICLVPortlet.PREFERENCE_CONTEXTUAL_FOLDER_ENABLE));
525     contextualFolderOptions.add(new SelectItemOption<String>(UICLVPortlet.PREFERENCE_CONTEXTUAL_FOLDER_DISABLE,
526         UICLVPortlet.PREFERENCE_CONTEXTUAL_FOLDER_DISABLE));
527     UIFormRadioBoxInput contextualFolderRadioBoxInput = new UIFormRadioBoxInput(CONTEXTUAL_FOLDER_RADIOBOX_INPUT,
528                                                                                 CONTEXTUAL_FOLDER_RADIOBOX_INPUT,
529                                                                                 contextualFolderOptions);
530     contextualFolderRadioBoxInput.setValue(contextualFolderMode);
531 
532     /** SHOW CLV BY */
533     UIFormStringInput showClvByInput = new UIFormStringInput(SHOW_CLV_BY_STRING_INPUT, SHOW_CLV_BY_STRING_INPUT, showClvBy);
534 
535     /** TARGET PAGE */
536     UIFormInputSetWithAction targetPageInputSet = new UIFormInputSetWithAction(TARGET_PAGE_FORM_INPUT_SET);
537     UIFormStringInput basePathInput = new UIFormStringInput(TARGET_PAGE_FORM_STRING_INPUT,
538                                                             TARGET_PAGE_FORM_STRING_INPUT,
539                                                             targetPage);
540     basePathInput.setValue(targetPage);
541     basePathInput.setReadOnly(true);
542     targetPageInputSet.setActionInfo(TARGET_PAGE_FORM_STRING_INPUT, new String[] {"SelectTargetPage"}) ;
543     targetPageInputSet.addUIFormInput(basePathInput);
544 
545     /** CACHE MODE */
546     List<SelectItemOption<String>> cacheOptions = new ArrayList<SelectItemOption<String>>();
547     cacheOptions.add(new SelectItemOption<String>(ENABLE_CACHE, ENABLE_CACHE));
548     cacheOptions.add(new SelectItemOption<String>(DISABLE_CACHE, DISABLE_CACHE));
549     UIFormRadioBoxInput cacheEnableRadioBoxInput = new UIFormRadioBoxInput(CACHE_ENABLE_RADIOBOX_INPUT,
550                                                                            CACHE_ENABLE_RADIOBOX_INPUT,
551                                                                            cacheOptions);
552     cacheEnableRadioBoxInput.setValue("true".equals(isCacheEnabled)? ENABLE_CACHE : DISABLE_CACHE);
553 
554     /** WORKSPACE */
555     List<SelectItemOption<String>> workspaceOptions = new ArrayList<SelectItemOption<String>>();
556 
557     String[] workspaceList = WCMCoreUtils.getRepository().getWorkspaceNames();
558 
559     for (String wkspace : workspaceList) {
560       workspaceOptions.add(new SelectItemOption<String>(wkspace, wkspace));
561     }
562 
563     UIFormSelectBox workspaceSelector = new UIFormSelectBox(WORKSPACE_FORM_SELECT_BOX,
564                                                             WORKSPACE_FORM_SELECT_BOX,
565                                                             workspaceOptions);
566     workspaceSelector.setValue(workspace);
567 
568     /** CONTENT BY QUERY */
569     UIFormTextAreaInput queryTextAreaInput = new UIFormTextAreaInput(CONTENT_BY_QUERY_TEXT_AREA,
570                                                                      CONTENT_BY_QUERY_TEXT_AREA,
571                                                                      contentByQuery);
572 
573     /** ALLOW DYNAMIC URL */
574     UIFormStringInput showScvWithInput = new UIFormStringInput(SHOW_SCV_WITH_STRING_INPUT,
575                                                                SHOW_SCV_WITH_STRING_INPUT,
576                                                                showScvWith);
577     if (appType.equals(CATOGORIES_NAVIGATION_TYPE)) {
578       //Disable option
579       displayModeRadioBoxInput.setDisabled(true);
580       showAutomaticDetectionCheckBox.setDisabled(true);
581       showImageCheckbox.setDisabled(true);
582       showSummaryCheckbox.setDisabled(true);
583       showDateCreatedCheckbox.setDisabled(true);
584       showLinkCheckbox.setDisabled(true);
585       showRefreshCheckbox.setDisabled(true);
586       showMoreLinkCheckbox.setDisabled(true);
587       showRssLinkCheckbox.setDisabled(true);
588       showScvWithInput.setDisabled(true);
589     }
590     UIFormInputSet uiCLVContentTab = new UIFormInputSet(CONTENT_TAB) ;
591     uiCLVContentTab.addUIFormInput(displayModeRadioBoxInput);
592     uiCLVContentTab.addUIFormInput((UIFormInputSet)itemPathInputSet);
593     uiCLVContentTab.addUIFormInput(orderBySelectBox);
594     uiCLVContentTab.addUIFormInput(orderTypeSelectBox);
595     uiCLVContentTab.addUIFormInput(orderTypeRadioBoxInput);
596     setSelectedTab(CONTENT_TAB);
597     addUIComponentInput(uiCLVContentTab) ;
598 
599 
600     UIFormInputSet uiCLVDisplayTab = new UIFormInputSet(DISPLAY_TAB) ;
601     uiCLVDisplayTab.addUIFormInput(headerInput);
602     uiCLVDisplayTab.addUIFormInput(showAutomaticDetectionCheckBox);
603     uiCLVDisplayTab.addUIFormInput(formViewTemplateSelector);
604     uiCLVDisplayTab.addUIFormInput(paginatorTemplateSelector);
605     uiCLVDisplayTab.addUIFormInput(itemsPerPageStringInput);
606 
607     uiCLVDisplayTab.addUIFormInput(showTitleCheckbox);
608     uiCLVDisplayTab.addUIFormInput(showHeaderCheckBox);
609     uiCLVDisplayTab.addUIFormInput(showRefreshCheckbox);
610     uiCLVDisplayTab.addUIFormInput(showImageCheckbox);
611     uiCLVDisplayTab.addUIFormInput(showDateCreatedCheckbox);
612     uiCLVDisplayTab.addUIFormInput(showMoreLinkCheckbox);
613     uiCLVDisplayTab.addUIFormInput(showSummaryCheckbox);
614     uiCLVDisplayTab.addUIFormInput(showLinkCheckbox);
615     uiCLVDisplayTab.addUIFormInput(showRssLinkCheckbox);
616     addUIComponentInput(uiCLVDisplayTab) ;
617 
618 
619     UIFormInputSet uiCLVAdvancedTab = new UIFormInputSet(ADVANCED_TAB) ;
620     uiCLVAdvancedTab.addUIFormInput(contextualFolderRadioBoxInput);
621     uiCLVAdvancedTab.addUIFormInput(showClvByInput);
622     uiCLVAdvancedTab.addUIFormInput((UIFormInputSet)targetPageInputSet);
623     uiCLVAdvancedTab.addUIFormInput(showScvWithInput);
624     uiCLVAdvancedTab.addUIFormInput(cacheEnableRadioBoxInput);
625 
626 
627     if (this.isContentListByQuery()) {
628       uiCLVAdvancedTab.addUIFormInput(workspaceSelector);
629       uiCLVAdvancedTab.addUIFormInput(queryTextAreaInput);     
630     }
631     addUIComponentInput(uiCLVAdvancedTab) ;
632 
633     if ((contextualFolderMode != null && contextualFolderMode.equals(UICLVPortlet.PREFERENCE_CONTEXTUAL_FOLDER_ENABLE))
634         || this.isContentListByQuery()) {
635       isShowAdvancedBlock_ = true;
636     } else {
637       isShowAdvancedBlock_ = false;
638     }
639 
640     setActions(new String[] { "Save", "Cancel" });
641   }
642 
643   /**
644    * Gets the template list.
645    *
646    * @param portletName the portlet name
647    * @param category the category
648    * @return the template list
649    * @throws Exception the exception
650    */
651   private List<SelectItemOption<String>> getTemplateList(String portletName, String category) throws Exception {
652     List<SelectItemOption<String>> templateOptionList = new ArrayList<SelectItemOption<String>>();
653     ApplicationTemplateManagerService templateManagerService = getApplicationComponent(ApplicationTemplateManagerService.class);
654     List<Node> templateNodeList = templateManagerService.getTemplatesByCategory(portletName,
655                                                                                 category,
656                                                                                 WCMCoreUtils.getSystemSessionProvider());
657 
658     for (Node templateNode : templateNodeList) {
659       SelectItemOption<String> template = new SelectItemOption<String>();
660       template.setLabel(templateNode.getName());
661       template.setValue(templateNode.getPath());
662       templateOptionList.add(template);
663     }
664     return templateOptionList;
665   }
666   public boolean isCategoriesNavigation() {
667     return appType.equals(CATOGORIES_NAVIGATION_TYPE);
668   }
669 
670   /**
671    *
672    * @return True if is a CLV by Query
673    */
674   public boolean isContentListByQuery() {
675     return appType.equals(UICLVPortlet.APPLICATION_CLV_BY_QUERY);
676   }
677   /* (non-Javadoc)
678    * @see org.exoplatform.ecm.webui.selector.UISelectable#doSelect(java.lang.String, java.lang.Object)
679    */
680   public void doSelect(String selectField, Object value) throws Exception {
681     if (selectField != null && value != null) {
682       String sValue = (String) value;
683       String titles="";
684       String displayMode = ((UIFormRadioBoxInput) findComponentById(UICLVConfig.DISPLAY_MODE_FORM_RADIO_BOX_INPUT)).getValue();
685       if (ITEM_PATH_FORM_STRING_INPUT.equals(selectField) && UICLVPortlet.DISPLAY_MODE_MANUAL.equals(displayMode)) {
686         items = Arrays.asList(sValue.split(";"));
687         titles = getTitles(sValue);
688         savedPath = sValue;
689         getUIStringInput(selectField).setValue(titles);
690       } else if (TARGET_PAGE_FORM_STRING_INPUT.equals(selectField)){
691         getUIStringInput(selectField).setValue(sValue);
692       }else {
693         items = new ArrayList<String>();
694         String[] values = sValue.split(":");
695         if (values.length == 4) {
696           this.setDriveName(values[0]);
697           //check if drive is selected instead of folder
698           ManageDriveService managerDriveService = this.getApplicationComponent(ManageDriveService.class);
699           for (DriveData data : managerDriveService.getAllDrives()) {
700             if (data.getHomePath().equals(values[3])) {
701               this.setDriveName(data.getName());
702             }
703           }
704           sValue = sValue.substring(values[0].length() + 1);
705         }
706         titles = getTitle(sValue);
707         getUIStringInput(selectField).setValue(titles);
708         savedPath = sValue;
709       }
710     }
711     Utils.closePopupWindow(this, popupId);
712   }
713 
714   private String getTitles(String itemPath) throws RepositoryException {
715     if (itemPath == null || itemPath.length() == 0)
716       return "";
717     StringBuffer titles = new StringBuffer();
718     List<String> tmpItems;
719     tmpItems = Arrays.asList(itemPath.split(";"));
720     for (String item : tmpItems) {
721       String title = getTitle(item);
722       if (title != null) {
723         if (titles.length() > 0) {
724           titles.append(";").append(title);
725         } else {
726           titles.append(title);
727         }
728       }
729     }
730     return titles.toString();
731   }
732 
733   /**
734    *
735    * get the realnode with a path
736    * @param itemPath
737    * @return the realnode. null if the path is not ok
738    */
739   private Node getRealNode(String itemPath) throws RepositoryException{
740     String strRepository, strWorkspace, strIdentifier;
741     int repoIndex, wsIndex;
742     if (itemPath==null || itemPath.length() == 0)
743       return null;
744     repoIndex = itemPath.indexOf(':');
745     wsIndex = itemPath.lastIndexOf(':');
746     strRepository = itemPath.substring(0, repoIndex);
747     strWorkspace = itemPath.substring(repoIndex+1, wsIndex);
748     strIdentifier = itemPath.substring(wsIndex +1);
749     Node selectedNode = Utils.getRealNode(Text.escapeIllegalJcrChars(strRepository),
750                                           Text.escapeIllegalJcrChars(strWorkspace),
751                                           Text.escapeIllegalJcrChars(strIdentifier),
752                                           false);
753     return selectedNode;
754   }
755   
756  /**
757    *
758    * @param itemPath The path
759    * @return The title
760    * @throws RepositoryException
761    */
762   private String getTitle(String itemPath) throws RepositoryException {
763     Node selectedNode = getRealNode(itemPath);
764     if (selectedNode==null) return null;
765     String title = null;
766     if (selectedNode.hasProperty("exo:title")) {
767       title = selectedNode.getProperty("exo:title").getValue().getString();
768     }
769     if (selectedNode.hasNode("jcr:content")) {
770       Node content = selectedNode.getNode("jcr:content");
771       if (content.hasProperty("dc:title")) {
772         try {
773           title = content.getProperty("dc:title").getValues()[0].getString();
774         }
775         catch (PathNotFoundException e) {
776           title = null;
777         }
778         catch (RepositoryException e) {
779           title = null;
780         }
781         catch (IndexOutOfBoundsException e) {
782           title = null;
783         }
784       }
785     }
786     if (title==null) title = selectedNode.getName();
787 
788     return ContentReader.getUnescapeIllegalJcrContent(title);
789   }
790 
791   /**
792    * The listener interface for receiving saveAction events.
793    * The class that is interested in processing a saveAction
794    * event implements this interface, and the object created
795    * with that class is registered with a component using the
796    * component's <code>addSaveActionListener</code> method. When
797    * the saveAction event occurs, that object's appropriate
798    * method is invoked.
799    */
800   public static class SaveActionListener extends EventListener<UICLVConfig> {
801 
802     /* (non-Javadoc)
803      * @see org.exoplatform.webui.event.EventListener#execute(org.exoplatform.webui.event.Event)
804      */
805     public void execute(Event<UICLVConfig> event) throws Exception {
806       UICLVConfig clvConfig = event.getSource();
807 
808       /** GET VALUES FROM UIFORM */
809       String displayMode = ((UIFormRadioBoxInput) clvConfig.findComponentById(
810                                                                               UICLVConfig.DISPLAY_MODE_FORM_RADIO_BOX_INPUT)).getValue();
811       String itemPath = clvConfig.getSavedPath();
812 
813       if (itemPath == null || itemPath.length() == 0
814           || (itemPath.contains(";") && displayMode.equals(UICLVPortlet.DISPLAY_MODE_AUTOMATIC))
815           || (!itemPath.contains(";") && displayMode.equals(UICLVPortlet.DISPLAY_MODE_MANUAL))) {
816         Utils.createPopupMessage(clvConfig,
817                                  "UICLVConfig.msg.not-valid-path",
818                                  null,
819                                  ApplicationMessage.WARNING);
820         WebuiRequestContext requestContext = WebuiRequestContext.getCurrentInstance();
821         requestContext.addUIComponentToUpdateByAjax(clvConfig);
822         return;
823       }
824       String orderBy = clvConfig.getUIFormSelectBox(ORDER_BY_FORM_SELECT_BOX).getValue();
825       String orderType = clvConfig.getUIFormSelectBox(ORDER_TYPE_FORM_SELECT_BOX).getValue();
826 
827       String header = clvConfig.getUIStringInput(UICLVConfig.HEADER_FORM_STRING_INPUT).getValue();
828       if (header == null) header = "";
829       String showAutomaticDetection = clvConfig.getUICheckBoxInput(UICLVConfig.SHOW_AUTOMATIC_DETECTION_CHECKBOX_INPUT)
830           .isChecked() ? "true" : "false";
831       String displayTemplate = clvConfig.getUIFormSelectBox(UICLVConfig.DISPLAY_TEMPLATE_FORM_SELECT_BOX).getValue();
832       String paginatorTemplate = clvConfig.getUIFormSelectBox(UICLVConfig.PAGINATOR_TEMPLATE_FORM_SELECT_BOX).getValue();
833       String itemsPerPage = clvConfig.getUIStringInput(UICLVConfig.ITEMS_PER_PAGE_FORM_STRING_INPUT).getValue();
834 
835       String showTitle = clvConfig.getUICheckBoxInput(UICLVConfig.SHOW_TITLE_FORM_CHECKBOX_INPUT)
836           .isChecked() ? "true" : "false";
837       String showHeader = clvConfig.getUICheckBoxInput(UICLVConfig.SHOW_HEADER_FORM_CHECKBOX_INPUT)
838           .isChecked() ? "true" : "false";
839       String showRefresh = clvConfig.getUICheckBoxInput(UICLVConfig.SHOW_REFRESH_FORM_CHECKBOX_INPUT)
840           .isChecked() ? "true" : "false";
841 
842       String showImage = clvConfig.getUICheckBoxInput(UICLVConfig.SHOW_ILLUSTRATION_FORM_CHECKBOX_INPUT)
843           .isChecked() ? "true" : "false";
844       String showDateCreated = clvConfig.getUICheckBoxInput(UICLVConfig.SHOW_DATE_CREATED_FORM_CHECKBOX_INPUT)
845           .isChecked() ? "true" : "false";
846       String showMoreLink = clvConfig.getUICheckBoxInput(UICLVConfig.SHOW_READMORE_FORM_CHECKBOX_INPUT)
847           .isChecked() ? "true" : "false";
848 
849       String showSummary = clvConfig.getUICheckBoxInput(UICLVConfig.SHOW_SUMMARY_FORM_CHECKBOX_INPUT)
850           .isChecked() ? "true" : "false";
851       String showLink = clvConfig.getUICheckBoxInput(UICLVConfig.SHOW_LINK_FORM_CHECKBOX_INPUT)
852           .isChecked() ? "true" : "false";
853       String showRssLink = clvConfig.getUICheckBoxInput(UICLVConfig.SHOW_RSSLINK_FORM_CHECKBOX_INPUT)
854           .isChecked() ? "true" : "false";
855 
856       String contextualFolderMode = ((UIFormRadioBoxInput) clvConfig.findComponentById(
857                                                                                        UICLVConfig.CONTEXTUAL_FOLDER_RADIOBOX_INPUT)).getValue();
858       String showClvBy = clvConfig.getUIStringInput(UICLVConfig.SHOW_CLV_BY_STRING_INPUT).getValue();
859       if (showClvBy == null || showClvBy.length() == 0)
860         showClvBy = UICLVPortlet.DEFAULT_SHOW_CLV_BY;
861       String targetPage = clvConfig.getUIStringInput(UICLVConfig.TARGET_PAGE_FORM_STRING_INPUT).getValue();
862       String showScvWith = clvConfig.getUIStringInput(UICLVConfig.SHOW_SCV_WITH_STRING_INPUT).getValue();
863       if (showScvWith == null || showScvWith.length() == 0)
864         showScvWith = UICLVPortlet.DEFAULT_SHOW_SCV_WITH;
865 
866       String cacheEnabled = ((UIFormRadioBoxInput) clvConfig.
867           findComponentById(UICLVConfig.CACHE_ENABLE_RADIOBOX_INPUT)).getValue();
868 
869       /** SET VALUES TO PREFERENCES */
870       PortletRequestContext portletRequestContext = (PortletRequestContext) event.getRequestContext();
871       PortletPreferences portletPreferences = portletRequestContext.getRequest().getPreferences();
872       portletPreferences.setValue(UICLVPortlet.PREFERENCE_DISPLAY_MODE, displayMode);
873       portletPreferences.setValue(UICLVPortlet.PREFERENCE_ITEM_PATH, itemPath);
874       portletPreferences.setValue(UICLVPortlet.PREFERENCE_ITEM_DRIVE, clvConfig.getDriveName());
875 
876       portletPreferences.setValue(UICLVPortlet.PREFERENCE_ORDER_BY, orderBy);
877       portletPreferences.setValue(UICLVPortlet.PREFERENCE_ORDER_TYPE, orderType);
878 
879       portletPreferences.setValue(UICLVPortlet.PREFERENCE_HEADER, header);
880       portletPreferences.setValue(UICLVPortlet.PREFERENCE_AUTOMATIC_DETECTION, showAutomaticDetection);
881       portletPreferences.setValue(UICLVPortlet.PREFERENCE_DISPLAY_TEMPLATE, displayTemplate);
882       portletPreferences.setValue(UICLVPortlet.PREFERENCE_PAGINATOR_TEMPLATE, paginatorTemplate);
883       portletPreferences.setValue(UICLVPortlet.PREFERENCE_ITEMS_PER_PAGE, itemsPerPage);
884 
885       portletPreferences.setValue(UICLVPortlet.PREFERENCE_SHOW_TITLE, showTitle);
886       portletPreferences.setValue(UICLVPortlet.PREFERENCE_SHOW_HEADER, showHeader);
887       portletPreferences.setValue(UICLVPortlet.PREFERENCE_SHOW_REFRESH_BUTTON, showRefresh);
888 
889       portletPreferences.setValue(UICLVPortlet.PREFERENCE_SHOW_ILLUSTRATION, showImage);
890       portletPreferences.setValue(UICLVPortlet.PREFERENCE_SHOW_DATE_CREATED, showDateCreated);
891       portletPreferences.setValue(UICLVPortlet.PREFERENCE_SHOW_READMORE, showMoreLink);
892 
893       portletPreferences.setValue(UICLVPortlet.PREFERENCE_SHOW_SUMMARY, showSummary);
894       portletPreferences.setValue(UICLVPortlet.PREFERENCE_SHOW_LINK, showLink);
895       portletPreferences.setValue(UICLVPortlet.PREFERENCE_SHOW_RSSLINK, showRssLink);
896 
897       portletPreferences.setValue(UICLVPortlet.PREFERENCE_CONTEXTUAL_FOLDER, contextualFolderMode);
898       portletPreferences.setValue(UICLVPortlet.PREFERENCE_SHOW_CLV_BY, showClvBy);
899       portletPreferences.setValue(UICLVPortlet.PREFERENCE_TARGET_PAGE, targetPage);
900       portletPreferences.setValue(UICLVPortlet.PREFERENCE_SHOW_SCV_WITH, showScvWith);
901       portletPreferences.setValue(UICLVPortlet.PREFERENCE_CACHE_ENABLED, ENABLE_CACHE.equals(cacheEnabled)?"true":"false");
902       String appType = portletPreferences.getValue(UICLVPortlet.PREFERENCE_APPLICATION_TYPE, null);
903       if (UICLVPortlet.APPLICATION_CLV_BY_QUERY.equals(appType)) {
904         String workspace = ((UIFormSelectBox)clvConfig.findComponentById(UICLVConfig.WORKSPACE_FORM_SELECT_BOX)).getValue();
905         String query = ((UIFormTextAreaInput) clvConfig.findComponentById(UICLVConfig.CONTENT_BY_QUERY_TEXT_AREA)).getValue();
906         if (query == null) {
907           query = "";
908         }
909         portletPreferences.setValue(UICLVPortlet.PREFERENCE_WORKSPACE, workspace);
910         portletPreferences.setValue(UICLVPortlet.PREFERENCE_CONTENTS_BY_QUERY, query);
911       }
912       portletPreferences.store();
913 
914       UICLVPortlet portlet = clvConfig.getAncestorOfType(UICLVPortlet.class);
915 
916       if (Utils.isPortalEditMode()) {
917         portlet.updatePortlet();
918       } else {
919         if (clvConfig.getModeInternal()) {
920           portlet.changeToViewMode();
921         }else {
922           Utils.closePopupWindow(clvConfig, "UIViewerManagementPopupWindow");
923           portlet.updatePortlet();
924         }
925       }
926     }
927   }
928 
929   /**
930    * The listener interface for receiving cancelAction events.
931    * The class that is interested in processing a cancelAction
932    * event implements this interface, and the object created
933    * with that class is registered with a component using the
934    * component's <code>addCancelActionListener</code> method. When
935    * the cancelAction event occurs, that object's appropriate
936    * method is invoked.
937    */
938   public static class CancelActionListener extends EventListener<UICLVConfig> {
939 
940     /* (non-Javadoc)
941      * @see org.exoplatform.webui.event.EventListener#execute(org.exoplatform.webui.event.Event)
942      */
943     public void execute(Event<UICLVConfig> event) throws Exception {
944       UICLVConfig clvConfig = event.getSource();
945       if (!Utils.isPortalEditMode()) {
946         if (clvConfig.getModeInternal()) {
947           UICLVPortlet portlet = clvConfig.getAncestorOfType(UICLVPortlet.class);
948           portlet.changeToViewMode();
949         }else {
950           Utils.closePopupWindow(clvConfig, "UIViewerManagementPopupWindow");
951         }
952       }
953     }
954   }
955 
956 	/**
957 	 * The listener interface for receiving selectTabAction events.
958 	 * The class that is interested in processing a selectTabAction
959 	 * event implements this interface, and the object created
960 	 * with that class is registered with a component using the
961 	 * component's <code>addSelectTabActionListener</code> method. When
962 	 * the selectTabAction event occurs, that object's appropriate
963 	 * method is invoked.
964 	 */
965 	static public class SelectTabActionListener extends EventListener<UICLVConfig> {
966 
967 		/* (non-Javadoc)
968  * @see org.exoplatform.webui.event.EventListener#execute(org.exoplatform.webui.event.Event)
969  */
970 		public void execute(Event<UICLVConfig> event) throws Exception {
971 			WebuiRequestContext context = event.getRequestContext();
972 			String renderTab = context.getRequestParameter(UIComponent.OBJECTID);
973 			if (renderTab == null) {
974 				return;
975 			}
976 			event.getSource().setSelectedTab(renderTab);
977 			event.getRequestContext().addUIComponentToUpdateByAjax(event.getSource());
978 		}
979 	}
980 
981   /**
982    * The listener interface for receiving selectFolderPathAction events.
983    * The class that is interested in processing a selectFolderPathAction
984    * event implements this interface, and the object created
985    * with that class is registered with a component using the
986    * component's <code>addSelectFolderPathActionListener</code> method. When
987    * the selectFolderPathAction event occurs, that object's appropriate
988    * method is invoked.
989    */
990   public static class AddPathActionListener extends EventListener<UICLVConfig> {
991 
992     /* (non-Javadoc)
993      * @see org.exoplatform.webui.event.EventListener#execute(org.exoplatform.webui.event.Event)
994      */
995     public void execute(Event<UICLVConfig> event) throws Exception {
996       UICLVConfig clvConfig = event.getSource();
997       UIFormRadioBoxInput modeBoxInput = (UIFormRadioBoxInput) clvConfig.findComponentById(
998                                                                                            UICLVConfig.DISPLAY_MODE_FORM_RADIO_BOX_INPUT);
999       String mode = modeBoxInput.getValue();
1000       if (mode.equals(UICLVPortlet.DISPLAY_MODE_AUTOMATIC)) {
1001         UIContentSelectorFolder contentSelector = clvConfig.createUIComponent(UIContentSelectorFolder.class, null, null);
1002         UIContentBrowsePanelFolder folderContentSelector= contentSelector.getChild(UIContentBrowsePanelFolder.class);
1003         String location = clvConfig.getSavedPath();
1004         String[] locations = (location == null) ? null : location.split(":");
1005         Node node = (locations != null && locations.length >= 3) ? Utils.getViewableNodeByComposer(locations[0],
1006                                                                                                    locations[1],
1007                                                                                                    locations[2])
1008                                                                                                    : null;
1009         contentSelector.init(clvConfig.getDriveName(),
1010                              fixPath(node == null ? "" : node.getPath(),
1011                                                   clvConfig,
1012                                                   (locations != null && locations.length > 0) ? locations[0] : null));
1013         folderContentSelector.setSourceComponent(clvConfig, new String[] { UICLVConfig.ITEM_PATH_FORM_STRING_INPUT });
1014         Utils.createPopupWindow(clvConfig, contentSelector, UIContentSelector.FOLDER_PATH_SELECTOR_POPUP_WINDOW, 800);
1015         clvConfig.setPopupId(UIContentSelector.FOLDER_PATH_SELECTOR_POPUP_WINDOW);
1016       } else {
1017         UIContentSelectorMulti contentSelector = clvConfig.createUIComponent(UIContentSelectorMulti.class, null, null);
1018         UIContentBrowsePanelMulti multiContentSelector= contentSelector.getChild(UIContentBrowsePanelMulti.class);
1019         multiContentSelector.setSourceComponent(clvConfig, new String[] { UICLVConfig.ITEM_PATH_FORM_STRING_INPUT });
1020         String itemPath = clvConfig.getSavedPath();
1021         if (itemPath != null && itemPath.contains(";"))
1022           multiContentSelector.setItemPaths(itemPath);
1023         contentSelector.init();
1024         Utils.createPopupWindow(clvConfig, contentSelector, UIContentSelector.CORRECT_CONTENT_SELECTOR_POPUP_WINDOW, 800);
1025         clvConfig.setPopupId(UIContentSelector.CORRECT_CONTENT_SELECTOR_POPUP_WINDOW);
1026       }
1027     }
1028 
1029     private String fixPath(String path, UICLVConfig clvConfig, String repository) throws Exception {
1030       if (path == null || path.length() == 0 || repository == null || repository.length() == 0 ||
1031           clvConfig.getDriveName() == null || clvConfig.getDriveName().length() == 0)
1032         return "";
1033 
1034       ManageDriveService managerDriveService = clvConfig.getApplicationComponent(ManageDriveService.class);
1035       DriveData driveData = managerDriveService.getDriveByName(clvConfig.getDriveName());
1036       if (!path.startsWith(driveData.getHomePath()))
1037         return "";
1038       if ("/".equals(driveData.getHomePath()))
1039         return path;
1040       return path.substring(driveData.getHomePath().length());
1041     }
1042 
1043   }
1044 
1045   /**
1046    * The listener interface for receiving increaseAction events.
1047    * The class that is interested in processing a increaseAction
1048    * event implements this interface, and the object created
1049    * with that class is registered with a component using the
1050    * component's <code>addIncreaseActionListener</code> method. When
1051    * the increaseAction event occurs, that object's appropriate
1052    * method is invoked.
1053    */
1054   public static class IncreaseActionListener extends EventListener<UICLVConfig> {
1055 
1056     /* (non-Javadoc)
1057      * @see org.exoplatform.webui.event.EventListener#execute(org.exoplatform.webui.event.Event)
1058      */
1059     public void execute(Event<UICLVConfig> event) throws Exception {
1060       UICLVConfig clvConfig = event.getSource();
1061       List<String> items = clvConfig.items;
1062       int offset = Integer.parseInt(event.getRequestContext().getRequestParameter(OBJECTID));
1063       if (offset > 0) {
1064         String temp = items.get(offset - 1);
1065         items.set(offset - 1, items.get(offset));
1066         items.set(offset, temp);
1067       }
1068       StringBuffer sb = new StringBuffer("");
1069       for (String item : items) {
1070         sb.append(item).append(";");
1071       }
1072       String itemPath = sb.toString();
1073       clvConfig.getUIStringInput(UICLVConfig.ITEM_PATH_FORM_STRING_INPUT).setValue(clvConfig.getTitles(itemPath));
1074       clvConfig.setSavedPath(itemPath);
1075 
1076     }
1077   }
1078 
1079   /**
1080    * The listener interface for receiving decreaseAction events.
1081    * The class that is interested in processing a decreaseAction
1082    * event implements this interface, and the object created
1083    * with that class is registered with a component using the
1084    * component's <code>addDecreaseActionListener</code> method. When
1085    * the decreaseAction event occurs, that object's appropriate
1086    * method is invoked.
1087    */
1088   public static class DecreaseActionListener extends EventListener<UICLVConfig> {
1089 
1090     /* (non-Javadoc)
1091      * @see org.exoplatform.webui.event.EventListener#execute(org.exoplatform.webui.event.Event)
1092      */
1093     public void execute(Event<UICLVConfig> event) throws Exception {
1094       UICLVConfig clvConfig = event.getSource();
1095       List<String> items = clvConfig.items;
1096       int offset = Integer.parseInt(event.getRequestContext().getRequestParameter(OBJECTID));
1097       if (offset < items.size() - 1) {
1098         String temp = items.get(offset + 1);
1099         items.set(offset + 1, items.get(offset));
1100         items.set(offset, temp);
1101       }
1102       StringBuffer sb = new StringBuffer("");
1103       for (String item : items) {
1104         sb.append(item).append(";");
1105       }
1106       String itemPath = sb.toString();
1107       clvConfig.getUIStringInput(UICLVConfig.ITEM_PATH_FORM_STRING_INPUT).setValue(clvConfig.getTitles(itemPath));
1108       clvConfig.setSavedPath(itemPath);
1109     }
1110   }
1111 
1112   /**
1113    * The listener interface for receiving selectTargetPageAction events.
1114    * The class that is interested in processing a selectTargetPageAction
1115    * event implements this interface, and the object created
1116    * with that class is registered with a component using the
1117    * component's <code>addSelectTargetPageActionListener</code> method. When
1118    * the selectTargetPageAction event occurs, that object's appropriate
1119    * method is invoked.
1120    */
1121   public static class SelectTargetPageActionListener extends EventListener<UICLVConfig> {
1122 
1123     /* (non-Javadoc)
1124      * @see org.exoplatform.webui.event.EventListener#execute(org.exoplatform.webui.event.Event)
1125      */
1126     public void execute(Event<UICLVConfig> event) throws Exception {
1127       UICLVConfig viewerManagementForm = event.getSource();
1128       UIPageSelector pageSelector = viewerManagementForm.createUIComponent(UIPageSelector.class, null, null);
1129       pageSelector.setSourceComponent(viewerManagementForm, new String[] {TARGET_PAGE_FORM_STRING_INPUT});
1130       Utils.createPopupWindow(viewerManagementForm, pageSelector, TARGET_PAGE_SELECTOR_POPUP_WINDOW, 800);
1131       viewerManagementForm.setPopupId(TARGET_PAGE_SELECTOR_POPUP_WINDOW);
1132     }
1133   }
1134 
1135   public static class ShowAdvancedBlockActionListener extends EventListener<UICLVConfig> {
1136     /* (non-Javadoc)
1137      * @see org.exoplatform.webui.event.EventListener#execute(org.exoplatform.webui.event.Event)
1138      */
1139     public void execute(Event<UICLVConfig> event) throws Exception {
1140       UICLVConfig clvConfig = event.getSource();
1141       String showValue = event.getRequestContext().getRequestParameter(OBJECTID);
1142       clvConfig.isShowAdvancedBlock_ = "true".equalsIgnoreCase(showValue);
1143       event.getRequestContext().addUIComponentToUpdateByAjax(clvConfig);
1144     }
1145   }
1146   private boolean modeInternal = false;
1147   public void setModeInternal(boolean value) {
1148     this.modeInternal = value;
1149   }
1150   public boolean getModeInternal() {
1151     return this.modeInternal;
1152   }
1153 
1154   private class TemplateNameComparator implements Comparator<SelectItemOption<String>> {
1155     public int compare(SelectItemOption<String> item1,SelectItemOption<String> item2) {
1156       String s1 = item1.getLabel().toLowerCase();
1157       String s2 = item2.getLabel().toLowerCase();
1158       return s1.compareTo(s2);
1159     }
1160   }
1161 }