KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > data > beans > SiteBean


1 package org.jahia.data.beans;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.Iterator JavaDoc;
5 import java.util.List JavaDoc;
6 import java.util.SortedSet JavaDoc;
7 import java.util.Vector JavaDoc;
8
9 import org.jahia.data.containers.JahiaContainerList;
10 import org.jahia.data.fields.LoadFlags;
11 import org.jahia.exceptions.JahiaException;
12 import org.jahia.params.ParamBean;
13 import org.jahia.registries.ServicesRegistry;
14 import org.jahia.services.acl.JahiaBaseACL;
15 import org.jahia.services.containers.ContainerFactory;
16 import org.jahia.services.pages.ContentPage;
17 import org.jahia.services.pages.JahiaPage;
18 import org.jahia.services.sites.JahiaSite;
19
20 /**
21  * <p>Title: Site JavaBean compliant JahiaSite facade</p>
22  * <p>Description: </p>
23  * <p>Copyright: Copyright (c) 2002</p>
24  * <p>Company: Jahia Ltd</p>
25  * @author Serge Huber
26  * @version 1.0
27  */

28
29 public class SiteBean {
30
31     private static org.apache.log4j.Logger logger =
32             org.apache.log4j.Logger.getLogger(SiteBean.class);
33
34     private JahiaSite jahiaSite;
35     private ParamBean paramBean;
36
37     public SiteBean() {
38     }
39
40     public SiteBean(JahiaSite jahiaSite, ParamBean paramBean) {
41         this.jahiaSite = jahiaSite;
42         this.paramBean = paramBean;
43     }
44
45     public JahiaSite getJahiaSite() {
46         return jahiaSite;
47     }
48
49     public PageBean getPage(int pageID) {
50         try {
51             ContentPage contentPage = ContentPage.getPage(pageID);
52             JahiaPage jahiaPage = contentPage.getPage(paramBean.getEntryLoadRequest(), paramBean.getOperationMode(), paramBean.getUser());
53             PageBean pageBean = new PageBean(jahiaPage, paramBean);
54             return pageBean;
55         } catch (JahiaException je) {
56             logger.error("Error while retrieving page " + pageID + " for site + " + getId() + " : ", je);
57             return null;
58         }
59     }
60
61     public PageBean getPageByStringID(String JavaDoc pageIDStr) {
62         return getPage(Integer.parseInt(pageIDStr));
63     }
64
65     /**
66      * Optimized method to retrieve all the container lists by a name in a
67      * Jahia site.
68      * WARNING : This method does *NOT* give access to sub container lists
69      * if they exist. Use the getAllContainerLists method if you need access
70      * to sub container lists.
71      * @param name String
72      * @return List
73      * @todo FIXME complete object model loading to include sub container list
74      * access
75      */

76     public List JavaDoc getLightContainerLists(String JavaDoc name) {
77         List JavaDoc containerLists = new ArrayList JavaDoc();
78         try {
79             SortedSet JavaDoc containerListIDs = ServicesRegistry.getInstance().
80                                          getJahiaContainersService().
81                                          getSiteTopLevelContainerListsIDsByName(
82                 getId(), name, paramBean.getEntryLoadRequest());
83             ContainerFactory containerFactory = ContainerFactory.getInstance();
84             Iterator JavaDoc containerListIDIter = containerListIDs.iterator();
85             while (containerListIDIter.hasNext()) {
86                 Integer JavaDoc curContainerListID = (Integer JavaDoc) containerListIDIter.next();
87                 JahiaContainerList curContainerList = ServicesRegistry
88                                         .getInstance()
89                                         .getJahiaContainersService()
90                                         .loadContainerList (
91                                         curContainerListID.intValue(),
92                                                     LoadFlags.ALL,
93                                                     paramBean,
94                                                     paramBean.getEntryLoadRequest(),
95                                                     null,
96                                                     null, null);
97
98                 ContainerListBean containerListBean = new ContainerListBean(curContainerList, paramBean);
99                 containerLists.add(containerListBean);
100             }
101             return containerLists;
102         } catch (JahiaException je) {
103             logger.error("Error while retrieving site top level container lists with name " + name + ":", je);
104             return null;
105         }
106     }
107
108     public List JavaDoc getAllContainerLists(String JavaDoc name) {
109         List JavaDoc containerLists = new ArrayList JavaDoc();
110         try {
111             SortedSet JavaDoc containerListIDs = ServicesRegistry.getInstance().
112                                          getJahiaContainersService().
113                                          getSiteTopLevelContainerListsIDsByName(
114                 getId(), name, paramBean.getEntryLoadRequest());
115             Iterator JavaDoc containerListIDIter = containerListIDs.iterator();
116             while (containerListIDIter.hasNext()) {
117                 Integer JavaDoc curContainerListID = (Integer JavaDoc) containerListIDIter.next();
118                 JahiaContainerList curContainerList = ServicesRegistry.getInstance().getJahiaContainersService()
119                         .loadContainerList(curContainerListID.intValue(), LoadFlags.ALL, paramBean,
120                                 paramBean.getEntryLoadRequest(), null, null, null);
121                 ContainerListBean containerListBean = new ContainerListBean(curContainerList, paramBean);
122                 containerLists.add(containerListBean);
123             }
124             return containerLists;
125         } catch (JahiaException je) {
126             logger.error("Error while retrieving site top level container lists with name " + name + ":", je);
127             return null;
128         }
129     }
130
131     public int getId() {
132         return jahiaSite.getID();
133     }
134
135     public JahiaBaseACL getACL() {
136         return jahiaSite.getACL();
137     }
138
139     public int getAclID() {
140         return jahiaSite.getAclID();
141     }
142
143     public int getDefaultTemplateID() {
144         return jahiaSite.getDefaultTemplateID();
145     }
146
147     public String JavaDoc getDescription() {
148         return jahiaSite.getDescr();
149     }
150
151     public int getGroupDefaultHomepageDef() {
152         return jahiaSite.getGroupDefaultHomepageDef();
153     }
154
155     public int getGroupDefaultHomepageDefActiveState() {
156         return jahiaSite.getGroupDefaultHomepageDefActiveState();
157     }
158
159     public int getGroupDefaultHomepageDefAtCreationOnly() {
160         return jahiaSite.getGroupDefaultHomepageDefAtCreationOnly();
161     }
162
163     public ContentPage getHomeContentPage() {
164         return jahiaSite.getHomeContentPage();
165     }
166
167     public PageBean getHomePage() {
168         try {
169             JahiaPage homeJahiaPage = getHomeContentPage().getPage(paramBean.
170                 getEntryLoadRequest(), paramBean.getOperationMode(),
171                 paramBean.getUser());
172             if (homeJahiaPage != null) {
173                 return new PageBean(homeJahiaPage, paramBean);
174             } else {
175                 return null;
176             }
177         } catch (JahiaException je) {
178             logger.error("Error while retrieving site home page :", je);
179             return null;
180         }
181     }
182
183     public int getHomepageID() {
184         return jahiaSite.getHomePageID();
185     }
186
187     public Vector JavaDoc getLanguageMappings() {
188         try {
189             return jahiaSite.getLanguageMappings();
190         } catch (JahiaException je) {
191             logger.error("Error while retrieving language mappings for site " + getId() + ":", je);
192             return null;
193         }
194     }
195
196     public Vector JavaDoc getLanguageSettings() {
197         try {
198             return jahiaSite.getLanguageSettings();
199         } catch (JahiaException je) {
200             logger.error("Error while retrieving language settings for site " + getId() + ":", je);
201             return null;
202         }
203     }
204
205     public String JavaDoc getServerName() {
206         return jahiaSite.getServerName();
207     }
208
209     public String JavaDoc getSiteKey() {
210         return jahiaSite.getSiteKey();
211     }
212
213     public String JavaDoc getTemplateFolder() {
214         return jahiaSite.getTemplateFolder();
215     }
216
217     public boolean isTemplatesAutoDeployMode() {
218         return jahiaSite.getTemplatesAutoDeployMode();
219     }
220
221     public String JavaDoc getTitle() {
222         return jahiaSite.getTitle();
223     }
224
225     public int getUserDefaultHomepageDef() {
226         return jahiaSite.getUserDefaultHomepageDef();
227     }
228
229     public int getUserDefaultHomepageDefActiveState() {
230         return jahiaSite.getUserDefaultHomepageDefActiveState();
231     }
232
233     public int getUserDefaultHomepageDefAtCreationOnly() {
234         return jahiaSite.getUserDefaultHomepageDefAtCreationOnly();
235     }
236
237     public boolean isWebAppsAutoDeployMode() {
238         return jahiaSite.getWebAppsAutoDeployMode();
239     }
240
241     public boolean isActive() {
242         return jahiaSite.isActive();
243     }
244
245     public boolean isMixLanguagesActive() {
246         return jahiaSite.isMixLanguagesActive();
247     }
248
249     public boolean isStagingEnabled() {
250         return jahiaSite.isStagingEnabled();
251     }
252
253     public boolean isVersioningEnabled() {
254         return jahiaSite.isVersioningEnabled();
255     }
256 }
257
Popular Tags