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;
019
020import org.ametys.cms.filter.ContentFilter;
021import org.ametys.cms.repository.Content;
022import org.ametys.plugins.repository.AmetysObjectIterable;
023import org.ametys.plugins.repository.query.expression.Expression;
024import org.ametys.runtime.i18n.I18nizableText;
025import org.ametys.web.repository.page.Page;
026
027/**
028 * This interface represents a filter in a web context
029 */
030public interface WebContentFilter extends ContentFilter
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_LIST
048        {
049            @Override
050            public String toString()
051            {
052                return "sites-list";
053            }
054        },
055        /** Constant to search in all sites */
056        SITES
057        {
058            @Override
059            public String toString()
060            {
061                return "all-sites";
062            }
063        },
064        /** Constant to search in other sites */
065        OTHER_SITES
066        {
067            @Override
068            public String toString()
069            {
070                return "other-sites";
071            }
072        },
073        /** Constant to search in child pages */
074        CHILD_PAGES
075        {
076            @Override
077            public String toString()
078            {
079                return "child-pages";
080            }
081        },
082        /** Constant to search outside a site */
083        NO_SITE
084        {
085            @Override
086            public String toString()
087            {
088                return "no-site";
089            }
090        }
091    }
092    
093    /** 
094     * The access limitation policy.
095     */
096    public enum AccessLimitation 
097    {
098        /**
099         * When in this access limitation mode, only contents displayed in a page
100         * having the same access rights as the current page will be displayed.
101         */
102        PAGE_ACCESS
103        {
104            @Override
105            public String toString()
106            {
107                return "page-access";
108            }
109        },
110        /**
111         * When in this access limitation mode, only contents displayed in a page
112         * accessible by the current user will be displayed (not cacheable).
113         */
114        USER_ACCESS
115        {
116            @Override
117            public String toString()
118            {
119                return "user-access";
120            }
121        }
122    }
123    
124    /**
125     * Get the filter's title
126     * @return The filter's title
127     */
128    public I18nizableText getTitle ();
129    
130    /**
131     * Get the filter's description
132     * @return the filter's description
133     */
134    public I18nizableText getDescription ();
135    
136    /**
137     * Set the filter's title
138     * @param title The title to set
139     */
140    public void setTitle (I18nizableText title);
141    
142    /**
143     * Set the filter's description
144     * @param description The description to set
145     */
146    public void setDescription (I18nizableText description);
147    
148    /**
149     * Get the list of search contexts.
150     * @return the list of search contexts.
151     */
152    public List<FilterSearchContext> getSearchContexts();
153    
154    /**
155     * Add a search context.
156     * @return the created search context.
157     */
158    public FilterSearchContext addSearchContext();
159    
160    /**
161     * Set if orphan contents must be masked
162     * @param mask true to mask orphan contents
163     */
164    public void setMaskOrphanContents (boolean mask);
165    
166    /**
167     * Determines if orphan contents must be masked
168     * @return true if orphan contents must be masked
169     */
170    public boolean maskOrphanContents ();
171    
172    /**
173     * Determines the access limitation policy.
174     * @return the access limitation policy.
175     */
176    public AccessLimitation getAccessLimitation();
177    
178    /**
179     * Set the access limitation policy.
180     * @param limitation the access limitation policy to set.
181     */
182    public void setAccessLimitation(AccessLimitation limitation);
183    
184    /**
185     * Get the contents matching this filter.&lt;br/&gt;
186     * In most cases, the results will need to be re-filtered by the {@link ContentFilterHelper#isContentValid} method.
187     * @see ContentFilterHelper#isContentValid(Content, Page, ContentFilter)
188     * @param siteName The current site name. Can be null.
189     * @param lang The current language. Can be null.
190     * @param page The current page. Can be null.
191     * @return The matching contents.
192     */
193    public AmetysObjectIterable<Content> getMatchingContents (String siteName, String lang, Page page);
194    
195    /**
196     * Interface representing a filter search context.
197     */
198    public interface FilterSearchContext
199    {
200        
201        /**
202         * Get the search context
203         * @return The search context
204         */
205        public Context getContext();
206        
207        /**
208         * Set the search context
209         * @param context The search context to set
210         */
211        public void setContext(Context context);
212        
213        /**
214         * Get the site names to match contents
215         * @return The the site names to match contents
216         */
217        public List<String> getSites();
218        
219        /**
220         * Add a site to the filter
221         * @param siteName The site name to add
222         */
223        public void addSite(String siteName);
224        
225        /**
226         * Get the search depth
227         * @return The search depth
228         */
229        public int getDepth();
230        
231        /**
232         * Get the parent page id
233         * @return The parent page id
234         */
235        public String getPageId();
236        
237        /**
238         * Set the search depth 
239         * @param depth The search depth. Set to <code>0</code> for no depth limitation.
240         */
241        public void setDepth(int depth);
242        
243        /**
244         * Get the context language
245         * @return The context language
246         */
247        public ContextLanguage getContextLanguage();
248        
249        /**
250         * Set the context language
251         * @param context The context language to set
252         */
253        public void setContextLanguage(ContextLanguage context);
254        
255        /**
256         * Get the tag keys to match contents
257         * @return The tag keys to match contents
258         */
259        public List<String> getTags();
260        
261        /**
262         * The tags condition
263         * @return The tags condition
264         */
265        public Condition getTagsCondition();
266        
267        /**
268         * Is the tag auto posting enabled?
269         * @return true if it is
270         */
271        public boolean getTagsAutoPosting();
272        
273        /**
274         * Add a tag to the filter
275         * @param tag The tag key to add
276         */
277        public void addTag(String tag);
278        
279        /**
280         * Set the tags condition
281         * @param condition The condition to set
282         */
283        public void setTagsCondition(Condition condition);
284        
285        /**
286         * Enable/disable the tag autoposting feature.
287         * @param enable True to enable the autposting, false to remains in strict match mode.
288         */
289        public void setTagsAutoPosting(boolean enable);
290        
291        /**
292         * set the parent page Id.
293         * @param pageId Id of the parent page (when fetching child of a page).
294         */
295        public void setPageId(String pageId);
296        
297        /**
298         * Get the Expression.
299         * @param siteName the site name
300         * @param language the language
301         * @return the expression.
302         */
303        public Expression getFullExpression(String siteName, String language);
304        
305        /**
306         * Get the expression corresponding to the filter's tags
307         * @param siteName The current site name
308         * @return The expression corresponding to the filter's tags
309         */
310        public Expression getTagsExpression(String siteName);
311    }
312}