1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.exoplatform.wcm.webui.clv;
18
19 import javax.jcr.Node;
20 import javax.jcr.PathNotFoundException;
21 import javax.jcr.Session;
22 import javax.jcr.query.Row;
23 import javax.portlet.PortletPreferences;
24
25 import org.exoplatform.commons.api.search.data.SearchResult;
26 import org.exoplatform.ecm.resolver.JCRResourceResolver;
27 import org.exoplatform.resolver.ResourceResolver;
28 import org.exoplatform.services.cms.impl.DMSConfiguration;
29 import org.exoplatform.services.jcr.access.PermissionType;
30 import org.exoplatform.services.jcr.core.ExtendedNode;
31 import org.exoplatform.services.wcm.core.NodeLocation;
32 import org.exoplatform.services.wcm.search.base.SearchDataCreator;
33 import org.exoplatform.services.wcm.utils.WCMCoreUtils;
34 import org.exoplatform.wcm.webui.Utils;
35 import org.exoplatform.webui.application.WebuiRequestContext;
36 import org.exoplatform.webui.application.portlet.PortletRequestContext;
37 import org.exoplatform.webui.core.UIContainer;
38 import org.exoplatform.webui.event.Event;
39 import org.exoplatform.webui.event.EventListener;
40
41
42
43
44
45
46
47 public abstract class UICLVContainer extends UIContainer {
48
49
50 protected String messageKey;
51
52
53
54
55
56
57 public abstract void init() throws Exception;
58
59
60
61
62
63
64 public abstract String getPortletName() throws Exception;
65
66
67
68
69
70
71
72
73 public String getMessageKey() throws Exception {
74 return messageKey;
75 }
76
77
78
79
80
81
82 public String getPortletId() {
83 PortletRequestContext pContext = (PortletRequestContext) WebuiRequestContext.getCurrentInstance();
84 return pContext.getWindowId();
85 }
86
87
88
89
90 public void processRender(WebuiRequestContext context) throws Exception {
91 if(!Boolean.parseBoolean(Utils.getCurrentMode()) || context.getFullRender()) {
92 init();
93 }
94 super.processRender(context);
95 }
96
97 public String getEditLink(boolean isEditable, boolean isNew) throws Exception {
98 String folderPath = this.getAncestorOfType(UICLVPortlet.class).getFolderPath();
99 if (folderPath==null) folderPath="";
100 Node folderNode = null;
101 try{
102 folderNode = getFolderNode(folderPath);
103 }catch(PathNotFoundException e){
104 folderNode = getFolderNode("");
105 }
106 return Utils.getEditLink(folderNode, isEditable, isNew);
107 }
108
109 public Node getFolderNode() {
110 return NodeLocation.getNodeByExpression(
111 Utils.getPortletPreference(UICLVPortlet.PREFERENCE_ITEM_PATH));
112 }
113
114 private Node getFolderNode(String oldPath) throws Exception {
115 if ((oldPath==null) || ((oldPath!=null) && (oldPath.length()==0))) return null;
116 int slashIndex = oldPath.indexOf("/");
117 String path = oldPath.substring(slashIndex);
118 String[] repoWorkspace = oldPath.substring(0, slashIndex).split(":");
119 String strWorkspace = repoWorkspace[1];
120 Session session = WCMCoreUtils.getUserSessionProvider().getSession(strWorkspace, WCMCoreUtils.getRepository());
121 return (Node)session.getItem(path);
122 }
123
124
125
126
127
128
129
130
131
132 public ResourceResolver getTemplateResourceResolver() throws Exception {
133 DMSConfiguration dmsConfiguration = getApplicationComponent(DMSConfiguration.class);
134 String workspace = dmsConfiguration.getConfig().getSystemWorkspace();
135 return new JCRResourceResolver(workspace);
136 }
137
138
139
140
141
142
143
144
145
146
147
148 public static class PreferencesActionListener extends EventListener<UICLVFolderMode> {
149
150
151
152 public void execute(Event<UICLVFolderMode> event) throws Exception {
153 UICLVContainer clvContainer = event.getSource();
154 UICLVConfig viewerManagementForm = clvContainer.createUIComponent(UICLVConfig.class, null, null);
155 Utils.createPopupWindow(clvContainer, viewerManagementForm, "UIViewerManagementPopupWindow", 800);
156 }
157 }
158
159
160 public void onRefresh(Event<UICLVPresentation> event) throws Exception {
161 UICLVPresentation clvPresentation = event.getSource();
162 UICLVContainer uiListViewerBase = clvPresentation.getParent();
163 uiListViewerBase.getChildren().clear();
164 uiListViewerBase.init();
165 }
166
167 public boolean isModeByFolder() {
168 PortletPreferences portletPreferences = Utils.getAllPortletPreferences();
169 String currentApplicationMode = portletPreferences.getValue(UICLVPortlet.PREFERENCE_APPLICATION_TYPE, null);
170 if (currentApplicationMode.equals(UICLVPortlet.APPLICATION_CLV_BY_QUERY))
171 return false;
172
173 return UICLVPortlet.DISPLAY_MODE_AUTOMATIC.equals(
174 Utils.getPortletPreference(UICLVPortlet.PREFERENCE_DISPLAY_MODE));
175 }
176
177 public boolean hasFolderPath() {
178 PortletPreferences portletPreferences = Utils.getAllPortletPreferences();
179 String itemPath = portletPreferences.getValue(UICLVPortlet.PREFERENCE_ITEM_PATH, null);
180
181 return (itemPath != null && itemPath.length() > 0) ? true : false;
182 }
183
184 public boolean isShowManageContent() {
185 return (Utils.isShowQuickEdit() && isModeByFolder() && hasFolderPath());
186 }
187
188 public boolean isShowAddContent() {
189 if (isShowManageContent()) {
190 PortletPreferences portletPreferences = ((PortletRequestContext) WebuiRequestContext.
191 getCurrentInstance()).getRequest().getPreferences();
192 String itemPath = portletPreferences.getValue(UICLVPortlet.PREFERENCE_ITEM_PATH, null);
193 try {
194 Node content = NodeLocation.getNodeByExpression(itemPath);
195 ((ExtendedNode) content).checkPermission(PermissionType.ADD_NODE);
196 } catch (Exception e) {
197 return false;
198 }
199 return true;
200 } else return false;
201 }
202
203 public boolean isShowPreferences() {
204 try {
205 return Utils.isShowQuickEdit() && Utils.hasEditPermissionOnPage();
206 } catch (Exception e) {
207 return false;
208 }
209 }
210
211 public static class CLVNodeCreator implements SearchDataCreator<NodeLocation> {
212
213 @Override
214 public NodeLocation createData(Node node, Row row, SearchResult searchResult) {
215 return NodeLocation.getNodeLocationByNode(node);
216 }
217 }
218
219 }