KickJava   Java API By Example, From Geeks To Geeks.

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


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.Collection JavaDoc;
27 import java.util.Date JavaDoc;
28 import java.util.LinkedList JavaDoc;
29 import java.util.Locale JavaDoc;
30 import java.util.Map JavaDoc;
31
32 import org.riotfamily.components.ComponentVersion;
33 import org.riotfamily.components.VersionContainer;
34
35
36 /**
37  * @author Felix Gnass [fgnass at neteye dot de]
38  * @author Jan-Frederic Linde [jfl at neteye dot de]
39  * @since 6.5
40  */

41 public class Page {
42
43     private Long JavaDoc id;
44
45     private PageNode node;
46
47     private Locale JavaDoc locale;
48
49     private String JavaDoc pathComponent;
50
51     private boolean hidden;
52
53     private boolean folder;
54
55     private String JavaDoc path;
56     
57     private boolean wildcardInPath;
58
59     private boolean published;
60
61     private Date JavaDoc creationDate;
62
63     private VersionContainer versionContainer;
64
65     public Page() {
66     }
67
68     public Page(String JavaDoc pathComponent, Locale JavaDoc locale) {
69         this.pathComponent = pathComponent;
70         this.locale = locale;
71     }
72
73     public Long JavaDoc getId() {
74         return this.id;
75     }
76
77     public void setId(Long JavaDoc id) {
78         this.id = id;
79     }
80
81     public PageNode getNode() {
82         return this.node;
83     }
84
85     public void setNode(PageNode node) {
86         this.node = node;
87     }
88
89     public Locale JavaDoc getLocale() {
90         return this.locale;
91     }
92
93     public void setLocale(Locale JavaDoc locale) {
94         this.locale = locale;
95     }
96
97     public Date JavaDoc getCreationDate() {
98         return creationDate;
99     }
100
101     public void setCreationDate(Date JavaDoc creationDate) {
102         this.creationDate = creationDate;
103     }
104
105     public String JavaDoc getPathComponent() {
106         return pathComponent;
107     }
108
109     public void setPathComponent(String JavaDoc pathComponent) {
110         this.pathComponent = pathComponent;
111     }
112
113     public boolean isHidden() {
114         return this.hidden;
115     }
116     
117     public void setHidden(boolean hidden) {
118         this.hidden = hidden;
119     }
120     
121     /**
122      * Returns whether the page only acts as container for other pages and
123      * has no own content.
124      */

125     public boolean isFolder() {
126         return this.folder;
127     }
128
129     public void setFolder(boolean folder) {
130         this.folder = folder;
131     }
132
133     public String JavaDoc getPath() {
134         if (path == null) {
135             path = buildPath();
136         }
137         return path;
138     }
139
140     public void setPath(String JavaDoc path) {
141         this.path = path;
142     }
143
144     public boolean isWildcard() {
145         return pathComponent.indexOf("@{") != -1;
146     }
147     
148     public boolean isWildcardInPath() {
149         return this.wildcardInPath;
150     }
151
152     public void setWildcardInPath(boolean wildcardInPath) {
153         this.wildcardInPath = wildcardInPath;
154     }
155
156     public String JavaDoc buildPath() {
157         StringBuffer JavaDoc path = new StringBuffer JavaDoc();
158         wildcardInPath = false;
159         Page page = this;
160         while (page != null) {
161             path.insert(0, page.getPathComponent());
162             path.insert(0, '/');
163             wildcardInPath |= page.isWildcard();
164             page = page.getParentPage();
165         }
166         return path.toString();
167     }
168
169     public Page getParentPage() {
170         PageNode parentNode = node.getParent();
171         if (parentNode == null) {
172             return null;
173         }
174         return parentNode.getPage(locale);
175     }
176
177     public Collection JavaDoc getChildPages() {
178         return node.getChildPages(locale);
179     }
180
181     public Collection JavaDoc getChildPages(Locale JavaDoc fallbackLocale) {
182         return node.getChildPages(locale, fallbackLocale);
183     }
184
185     public Collection JavaDoc getAncestors() {
186         LinkedList JavaDoc pages = new LinkedList JavaDoc();
187         Page page = this;
188         while (page != null) {
189             pages.addFirst(page);
190             page = page.getParentPage();
191         }
192         return pages;
193     }
194
195     public void addChildPage(Page child) {
196         child.setLocale(locale);
197         node.addChildNode(new PageNode(child));
198     }
199
200     public String JavaDoc getHandlerName() {
201         return node.getHandlerName();
202     }
203
204     public VersionContainer getVersionContainer() {
205         if (versionContainer == null) {
206             versionContainer = new VersionContainer();
207             ComponentVersion version = new ComponentVersion(Page.class.getName());
208             versionContainer.setLiveVersion(version);
209         }
210         return versionContainer;
211     }
212
213     public void setVersionContainer(VersionContainer versionContainer) {
214         this.versionContainer = versionContainer;
215     }
216
217     public Map JavaDoc getProperties(boolean preview) {
218         if (preview) {
219             return getVersionContainer().getLatestVersion().getProperties();
220         }
221         ComponentVersion version = getVersionContainer().getLiveVersion();
222         return version != null ? version.getProperties() : null;
223     }
224
225     public String JavaDoc getProperty(String JavaDoc key, boolean preview) {
226         ComponentVersion version = preview
227                 ? getVersionContainer().getLatestVersion()
228                 : getVersionContainer().getLiveVersion();
229
230         return version != null ? version.getProperty(key) : null;
231     }
232
233     public boolean isDirty() {
234         return getVersionContainer().isDirty();
235     }
236
237     public boolean isPublished() {
238         return this.published;
239     }
240
241     public void setPublished(boolean published) {
242         this.published = published;
243     }
244
245     public boolean isEnabled() {
246         return published && getNode().getSite().isLocaleEnabled(locale);
247     }
248
249     public String JavaDoc toString() {
250         return locale + ":" + path;
251     }
252
253     public boolean equals(Object JavaDoc o) {
254         if (o instanceof Page) {
255             Page page = (Page) o;
256             if (id == null) {
257                 return this == o;
258             }
259             return id.equals(page.getId());
260         }
261         return false;
262     }
263
264     public int hashCode() {
265         return id != null ? id.hashCode() : 0;
266     }
267
268 }
269
Popular Tags