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.services.wcm.core;
18  
19  import java.util.Arrays;
20  import java.util.Collection;
21  import java.util.Iterator;
22  
23  import org.exoplatform.commons.utils.ExoProperties;
24  import org.exoplatform.container.xml.InitParams;
25  import org.exoplatform.container.xml.ObjectParameter;
26  import org.exoplatform.container.xml.PropertiesParam;
27  import org.exoplatform.services.cms.drives.DriveData;
28  import org.exoplatform.services.jcr.RepositoryService;
29  import org.exoplatform.services.log.ExoLogger;
30  import org.exoplatform.services.log.Log;
31  
32  /*
33   * Created by The eXo Platform SAS
34   * @author : Hoa.Pham
35   *          hoa.pham@exoplatform.com
36   * Jun 20, 2008
37   */
38  public class WCMConfigurationService {
39  
40    public static final String SITE_PATH_EXP = "\\{sitePath\\}";
41    public static final String SITE_NAME_EXP = "\\{siteName\\}";
42  
43    public static final String PARAMETERIZED_PAGE_URI         = "parameterizedPageURI";
44  
45    public static final String PRINT_PAGE_URI                 = "printPageURI";
46  
47    public static final String PRINT_VIEWER_PAGE              = "printViewerPage";
48  
49    public static final String EDITOR_PAGE_URI                = "editorPageURI";
50    
51    public static final String EDIT_PAGE_URI                  = "editPageURI";
52  
53    public static final String SITE_EXPLORER_URI              = "siteExplorerURI";
54  
55    public static final String CREATE_WIKI_PAGE_URI           = "createWikiPageURI";
56  
57    public static final String CLV_PORTLET                    = "CLVPortlet";
58  
59    public static final String SCV_PORTLET                    = "SCVPortlet";
60  
61    public static final String FORM_VIEW_TEMPLATE_PATH        = "formViewTemplatePath";
62  
63    public static final String PAGINATOR_TEMPLAET_PATH        = "paginatorTemplatePath";
64  
65    private static final Log LOG = ExoLogger.getLogger(WCMConfigurationService.class.getName());
66  
67    private NodeLocation livePortalsLocation = null;
68    private ExoProperties runtimeContextParams;
69    private DriveData siteDriveConfig;
70  
71    private String sharedPortal = null;
72  
73    @SuppressWarnings("unchecked")
74    public WCMConfigurationService(InitParams initParams, RepositoryService repoService) throws Exception {
75      Iterator<PropertiesParam> iterator = initParams.getPropertiesParamIterator();
76      while (iterator.hasNext()) {
77        PropertiesParam param = iterator.next();
78        if ("share.portal.config".endsWith(param.getName())) {
79          String portalName = param.getProperty("portalName");
80          sharedPortal = portalName;
81          if (LOG.isInfoEnabled()) {
82            LOG.info("Name of shared portal to share resources for all portals in repository is: "+ portalName);
83          }
84        } else if("RuntimeContextParams".equalsIgnoreCase(param.getName())) {
85          runtimeContextParams = param.getProperties();
86        }
87      }
88      Iterator<ObjectParameter> locations = initParams.getObjectParamIterator();
89      while (locations.hasNext()) {
90        ObjectParameter objectParameter = locations.next();
91        if ("live.portals.location.config".equals(objectParameter.getName())) {
92          NodeLocation objectParam = (NodeLocation)objectParameter.getObject();
93          livePortalsLocation  = objectParam;
94          if (LOG.isInfoEnabled()) {
95            LOG.info("Location that resources for all live portal is stored in repository"
96              + " is in workspace: "+ objectParam.getWorkspace() + " and with path: "+objectParam.getPath());
97          }
98        }
99        if("site.drive.config".equals(objectParameter.getName())) {
100         siteDriveConfig = (DriveData)objectParameter.getObject();
101       }
102     }
103   }
104 
105   public DriveData getSiteDriveConfig() {return this.siteDriveConfig; }
106 
107   public NodeLocation getLivePortalsLocation() {
108     return livePortalsLocation;
109   }
110 
111   public String getRuntimeContextParam(String paramName) {
112     if(runtimeContextParams != null)
113       return runtimeContextParams.get(paramName);
114     return null;
115   }
116 
117   public Collection<String> getRuntimeContextParams() {
118     if(runtimeContextParams != null)
119       return runtimeContextParams.values();
120     return null;
121   }
122 
123   public String getSharedPortalName() {
124     return sharedPortal;
125   }
126 
127   public Collection<NodeLocation> getAllLivePortalsLocation() {
128     return Arrays.asList(new NodeLocation[]{livePortalsLocation});
129   }
130 
131 }