KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Feb 3 2003 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.text.MessageFormat JavaDoc;
45 import java.util.Hashtable JavaDoc;
46 import java.util.Locale JavaDoc;
47
48 import org.jahia.exceptions.JahiaException;
49 import org.jahia.resourcebundle.JahiaResourceBundle;
50 import org.jahia.services.pages.ContentPage;
51 import org.jahia.services.pages.JahiaPageBaseService;
52 import org.jahia.utils.LanguageCodeConverters;
53 import java.io.Serializable JavaDoc;
54
55 /**
56  * <p>Title: Informations site map page</p>
57  * <p>Description: Node information of each Jahia page contained in the
58  * site map.
59  * Private class, should be used with the site map view helper.
60  * </p>
61  * <p>Copyright: MAP (Jahia Solutions Sàrl 2002)</p>
62  * <p>Company: Jahia Solutions Sàrl</p>
63  * @author MAP
64  * @version 1.0
65  */

66 final class PageSiteMap implements Serializable JavaDoc {
67
68     public PageSiteMap(int pageID, int pageLevel, boolean hasChild,
69                        int parentPageID, boolean isLastSister, Hashtable JavaDoc titles,
70                        int currentLevel, int defaultMaxLevel) {
71         this.pageLevel = pageLevel;
72         this.pageID = pageID;
73         this.hasChild = hasChild;
74         this.parentPageID = parentPageID;
75         this.isLastSister = isLastSister;
76         this.titles = titles;
77         this.expanded = currentLevel < defaultMaxLevel && hasChild ? true : false;
78         this.displayable = currentLevel <= defaultMaxLevel ? true : false;
79         this.showInformation = false;
80         this.showWarnings = false;
81         this.showErrors = false;
82         this.showEvents = false;
83     }
84
85     public int getPageID() {
86         return pageID;
87     }
88
89     public int getPageLevel() {
90         return pageLevel;
91     }
92
93     public boolean hasChild() {
94         return hasChild;
95     }
96
97     public int getParentPageID() {
98         return parentPageID;
99     }
100
101     public boolean isLastSister() {
102         return isLastSister;
103     }
104
105     public String JavaDoc getPageTitle(String JavaDoc languageCode) {
106         return getAPageTitleAnyway(languageCode);
107     }
108     
109     public boolean isDisplayable() {
110         return displayable;
111     }
112
113     public void setDisplayable(boolean displayable) {
114         this.displayable = displayable;
115     }
116
117     public void setExpanded(boolean expanded) {
118         this.expanded = expanded;
119     }
120
121     public boolean isExpanded() {
122         return expanded;
123     }
124
125     public void setShowInformation(boolean showInformation) {
126         this.showInformation = showInformation;
127     }
128
129     public boolean isShowInformation() {
130         return showInformation;
131     }
132
133     public void setShowWarnings(boolean showWarnings) {
134         this.showWarnings = showWarnings;
135     }
136
137     public boolean isShowWarnings() {
138         return showWarnings;
139     }
140
141     public void setShowErrors(boolean showErrors) {
142         this.showErrors = showErrors;
143     }
144
145     public boolean isShowErrors() {
146         return showErrors;
147     }
148
149     public void setShowEvents(boolean showEvents) {
150         this.showEvents = showEvents;
151     }
152
153     public boolean isShowEvents() {
154         return showEvents;
155     }
156
157     private String JavaDoc getAPageTitleAnyway(String JavaDoc languageCode) {
158         String JavaDoc pageTitle1 = ((String JavaDoc)this.titles.get(languageCode));
159         if (pageTitle1 == null) {
160             Locale JavaDoc locale = LanguageCodeConverters.languageCodeToLocale(languageCode);
161             try {
162                 ContentPage contentPage = JahiaPageBaseService.getInstance().
163                         lookupContentPage(pageID, false);
164                 if (contentPage.isStagedEntryMarkedForDeletion(languageCode)) {
165                     Hashtable JavaDoc titles = contentPage.getTitles(ContentPage.ACTIVATED_PAGE_TITLES);
166                     pageTitle1 = (String JavaDoc)titles.get(languageCode);
167                 } else {
168                     String JavaDoc msgFormat = JahiaResourceBundle.getMessageResource("org.jahia.engines.workflow.pageNotApplicable", locale);
169                     Object JavaDoc[] arguments = {new Integer JavaDoc(this.pageID), LanguageCodeConverters.languageCodeToLocale(languageCode).getDisplayName(locale)};
170                     pageTitle1 = MessageFormat.format(msgFormat, arguments);
171                 }
172             } catch (JahiaException je) {
173                 logger.debug("Cannot recover the page with ID " + pageID);
174                 return JahiaResourceBundle.getMessageResource("org.jahia.engines.workflow.pageNotExisting", locale);
175             }
176         }
177         return pageTitle1;
178     }
179
180     // Page status attributes
181
private final int pageID;
182     private final int pageLevel;
183     private final boolean hasChild;
184     private final int parentPageID;
185     private final boolean isLastSister;
186     private final Hashtable JavaDoc titles;
187     // Display parameters
188
private boolean expanded;
189     private boolean displayable;
190     private boolean showInformation;
191     private boolean showWarnings;
192     private boolean showErrors;
193     private boolean showEvents;
194
195     private static org.apache.log4j.Logger logger =
196             org.apache.log4j.Logger.getLogger(PageSiteMap.class);
197 }
198
Popular Tags