1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.pluto.portlet.admin.services;
17
18
19 import java.util.ArrayList;
20 import java.util.Collection;
21 import java.util.Collections;
22 import java.util.HashMap;
23 import java.util.Iterator;
24 import java.util.List;
25 import java.util.Map;
26
27 import javax.portlet.ActionRequest;
28 import javax.portlet.PortletSession;
29 import javax.portlet.RenderRequest;
30
31 import org.apache.pluto.portalImpl.om.entity.impl.PortletApplicationEntityImpl;
32 import org.apache.pluto.portalImpl.om.entity.impl.PortletApplicationEntityListImpl;
33 import org.apache.pluto.portlet.admin.BaseAdminObject;
34 import org.apache.pluto.portlet.admin.PlutoAdminConstants;
35 import org.apache.pluto.portlet.admin.PlutoAdminException;
36 import org.apache.pluto.portlet.admin.PlutoAdminLogger;
37 import org.apache.pluto.portlet.admin.util.PortletApplicationEntityImplComparator;
38
39 /***
40 * Service concerned with portletentityregistry.xml persistence
41 *
42 * @author Craig Doremus
43 * @see org.apache.pluto.portlet.admin.controller.PortletEntityRegistryPortlet
44 *
45 */
46 public class PortletRegistryService extends BaseAdminObject {
47
48 private static final String CLASS_NAME = "PortletRegistryService";
49
50
51 /***
52 * Default constructor
53 */
54 public PortletRegistryService() {
55 super(CLASS_NAME);
56 }
57
58 public List getPageRegistryData(String prPath) {
59 return null;
60 }
61
62
63
64
65
66
67
68
69
70
71
72
73
74 public List getPortletEntityRegistry(String perPath) {
75 final String METHOD_NAME = "getPortletEntityRegistry(perPath)";
76 logMethodStart(METHOD_NAME);
77 logParam(METHOD_NAME, "perPath", perPath);
78 List alist = null;
79
80
81
82
83
84
85
86
87
88
89 return alist;
90 }
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109 public List getPortletPreferences(String perPath, String appId, String portletId ) {
110 final String METHOD_NAME = "getPortletPreferences(perPath,appId,portletId)";
111 logMethodStart(METHOD_NAME);
112 List list = null;
113
114
115
116
117
118 return list;
119 }
120
121 public List addPortletPreference(String perPath, String appId, String portletId ) {
122 final String METHOD_NAME = "addPortletPreferences(perPath,appId,portletId)";
123 logMethodStart(METHOD_NAME);
124 List list = null;
125
126
127
128
129
130
131
132
133
134
135 return list;
136 }
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152 public static String getNextAppId() {
153 final String METHOD_NAME = "getNextAppId()";
154 PlutoAdminLogger.logMethodStart(CLASS_NAME, METHOD_NAME);
155 String appId = null;
156 Collection apps;
157 try {
158 org.apache.pluto.portlet.admin.model.PortletEntityRegistryXao xao =
159 new org.apache.pluto.portlet.admin.model.PortletEntityRegistryXao();
160 apps = xao.getApplications();
161 } catch (Exception e) {
162 PlutoAdminLogger.logError(CLASS_NAME, METHOD_NAME, e);
163 throw new PlutoAdminException(e);
164 }
165 ArrayList list = new ArrayList(apps);
166 Iterator iter = list.iterator();
167 int nNewId = 0;
168 while (iter.hasNext()) {
169 PortletApplicationEntityImpl app = (PortletApplicationEntityImpl) iter.next();
170 String currAppId = app.getCastorId();
171 int nCurrAppId = Integer.parseInt(currAppId);
172 if (nNewId <= nCurrAppId) {
173 nNewId = nCurrAppId;
174 }
175 }
176 nNewId++;
177 appId = Integer.toString(nNewId);
178 PlutoAdminLogger.logMethodEnd(CLASS_NAME, METHOD_NAME, appId);
179 return appId;
180
181 }
182
183 public void getPortletEntityRegistry(RenderRequest request) {
184 final String METHOD_NAME = "getPortletEntityRegistry(request)";
185 logMethodStart(METHOD_NAME);
186 Collection alist = null;
187 try {
188 org.apache.pluto.portlet.admin.model.PortletEntityRegistryXao xao =
189 new org.apache.pluto.portlet.admin.model.PortletEntityRegistryXao();
190 PortletApplicationEntityListImpl registry = xao.load();
191 alist = registry.getCastorApplications();
192 logDebug(METHOD_NAME, "App list: " + alist);
193 } catch (Exception e) {
194 logError(METHOD_NAME, e);
195 throw new PlutoAdminException(e);
196 }
197
198 ArrayList slist = new ArrayList(alist);
199 Collections.sort(slist, new PortletApplicationEntityImplComparator());
200 Iterator iter = slist.iterator();
201 request.setAttribute(PlutoAdminConstants.PER_LIST_ATTR, iter);
202 logMethodEnd(METHOD_NAME, alist);
203 }
204
205 public void getPortletEntityRegistryApp(ActionRequest request) {
206 final String METHOD_NAME = "getPortletEntityRegistryApp(request)";
207 logMethodStart(METHOD_NAME);
208 String appId = request.getParameter("appid");
209 logDebug(METHOD_NAME, "AppId selected: " + appId);
210 PortletSession session = request.getPortletSession();
211 PortletApplicationEntityImpl app;
212 try {
213 org.apache.pluto.portlet.admin.model.PortletEntityRegistryXao xao =
214 new org.apache.pluto.portlet.admin.model.PortletEntityRegistryXao();
215 app = xao.getApplication(appId);
216 } catch (Exception e) {
217 logError(METHOD_NAME, e);
218 throw new PlutoAdminException(e);
219 }
220 session.setAttribute(PlutoAdminConstants.APP_ATTR, app, PortletSession.APPLICATION_SCOPE);
221 logMethodEnd(METHOD_NAME);
222 }
223
224 public void getPortletPreferences(ActionRequest request) {
225 String METHOD_NAME = "getPortletPreferences(request)";
226 logMethodStart(METHOD_NAME);
227 String appId = request.getParameter("appId");
228 logDebug(METHOD_NAME, "AppId selected: " + appId);
229 String portletId = request.getParameter("portletId");
230 logDebug(METHOD_NAME, "PortletId selected: " + portletId);
231 List prefs = null;
232 try {
233 org.apache.pluto.portlet.admin.model.PortletEntityRegistryXao xao =
234 new org.apache.pluto.portlet.admin.model.PortletEntityRegistryXao();
235 Collection coll = xao.getPortletPreferences(appId, portletId);
236 prefs = new ArrayList(coll);
237 } catch (Exception e) {
238 logError(METHOD_NAME, e);
239 throw new PlutoAdminException(e);
240 }
241 PortletSession session = request.getPortletSession();
242 Map map = (Map)session.getAttribute(PlutoAdminConstants.PREF_LIST_ATTR);
243 if (map == null) {
244 map = new HashMap();
245 }
246 map.put(portletId, prefs);
247 session.setAttribute(PlutoAdminConstants.PREF_LIST_ATTR, map, PortletSession.APPLICATION_SCOPE);
248 logMethodEnd(METHOD_NAME);
249 }
250 }