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 java.util.ArrayList;
20 import java.util.HashMap;
21
22 import javax.jcr.AccessDeniedException;
23 import javax.jcr.ItemNotFoundException;
24 import javax.jcr.Node;
25 import javax.jcr.query.Query;
26 import javax.portlet.PortletPreferences;
27
28 import org.exoplatform.portal.webui.application.UIPortlet;
29 import org.exoplatform.portal.webui.util.Util;
30 import org.exoplatform.resolver.ResourceResolver;
31 import org.exoplatform.services.wcm.core.NodeLocation;
32 import org.exoplatform.services.wcm.publication.NodeLocationPaginatedResultIterator;
33 import org.exoplatform.services.wcm.publication.PaginatedResultIterator;
34 import org.exoplatform.services.wcm.publication.Result;
35 import org.exoplatform.services.wcm.publication.WCMComposer;
36 import org.exoplatform.services.wcm.utils.WCMCoreUtils;
37 import org.exoplatform.wcm.webui.Utils;
38 import org.exoplatform.webui.application.WebuiRequestContext;
39 import org.exoplatform.webui.application.portlet.PortletRequestContext;
40 import org.exoplatform.webui.config.annotation.ComponentConfig;
41 import org.exoplatform.webui.config.annotation.EventConfig;
42 import org.exoplatform.webui.core.lifecycle.Lifecycle;
43
44
45
46
47
48
49
50
51
52 @ComponentConfig(
53 lifecycle = Lifecycle.class,
54 template = "system:/groovy/ContentListViewer/UICLVContainer.gtmpl",
55 events = {
56 @EventConfig(listeners = UICLVFolderMode.PreferencesActionListener.class)
57 }
58 )
59 public class UICLVFolderMode extends UICLVContainer {
60
61 private UICLVPresentation clvPresentation;
62
63
64
65
66 public void init() throws Exception {
67 PortletPreferences portletPreferences = Utils.getAllPortletPreferences();
68
69 Result result = null;
70 messageKey = null;
71 try {
72 result = getRenderedContentNodes();
73 } catch (ItemNotFoundException e) {
74 messageKey = "UICLVContainer.msg.item-not-found";
75 return;
76 } catch (AccessDeniedException e) {
77 messageKey = "UICLVContainer.msg.no-permission";
78 result = new Result(new ArrayList<Node>(), 0, 0, null, null);
79 }
80 if (result.getNumTotal() == 0) {
81 messageKey = "UICLVContainer.msg.non-contents";
82 }
83 int itemsPerPage = Integer.parseInt(portletPreferences.getValue(UICLVPortlet.PREFERENCE_ITEMS_PER_PAGE, null));
84 PaginatedResultIterator paginatedResultIterator = new NodeLocationPaginatedResultIterator(result, itemsPerPage);
85 getChildren().clear();
86 PortletRequestContext pContext = (PortletRequestContext) WebuiRequestContext.getCurrentInstance();
87 clvPresentation =
88 addChild(UICLVPresentation.class,
89 null,
90 UICLVPresentation.class.getSimpleName() + "_" + pContext.getWindowId()
91 );
92 ResourceResolver resourceResolver = getTemplateResourceResolver();
93 clvPresentation.init(resourceResolver, paginatedResultIterator);
94 }
95
96
97
98
99
100
101
102
103 public Result getRenderedContentNodes() throws Exception {
104 PortletRequestContext portletRequestContext = WebuiRequestContext.getCurrentInstance();
105 PortletPreferences preferences = portletRequestContext.getRequest().getPreferences();
106 WCMComposer wcmComposer = getApplicationComponent(WCMComposer.class);
107 HashMap<String, String> filters = new HashMap<String, String>();
108 filters.put(WCMComposer.FILTER_MODE, Utils.getCurrentMode());
109 String orderBy = preferences.getValue(UICLVPortlet.PREFERENCE_ORDER_BY, null);
110 String orderType = preferences.getValue(UICLVPortlet.PREFERENCE_ORDER_TYPE, null);
111 String itemsPerPage = preferences.getValue(UICLVPortlet.PREFERENCE_ITEMS_PER_PAGE, null);
112 String sharedCache = preferences.getValue(UICLVPortlet.PREFERENCE_SHARED_CACHE, "true");
113 String contextualMode = preferences.getValue(UICLVPortlet.PREFERENCE_CONTEXTUAL_FOLDER, "true");
114 String workspace = preferences.getValue(UICLVPortlet.PREFERENCE_WORKSPACE, null);
115 String query = preferences.getValue(UICLVPortlet.PREFERENCE_CONTENTS_BY_QUERY, null);
116 if (orderType == null) orderType = "DESC";
117 if (orderBy == null) orderBy = "exo:title";
118 filters.put(WCMComposer.FILTER_ORDER_BY, orderBy);
119 filters.put(WCMComposer.FILTER_ORDER_TYPE, orderType);
120 StringBuffer filterLang = new StringBuffer(Util.getPortalRequestContext().getLocale().getLanguage());
121 String country = Util.getPortalRequestContext().getLocale().getCountry();
122 if (country != null && country.length() > 0) {
123 filterLang.append("_").append(country);
124 }
125 filters.put(WCMComposer.FILTER_LANGUAGE, filterLang.toString());
126 filters.put(WCMComposer.FILTER_LIMIT, itemsPerPage);
127 filters.put(WCMComposer.FILTER_VISIBILITY, ("true".equals(sharedCache))?
128 WCMComposer.VISIBILITY_PUBLIC:WCMComposer.VISIBILITY_USER);
129
130
131 if (this.getAncestorOfType(UICLVPortlet.class).isQueryApplication()) {
132 String folderPath = preferences.getValue(UICLVPortlet.PREFERENCE_ITEM_PATH, null);
133 if (folderPath == null) {
134 return new Result(new ArrayList<Node>(), 0, 0, null, null);
135 }
136 folderPath = folderPath.replace("{siteName}", Util.getPortalRequestContext().getSiteName());
137 String strQuery = this.getAncestorOfType(UICLVPortlet.class).getQueryStatement(query);
138 if (strQuery != null) strQuery = strQuery.replaceAll("\"", "'");
139 if (UICLVPortlet.PREFERENCE_CONTEXTUAL_FOLDER_ENABLE.equals(contextualMode)
140 && org.exoplatform.wcm.webui.Utils.checkQuery(workspace, strQuery, Query.SQL)) {
141 String[] contentList = null;
142 if (preferences.getValue(UICLVPortlet.PREFERENCE_ITEM_PATH, null) != null) {
143 contentList = preferences.getValue(UICLVPortlet.PREFERENCE_ITEM_PATH, null).split(";");
144 }
145 if (contentList != null && contentList.length != 0) {
146 for (String itemPath : contentList) {
147 itemPath = itemPath.replace("{siteName}", Util.getPortalRequestContext().getSiteName());
148 Node currentNode = NodeLocation.getNodeByExpression(itemPath);
149 NodeLocation nodeLocation = new NodeLocation();
150 if (currentNode != null) {
151 String path = currentNode.getPath();
152 nodeLocation.setPath(path);
153 nodeLocation.setWorkspace(workspace);
154 nodeLocation.setSystemSession(false);
155 }
156 filters.put(WCMComposer.FILTER_QUERY_FULL, strQuery);
157 return wcmComposer.getPaginatedContents(nodeLocation,
158 filters,
159 WCMCoreUtils.getUserSessionProvider());
160 }
161 }
162 }
163 }
164 String folderPath = this.getAncestorOfType(UICLVPortlet.class).getFolderPath();
165 if (folderPath == null) {
166 folderPath = preferences.getValue(UICLVPortlet.PREFERENCE_ITEM_PATH, null);
167 }
168 if (folderPath != null) {
169 folderPath = folderPath.replace("{siteName}", Util.getPortalRequestContext().getSiteName());
170 }
171 if (folderPath == null) {
172 return new Result(new ArrayList<Node>(), 0, 0, null, null);
173 }
174 NodeLocation nodeLocation = NodeLocation.getNodeLocationByExpression(folderPath);
175 Node targetNode = NodeLocation.getNodeByLocation(nodeLocation);
176
177 if (targetNode == null || !targetNode.hasNodes()) {
178 return new Result(new ArrayList<Node>(), 0, 0, nodeLocation, filters);
179 } else {
180 return wcmComposer.getPaginatedContents(nodeLocation,
181 filters,
182 WCMCoreUtils.getUserSessionProvider());
183 }
184 }
185
186
187
188
189
190
191
192
193 public boolean isShowInfoBar() throws Exception {
194 if (UIPortlet.getCurrentUIPortlet().getShowInfoBar())
195 return true;
196 return false;
197 }
198
199
200
201
202
203 public String getPortletName() throws Exception {
204 return UICLVFolderMode.class.getSimpleName();
205 }
206 }