1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
40
41
42
43
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
61
62
63
64
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
88
89
90
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 }