001/* 002 * Copyright 2010 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.web.filter; 017 018import java.util.List; 019import java.util.Map; 020 021import org.ametys.plugins.repository.AmetysObjectIterable; 022import org.ametys.plugins.repository.AmetysObjectResolver; 023import org.ametys.plugins.repository.query.SortCriteria; 024import org.ametys.runtime.i18n.I18nizableText; 025import org.ametys.web.repository.page.Page; 026 027/** 028 * This interface represents a filter for {@link Page} 029 */ 030public interface PageFilter 031{ 032 /** 033 * The search context 034 */ 035 public enum Context 036 { 037 /** Constant to search only on current site */ 038 CURRENT_SITE 039 { 040 @Override 041 public String toString() 042 { 043 return "current-site"; 044 } 045 }, 046 /** Constant to search in all sites */ 047 SITES 048 { 049 @Override 050 public String toString() 051 { 052 return "all-sites"; 053 } 054 }, 055 /** Constant to search in other sites */ 056 OTHER_SITES 057 { 058 @Override 059 public String toString() 060 { 061 return "other-sites"; 062 } 063 }, 064 /** Constant to search in child pages */ 065 CHILD_PAGES 066 { 067 @Override 068 public String toString() 069 { 070 return "child-pages"; 071 } 072 } 073 } 074 075 /** 076 * The context language 077 */ 078 public enum ContextLanguage 079 { 080 /** Constant to search only in the current sitemap */ 081 CURRENT 082 { 083 @Override 084 public String toString () 085 { 086 return "current"; 087 } 088 }, 089 /** Constant to search in all sitemap */ 090 ALL 091 { 092 @Override 093 public String toString () 094 { 095 return "all"; 096 } 097 }, 098 /** Constant to search in other sitemaps */ 099 OTHERS 100 { 101 @Override 102 public String toString () 103 { 104 return "others"; 105 } 106 } 107 } 108 109 /** 110 * Get the filter id 111 * @return The filter id 112 */ 113 public String getId (); 114 115 /** 116 * Set the filter id. 117 * @param id The id to set. 118 */ 119 public void setId (String id); 120 121 /** 122 * Get the metadata id and value to match 123 * @return The metadata to match pages 124 */ 125 public Map<String, String> getMetadataValues (); 126 127 /** 128 * Add a metadata filter 129 * @param metadataId The metadata id. 130 * @param value The value to test. Set null to test existence 131 */ 132 public void addMetadata (String metadataId, String value); 133 134 /** 135 * Get the tag keys to match pages 136 * @return The tag keys to match pages 137 */ 138 public List<String> getTags (); 139 140 /** 141 * Add a tag to the filter 142 * @param tag The tag key to add 143 */ 144 public void addTag (String tag); 145 146 /** 147 * Get the search context 148 * @return The search context 149 */ 150 public Context getContext (); 151 152 /** 153 * Set the search context 154 * @param context The search context to set 155 */ 156 public void setContext (Context context); 157 158 /** 159 * Get the context language 160 * @return The context language 161 */ 162 public ContextLanguage getContextLanguage (); 163 164 /** 165 * Set the context language 166 * @param contextLang The context language 167 */ 168 public void setContextLanguage (ContextLanguage contextLang); 169 170 /** 171 * Get the search depth 172 * @return The search depth 173 */ 174 public int getDepth (); 175 176 /** 177 * Set the search depth 178 * @param depth The search depth. Set to <code>0</code> for no depth limitation. 179 */ 180 public void setDepth (int depth); 181 182 /** 183 * Get the max number of results 184 * @return The max number of results 185 */ 186 public int getLength (); 187 188 /** 189 * Set the max number o results 190 * @param length The max number of results 191 */ 192 public void setLength (int length); 193 194 /** 195 * Get the sort criteria allows to sort query results. 196 * @return the sort criteria 197 */ 198 public SortCriteria getSortCriteria (); 199 200 /** 201 * Get the parent page id 202 * @return The parent page id 203 */ 204 public String getPageId(); 205 206 /** 207 * set the parent page Id. 208 * @param pageId Id of the parent page (when fetching child of a page). 209 */ 210 public void setPageId(String pageId); 211 212 /** 213 * Add a sort criteria 214 * @param metadataId The metadata id to sort 215 * @param ascending true to ascending sort 216 * @param useLowerCase <code>true</code> for case insensitive order on a string property 217 */ 218 public void addSortCriteria (String metadataId, boolean ascending, boolean useLowerCase); 219 220 /** 221 * Set the ametys object resolver to execute query 222 * @param resolver The ametys object resolver to set 223 */ 224 public void setResolver (AmetysObjectResolver resolver); 225 226 /** 227 * Get the pages matching this filter. 228 * @param siteName The current site name. 229 * @param lang The current language. Can be null. 230 * @param page The current page. 231 * @return The matching pages. 232 */ 233 public AmetysObjectIterable<Page> getMatchingPages (String siteName, String lang, Page page); 234 235 /** 236 * Get the title 237 * @return The title 238 */ 239 public I18nizableText getTitle (); 240 241 /** 242 * Set the title 243 * @param title The title 244 */ 245 public void setTitle (I18nizableText title); 246}