01: /* ***** BEGIN LICENSE BLOCK *****
02: * Version: MPL 1.1
03: * The contents of this file are subject to the Mozilla Public License Version
04: * 1.1 (the "License"); you may not use this file except in compliance with
05: * the License. You may obtain a copy of the License at
06: * http://www.mozilla.org/MPL/
07: *
08: * Software distributed under the License is distributed on an "AS IS" basis,
09: * 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 org.riotfamily.pages.model.Page;
27: import org.riotfamily.pages.model.Site;
28: import org.riotfamily.riot.list.command.CommandContext;
29:
30: /**
31: * @author Felix Gnass [fgnass at neteye dot de]
32: * @since 6.5
33: */
34: public final class PageCommandUtils {
35:
36: private PageCommandUtils() {
37: }
38:
39: public static Page getPage(CommandContext context) {
40: return (Page) context.getBean();
41: }
42:
43: public static Site getSite(CommandContext context) {
44: return getPage(context).getSite();
45: }
46:
47: /**
48: * If the parent cannot be determined the return will be <code>null</code>.
49: */
50: public static Site getParentSite(CommandContext context) {
51: Object parent = context.getParent();
52: if (parent instanceof Page) {
53: return ((Page) parent).getSite();
54: } else if (parent instanceof Site) {
55: return (Site) parent;
56: }
57: return null;
58: }
59:
60: public static boolean isMasterLocale(CommandContext context) {
61: return getSite(context).getMasterSite() == null;
62: }
63:
64: public static boolean isMasterLocaleList(CommandContext context) {
65: Site parentSite = getParentSite(context);
66: return parentSite == null || parentSite.getMasterSite() == null;
67: }
68:
69: public static boolean hasTranslation(CommandContext context) {
70: return getPage(context).getNode().getPages().size() > 1;
71: }
72:
73: public static boolean isTranslated(CommandContext context) {
74: Page page = getPage(context);
75: Site parentSite = getParentSite(context);
76: return parentSite == null || parentSite.equals(page.getSite());
77: }
78:
79: public static boolean isSystemPage(CommandContext context) {
80: return getPage(context).getNode().isSystemNode();
81: }
82:
83: public static boolean isHiddenNode(CommandContext context) {
84: return getPage(context).getNode().isHidden();
85: }
86:
87: public static boolean isHiddenPage(CommandContext context) {
88: return getPage(context).isHidden();
89: }
90:
91: public static boolean isFolder(CommandContext context) {
92: return getPage(context).isFolder();
93: }
94:
95: }
|