KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > pluto > portlet > admin > services > PortletRegistryService


1 /*
2  * Copyright 2003,2004,2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.pluto.portlet.admin.services;
17
18
19 import java.util.ArrayList JavaDoc;
20 import java.util.Collection JavaDoc;
21 import java.util.Collections JavaDoc;
22 import java.util.HashMap JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.List JavaDoc;
25 import java.util.Map JavaDoc;
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 JavaDoc CLASS_NAME = "PortletRegistryService";
49
50
51     /**
52      * Default constructor
53      */

54     public PortletRegistryService() {
55         super(CLASS_NAME);
56     }
57
58     public List JavaDoc getPageRegistryData(String JavaDoc prPath) {
59         List JavaDoc alist = null;
60         return alist;
61     }
62
63     /*
64     public void savePortlet(String perPath, ApplicationTypeImpl app){
65         final String METHOD_NAME = "savePortlet(perPath,app)";
66         logMethodStart(METHOD_NAME);
67         logParam(METHOD_NAME, "perPath", perPath);
68         logParam(METHOD_NAME, "app", app);
69         PortletEntityRegistryXao xao = new PortletEntityRegistryXao();
70         xao.saveApplications(perPath,app);
71         logMethodEnd(METHOD_NAME);
72     }
73         */

74
75     public List JavaDoc getPortletEntityRegistry(String JavaDoc perPath) {
76         final String JavaDoc METHOD_NAME = "getPortletEntityRegistry(perPath)";
77         logMethodStart(METHOD_NAME);
78         logParam(METHOD_NAME, "perPath", perPath);
79         List JavaDoc alist = null;
80         /*
81         PortletEntityRegistryXao xao = new PortletEntityRegistryXao();
82         alist = xao.getApplications(perPath);
83         Iterator iter = alist.iterator();
84         while (iter.hasNext()) {
85             ApplicationTypeImpl app = (ApplicationTypeImpl) iter.next();
86             logVar(METHOD_NAME, "appId", app.getId());
87         }
88         logMethodEnd(METHOD_NAME, alist);
89         */

90         return alist;
91     }
92
93     /*
94     public ApplicationTypeImpl getPortletEntityRegistryApp(String perPath, String appId) {
95         final String METHOD_NAME = "getPortletEntityRegistryApp(perPath, appId)";
96         logMethodStart(METHOD_NAME);
97         logParam(METHOD_NAME, "perPath", perPath);
98         logParam(METHOD_NAME, "appId", appId);
99         ApplicationTypeImpl app = null;
100         PortletEntityRegistryXao xao = new PortletEntityRegistryXao();
101         app = xao.getApplication(perPath, appId);
102         if (app != null) {
103             logDebug(METHOD_NAME, "looked up appId=" + app.getId());
104         }
105         logMethodEnd(METHOD_NAME, app);
106         return app;
107     }
108         */

109
110         public List JavaDoc getPortletPreferences(String JavaDoc perPath, String JavaDoc appId, String JavaDoc portletId ) {
111             final String JavaDoc METHOD_NAME = "getPortletPreferences(perPath,appId,portletId)";
112             logMethodStart(METHOD_NAME);
113             List JavaDoc list = null;
114             /*
115             PortletEntityRegistryXao xao = new PortletEntityRegistryXao();
116             list = xao.getPortletPreferencesList(perPath, appId, portletId);
117             logMethodEnd(METHOD_NAME, list);
118 */

119             return list;
120         }
121
122         public List JavaDoc addPortletPreference(String JavaDoc perPath, String JavaDoc appId, String JavaDoc portletId ) {
123             final String JavaDoc METHOD_NAME = "addPortletPreferences(perPath,appId,portletId)";
124             logMethodStart(METHOD_NAME);
125             List JavaDoc list = null;
126             /*
127             list = getPortletPreferences(perPath, appId, portletId);
128             //create a new empty preference and add it
129             PreferencesTypeImpl pref = new PreferencesTypeImpl();
130             pref.setPrefName("");
131             pref.setPrefValue("");
132             pref.setReadOnly(false);
133             list.add(pref);
134             logMethodEnd(METHOD_NAME, list);
135             */

136             return list;
137         }
138
139 /*
140         public PortletTypeImpl getNewPortlet(String perPath, String appId) {
141             final String METHOD_NAME = "getNewPortlet(perPath,appId,portletId)";
142             logMethodStart(METHOD_NAME);
143             PortletTypeImpl portlet = null;
144             PortletEntityRegistryXao xao = new PortletEntityRegistryXao();
145             ApplicationTypeImpl app = xao.getApplication(perPath, appId);
146             portlet.setDefinitionId("");
147             portlet.setId("");
148             logMethodEnd(METHOD_NAME, portlet);
149             return portlet;
150         }
151 */

