KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > data > viewhelper > sitemap > TreeSiteMapViewHelper


1 //
2
// ____.
3
// __/\ ______| |__/\. _______
4
// __ .____| | \ | +----+ \
5
// _______| /--| | | - \ _ | : - \_________
6
// \\______: :---| : : | : | \________>
7
// |__\---\_____________:______: :____|____:_____\
8
// /_____|
9
//
10
// . . . i n j a h i a w e t r u s t . . .
11
//
12
//
13

14 /*
15  * ----- BEGIN LICENSE BLOCK -----
16  * Version: JCSL 1.0
17  *
18  * The contents of this file are subject to the Jahia Community Source License
19  * 1.0 or later (the "License"); you may not use this file except in
20  * compliance with the License. You may obtain a copy of the License at
21  * http://www.jahia.org/license
22  *
23  * Software distributed under the License is distributed on an "AS IS" basis,
24  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
25  * for the rights, obligations and limitations governing use of the contents
26  * of the file. The Original and Upgraded Code is the Jahia CMS and Portal
27  * Server. The developer of the Original and Upgraded Code is JAHIA Ltd. JAHIA
28  * Ltd. owns the copyrights in the portions it created. All Rights Reserved.
29  *
30  * The Shared Modifications are Jahia View Helper.
31  *
32  * The Developer of the Shared Modifications is Jahia Solution Sàrl.
33  * Portions created by the Initial Developer are Copyright (C) 2002 by the
34  * Initial Developer. All Rights Reserved.
35  *
36  * Contributor(s):
37  * Sep 24 2002 Jahia Solutions Sàrl: MAP Initial release.
38  *
39  * ----- END LICENSE BLOCK -----
40  */

41
42 package org.jahia.data.viewhelper.sitemap;
43
44 import java.util.ArrayList JavaDoc;
45 import java.util.List JavaDoc;
46
47 import org.jahia.params.ParamBean;
48 import org.jahia.services.pages.ContentPage;
49 import org.jahia.services.usermanager.JahiaUser;
50
51 /**
52  * <p>The Jahia Shared Modification is: Jahia View Helper</p>
53  *
54  * <p>Description:
55  * Create a flat tree from Jahia page tree structure destinated to display a
56  * sorted Jahia site map.
57  * </p>
58  * <p>Copyright: MAP (Jahia Solutions Sàrl 2002)</p>
59  * <p>Company: Jahia Solutions Sàrl</p>
60  * @author MAP
61  * @version 1.0
62  */

