1 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 46 public class PortletRegistryService extends BaseAdminObject { 47 48 private static final String CLASS_NAME = "PortletRegistryService"; 49 50 51 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 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 90 return alist; 91 } 92 93 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 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 136 return list; 137 } 138 139 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 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 } 252 | Popular Tags |