1 24 package org.riotfamily.pages; 25 26 import java.util.ArrayList ; 27 import java.util.Collection ; 28 import java.util.Iterator ; 29 import java.util.Locale ; 30 31 35 public final class PageValidationUtils { 36 37 private PageValidationUtils() { } 38 39 40 public static boolean isValidChild(PageNode node, Page page) { 41 Collection childs = getChildsWithoutPage(node, page); 42 return !containsPathComponent(childs, page.getPathComponent()); 43 } 44 45 public static boolean isTranslatable(Page page, Locale targetLocale) { 46 Collection siblings = getSiblings(page, targetLocale); 47 return !PageValidationUtils.containsPathComponent(siblings, 48 page.getPathComponent()); 49 } 50 51 public static boolean containsPathComponent(Collection pages, String pathComponent) { 52 Iterator it = pages.iterator(); 53 while (it.hasNext()) { 54 Page page = (Page) it.next(); 55 if (page.getPathComponent().equals(pathComponent)) { 56 return true; 57 } 58 } 59 return false; 60 } 61 62 66 public static Collection getSiblings(Page page, Locale locale) { 67 return page.getNode().getParent().getChildPages(locale); 68 } 69 70 private static Collection getChildsWithoutPage(PageNode node, Page page) { 71 return without(node.getChildPages(page.getLocale()), page); 72 } 73 74 private static Collection without(Collection collection, Object item) { 75 ArrayList result = new ArrayList (collection); 76 result.remove(item); 77 return result; 78 } 79 80 81 } 82 | Popular Tags |