152
153         public static String JavaDoc getNextAppId() {
154             final String JavaDoc METHOD_NAME = "getNextAppId()";
155             PlutoAdminLogger.logMethodStart(CLASS_NAME, METHOD_NAME);
156             String JavaDoc appId = null;
157             Collection JavaDoc 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 JavaDoc e) {
163                 PlutoAdminLogger.logError(CLASS_NAME, METHOD_NAME, e);
164                 throw new PlutoAdminException(e);
165             }
166             ArrayList JavaDoc list = new ArrayList JavaDoc(apps);
167             Iterator JavaDoc iter = list.iterator();
168             int nNewId = 0;
169             while (iter.hasNext()) {
170                 PortletApplicationEntityImpl app = (PortletApplicationEntityImpl) iter.next();
171                 String JavaDoc 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 JavaDoc METHOD_NAME = "getPortletEntityRegistry(request)";
186             logMethodStart(METHOD_NAME);
187             Collection JavaDoc 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 JavaDoc e) {
195                 logError(METHOD_NAME, e);
196                 throw new PlutoAdminException(e);
197             }
198             //sort the collection
199
ArrayList JavaDoc slist = new ArrayList JavaDoc(alist);
200             Collections.sort(slist, new PortletApplicationEntityImplComparator());
201             Iterator JavaDoc 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 JavaDoc METHOD_NAME = "getPortletEntityRegistryApp(request)";
208             logMethodStart(METHOD_NAME);
209             String JavaDoc 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 JavaDoc 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 JavaDoc METHOD_NAME = "getPortletPreferences(request)";
227             logMethodStart(METHOD_NAME);
228             String JavaDoc appId = request.getParameter("appId");
229             logDebug(METHOD_NAME, "AppId selected: " + appId);
230             String JavaDoc portletId = request.getParameter("portletId");
231             logDebug(METHOD_NAME, "PortletId selected: " + portletId);
232             List JavaDoc prefs = null;
233             try {
234                 org.apache.pluto.portlet.admin.model.PortletEntityRegistryXao xao =
235                     new org.apache.pluto.portlet.admin.model.PortletEntityRegistryXao();
236                 Collection JavaDoc coll = xao.getPortletPreferences(appId, portletId);
237                 prefs = new ArrayList JavaDoc(coll);
238             } catch (Exception JavaDoc e) {
239                 logError(METHOD_NAME, e);
240                 throw new PlutoAdminException(e);
241             }
242             PortletSession session = request.getPortletSession();
243             Map JavaDoc map = (Map JavaDoc)session.getAttribute(PlutoAdminConstants.PREF_LIST_ATTR);
244             if (map == null) {
245                 map = new HashMap JavaDoc();
246             }
247             map.put(portletId, prefs);
248             session.setAttribute(PlutoAdminConstants.PREF_LIST_ATTR, map, PortletSession.APPLICATION_SCOPE);
249             logMethodEnd(METHOD_NAME);
250         }
251 }
252
Popular Tags