KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > riotfamily > pages > PageNode


1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1
3  * The contents of this file are subject to the Mozilla Public License Version
4  * 1.1 (the "License"); you may not use this file except in compliance with
5  * the License. You may obtain a copy of the License at
6  * http://www.mozilla.org/MPL/
7  *
8  * Software distributed under the License is distributed on an "AS IS" basis,
9  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
10  * for the specific language governing rights and limitations under the
11  * License.
12  *
13  * The Original Code is Riot.
14  *
15  * The Initial Developer of the Original Code is
16  * Neteye GmbH.
17  * Portions created by the Initial Developer are Copyright (C) 2007
18  * the Initial Developer. All Rights Reserved.
19  *
20  * Contributor(s):
21  * Felix Gnass [fgnass at neteye dot de]
22  *
23  * ***** END LICENSE BLOCK ***** */

24 package org.riotfamily.pages;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.Collection JavaDoc;
28 import java.util.Collections JavaDoc;
29 import java.util.HashSet JavaDoc;
30 import java.util.Iterator JavaDoc;
31 import java.util.LinkedList JavaDoc;
32 import java.util.List JavaDoc;
33 import java.util.Locale JavaDoc;
34 import java.util.Set JavaDoc;
35
36 import org.springframework.util.ObjectUtils;
37
38 /**
39  * @author Felix Gnass [fgnass at neteye dot de]
40  * @author Jan-Frederic Linde [jfl at neteye dot de]
41  * @since 6.5
42  */

43 public class PageNode {
44
45     private Long JavaDoc id;
46
47     private PageNode parent;
48
49     private Site site;
50
51     private List JavaDoc childNodes;
52
53     private Set JavaDoc pages;
54
55     private String JavaDoc handlerName;
56
57     private boolean systemNode;
58
59     private String JavaDoc childHandlerName;
60
61     private boolean hidden;
62
63     public PageNode() {
64     }
65
66     public PageNode(Page page) {
67         addPage(page);
68     }
69
70     public Long JavaDoc getId() {
71         return id;
72     }
73
74     public void setId(Long JavaDoc id) {
75         this.id = id;
76     }
77
78     public PageNode getParent() {
79         return this.parent;
80     }
81
82     public void setParent(PageNode parent) {
83         this.parent = parent;
84     }
85
86     public Site getSite() {
87         return this.site;
88     }
89
90     public void setSite(Site site) {
91         this.site = site;
92     }
93
94     public Set JavaDoc getPages() {
95         return pages;
96     }
97
98     public void setPages(Set JavaDoc pages) {
99         this.pages = pages;
100     }
101
102     public void setChildNodes(List JavaDoc childNodes) {
103         this.childNodes = childNodes;
104     }
105
106     /**
107      * Adds a child node. If the given node has no handlerName, it will be
108      * set to the childHandlerName.
109      */

110     public void addChildNode(PageNode node) {
111         node.setParent(this);
112         node.setSite(site);
113         if (node.getHandlerName() == null) {
114             node.setHandlerName(childHandlerName);
115         }
116         if (node.getChildHandlerName() == null) {
117             node.setChildHandlerName(childHandlerName);
118         }
119         if (childNodes == null) {
120             childNodes = new ArrayList JavaDoc();
121         }
122         childNodes.add(node);
123     }
124
125     public List JavaDoc getChildNodes() {
126         return this.childNodes;
127     }
128
129     public Collection JavaDoc getChildPages(Locale JavaDoc locale) {
130         LinkedList JavaDoc pages = new LinkedList JavaDoc();
131         if (childNodes != null) {
132             Iterator JavaDoc it = childNodes.iterator();
133             while (it.hasNext()) {
134                 PageNode childNode = (PageNode) it.next();
135                 Page page = childNode.getPage(locale);
136                 if (page != null) {
137                     pages.add(page);
138                 }
139             }
140         }
141         return Collections.unmodifiableCollection(pages);
142     }
143
144     public Collection JavaDoc getChildPages(Locale JavaDoc locale, Locale JavaDoc fallback) {
145         LinkedList JavaDoc pages = new LinkedList JavaDoc();
146         if (childNodes != null) {
147             Iterator JavaDoc it = childNodes.iterator();
148             while (it.hasNext()) {
149                 PageNode childNode = (PageNode) it.next();
150                 Page page = childNode.getPage(locale);
151                 if (page == null) {
152                     page = fallback != null
153                         ? childNode.getPage(fallback)
154                         : childNode.getFirstPage();
155                 }
156                 if (page != null) {
157                     pages.add(page);
158                 }
159             }
160         }
161         return Collections.unmodifiableCollection(pages);
162     }
163
164     public Page getPage(Locale JavaDoc locale) {
165         if (pages == null) {
166             return null;
167         }
168         Iterator JavaDoc it = pages.iterator();
169         while (it.hasNext()) {
170             Page page = (Page) it.next();
171             if (ObjectUtils.nullSafeEquals(page.getLocale(), locale)) {
172                 return page;
173             }
174         }
175         return null;
176     }
177
178     private Page getFirstPage() {
179         return (Page) pages.iterator().next();
180     }
181
182     public void addPage(Page page) {
183         page.setNode(this);
184         if (pages == null) {
185             pages = new HashSet JavaDoc();
186         }
187         pages.add(page);
188     }
189
190     public void removePage(Page page) {
191         pages.remove(page);
192     }
193
194     public boolean hasPages() {
195         return !pages.isEmpty();
196     }
197
198     /**
199      * Returns the name of the handler that will be used to serve the page.
200      */

201     public String JavaDoc getHandlerName() {
202         return handlerName;
203     }
204
205     public void setHandlerName(String JavaDoc handlerName) {
206         this.handlerName = handlerName;
207     }
208
209     /**
210      * Returns the handlerName that will be assigned to child nodes that
211      * don't have an expicit handlerName set.
212      */

213     public String JavaDoc getChildHandlerName() {
214         return this.childHandlerName;
215     }
216
217     public void setChildHandlerName(String JavaDoc childHandlerName) {
218         this.childHandlerName = childHandlerName;
219     }
220
221     /**
222      * Returns whether the page should be hidden in menus.
223      */

224     public boolean isHidden() {
225         return this.hidden;
226     }
227
228     public void setHidden(boolean hidden) {
229         this.hidden = hidden;
230     }
231
232     /**
233      * Returns whether the node is a system node. System nodes are usually
234      * created by a PageSetupBean and provide some kind of functionality
235      * (in contrast to nodes that only contain content) and must not be deleted.
236      */

237     public boolean isSystemNode() {
238         return this.systemNode;
239     }
240
241     public void setSystemNode(boolean systemNode) {
242         this.systemNode = systemNode;
243     }
244
245 }
246
Popular Tags