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.impl;
18  
19  import javax.jcr.ItemNotFoundException;
20  import javax.jcr.Node;
21  import javax.jcr.Session;
22  
23  import org.exoplatform.container.xml.InitParams;
24  import org.exoplatform.container.xml.PropertiesParam;
25  import org.exoplatform.management.annotations.Managed;
26  import org.exoplatform.management.annotations.ManagedDescription;
27  import org.exoplatform.management.annotations.ManagedName;
28  import org.exoplatform.management.jmx.annotations.NameTemplate;
29  import org.exoplatform.management.jmx.annotations.Property;
30  import org.exoplatform.management.rest.annotations.RESTEndpoint;
31  import org.exoplatform.services.jcr.RepositoryService;
32  import org.exoplatform.services.jcr.core.ManageableRepository;
33  import org.exoplatform.services.jcr.ext.common.SessionProvider;
34  import org.exoplatform.services.wcm.core.WCMService;
35  import org.exoplatform.services.wcm.portal.LivePortalManagerService;
36  import org.exoplatform.services.wcm.utils.WCMCoreUtils;
37  
38  /**
39   * Created by The eXo Platform SAS.
40   *
41   * @author Benjamin Paillereau
42   * benjamin.paillereau@exoplatform.com
43   * Apr 30, 2009
44   */
45  @Managed
46  @NameTemplate( { @Property(key = "view", value = "portal"),
47      @Property(key = "service", value = "wcm"), @Property(key = "type", value = "content") })
48  @ManagedDescription("WCM Service")
49  @RESTEndpoint(path = "wcmservice")
50  public class WCMServiceImpl implements WCMService {
51    int expirationCache;
52  
53    public WCMServiceImpl(InitParams initParams) throws Exception {
54      PropertiesParam propertiesParam = initParams.getPropertiesParam("server.config");
55      String expirationCache = propertiesParam.getProperty("expirationCache");
56      this.setPortletExpirationCache(new Integer(expirationCache));
57    }
58  
59    /*
60     * (non-Javadoc)
61     * @see
62     * org.exoplatform.services.wcm.core.WCMService#getReferencedContent(java.
63     * lang.String, java.lang.String, java.lang.String,
64     * org.exoplatform.services.jcr.ext.common.SessionProvider)
65     */
66    public Node getReferencedContent(SessionProvider sessionProvider,
67                                     String workspace,
68                                     String nodeIdentifier) throws Exception {
69      if(workspace == null || nodeIdentifier == null) throw new ItemNotFoundException();
70      RepositoryService repositoryService = WCMCoreUtils.getService(RepositoryService.class);
71      ManageableRepository manageableRepository = repositoryService.getCurrentRepository();
72      Session session = sessionProvider.getSession(workspace, manageableRepository);
73      Node content = null;
74      try {
75        content = session.getNodeByUUID(nodeIdentifier);
76      } catch (ItemNotFoundException itemNotFoundException) {
77        try {
78          content = (Node) session.getItem(nodeIdentifier);
79        } catch(Exception exception) {
80          content = null;
81        }
82      }
83      return content;
84    }
85  
86    /*
87     * (non-Javadoc)
88     * @see
89     * org.exoplatform.services.wcm.core.WCMService#isSharedPortal(java.lang.String
90     * , org.exoplatform.services.jcr.ext.common.SessionProvider)
91     */
92    public boolean isSharedPortal(SessionProvider sessionProvider, String portalName) throws Exception {
93      LivePortalManagerService livePortalManagerService = WCMCoreUtils.getService(LivePortalManagerService.class);
94      boolean isShared = false;
95      Node sharedPortal = livePortalManagerService.getLiveSharedPortal(sessionProvider);
96      isShared = sharedPortal.getName().equals(portalName);
97      return isShared;
98    }
99  
100   @Managed
101   @ManagedDescription("Sets the WCM Portlet Expiration cache (in seconds) ?")
102   public void setPortletExpirationCache(@ManagedDescription("Change the WCM Portlet Expiration cache")
103                                         @ManagedName("expirationCache") int expirationCache) throws Exception {
104     this.expirationCache = expirationCache;
105   }
106 
107   @Managed
108   @ManagedDescription("What is the WCM Portlet Expiration cache (in seconds) ?")
109   public int getPortletExpirationCache() throws Exception {
110     return this.expirationCache;
111   }
112 
113 }