KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > layout > PortletSetPersistanceManager


1 package org.jahia.layout;
2
3 /**
4  * Title: PortletSet persistance manager, store and retrieve PortletSet
5  * objects to/from persistant storage
6  * Description: This object uses the PortletsPersistanceStorage to do most of
7  * it's job.
8  * Copyright: Copyright (c) 2002
9  * Company: Jahia Ltd
10  * @author Serge Huber
11  * @version 1.0
12  */

13
14 import java.util.Enumeration JavaDoc;
15
16 import org.jahia.data.JahiaData;
17 import org.jahia.exceptions.JahiaException;
18 import org.jahia.params.ParamBean;
19 import org.jahia.utils.JahiaConsole;
20
21 public class PortletSetPersistanceManager {
22
23     private boolean personalizationActivated;
24     private static PortletSetPersistanceManager sharingManager = null;
25     private static PortletSetPersistanceManager personalizedManager = null;
26
27     private PortletSetPersistanceManager(boolean personalizationActivated) {
28         this.personalizationActivated = personalizationActivated;
29     }
30
31     public static synchronized PortletSetPersistanceManager getInstance(boolean personalizationActivated) {
32         if (personalizationActivated) {
33             if (personalizedManager == null) {
34                 personalizedManager =
35                     new PortletSetPersistanceManager(personalizationActivated);
36             }
37             return personalizedManager;
38         } else {
39             if (sharingManager == null) {
40                 sharingManager = new PortletSetPersistanceManager(personalizationActivated);
41             }
42             return sharingManager;
43         }
44     }
45
46     public PortletBeanSet getPortletSet(ParamBean jParams,
47                                         JahiaData jData,
48                                         String JavaDoc portletGroupName) {
49         JahiaConsole.println("PortletSetPersistanceManager.getPortletSet",
50                              "Retrieving portlet set for portletGroup=[" + portletGroupName + "]");
51         int pageID = jParams.getPageID();
52         PortletsPersistanceManager portletsManager =
53             PortletsPersistanceManager.getInstance(personalizationActivated);
54         Enumeration JavaDoc portletEnum = portletsManager.getPortlets(jParams,
55                                                               jData,
56                                                               jParams.getPageID(),
57                                                               portletGroupName,
58                                                               jParams.getUser().getUsername(),
59                                                               jParams.settings().getJahiaTemplatesDiskPath());
60         PortletBeanSet portletSet = new PortletBeanSet();
61         int count = 0;
62         while (portletEnum.hasMoreElements()) {
63             PortletBean portlet = (PortletBean) portletEnum.nextElement();
64             portletSet.add(portlet);
65             count++;
66         }
67         JahiaConsole.println("PortletSetPersistanceManager.getPortletSet",
68                              "Found " + Integer.toString(count) + " portlets...");
69         return portletSet;
70     }
71
72     public void setPortletSet(PortletBeanSet portletSet,
73                               String JavaDoc portletGroupName,
74                               ParamBean jParams,
75                               JahiaData jData) throws JahiaException {
76         Enumeration JavaDoc portletEnum = portletSet.elements();
77         PortletsPersistanceManager portletsManager =
78             PortletsPersistanceManager.getInstance(personalizationActivated);
79         while (portletEnum.hasMoreElements()) {
80             PortletBean portlet = (PortletBean) portletEnum.nextElement();
81             if (portlet.isModified()) {
82                 portletsManager.setPortlet(jParams,
83                                            jData,
84                                            portlet,
85                                            portletGroupName,
86                                            jParams.getPageID(),
87                                            jParams.getUser().getUsername(),
88                                            jParams.settings().getJahiaTemplatesDiskPath());
89             } else {
90                 /*
91                 JahiaConsole.println("PortletSetPersistanceManager.setPortletSet",
92                                      "No modifications in portlet " + portlet.getPortletID() + ", no need to save...");
93                 */

94             }
95         }
96     }
97
98     public void removePortletSet(PortletBeanSet portletSet,
99                                  String JavaDoc portletGroupName,
100                                  ParamBean jParams) {
101     }
102
103 }
Popular Tags