KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > model > core > Page


1 /*
2  * Copyright 2004 Blandware (http://www.blandware.com)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package com.blandware.atleap.model.core;
17
18 import java.util.ArrayList JavaDoc;
19 import java.util.HashMap JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.List JavaDoc;
22 import java.util.Map JavaDoc;
23
24 /**
25  * <p>Base class for pages.</p>
26  * <p>In Atleap, pages are {@link ContentPage}s, {@link ActionPage}s and other
27  * objects which are called <b>linkable objects</b> (news items, for example).</p>
28  * <p>Page has URI by which it is accessible. It also has a <b>usage counter</b>
29  * attached, activity flag (inactive page, for example, may be hidden). Localized
30  * title, description and keywords are defined for page.</p>
31  * <p>Every Page has a list of {@link Role}s that are allowed to access it.
32  * If that list is empty, everyone is allowed to access such Page, otherwise
33  * only users that have at least one role from that list can access the Page.</p>
34  * <p>
35  * Every page is indexed for search and its content (actually content of fields
36  * that belong to this page and its layout) becomes a subject for full-text
37  * search.
38  * </p>
39  * <p><a HREF="Page.java.htm"><i>View Source</i></a>
40  * </p>
41  * <p/>
42  *
43  * @author Andrey Grebnev <a HREF="mailto:andrey.grebnev@blandware.com">&lt;andrey.grebnev@blandware.com&gt;</a>
44  * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
45  * @version $Revision: 1.42 $ $Date: 2005/12/18 16:43:43 $
46  * @hibernate.joined-subclass table="`al_core_page`" lazy="false"
47  * @hibernate.joined-subclass-key column="`localizable_id`"
48  */

