View Javadoc
1   /***************************************************************************
2    * Copyright 2001-2010 The eXo Platform SARL         All rights reserved.  *
3    * Please look at license.txt in info directory for more license detail.   *
4    **************************************************************************/
5   package org.exoplatform.wcm.webui.scv;
6   
7   import org.exoplatform.ecm.utils.text.Text;
8   import org.exoplatform.ecm.webui.selector.UISelectable;
9   import org.exoplatform.services.cms.drives.DriveData;
10  import org.exoplatform.services.cms.drives.ManageDriveService;
11  import org.exoplatform.services.wcm.utils.WCMCoreUtils;
12  import org.exoplatform.wcm.webui.Utils;
13  import org.exoplatform.wcm.webui.reader.ContentReader;
14  import org.exoplatform.wcm.webui.selector.content.UIContentSelector;
15  import org.exoplatform.wcm.webui.selector.content.one.UIContentBrowsePanelOne;
16  import org.exoplatform.wcm.webui.selector.content.one.UIContentSelectorOne;
17  import org.exoplatform.wcm.webui.selector.page.UIPageSelector;
18  import org.exoplatform.web.application.ApplicationMessage;
19  import org.exoplatform.webui.application.WebuiRequestContext;
20  import org.exoplatform.webui.application.portlet.PortletRequestContext;
21  import org.exoplatform.webui.config.annotation.ComponentConfig;
22  import org.exoplatform.webui.config.annotation.EventConfig;
23  import org.exoplatform.webui.core.UIComponent;
24  import org.exoplatform.webui.core.lifecycle.UIFormLifecycle;
25  import org.exoplatform.webui.core.model.SelectItemOption;
26  import org.exoplatform.webui.event.Event;
27  import org.exoplatform.webui.event.Event.Phase;
28  import org.exoplatform.webui.event.EventListener;
29  import org.exoplatform.webui.form.UIFormInputSet;
30  import org.exoplatform.webui.form.UIFormRadioBoxInput;
31  import org.exoplatform.webui.form.UIFormStringInput;
32  import org.exoplatform.webui.form.UIFormTabPane;
33  import org.exoplatform.webui.form.ext.UIFormInputSetWithAction;
34  import org.exoplatform.webui.form.input.UICheckBoxInput;
35  
36  import javax.jcr.Node;
37  import javax.jcr.RepositoryException;
38  import javax.portlet.PortletPreferences;
39  import java.util.ArrayList;
40  import java.util.List;
41  
42  
43  /**
44   * Created by The eXo Platform SARL
45   * Author : Nguyen The Vinh
46   *          vinh.nguyen@exoplatform.com
47   * Jul 16, 2010
48   */
49  @ComponentConfig(
50                   lifecycle = UIFormLifecycle.class,
51                   template = "app:/groovy/SingleContentViewer/UISCVPreferences.gtmpl",
52                   events = {
53                     @EventConfig(listeners = UISCVPreferences.SaveActionListener.class),
54                     @EventConfig(listeners = UISCVPreferences.AddPathActionListener.class, phase = Phase.DECODE),
55                     @EventConfig(listeners = UISCVPreferences.CancelActionListener.class, phase = Phase.DECODE),
56  	                 @EventConfig(listeners = UISCVPreferences.SelectTabActionListener.class, phase = Phase.DECODE),
57                     @EventConfig(listeners = UISCVPreferences.SelectTargetPageActionListener.class, phase = Phase.DECODE)
58                   }
59      )
60  public class UISCVPreferences extends UIFormTabPane implements UISelectable{
61  
62    /** The Constant ITEM_PATH_FORM_INPUT_SET. */
63    public final static String ITEM_PATH_FORM_INPUT_SET     = "UISCVConfigItemPathFormInputSet";
64  
65    public final static String CONTENT_FORM_INPUT_SET       = "UISCVConfigContentFormInputSet";
66    public final static String DISPLAY_FORM_INPUT_SET       = "UISCVConfigDisplayFormInputSet";
67    public final static String PRINT_FORM_INPUT_SET         = "UISCVConfigPrintFormInputSet";
68    public final static String ADVANCED_FORM_INPUT_SET      = "UISCVConfigAdvancedFormInputSet";
69  
70    public static final String CONTENT_PATH_INPUT           = "UISCVContentPathConfigurationInputBox";
71  
72    public static final String SHOW_TITLE_CHECK_BOX         = "UISCVShowTitleConfigurationCheckBox";
73  
74    public static final String SHOW_DATE_CHECK_BOX          = "UISCVShowDateConfigurationCheckBox";
75  
76    public static final String SHOW_OPION_BAR_CHECK_BOX     = "UISCVShowOptionBarConfigurationCheckBox";
77  
78    public static final String CONTEXTUAL_SELECT_RADIO_BOX  = "UISCVContextualRadioBox";
79  
80    public static final String PARAMETER_INPUT_BOX          = "UISCVParameterInputBox";
81  
82    public static final String CACHE_ENABLE_SELECT_RADIO_BOX = "UISCVCacheRadioBox";
83  
84    public final static String PRINT_PAGE_FORM_INPUT_SET    = "UISCVConfigPrintPageFormInputSet";
85    public static final String PRINT_VIEW_PAGE_INPUT        = "UISCVPrintViewPageInput";
86    /** The Constant PRINT_PAGE_SELECTOR_POPUP. */
87    public final static String PRINT_PAGE_SELECTOR_POPUP    = "UISCVConfigPrintPageSelectorPopupWindow";
88  
89    public static final String PRINT_PAGE_PARAMETER_INPUT   = "UISCVPrintPageParameter";
90  
91    public static final String ENABLE_STRING                = "Enable";
92    public static final String DISABLE_STRING               = "Disable";
93  
94    protected PortletPreferences portletPreferences;
95  
96    protected String contentSelectorID;
97    protected String selectedNodeUUID =null;
98    protected String selectedNodeReporitory =null;
99    protected String selectedNodeWorkspace =null;
100   protected String selectedNodeDrive = null;
101   protected String selectedNodePath = null;
102 
103   private UIFormStringInput             txtContentPath, txtPrintPage, txtPrintPageParameter;
104 
105   private UICheckBoxInput               chkShowTitle;
106   private UICheckBoxInput               chkShowDate;
107   private UICheckBoxInput               chkShowOptionBar;
108   private UIFormRadioBoxInput           contextOptionsRadioInputBox;
109   private UIFormRadioBoxInput           cacheOptionsRadioInputBox;
110 
111   public UISCVPreferences() throws Exception{
112     super("UISCVPreferences");
113     portletPreferences = ((PortletRequestContext) WebuiRequestContext.getCurrentInstance()).getRequest().getPreferences();
114     initComponent();
115     setActions(new String[] { "Save", "Cancel" });
116   }
117 
118   /**
119    * Initialize the preferences setting form
120    *
121    * @throws Exception
122    */
123 
124   public void initComponent() throws Exception{
125     /** Content name **/
126     String strNodeName = getNodeNameByPreferences();
127     txtContentPath = new UIFormStringInput(CONTENT_PATH_INPUT, CONTENT_PATH_INPUT, strNodeName);
128     txtContentPath.setReadOnly(true);
129 
130     UIFormInputSetWithAction itemPathInputSet = new UIFormInputSetWithAction(ITEM_PATH_FORM_INPUT_SET);
131     itemPathInputSet.setActionInfo(CONTENT_PATH_INPUT, new String[] { "AddPath" }) ;
132     itemPathInputSet.addUIFormInput(txtContentPath);
133     UIFormInputSetWithAction contentInputSet = new UIFormInputSetWithAction(CONTENT_FORM_INPUT_SET);
134     contentInputSet.addUIFormInput((UIFormInputSet)itemPathInputSet);
135     setSelectedTab(CONTENT_FORM_INPUT_SET);
136 
137     /** Option Show Title/Show Date/Show OptionBar **/
138     boolean blnShowTitle = Boolean.parseBoolean(portletPreferences.getValue(UISingleContentViewerPortlet.SHOW_TITLE,
139                                                                             null));
140     chkShowTitle = new UICheckBoxInput(SHOW_TITLE_CHECK_BOX, SHOW_TITLE_CHECK_BOX, null);
141     chkShowTitle.setChecked(blnShowTitle);
142 
143     boolean blnShowDate = Boolean.parseBoolean(portletPreferences.getValue(UISingleContentViewerPortlet.SHOW_DATE,
144                                                                            null));
145     chkShowDate = new UICheckBoxInput(SHOW_DATE_CHECK_BOX, SHOW_DATE_CHECK_BOX, null);
146     chkShowDate.setChecked(blnShowDate);
147 
148     boolean blnShowOptionBar = Boolean.parseBoolean(portletPreferences.getValue(UISingleContentViewerPortlet.SHOW_OPTIONBAR,
149                                                                                 null));
150     chkShowOptionBar = new UICheckBoxInput(SHOW_OPION_BAR_CHECK_BOX, SHOW_OPION_BAR_CHECK_BOX, null);
151     chkShowOptionBar.setChecked(blnShowOptionBar);
152 
153     UIFormInputSetWithAction displayInputSet = new UIFormInputSetWithAction(DISPLAY_FORM_INPUT_SET);
154     displayInputSet.addChild(chkShowTitle);
155     displayInputSet.addChild(chkShowDate);
156     displayInputSet.addChild(chkShowOptionBar);
157 
158 
159     /** CONTEXTUAL MODE */
160     boolean isShowContextOption = Boolean.parseBoolean(portletPreferences.getValue(UISingleContentViewerPortlet.CONTEXTUAL_MODE,
161         "false"));
162     List<SelectItemOption<String>> contextOptions = new ArrayList<SelectItemOption<String>>();
163     contextOptions.add(new SelectItemOption<String>(ENABLE_STRING, ENABLE_STRING));
164     contextOptions.add(new SelectItemOption<String>(DISABLE_STRING, DISABLE_STRING));
165     contextOptionsRadioInputBox = new UIFormRadioBoxInput(CONTEXTUAL_SELECT_RADIO_BOX,
166                                                           CONTEXTUAL_SELECT_RADIO_BOX,
167                                                           contextOptions);
168     contextOptionsRadioInputBox.setValue(isShowContextOption?ENABLE_STRING:DISABLE_STRING);
169 
170     String strParameterName = portletPreferences.getValue(UISingleContentViewerPortlet.PARAMETER, null);
171     UIFormStringInput txtParameterName = new UIFormStringInput(PARAMETER_INPUT_BOX, strParameterName);
172 
173     /** CACHE MANAGEMENT */
174     boolean isCacheEnabled = Boolean.parseBoolean(portletPreferences.getValue(UISingleContentViewerPortlet.ENABLE_CACHE,
175         "false"));
176 
177     List<SelectItemOption<String>> cacheOptions = new ArrayList<SelectItemOption<String>>();
178     cacheOptions.add(new SelectItemOption<String>(ENABLE_STRING, ENABLE_STRING));
179     cacheOptions.add(new SelectItemOption<String>(DISABLE_STRING, DISABLE_STRING));
180     cacheOptionsRadioInputBox = new UIFormRadioBoxInput(CACHE_ENABLE_SELECT_RADIO_BOX,
181                                                         CACHE_ENABLE_SELECT_RADIO_BOX,
182                                                         cacheOptions);
183     cacheOptionsRadioInputBox.setValue(isCacheEnabled ? ENABLE_STRING : DISABLE_STRING);
184 
185     UIFormInputSetWithAction advancedInputSet = new UIFormInputSetWithAction(ADVANCED_FORM_INPUT_SET);
186     advancedInputSet.addChild(cacheOptionsRadioInputBox);
187     advancedInputSet.addChild(txtParameterName);
188     advancedInputSet.addChild(contextOptionsRadioInputBox);
189 
190     /** PRINT PAGE */
191     String strPrintParameterName = portletPreferences.getValue(UISingleContentViewerPortlet.PRINT_PARAMETER, null);
192     txtPrintPageParameter = new UIFormStringInput(PRINT_PAGE_PARAMETER_INPUT, strPrintParameterName);
193 
194 
195     /** TARGET PAGE */
196     String strPrintPageName = portletPreferences.getValue(UISingleContentViewerPortlet.PRINT_PAGE, null);
197     UIFormInputSetWithAction targetPageInputSet = new UIFormInputSetWithAction(PRINT_PAGE_FORM_INPUT_SET);
198     txtPrintPage = new UIFormStringInput(PRINT_VIEW_PAGE_INPUT, PRINT_VIEW_PAGE_INPUT, strPrintPageName);
199     txtPrintPage.setValue(strPrintPageName);
200     txtPrintPage.setReadOnly(true);
201     targetPageInputSet.setActionInfo(PRINT_VIEW_PAGE_INPUT, new String[] {"SelectTargetPage"}) ;
202     targetPageInputSet.addUIFormInput(txtPrintPage);
203 
204     UIFormInputSetWithAction printInputSet = new UIFormInputSetWithAction(PRINT_FORM_INPUT_SET);
205     printInputSet.addChild(txtPrintPageParameter);
206     printInputSet.addChild(targetPageInputSet);
207 
208 
209     addChild(contentInputSet);
210     addChild(displayInputSet);
211     addChild(printInputSet);
212     addChild(advancedInputSet);
213   }
214 
215   /**
216    * ActionListener: save preferences action
217    * @author exo.VinhNT
218    *
219    */
220   public static class SaveActionListener extends EventListener<UISCVPreferences> {
221     public void execute(Event<UISCVPreferences> event) throws Exception {
222       WebuiRequestContext requestContext = WebuiRequestContext.getCurrentInstance();
223       UISCVPreferences uiSCVPref = event.getSource();
224       PortletPreferences portletPreferences = ((PortletRequestContext) event.getRequestContext()).getRequest()
225           .getPreferences();
226       UIFormInputSetWithAction displayInputSet = uiSCVPref.findComponentById(DISPLAY_FORM_INPUT_SET);
227       String strShowTitle = displayInputSet.getUICheckBoxInput(SHOW_TITLE_CHECK_BOX).isChecked() ? "true" : "false";
228       String strShowDate = displayInputSet.getUICheckBoxInput(SHOW_DATE_CHECK_BOX).isChecked() ? "true" : "false";
229       String strShowOptionBar = displayInputSet.getUICheckBoxInput(SHOW_OPION_BAR_CHECK_BOX) .isChecked() ? "true" : "false";
230 
231       String strIsContextEnable = ((UIFormRadioBoxInput) uiSCVPref.findComponentById(CONTEXTUAL_SELECT_RADIO_BOX)).getValue();
232       UIFormInputSetWithAction advancedInputSet = uiSCVPref.findComponentById(ADVANCED_FORM_INPUT_SET);      
233       strIsContextEnable = strIsContextEnable.equals(ENABLE_STRING) ? "true":"false";
234       String strParameterName = advancedInputSet.getUIStringInput(PARAMETER_INPUT_BOX).getValue();
235       String strIsCacheEnabled = ((UIFormRadioBoxInput) advancedInputSet.getChildById(CACHE_ENABLE_SELECT_RADIO_BOX)).getValue();
236       strIsCacheEnabled = ENABLE_STRING.equals(strIsCacheEnabled) ? "true" : "false";
237 
238 
239       UIFormInputSetWithAction printInputSet = uiSCVPref.findComponentById(PRINT_FORM_INPUT_SET);
240       String strPrintPageName = printInputSet.getUIStringInput(PRINT_VIEW_PAGE_INPUT).getValue();
241       String strPrintParameterName  = printInputSet.getUIStringInput(PRINT_PAGE_PARAMETER_INPUT).getValue();
242 
243 
244 
245       if (!Boolean.parseBoolean(strIsContextEnable)) {
246         if (uiSCVPref.getSelectedNodeUUID() != null) {
247           if (uiSCVPref.getSelectedNodeUUID().length() == 0) {
248             Utils.createPopupMessage(uiSCVPref,
249                                      "UISCVPreferences.msg.not-valid-path",
250                                      null,
251                                      ApplicationMessage.WARNING);
252             requestContext.addUIComponentToUpdateByAjax(uiSCVPref);
253             return;
254           }
255         } else {
256           Utils.createPopupMessage(uiSCVPref,
257                                    "UISCVPreferences.msg.not-valid-path",
258                                    null,
259                                    ApplicationMessage.WARNING);
260           requestContext.addUIComponentToUpdateByAjax(uiSCVPref);
261           return;
262         }
263       }
264       portletPreferences.setValue(UISingleContentViewerPortlet.REPOSITORY, uiSCVPref.getSelectedNodeRepository());
265       portletPreferences.setValue(UISingleContentViewerPortlet.WORKSPACE, uiSCVPref.getSelectedNodeWorkspace());
266       portletPreferences.setValue(UISingleContentViewerPortlet.IDENTIFIER, uiSCVPref.getSelectedNodeUUID()) ;
267       portletPreferences.setValue(UISingleContentViewerPortlet.DRIVE, uiSCVPref.getSelectedNodeDrive());
268 
269       portletPreferences.setValue(UISingleContentViewerPortlet.SHOW_TITLE, strShowTitle);
270       portletPreferences.setValue(UISingleContentViewerPortlet.SHOW_DATE, strShowDate);
271       portletPreferences.setValue(UISingleContentViewerPortlet.SHOW_OPTIONBAR, strShowOptionBar);
272       portletPreferences.setValue(UISingleContentViewerPortlet.CONTEXTUAL_MODE, strIsContextEnable);
273       portletPreferences.setValue(UISingleContentViewerPortlet.PARAMETER, strParameterName);
274       portletPreferences.setValue(UISingleContentViewerPortlet.PRINT_PAGE, strPrintPageName);
275       portletPreferences.setValue(UISingleContentViewerPortlet.PRINT_PARAMETER, strPrintParameterName);
276       portletPreferences.setValue(UISingleContentViewerPortlet.ENABLE_CACHE, strIsCacheEnabled);
277       portletPreferences.store();
278       if (uiSCVPref.getInternalPreferencesMode()) {
279         if (!Utils.isPortalEditMode()) {
280           uiSCVPref.getAncestorOfType(UISingleContentViewerPortlet.class).changeToViewMode();
281         }
282       } else {
283         Utils.closePopupWindow(uiSCVPref, UISingleContentViewerPortlet.UIPreferencesPopupID);
284       }
285     }
286   }
287   public static class CancelActionListener extends EventListener<UISCVPreferences> {
288     public void execute(Event<UISCVPreferences> event) throws Exception {
289       UISCVPreferences uiSCVPref = event.getSource();
290       if (uiSCVPref.getInternalPreferencesMode()) {
291         if (!Utils.isPortalEditMode()) {
292           uiSCVPref.getAncestorOfType(UISingleContentViewerPortlet.class).changeToViewMode();
293         }
294       } else {
295         Utils.closePopupWindow(uiSCVPref, UISingleContentViewerPortlet.UIPreferencesPopupID);
296       }
297     }
298   }
299   /**
300    * setSelectedNodeInfo: Save temporary data when user select a node from ContentSelector
301    * @param nodeUUID
302    * @param nodeRepo
303    * @param nodeWS
304    */
305   public void setSelectedNodeInfo(String nodeUUID, String nodeRepo, String nodeWS, String nodeDrive) {
306     this.selectedNodeUUID = nodeUUID;
307     this.selectedNodeReporitory = nodeRepo;
308     this.selectedNodeWorkspace = nodeWS;
309     this.selectedNodeDrive = nodeDrive;
310   }
311   public void setSelectedNodePath(String path)
312   {
313     this.selectedNodePath = path;
314   }
315   public String getSelectedNodePath() {
316     return this.selectedNodePath;
317   }
318   /**
319    * Get the temporary node UUID
320    * @return
321    */
322   public String getSelectedNodeUUID() {
323     return this.selectedNodeUUID;
324   }
325   /**
326    * Get the temporary Node Repository string
327    * @return
328    */
329   public String getSelectedNodeRepository() {
330     return this.selectedNodeReporitory;
331   }
332   /**
333    * Get the temporary node Workspace string
334    * @return
335    */
336   public String getSelectedNodeWorkspace() {
337     return this.selectedNodeWorkspace;
338   }
339 
340   /**
341    * Get the temporary node Drive string
342    * @return
343    */
344   public String getSelectedNodeDrive() {
345     return this.selectedNodeDrive;
346   }
347 
348 	/**
349 	 * The listener interface for receiving selectTabAction events.
350 	 * The class that is interested in processing a selectTabAction
351 	 * event implements this interface, and the object created
352 	 * with that class is registered with a component using the
353 	 * component's <code>addSelectTabActionListener</code> method. When
354 	 * the selectTabAction event occurs, that object's appropriate
355 	 * method is invoked.
356 	 */
357 	static public class SelectTabActionListener extends EventListener<UISCVPreferences> {
358 
359 		/* (non-Javadoc)
360  * @see org.exoplatform.webui.event.EventListener#execute(org.exoplatform.webui.event.Event)
361  */
362 		public void execute(Event<UISCVPreferences> event) throws Exception {
363 			WebuiRequestContext context = event.getRequestContext();
364 			String renderTab = context.getRequestParameter(UIComponent.OBJECTID);
365 			if (renderTab == null) {
366 				return;
367 			}
368 			event.getSource().setSelectedTab(renderTab);
369 			event.getRequestContext().addUIComponentToUpdateByAjax(event.getSource());
370 		}
371 	}
372 
373   public static class AddPathActionListener extends EventListener<UISCVPreferences> {
374     public void execute(Event<UISCVPreferences> event) throws Exception {
375       UISCVPreferences uiSCVPref = event.getSource();
376       UIContentSelectorOne contentSelector = uiSCVPref.createUIComponent(UIContentSelectorOne.class,
377                                                                          null,
378                                                                          null);
379       Node node = Utils.getViewableNodeByComposer(uiSCVPref.getSelectedNodeRepository(),
380                                                   uiSCVPref.getSelectedNodeWorkspace(),
381                                                   uiSCVPref.getSelectedNodeUUID());
382       contentSelector.init(uiSCVPref.getSelectedNodeDrive(), fixPath(node == null ? ""
383                                                                                     : node.getPath(),
384                                                                                     uiSCVPref));
385       contentSelector.getChild(UIContentBrowsePanelOne.class)
386       .setSourceComponent(uiSCVPref,
387                           new String[] { UISCVPreferences.CONTENT_PATH_INPUT });
388       Utils.createPopupWindow(uiSCVPref,
389                               contentSelector,
390                               UIContentSelector.CORRECT_CONTENT_SELECTOR_POPUP_WINDOW,
391                               800);
392       uiSCVPref.setContentSelectorID(UIContentSelector.CORRECT_CONTENT_SELECTOR_POPUP_WINDOW);
393     }
394 
395     private String fixPath(String path, UISCVPreferences uiScvPref) throws Exception {
396       if (path == null || path.length() == 0 ||
397           uiScvPref.getSelectedNodeDrive() == null || uiScvPref.getSelectedNodeDrive().length() == 0 ||
398           uiScvPref.getSelectedNodeRepository() == null || uiScvPref.getSelectedNodeRepository().length() == 0)
399         return "";
400       ManageDriveService managerDriveService = uiScvPref.getApplicationComponent(ManageDriveService.class);
401       DriveData driveData = managerDriveService.getDriveByName(uiScvPref.getSelectedNodeDrive());
402       if (!path.startsWith(driveData.getHomePath()))
403         return "";
404       if ("/".equals(driveData.getHomePath()))
405         return path;
406       return path.substring(driveData.getHomePath().length());
407     }
408   }
409 
410   /**
411    *
412    * @return A string point to the node from preferences
413    */
414 
415   protected String getNodeNameByPreferences(){
416     String repository = WCMCoreUtils.getRepository().getConfiguration().getName();
417     String workspace = portletPreferences.getValue(UISingleContentViewerPortlet.WORKSPACE, null);
418     String nodeIdentifier = portletPreferences.getValue(UISingleContentViewerPortlet.IDENTIFIER, null);
419     String nodeDrive = portletPreferences.getValue(UISingleContentViewerPortlet.DRIVE, null);
420     try {
421       Node savedNode = Utils.getRealNode(repository, workspace, nodeIdentifier, false);
422       if (savedNode==null) return null;
423       this.setSelectedNodeInfo(savedNode.getUUID(), repository, workspace, nodeDrive);
424       this.setSelectedNodePath(savedNode.getPath());
425       return getTitle(savedNode);
426     }catch (RepositoryException re) {
427       return null;
428     }
429   }
430   /**
431    * Gets the title.
432    *
433    * @param node the node
434    *
435    * @return the title
436    *
437    * @throws Exception the exception
438    */
439   private String getTitle(Node node) throws RepositoryException {
440     String title = null;
441     if (node.hasProperty("exo:title")) {
442       title = node.getProperty("exo:title").getValue().getString();
443     }
444     if (node.hasNode("jcr:content")) {
445       Node content = node.getNode("jcr:content");
446       if (content.hasProperty("dc:title")) {
447         try {
448           title = content.getProperty("dc:title").getValues()[0].getString();
449         } catch (Exception e) {
450           title = null;
451         }
452       }
453     }
454     if (title==null) title = node.getName();
455 
456     return ContentReader.getUnescapeIllegalJcrContent(title);
457   }
458   public void setContentSelectorID(String id) {
459     this.contentSelectorID = id;
460   }
461   public String getContetSelectorID() {
462     return this.contentSelectorID;
463   }
464 
465   public boolean isContextualEnable() {
466     return Boolean.parseBoolean(portletPreferences.getValue(UISingleContentViewerPortlet.CONTEXTUAL_MODE,
467         "false"));
468   }
469   public void doSelect(String selectField, Object value) throws Exception {
470     String strRepository, strWorkspace, strDrive, strIdentifier, strNodeUUID;
471     int driveIndex;
472     String strPath = (String) value;
473 
474     if (CONTENT_PATH_INPUT.equals(selectField) ) {
475       String[] splits = strPath.split(":");
476       driveIndex = (splits.length == 4) ? 1 : 0;
477       strRepository = splits[driveIndex];
478       strWorkspace = splits[driveIndex + 1];
479       strIdentifier = splits[driveIndex + 2];
480       strDrive=  (driveIndex == 1) ? splits[0] : "";
481       strIdentifier = Text.escapeIllegalJcrChars(strIdentifier);
482       Node selectedNode = Utils.getRealNode(strRepository, strWorkspace, strIdentifier, false);
483       if (selectedNode==null) return;
484       strNodeUUID = selectedNode.getUUID();
485       this.setSelectedNodeInfo(strNodeUUID, strRepository, strWorkspace, strDrive);
486       this.setSelectedNodePath(selectedNode.getPath());
487       getUIStringInput(selectField).setValue(getTitle(selectedNode));
488     }else if (PRINT_VIEW_PAGE_INPUT.equals(selectField)) {
489       getUIStringInput(selectField).setValue(strPath);
490     }
491     Utils.closePopupWindow(this, contentSelectorID);
492   }
493 
494 
495   /**
496    * The listener interface for receiving selectTargetPageAction events.
497    * The class that is interested in processing a selectTargetPageAction
498    * event implements this interface, and the object created
499    * with that class is registered with a component using the
500    * component's <code>addSelectTargetPageActionListener</code> method. When
501    * the selectTargetPageAction event occurs, that object's appropriate
502    * method is invoked.
503    */
504   public static class SelectTargetPageActionListener extends EventListener<UISCVPreferences> {
505 
506     /* (non-Javadoc)
507      * @see org.exoplatform.webui.event.EventListener#execute(org.exoplatform.webui.event.Event)
508      */
509     public void execute(Event<UISCVPreferences> event) throws Exception {
510       UISCVPreferences uiscv = event.getSource();
511       UIPageSelector pageSelector = uiscv.createUIComponent(UIPageSelector.class, null, null);
512       pageSelector.setSourceComponent(uiscv, new String[] {PRINT_VIEW_PAGE_INPUT});
513       Utils.createPopupWindow(uiscv, pageSelector, PRINT_PAGE_SELECTOR_POPUP, 800);
514       uiscv.setContentSelectorID(PRINT_PAGE_SELECTOR_POPUP);
515     }
516   }
517 
518   public void setInternalPreferencesMode(boolean isInternal) {
519     this.isInternal = isInternal;
520   }
521   public boolean getInternalPreferencesMode() {
522     return this.isInternal;
523   }
524   boolean isInternal = false;
525 }