1 package org.jahia.data.viewhelper.sitemap; 2 3 import java.util.ArrayList ; 4 import java.util.HashSet ; 5 import java.util.List ; 6 import java.util.Set ; 7 import java.util.StringTokenizer ; 8 9 import org.apache.commons.lang.StringUtils; 10 import org.jahia.params.ParamBean; 11 import org.jahia.services.pages.ContentPage; 12 import org.jahia.services.usermanager.JahiaUser; 13 14 public class LimitedTemplatesFilter extends PagesFilter { 15 16 private static final org.apache.log4j.Logger logger = org.apache.log4j.Logger 17 .getLogger(LimitedTemplatesFilter.class); 18 19 Set allowedTemplates = new HashSet (); 20 21 public void setFieldDefaultValue(String aFieldDefaultValue) { 22 super.setFieldDefaultValue(aFieldDefaultValue); 23 24 if (aFieldDefaultValue.indexOf("[") != -1) { 25 int p1 = aFieldDefaultValue.indexOf("["); 26 int p2 = aFieldDefaultValue.lastIndexOf("]"); 27 String tList = aFieldDefaultValue.substring(p1, p2 + 1); 28 aFieldDefaultValue = StringUtils.replace(aFieldDefaultValue, tList, 29 ""); 30 31 tList = tList.substring(1, tList.length() - 1); 32 allowedTemplates = getStringToSet(tList); 33 logger.debug("tlist: " + allowedTemplates); 34 } 35 } 36 37 44 private Set getStringToSet(final String s) { 45 final Set vlist = new HashSet (); 46 final StringTokenizer tok = new StringTokenizer (s, ","); 47 while (tok.hasMoreTokens()) { 48 final String v = tok.nextToken().trim(); 49 vlist.add(v); 50 } 51 return vlist; 52 } 53 54 public boolean filterForDisplay(ContentPage contentPage, ParamBean jParams) { 55 return false; 56 } 57 58 public boolean filterForSelection(ContentPage contentPage, ParamBean jParams) { 59 return allowedTemplates.size() == 0 60 || allowedTemplates.contains(getPageTemplateName(contentPage, 61 jParams)) ? false : true; 62 } 63 64 public boolean filterForRelease(ContentPage contentPage, ParamBean jParams) { 65 return false; 66 } 67 68 public List filterChildren(ContentPage contentPage, List childPages, 69 ParamBean jParams) { 70 return childPages; 71 } 72 73 public List getStartPages(ContentPage startPage, JahiaUser user, 74 int pageInfosFlag, String languageCode, ParamBean jParams) { 75 List startPages = new ArrayList (); 76 77 startPages.add(startPage); 78 79 return startPages; 80 } 81 } 82 | Popular Tags |