View Javadoc
1   /*
2    * Copyright (C) 2003-2007 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.fastcontentcreator;
18  
19  import org.exoplatform.services.jcr.RepositoryService;
20  import org.exoplatform.wcm.webui.fastcontentcreator.config.UIFCCConfig;
21  import org.exoplatform.webui.application.WebuiApplication;
22  import org.exoplatform.webui.application.WebuiRequestContext;
23  import org.exoplatform.webui.application.portlet.PortletRequestContext;
24  import org.exoplatform.webui.config.annotation.ComponentConfig;
25  import org.exoplatform.webui.core.UIPopupContainer;
26  import org.exoplatform.webui.core.UIPortletApplication;
27  import org.exoplatform.webui.core.lifecycle.UIApplicationLifecycle;
28  
29  import javax.portlet.PortletMode;
30  import javax.portlet.PortletPreferences;
31  
32  /**
33   * Created by The eXo Platform SAS
34   * Author : eXoPlatform
35   * chuong.phan@exoplatform.com, phan.le.thanh.chuong@gmail.com
36   * Jun 25, 2009
37   */
38  @ComponentConfig(
39      lifecycle = UIApplicationLifecycle.class
40  )
41  public class UIFCCPortlet extends UIPortletApplication {
42  
43    /**
44     * Instantiates a new uIFCC portlet.
45     *
46     * @throws Exception the exception
47     */
48    public UIFCCPortlet() throws Exception {
49      addChild(UIPopupContainer.class, null, null);
50    }
51  
52    /*
53     * (non-Javadoc)
54     * @see
55     * org.exoplatform.webui.core.UIPortletApplication#processRender(org.exoplatform
56     * .webui.application.WebuiApplication,
57     * org.exoplatform.webui.application.WebuiRequestContext)
58     */
59    public void processRender(WebuiApplication app, WebuiRequestContext context) throws Exception {
60  //    context.getJavascriptManager().importJavascript("eXo.ecm.ECMUtils",
61  //                                                    "/ecm-wcm-extension/javascript/");
62      context.getJavascriptManager().require("SHARED/ecm-utils", "ecmutil").
63              addScripts("ecmutil.ECMUtils.init('UIFastContentCreatorPortlet');");
64      PortletRequestContext portletRequestContext = (PortletRequestContext) context;
65      if (portletRequestContext.getApplicationMode() == PortletMode.VIEW) {
66        if (getChild(UIFCCConfig.class) != null) {
67          removeChild(UIFCCConfig.class);
68        }
69        if (getChild(UIFCCForm.class) == null) {
70          UIFCCForm fastContentCreatorForm = addChild(UIFCCForm.class, null, null);
71          PortletPreferences preferences = UIFCCUtils.getPortletPreferences();
72          fastContentCreatorForm.setTemplateNode(preferences.getValue(UIFCCConstant.PREFERENCE_TYPE,
73                                                                      ""));
74          fastContentCreatorForm.setWorkspace(preferences.getValue(UIFCCConstant.PREFERENCE_WORKSPACE,
75                                                                   ""));
76          fastContentCreatorForm.setStoredPath(preferences.getValue(UIFCCConstant.PREFERENCE_PATH, ""));
77          fastContentCreatorForm.setRepositoryName(getApplicationComponent(RepositoryService.class).getCurrentRepository()
78                                                                                                   .getConfiguration()
79                                                                                                   .getName());
80        }
81      } else if (portletRequestContext.getApplicationMode() == PortletMode.EDIT) {
82        if (getChild(UIFCCForm.class) != null) {
83          removeChild(UIFCCForm.class);
84        }
85        if (getChild(UIFCCConfig.class) == null) {
86          UIFCCConfig fastContentCreatorConfig = addChild(UIFCCConfig.class, null, null);
87          fastContentCreatorConfig.initEditMode();
88        }
89      }
90      super.processRender(app, context) ;
91    }
92  }