View Javadoc
1   /*
2    * Copyright (C) 2003-2008 eXo Platform SAS. This program is free software; you
3    * can redistribute it and/or modify it under the terms of the GNU Affero
4    * General Public License as published by the Free Software Foundation; either
5    * version 3 of the License, or (at your option) any later version. This program
6    * is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
7    * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
8    * PARTICULAR PURPOSE. See the GNU General Public License for more details. You
9    * should have received a copy of the GNU General Public License along with this
10   * program; if not, see<http://www.gnu.org/licenses/>.
11   */
12  package org.exoplatform.wcm.webui.search;
13  
14  import javax.portlet.PortletMode;
15  
16  import org.exoplatform.wcm.webui.search.config.UIPortletConfig;
17  import org.exoplatform.webui.application.WebuiApplication;
18  import org.exoplatform.webui.application.WebuiRequestContext;
19  import org.exoplatform.webui.application.portlet.PortletRequestContext;
20  import org.exoplatform.webui.config.annotation.ComponentConfig;
21  import org.exoplatform.webui.core.UIPopupContainer;
22  import org.exoplatform.webui.core.UIPortletApplication;
23  import org.exoplatform.webui.core.lifecycle.UIApplicationLifecycle;
24  
25  /*
26   * Created by The eXo Platform SAS Author : Anh Do Ngoc anh.do@exoplatform.com
27   * Oct 31, 2008
28   */
29  @ComponentConfig(lifecycle = UIApplicationLifecycle.class)
30  public class UIWCMSearchPortlet extends UIPortletApplication {
31  
32    /** The mode. */
33    private PortletMode        mode                             = PortletMode.VIEW;
34  
35    /** The Constant SEARCH_FORM_TEMPLATE_PATH. */
36    public static final String SEARCH_FORM_TEMPLATE_PATH        = "searchFormTemplatePath";
37  
38    /** The Constant SEARCH_RESULT_TEMPLATE_PATH. */
39    public static final String SEARCH_RESULT_TEMPLATE_PATH      = "searchResultTemplatePath";
40  
41    /** The Constant SEARCH_PAGINATOR_TEMPLATE_PATH. */
42    public static final String SEARCH_PAGINATOR_TEMPLATE_PATH   = "searchPaginatorTemplatePath";
43  
44    /** The Constant SEARCH_PAGE_LAYOUT_TEMPLATE_PATH. */
45    public static final String SEARCH_PAGE_LAYOUT_TEMPLATE_PATH = "searchPageLayoutTemplatePath";
46  
47    /** The Constant REPOSITORY. */
48    public static final String REPOSITORY                       = "repository";
49  
50    /** The Constant WORKSPACE. */
51    public static final String WORKSPACE                        = "workspace";
52  
53    /** The Constant ITEMS_PER_PAGE. */
54    public final static String ITEMS_PER_PAGE                   = "itemsPerPage";
55  
56    /** The Constant PAGE_MODE. */
57    public final static String  PAGE_MODE                       = "pageMode";
58  
59    /** The Constant SHOW_DATE_CREATED. */
60    public final static String BASE_PATH                        = "basePath";
61    
62    /** The Constant DETAIL_PARAMETER_NAME. */
63    public final static String DETAIL_PARAMETER_NAME            = "detailParameterName";
64  
65    /** Search Page Mode **/
66    public static final String SEARCH_PAGE_MODE = "Page";
67  
68    /** Search Content Mode **/
69    public static final String SEARCH_CONTENT_MODE = "Document";
70    
71    
72  
73    /**
74     * Instantiates a new uIWCM search portlet.
75     *
76     * @throws Exception the exception
77     */
78    public UIWCMSearchPortlet() throws Exception {
79      activateMode(mode);
80  
81    }
82  
83    /*
84     * (non-Javadoc)
85     * @see
86     * org.exoplatform.webui.core.UIPortletApplication#processRender(org.exoplatform
87     * .webui.application.WebuiApplication,
88     * org.exoplatform.webui.application.WebuiRequestContext)
89     */
90    public void processRender(WebuiApplication app, WebuiRequestContext context) throws Exception {
91      PortletRequestContext pContext = (PortletRequestContext) context;
92      PortletMode newMode = pContext.getApplicationMode();
93      if (!mode.equals(newMode)) {
94        activateMode(newMode);
95        mode = newMode;
96      }
97      super.processRender(app, context);
98    }
99  
100   /**
101    * Activate mode.
102    *
103    * @param mode the mode
104    * @throws Exception the exception
105    */
106   private void activateMode(PortletMode mode) throws Exception {
107     getChildren().clear();
108     addChild(UIPopupContainer.class, null, "UISearchedContentEdittingPopup");
109     if (PortletMode.VIEW.equals(mode)) {
110       addChild(UISearchPageLayout.class, null, UIPortletApplication.VIEW_MODE);
111     } else if (PortletMode.EDIT.equals(mode)) {
112       addChild(UIPortletConfig.class, null, UIPortletApplication.EDIT_MODE);
113     }
114   }
115 }