1 5 package org.exoplatform.services.portal.impl; 6 7 import java.io.Serializable ; 8 9 import org.apache.commons.logging.Log; 10 import org.exoplatform.container.PortalContainer; 11 import org.exoplatform.services.log.LogService; 12 import org.exoplatform.services.portal.model.Container; 13 import org.exoplatform.services.portal.model.Page; 14 import org.exoplatform.services.portal.model.PortalConfig; 15 import org.exoplatform.services.portal.model.Portlet; 16 import org.exoplatform.services.portletcontainer.pci.ExoWindowID; 17 import org.exoplatform.services.portletcontainer.pci.WindowID; 18 import org.exoplatform.services.portletcontainer.pci.model.ExoPortletPreferences; 19 import org.exoplatform.services.portletcontainer.persistence.PortletPreferencesPersister; 20 21 27 public class PortletPreferencesPersisterImpl implements PortletPreferencesPersister, Serializable { 28 private transient PortalConfigServiceImpl service_ ; 29 private transient Log log_; 30 31 public PortletPreferencesPersisterImpl(PortalConfigServiceImpl impl, 32 LogService lservice) { 33 service_ = impl ; 34 log_ = lservice.getLog(getClass()); 35 } 36 37 public ExoPortletPreferences getPortletPreferences(WindowID windowID) throws Exception { 38 if(service_ == null){ 39 service_ = (PortalConfigServiceImpl) PortalContainer.getInstance().getComponentInstanceOfType( 40 PortalConfigServiceImpl.class); 41 LogService lservice = (LogService) PortalContainer.getInstance().getComponentInstanceOfType( 42 LogService.class); 43 log_ = lservice.getLog(getClass()); 44 } 45 46 ExoWindowID exoWindowID = (ExoWindowID) windowID ; 47 String configurationSource = exoWindowID.getConfigurationSource() ; 48 Container layout = null ; 49 if(ExoWindowID.DEFAULT_PORTAL_CONFIG.equals(configurationSource)) { 50 PortalConfig config = service_.getPortalConfig(windowID.getOwner()) ; 51 layout = config.getLayout() ; 52 } else if(ExoWindowID.MOBILE_PORTAL_CONFIG.equals(configurationSource)) { 53 PortalConfig config = service_.getPortalConfig(windowID.getOwner()) ; 54 layout = config.getMobilePortalLayout() ; 55 } else { 56 layout = service_.getPage(configurationSource) ; 57 } 58 Portlet portlet = layout.findPortletByWindowId(exoWindowID.getPersistenceId()) ; 59 if(portlet != null) { 60 return portlet.getPortletPreferences() ; 61 } 62 return null ; 63 } 64 65 public void savePortletPreferences(WindowID windowID, 66 ExoPortletPreferences exoPref) throws Exception { 67 if(service_ == null){ 68 service_ = (PortalConfigServiceImpl) PortalContainer.getInstance().getComponentInstanceOfType( 69 PortalConfigServiceImpl.class); 70 LogService lservice = (LogService) PortalContainer.getInstance().getComponentInstanceOfType( 71 LogService.class); 72 log_ = lservice.getLog(getClass()); 73 } 74 ExoWindowID exoWindowID = (ExoWindowID) windowID ; 75 String configurationSource = exoWindowID.getConfigurationSource() ; 76 Container layout = null ; 77 PortalConfig config = null ; 78 if(ExoWindowID.DEFAULT_PORTAL_CONFIG.equals(configurationSource)) { 79 config = service_.getPortalConfig(windowID.getOwner()) ; 80 layout = config.getLayout() ; 81 } else if(ExoWindowID.MOBILE_PORTAL_CONFIG.equals(configurationSource)) { 82 config = service_.getPortalConfig(windowID.getOwner()) ; 83 layout = config.getMobilePortalLayout() ; 84 } else { 85 layout = service_.getPage(configurationSource) ; 86 } 87 Portlet portlet = layout.findPortletByWindowId(exoWindowID.getPersistenceId()) ; 88 if(portlet == null) { 89 log_.error("cannot find the portlet, portlet persitence id: " + exoWindowID.getPersistenceId()) ; 90 throw new Exception ("Cannot find the portlet in " + configurationSource) ; 91 } 92 portlet.setPortletPreferences(exoPref) ; 93 if(config != null) service_.savePortalConfig(config) ; 94 else service_.savePage((Page)layout) ; 95 } 96 } | Popular Tags |