KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > riotfamily > pages > riot > command > PageCommandUtils


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.riot.command;
25
26 import java.util.Locale JavaDoc;
27
28 import org.riotfamily.pages.Page;
29 import org.riotfamily.pages.riot.dao.PageRiotDao;
30 import org.riotfamily.pages.riot.dao.SiteLocale;
31 import org.riotfamily.riot.list.command.CommandContext;
32 import org.springframework.util.ObjectUtils;
33
34 /**
35  * @author Felix Gnass [fgnass at neteye dot de]
36  * @since 6.5
37  */

38 public final class PageCommandUtils {
39
40     private PageCommandUtils() {
41     }
42
43     public static Page getPage(CommandContext context) {
44         return (Page) context.getBean();
45     }
46
47     public static Locale JavaDoc getLocale(CommandContext context) {
48         return getPage(context).getLocale();
49     }
50
51     /**
52      * If the parent cannot be determined the return will be <code>null</code>.
53      */

54     public static Locale JavaDoc getParentLocale(CommandContext context) {
55         Object JavaDoc parent = context.getParent();
56         Locale JavaDoc locale = null;
57         if (parent instanceof Page) {
58             locale = ((Page) parent).getLocale();
59         }
60         else if (parent instanceof SiteLocale) {
61             locale = ((SiteLocale) parent).getLocale();
62         }
63         else {
64             Page page = getPage(context);
65             if (page != null) { // TODO: This needs to change somehow...
66
locale = page.getLocale();
67             }
68         }
69         return locale;
70     }
71
72     public static Locale JavaDoc getMasterLocale(CommandContext context) {
73         PageRiotDao dao = (PageRiotDao) context.getDao();
74         return dao.getMasterLocale();
75     }
76
77     public static boolean isMasterLocale(CommandContext context) {
78         return getLocale(context).equals(getMasterLocale(context));
79     }
80
81     public static boolean isMasterLocaleList(CommandContext context) {
82         return ObjectUtils.nullSafeEquals(getParentLocale(context),
83                     getMasterLocale(context));
84     }
85
86     public static boolean hasTranslation(CommandContext context) {
87         return getPage(context).getNode().getPages().size() > 1;
88     }
89
90     public static boolean isTranslated(CommandContext context) {
91         Page page = getPage(context);
92         Locale JavaDoc locale = getParentLocale(context);
93         return ObjectUtils.nullSafeEquals(page.getLocale(), locale);
94     }
95
96     public static boolean isSystemPage(CommandContext context) {
97         return getPage(context).getNode().isSystemNode();
98     }
99     public static boolean isHiddenNode(CommandContext context) {
100         return getPage(context).getNode().isHidden();
101     }
102     public static boolean isHiddenPage(CommandContext context) {
103         return getPage(context).isHidden();
104     }
105     public static boolean isFolder(CommandContext context) {
106         return getPage(context).isFolder();
107     }
108
109 }
110
Popular Tags