KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > data > viewhelper > sitemap > LimitedTemplatesFilter


1 package org.jahia.data.viewhelper.sitemap;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.HashSet JavaDoc;
5 import java.util.List JavaDoc;
6 import java.util.Set JavaDoc;
7 import java.util.StringTokenizer JavaDoc;
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     /** logging */
16     private static final org.apache.log4j.Logger logger = org.apache.log4j.Logger
17             .getLogger(LimitedTemplatesFilter.class);
18
19     Set JavaDoc allowedTemplates = new HashSet JavaDoc();
20
21     public void setFieldDefaultValue(String JavaDoc aFieldDefaultValue) {
22         super.setFieldDefaultValue(aFieldDefaultValue);
23
24         if (aFieldDefaultValue.indexOf("[") != -1) {
25             int p1 = aFieldDefaultValue.indexOf("[");
26             int p2 = aFieldDefaultValue.lastIndexOf("]");
27             String JavaDoc 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     /**
38      * utility method
39      *
40      * @param s
41      * the long string
42      * @return a Set of string
43      */

44     private Set JavaDoc getStringToSet(final String JavaDoc s) {
45         final Set JavaDoc vlist = new HashSet JavaDoc();
46         final StringTokenizer JavaDoc tok = new StringTokenizer JavaDoc(s, ",");
47         while (tok.hasMoreTokens()) {
48             final String JavaDoc 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 JavaDoc filterChildren(ContentPage contentPage, List JavaDoc childPages,
69             ParamBean jParams) {
70         return childPages;
71     }
72
73     public List JavaDoc getStartPages(ContentPage startPage, JahiaUser user,
74             int pageInfosFlag, String JavaDoc languageCode, ParamBean jParams) {
75         List JavaDoc startPages = new ArrayList JavaDoc();
76
77         startPages.add(startPage);
78
79         return startPages;
80     }
81 }
82
Popular Tags