63 public class TreeSiteMapViewHelper extends SiteMapViewHelper {
64
65     /**
66      * Create a view helper on a entire Jahia site map restricted to the actual
67      * logged user.
68      *
69      * @param user The actual user logged in Jahia.
70      * @param startPage The start page for site map.
71      * @param pageInfosFlag Kind of page infos desired. This parameter can associate
72      * @param defaultMaxLevel Site map expansion default level max.
73      * the ContentPage ACTIVE_PAGE_INFOS, STAGING_PAGE_INFOS and
74      * ARCHIVED_PAGE_INFOS constants.
75      * @param languageCode Get the page with the specified language code.
76      */

77     public TreeSiteMapViewHelper(JahiaUser user, ContentPage startPage,
78                                  int pageInfosFlag, String JavaDoc languageCode,
79                                  int defaultMaxLevel) {
80         super(user, startPage, pageInfosFlag, languageCode, defaultMaxLevel);
81         _jahiaPageSiteMap = super.getJahiaPageSiteMap();
82     }
83     
84     /**
85      * Create a view helper on a entire Jahia site map restricted to the actual
86      * logged user.
87      *
88      * @param user The actual user logged in Jahia.
89      * @param startPage The start page for site map.
90      * @param pageInfosFlag Kind of page infos desired. This parameter can associate
91      * @param defaultMaxLevel Site map expansion default level max.
92      * the ContentPage ACTIVE_PAGE_INFOS, STAGING_PAGE_INFOS and
93      * ARCHIVED_PAGE_INFOS constants.
94      * @param languageCode Get the page with the specified language code.
95      * @param jParams The ParamBean.
96      */

97     public TreeSiteMapViewHelper(JahiaUser user, ContentPage startPage,
98                                  int pageInfosFlag, String JavaDoc languageCode,
99                                  int defaultMaxLevel, PagesFilter pagesFilter, ParamBean jParams) {
100         super(user, startPage, pageInfosFlag, languageCode, defaultMaxLevel, pagesFilter, jParams);
101         _jahiaPageSiteMap = super.getJahiaPageSiteMap();
102     }
103
104     /**
105      * Create a view helper on a entire Jahia site map restricted to the actual
106      * logged user.
107      *
108      * @param user The actual user logged in Jahia.
109      * @param startPage The start page for site map.
110      * @param pageInfosFlag Kind of page infos desired. This parameter can associate
111      * @param defaultMaxLevel Site map expansion default level max.
112      * the ContentPage ACTIVE_PAGE_INFOS, STAGING_PAGE_INFOS and
113      * ARCHIVED_PAGE_INFOS constants.
114      * @param languageCode Get the page with the specified language code.
115      */

116     public TreeSiteMapViewHelper(JahiaUser user, ContentPage startPage,
117                                  int pageInfosFlag, String JavaDoc languageCode,
118                                  int defaultMaxLevel, boolean directPagesOnly) {
119         super(user, startPage, pageInfosFlag, languageCode, defaultMaxLevel, directPagesOnly);
120         _jahiaPageSiteMap = super.getJahiaPageSiteMap();
121
122     }
123
124     /**
125      * Create a view helper on a entire Jahia site map restricted to the actual
126      * logged user.
127      *
128      * @param user The actual user logged in Jahia.
129      * @param startPage The start page for site map.
130      * @param pageInfosFlag Kind of page infos desired. This parameter can associate
131      * @param defaultMaxLevel Site map expansion default level max.
132      * the ContentPage ACTIVE_PAGE_INFOS, STAGING_PAGE_INFOS and
133      * ARCHIVED_PAGE_INFOS constants.
134      * @param languageCode Get the page with the specified language code.
135      * @param jParams The ParamBean.
136      */

137     public TreeSiteMapViewHelper(JahiaUser user, ContentPage startPage,
138                                  int pageInfosFlag, String JavaDoc languageCode,
139                                  int defaultMaxLevel, boolean directPagesOnly,
140                                  PagesFilter pagesFilter, ParamBean jParams) {
141         super(user, startPage, pageInfosFlag, languageCode, defaultMaxLevel, directPagesOnly, pagesFilter, jParams);
142         _jahiaPageSiteMap = super.getJahiaPageSiteMap();
143   
144     }
145
146     public TreeSiteMapViewHelper(JahiaUser user, List JavaDoc startPages,
147             int pageInfosFlag, String JavaDoc languageCode, int defaultMaxLevel,
148             boolean directPageOnly, PagesFilter pagesFilter, ParamBean jParams) {
149         super(user, startPages, pageInfosFlag, languageCode, defaultMaxLevel,
150                 directPageOnly, pagesFilter, jParams);
151         _jahiaPageSiteMap = super.getJahiaPageSiteMap();
152
153     }
154     
155     /**
156      * Return the page pointed by the index. If the page is not displayable
157      * a null pointer is returned.
158      * WARNING ! A null result does NOT automatically mean that the page does
159      * not exist !
160      *
161      * @param index The array index of the desired page.
162      * @return The JahiaPage, null is not displayable or problem finding it.
163      */

164     public ContentPage getContentPage(int index) {
165         PageSiteMap pageSiteMap = (PageSiteMap)_jahiaPageSiteMap.get(index);
166         return pageSiteMap.isDisplayable() ? lookupContentPage(pageSiteMap.getPageID()) : null;
167     }
168
169     /**
170      * Return a Jahia page corresponding ID
171      *
172      * @param index The array index of the desired page.
173      * @return The ID of the page.
174      */

175     public int getPageID(int index) {
176         return ((PageSiteMap)_jahiaPageSiteMap.get(index)).getPageID();
177     }
178
179     /**
180      * Return the index of a given pageID, -1 if not found
181      *
182      * @param pageID
183      * @return
184      */

185     public int getPageIndex(int pageID){
186         PageSiteMap pageSiteMap = null;
187         for ( int i=0 ; i<_jahiaPageSiteMap.size() ; i++ ){
188             pageSiteMap = (PageSiteMap)_jahiaPageSiteMap.get(i);
189             if ( pageSiteMap.getPageID() == pageID ){
190                 return i;
191             }
192         }
193         return -1;
194     }
195
196     /**
197      * Return the RELATIVE page level for the tree structure. Used for indent
198      * display.
199      * WARNING ! The RELATIVE page level is ABSOLUTE if the home page is given
200      * in the constructor.
201      *
202      * @param index The array index of the desired page.
203      * @return The page level starting from 0.
204      */

205     public int getPageLevel(int index) {
206         return ((PageSiteMap)_jahiaPageSiteMap.get(index)).getPageLevel();
207     }
208
209     /**
210      * Return if the page pointed by the index has childs or not.
211      *
212      * @param index The array index of the desired page.
213      * @return True if childs, otherwise false.
214      */

215     public boolean hasChild(int index) {
216         return ((PageSiteMap)_jahiaPageSiteMap.get(index)).hasChild();
217     }
218
219     /**
220      * Get the parent page ID from the current indexed page.
221      *
222      * @param index The array index of the desired page.
223      * @return The parent page ID
224      */

225     public int getParentPageID(int index) {
226         return ((PageSiteMap)_jahiaPageSiteMap.get(index)).getParentPageID();
227     }
228
229     /**
230      * Return if the page pointed by the index is the last page sister.
231      *
232      * @param index The array index of the desired page.
233      * @return True if the page pointed by the index is the last page sister.
234      */

235     public boolean isLastSister(int index) {
236         return ((PageSiteMap)_jahiaPageSiteMap.get(index)).isLastSister();
237     }
238
239     /**
240      * Return the size of the site map.
241      *
242      * @return The ArrayList containing the page size.
243      */

244     public int size() {
245         return _jahiaPageSiteMap.size();
246     }
247
248     /**
249      * Return if the page pointed by the index is expanded or not.
250      *
251      * @param index The array index of the desired page.
252      * @return True if expanded.
253      */

254     public boolean isExpanded(int index) {
255         return ((PageSiteMap)_jahiaPageSiteMap.get(index)).isExpanded();
256     }
257
258     /**
259      * Mark for collapse the sub tree structure.
260      *
261      * @param index The index of the site map array list.
262      */

263     public void collapsePagesSubTree(int index) {
264         PageSiteMap pageSiteMap = (PageSiteMap)_jahiaPageSiteMap.get(index++);
265         pageSiteMap.setExpanded(false);
266         int pageLevel = pageSiteMap.getPageLevel();
267         for (int i = index; i < _jahiaPageSiteMap.size(); i++) {
268             pageSiteMap = (PageSiteMap)_jahiaPageSiteMap.get(i);
269             if (pageSiteMap.getPageLevel() > pageLevel) {
270                 pageSiteMap.setDisplayable(false);
271             } else {
272                 break;
273             }
274         }
275     }
276
277     /**
278      * Set the page information page flag. The information page is divided in
279      * three parts (Warning, Error, Event) informing the user if a page is
280      * valid for activation or not, which events has occured, etc...
281      *
282      * @param index The index of the site map array list.
283      */

284     public void showInformation(int index) {
285         ((PageSiteMap)_jahiaPageSiteMap.get(index)).setShowInformation(true);
286     }
287
288     public void hideInformation(int index) {
289         ((PageSiteMap)_jahiaPageSiteMap.get(index)).setShowInformation(false);
290     }
291
292     /**
293      * Return if the page information should be displayed or not.
294      *
295      * @param index The index of the site map array list.
296      * @return True if the view should display the informations, false otherwise.
297      */

298     public boolean shouldShowInformation(int index) {
299         return ((PageSiteMap)_jahiaPageSiteMap.get(index)).isShowInformation();
300     }
301
302     /**
303      * Set the Show/Hide errors flag.
304      *
305      * @param index The index of the site map array list.
306      */

307     public void showWarnings(int index) {
308         ((PageSiteMap)_jahiaPageSiteMap.get(index)).setShowWarnings(true);
309     }
310
311     public void hideWarnings(int index) {
312         ((PageSiteMap)_jahiaPageSiteMap.get(index)).setShowWarnings(false);
313     }
314
315     /**
316      * @param index The index of the site map array list.
317      * @return True if the view should display the warnings, false otherwise.
318      */

319     public boolean shouldShowWarnings(int index) {
320         return ((PageSiteMap)_jahiaPageSiteMap.get(index)).isShowWarnings();
321     }
322
323     /**
324      * Set the Show/Hide errors flag.
325      *
326      * @param index The index of the site map array list.
327      */

328     public void showErrors(int index) {
329         ((PageSiteMap)_jahiaPageSiteMap.get(index)).setShowErrors(true);
330     }
331
332     public void hideErrors(int index) {
333         ((PageSiteMap)_jahiaPageSiteMap.get(index)).setShowErrors(false);
334     }
335
336     /**
337      * @param index The index of the site map array list.
338      * @return True if the view should display the errors, false otherwise.
339      */

340     public boolean shouldShowErrors(int index) {
341         return ((PageSiteMap)_jahiaPageSiteMap.get(index)).isShowErrors();
342     }
343
344     /**
345      * Set the Show/Hide events flag.
346      *
347      * @param index The index of the site map array list.
348      */

349     public void showEvents(int index) {
350         ((PageSiteMap)_jahiaPageSiteMap.get(index)).setShowEvents(true);
351     }
352
353     public void hideEvents(int index) {
354         ((PageSiteMap)_jahiaPageSiteMap.get(index)).setShowEvents(false);
355     }
356
357     /**
358      * @param index The index of the site map array list.
359      * @return True if the view should display the events, false otherwise.
360      */

361     public boolean shouldShowEvents(int index) {
362         return ((PageSiteMap)_jahiaPageSiteMap.get(index)).isShowEvents();
363     }
364
365     /**
366      * Expand from root to the given page.
367      *
368      * @param pageID, the pageID
369      */

370     public void expandToPage(int pageID) {
371
372         int pageIndex = getPageIndex(pageID);
373         if ( pageIndex != -1 ){
374             expandPagesSubTree(pageIndex);
375             int parentID = this.getParentPageID(pageIndex);
376             if ( parentID != 0 ){
377                 expandToPage(parentID);
378             }
379         }
380     }
381
382     /**
383      * Mark for expansion the direct page childs from the subtree structure.
384      *
385      * @param index The index of the site map array list.
386      */

387     public void expandPagesSubTree(int index) {
388
389         PageSiteMap pageSiteMap = (PageSiteMap)_jahiaPageSiteMap.get(index++);
390         if (!pageSiteMap.hasChild()) return;
391         pageSiteMap.setExpanded(true);
392         int pageLevel = pageSiteMap.getPageLevel();
393         int actualPageLevel = pageSiteMap.getPageLevel() + 1;
394         for (int i = index; i < _jahiaPageSiteMap.size(); i++) {
395             pageSiteMap = (PageSiteMap)_jahiaPageSiteMap.get(i);
396             if (actualPageLevel == pageSiteMap.getPageLevel()) {
397                 pageSiteMap.setDisplayable(true);
398                 if (pageSiteMap.isExpanded()) {
399                     actualPageLevel++;
400                 }
401             } else if (actualPageLevel > pageSiteMap.getPageLevel()) {
402                 actualPageLevel = pageSiteMap.getPageLevel() + 1;
403                 pageSiteMap.setDisplayable(true);
404             }
405             if (pageLevel >= pageSiteMap.getPageLevel()) break;
406         }
407     }
408
409     /**
410      * Mark for expansion the entire sub tree structure.
411      *
412      * @param index The index of the site map array list.
413      */

414     public void expandAllPagesSubTree(int index) {
415         PageSiteMap pageSiteMap = (PageSiteMap)_jahiaPageSiteMap.get(index++);
416         pageSiteMap.setExpanded(true);
417         int pageLevel = pageSiteMap.getPageLevel();
418         for (int i = index; i < _jahiaPageSiteMap.size(); i++) {
419             pageSiteMap = (PageSiteMap)_jahiaPageSiteMap.get(i);
420             if (pageLevel >= pageSiteMap.getPageLevel()) break;
421             pageSiteMap.setDisplayable(true);
422             if (pageSiteMap.hasChild()) {
423                 pageSiteMap.setExpanded(true);
424             }
425         }
426     }
427
428     /**
429      * Return the page title coresponding to a language code.
430      * @param index The index of the site map array list.
431      * @param languageCode The title language code desired.
432      * @return A string correponsding to the page title.
433      */

434     public String JavaDoc getPageTitle(int index, String JavaDoc languageCode) {
435         return ((PageSiteMap)_jahiaPageSiteMap.get(index)).getPageTitle(languageCode);
436     }
437
438     private ArrayList JavaDoc _jahiaPageSiteMap = null;
439
440     private static org.apache.log4j.Logger logger =
441             org.apache.log4j.Logger.getLogger(SiteMapViewHelper.class);
442
443 }
444
Popular Tags