49 public abstract class Page extends Localizable {
50
51     //~ Instance variables
52

53     /**
54      * The URI under which the page is accessible
55      */

56     protected String JavaDoc uri;
57     /**
58      * The number of links to this page
59      */

60     protected Integer JavaDoc usageCounter;
61     /**
62      * Is this page ready for publication (shown to users) or not
63      */

64     protected Boolean JavaDoc active;
65
66     /**
67      * Map of titles for different locales
68      */

69     protected Map JavaDoc title = new HashMap JavaDoc();
70     /**
71      * Map of keywords for different locales
72      */

73     protected Map JavaDoc keywords = new HashMap JavaDoc();
74     /**
75      * Map of descriptions for different locales
76      */

77     protected Map JavaDoc description = new HashMap JavaDoc();
78
79     /**
80      * List of CFVs which are linked to this page
81      */

82     protected List JavaDoc linkedContentFieldValues = new ArrayList JavaDoc();
83     /**
84      * List of menu items which are linked to this page
85      */

86     protected List JavaDoc linkedMenuItems = new ArrayList JavaDoc();
87
88     /**
89      * List of roles which are allowed to access this page
90      */

91     protected List JavaDoc roles = new ArrayList JavaDoc();
92
93
94     //~ Methods
95

96     /**
97      * Returns the URI under which this page is accessible
98      *
99      * @return URI
100      * @struts.form-field
101      * @struts.validator type="required"
102      * @struts.validator type="mask" msgkey="core.commons.errors.pageUri"
103      * @struts.validator-args arg0resource="core.page.form.uri"
104      * @struts.validator-var name="mask" value="^(\/[a-zA-Z0-9\-_\040]+)+$"
105      * @hibernate.property
106      * @hibernate.column name="`uri`" not-null="false" unique="true" length="252"
107      */

108     public String JavaDoc getUri() {
109         return uri;
110     }
111
112     /**
113      * Sets the URI under which this page will be accessible
114      *
115      * @param uri the URI to set
116      */

117     public void setUri(String JavaDoc uri) {
118         this.uri = uri;
119     }
120
121     /**
122      * Returns the usage counter of the page
123      *
124      * @return usage counter
125      * @hibernate.property column="`usage_counter`" not-null="false"
126      */

127     public Integer JavaDoc getUsageCounter() {
128         return usageCounter;
129     }
130
131     /**
132      * Sets the usage counter of the page
133      *
134      * @param usageCounter usage counter
135      */

136     public void setUsageCounter(Integer JavaDoc usageCounter) {
137         this.usageCounter = usageCounter;
138     }
139
140     /**
141      * Returns <code>Boolean.TRUE</code> if page is active (and visible for users)
142      *
143      * @return whether page is active
144      * @struts.form-field
145      * @hibernate.property column="`active`" not-null="true" type="true_false"
146      */

147     public Boolean JavaDoc getActive() {
148         return active;
149     }
150
151     /**
152      * Sets whether page is active (and visible for users)
153      *
154      * @param active whether page is active
155      */

156     public void setActive(Boolean JavaDoc active) {
157         this.active = active;
158     }
159
160     // Internal field values
161

162     /**
163      * Returns map of titles for different locales
164      *
165      * @return mapping from locale identifiers to titles
166      * @struts.form-field
167      */

168     public Map JavaDoc getTitle() {
169         return title;
170     }
171
172     /**
173      * Sets map of titles for different locales
174      *
175      * @param title mapping from locale identifiers to titles
176      */

177     public void setTitle(Map JavaDoc title) {
178         this.title = title;
179     }
180
181     /**
182      * Returns map of keywords for different locales
183      *
184      * @return mapping from locale identifiers to keyword sets
185      * @struts.form-field
186      */

187     public Map JavaDoc getKeywords() {
188         return keywords;
189     }
190
191     /**
192      * Sets map of keywords for different locales
193      *
194      * @param keywords mapping from locale identifiers to keyword sets
195      */

196     public void setKeywords(Map JavaDoc keywords) {
197         this.keywords = keywords;
198     }
199
200     /**
201      * Returns map of decriptions for different locales
202      *
203      * @return mapping from locale identifiers to descriptions
204      * @struts.form-field
205      */

206     public Map JavaDoc getDescription() {
207         return description;
208     }
209
210     /**
211      * Sets map of decriptions for different locales
212      *
213      * @param description mapping from locale identifiers to descriptions
214      */

215     public void setDescription(Map JavaDoc description) {
216         this.description = description;
217     }
218
219     /**
220      * Gets list of CFVs this page is linked with
221      *
222      * @return list if linked CFVs
223      * @hibernate.bag table="`al_core_field_value_page`" cascade="none" lazy="true" inverse="false" outer-join="false"
224      * @hibernate.collection-key column="`page_id`"
225      * @hibernate.collection-many-to-many class="com.blandware.atleap.model.core.ContentFieldValue" column="`field_value_id`" outer-join="false"
226      */

227     public List JavaDoc getLinkedContentFieldValues() {
228         return linkedContentFieldValues;
229     }
230
231     /**
232      * Sets list of CFVs this page is linked with
233      *
234      * @param linkedContentFieldValues list if linked CFVs
235      */

236     public void setLinkedContentFieldValues(List JavaDoc linkedContentFieldValues) {
237         this.linkedContentFieldValues = linkedContentFieldValues;
238     }
239
240     /**
241      * Gets list of menu items this page is linked with
242      *
243      * @return list of linked menu items
244      * @hibernate.bag table="`al_core_menu_item_page`" cascade="none" lazy="true" inverse="false" outer-join="false"
245      * @hibernate.collection-key column="`page_id`"
246      * @hibernate.collection-many-to-many class="com.blandware.atleap.model.core.MenuItem" column="`menu_item_id`" outer-join="false"
247      */

248     public List JavaDoc getLinkedMenuItems() {
249         return linkedMenuItems;
250     }
251
252     /**
253      * Sets list of menu items this page is linked with
254      *
255      * @param linkedMenuItems list of linked menu items
256      */

257     public void setLinkedMenuItems(List JavaDoc linkedMenuItems) {
258         this.linkedMenuItems = linkedMenuItems;
259     }
260
261     /**
262      * Returns <code>true</code> if this page is in use, i.e. there are links on it from content field values or menu items
263      * or its usage counter is greater than zero
264      * @return <code>true</code> if this page is in use
265      */

266     public boolean isInUse() {
267         return !linkedContentFieldValues.isEmpty() || !linkedMenuItems.isEmpty() || usageCounter.intValue() > 0;
268     }
269
270     /**
271      * Returns whether there are some objects linked to this page by URI that
272      * cannot be modified to have correct links when this page URI is changed
273      *
274      * @return whether there are unmodifiable linked objects
275      */

276     public boolean doUnmodifiableLinkedObjectsExist() {
277         for (Iterator JavaDoc i = linkedMenuItems.iterator(); i.hasNext();) {
278             MenuItem menuItem = (MenuItem) i.next();
279             if (!menuItem.isDynamic()) {
280                 return true;
281             }
282         }
283         return false;
284     }
285
286     /**
287      * Returns the page roles (the roles that are allowed to access this page)
288      *
289      * @return list of roles
290      * @hibernate.bag table="`al_core_page_role`" cascade="none" lazy="true" inverse="false" outer-join="false"
291      * @hibernate.collection-key column="`page_id`"
292      * @hibernate.collection-many-to-many class="com.blandware.atleap.model.core.Role"
293      * column="`rolename`" outer-join="false"
294      * @hibernate.cache usage="read-write"
295      */

296     public List JavaDoc getRoles() {
297         return roles;
298     }
299
300     /**
301      * Sets the page roles (the roles that are allowed to access this page)
302      *
303      * @param roles list of roles
304      */

305     public void setRoles(List JavaDoc roles) {
306         this.roles = roles;
307     }
308
309     /**
310      * Gets all page roles, represented as string (roles are separated with commas)
311      *
312      * @return roles separated with commas
313      */

314     public String JavaDoc getRolesAsString() {
315         StringBuffer JavaDoc roles = new StringBuffer JavaDoc();
316         if ( this.roles != null && !this.roles.isEmpty() ) {
317             for ( Iterator JavaDoc i = this.roles.iterator(); i.hasNext(); ) {
318                 Role role = (Role) i.next();
319                 roles.append(role.getTitle());
320                 if ( i.hasNext() ) {
321                     roles.append(", ");
322                 }
323             }
324         }
325         return roles.toString();
326     }
327
328     /**
329      * Adds a connection between this page and a given role
330      *
331      * @param role the role to be connected with
332      */

333     public void addRole(Role role) {
334         if ( !role.getPages().contains(this) ) {
335             role.getPages().add(this);
336         }
337         if ( !getRoles().contains(role) ) {
338             getRoles().add(role);
339         }
340     }
341
342     /**
343      * Removes a connection between this page and a given role
344      *
345      * @param role the role
346      */

347     public void removeRole(Role role) {
348         role.getPages().remove(this);
349         getRoles().remove(role);
350     }
351
352     public boolean equals(Object JavaDoc o) {
353         if ( this == o ) {
354             return true;
355         }
356         if ( !(o instanceof Page) ) {
357             return false;
358         }
359
360         final Page page = (Page) o;
361
362         if ( uri != null ? !uri.equals(page.uri) : page.uri != null ) {
363             return false;
364         }
365
366         return true;
367     }
368
369     public int hashCode() {
370         return (uri != null ? uri.hashCode() : 0);
371     }
372
373 }
374
Popular Tags