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 List alist = null;
60 return alist;
61 }
62
63
64
65
66
67
68
69
70
71
72
73
74
75 public List getPortletEntityRegistry(String perPath) {
76 final String METHOD_NAME = "getPortletEntityRegistry(perPath)";
77 logMethodStart(METHOD_NAME);
78 logParam(METHOD_NAME, "perPath", perPath);
79 List alist = null;
80
81
82
83
84
85
86
87
88
89
90 return alist;
91 }
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110 public List getPortletPreferences(String perPath, String appId, String portletId ) {
111 final String METHOD_NAME = "getPortletPreferences(perPath,appId,portletId)";
112 logMethodStart(METHOD_NAME);
113 List list = null;
114
115
116
117
118
119 return list;
120 }
121
122 public List addPortletPreference(String perPath, String appId, String portletId ) {
123 final String METHOD_NAME = "addPortletPreferences(perPath,appId,portletId)";
124 logMethodStart(METHOD_NAME);
125 List list = null;
126
127
128
129
130
131
132
133
134
135
136 return list;
137 }
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153 public static String getNextAppId() {
154 final String METHOD_NAME = "getNextAppId()";
155 PlutoAdminLogger.logMethodStart(CLASS_NAME, METHOD_NAME);
156 String appId = null;
157 Collection apps;
158 try {
159 org.apache.pluto.portlet.admin.model.PortletEntityRegistryXao xao =
160 new org.apache.pluto.portlet.admin.model.PortletEntityRegistryXao();
161 apps = xao.getApplications();
162 } catch (Exception e) {
163 PlutoAdminLogger.logError(CLASS_NAME, METHOD_NAME, e);
164 throw new PlutoAdminException(e);
165 }
166 ArrayList list = new ArrayList(apps);
167 Iterator iter = list.iterator();
168 int nNewId = 0;
169 while (iter.hasNext()) {
170 PortletApplicationEntityImpl app = (PortletApplicationEntityImpl) iter.next();
171 String currAppId = app.getCastorId();
172 int nCurrAppId = Integer.parseInt(currAppId);
173 if (nNewId <= nCurrAppId) {
174 nNewId = nCurrAppId;
175 }
176 }
177 nNewId++;
178 appId = Integer.toString(nNewId);
179 PlutoAdminLogger.logMethodEnd(CLASS_NAME, METHOD_NAME, appId);
180 return appId;
181
182 }
183
184 public void getPortletEntityRegistry(RenderRequest request) {
185 final String METHOD_NAME = "getPortletEntityRegistry(request)";
186 logMethodStart(METHOD_NAME);
187 Collection alist = null;
188 try {
189 org.apache.pluto.portlet.admin.model.PortletEntityRegistryXao xao =
190 new org.apache.pluto.portlet.admin.model.PortletEntityRegistryXao();
191 PortletApplicationEntityListImpl registry = xao.load();
192 alist = registry.getCastorApplications();
193 logDebug(METHOD_NAME, "App list: " + alist);
194 } catch (Exception e) {
195 logError(METHOD_NAME, e);
196 throw new PlutoAdminException(e);
197 }
198
199 ArrayList slist = new ArrayList(alist);
200 Collections.sort(slist, new PortletApplicationEntityImplComparator());
201 Iterator iter = slist.iterator();
202 request.setAttribute(PlutoAdminConstants.PER_LIST_ATTR, iter);
203 logMethodEnd(METHOD_NAME, alist);
204 }
205
206 public void getPortletEntityRegistryApp(ActionRequest request) {
207 final String METHOD_NAME = "getPortletEntityRegistryApp(request)";
208 logMethodStart(METHOD_NAME);
209 String appId = request.getParameter("appid");
210 logDebug(METHOD_NAME, "AppId selected: " + appId);
211 PortletSession session = request.getPortletSession();
212 PortletApplicationEntityImpl app;
213 try {
214 org.apache.pluto.portlet.admin.model.PortletEntityRegistryXao xao =
215 new org.apache.pluto.portlet.admin.model.PortletEntityRegistryXao();
216 app = xao.getApplication(appId);
217 } catch (Exception e) {
218 logError(METHOD_NAME, e);
219 throw new PlutoAdminException(e);
220 }
221 session.setAttribute(PlutoAdminConstants.APP_ATTR, app, PortletSession.APPLICATION_SCOPE);
222 logMethodEnd(METHOD_NAME);
223 }
224
225 public void getPortletPreferences(ActionRequest request) {
226 String METHOD_NAME = "getPortletPreferences(request)";
227 logMethodStart(METHOD_NAME);
228 String appId = request.getParameter("appId");
229 logDebug(METHOD_NAME, "AppId selected: " + appId);
230 String portletId = request.getParameter("portletId");
231 logDebug(METHOD_NAME, "PortletId selected: " + portletId);
232 List prefs = null;
233 try {
234 org.apache.pluto.portlet.admin.model.PortletEntityRegistryXao xao =
235 new org.apache.pluto.portlet.admin.model.PortletEntityRegistryXao();
236 Collection coll = xao.getPortletPreferences(appId, portletId);
237 prefs = new ArrayList(coll);
238 } catch (Exception e) {
239 logError(METHOD_NAME, e);
240 throw new PlutoAdminException(e);
241 }
242 PortletSession session = request.getPortletSession();
243 Map map = (Map)session.getAttribute(PlutoAdminConstants.PREF_LIST_ATTR);
244 if (map == null) {
245 map = new HashMap();
246 }
247 map.put(portletId, prefs);
248 session.setAttribute(PlutoAdminConstants.PREF_LIST_ATTR, map, PortletSession.APPLICATION_SCOPE);
249 logMethodEnd(METHOD_NAME);
250 }
251 }