1 24 package org.riotfamily.pages.riot.command; 25 26 import java.util.Locale ; 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 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 getLocale(CommandContext context) { 48 return getPage(context).getLocale(); 49 } 50 51 54 public static Locale getParentLocale(CommandContext context) { 55 Object parent = context.getParent(); 56 Locale 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) { locale = page.getLocale(); 67 } 68 } 69 return locale; 70 } 71 72 public static Locale 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 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 |