KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > portal > impl > PortletPreferencesPersisterImpl


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.services.portal.impl;
6
7 import java.io.Serializable JavaDoc;
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 /**
22  * Jul 16, 2004
23  * @author: Tuan Nguyen
24  * @email: tuan08@users.sourceforge.net
25  * @version: $Id: PortletPreferencesPersisterImpl.java,v 1.4 2004/08/11 02:22:16 tuan08 Exp $
26  */

27 public class PortletPreferencesPersisterImpl implements PortletPreferencesPersister, Serializable JavaDoc{
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 JavaDoc {
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 JavaDoc 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 JavaDoc {
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 JavaDoc 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 JavaDoc("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