001/* 002 * Copyright 2025 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.trash; 017 018import java.util.List; 019 020import org.apache.avalon.framework.context.Context; 021import org.apache.avalon.framework.context.ContextException; 022import org.apache.avalon.framework.context.Contextualizable; 023import org.apache.cocoon.components.ContextHelper; 024 025import org.ametys.cms.search.query.NotQuery; 026import org.ametys.cms.search.query.OrQuery; 027import org.ametys.cms.search.query.Query; 028import org.ametys.cms.search.query.StringQuery; 029import org.ametys.cms.search.ui.model.SearchUIColumn; 030import org.ametys.cms.trash.model.TrashSearchModel; 031import org.ametys.runtime.model.ModelItem; 032import org.ametys.web.WebHelper; 033 034/** 035 * Override the trash search model to handle the site item 036 */ 037public class WebTrashSearchModel extends TrashSearchModel implements Contextualizable 038{ 039 /** the avalon context */ 040 protected Context _context; 041 042 public void contextualize(Context context) throws ContextException 043 { 044 _context = context; 045 } 046 047 @Override 048 public List<Query> getFilterQueries() 049 { 050 List<Query> filterQueries = super.getFilterQueries(); 051 052 String siteName = WebHelper.getSiteName(ContextHelper.getRequest(_context)); 053 if (siteName != null) 054 { 055 filterQueries.add(new OrQuery( 056 new NotQuery(new StringQuery(TrashElementSiteProperty.NAME)), 057 new StringQuery(TrashElementSiteProperty.NAME, siteName) 058 )); 059 } 060 061 return filterQueries; 062 } 063 064 @Override 065 protected SearchUIColumn modelItem2Column(ModelItem modelItem) 066 { 067 SearchUIColumn column = super.modelItem2Column(modelItem); 068 if (WebTrashElementModel.SITE.equals(column.getName())) 069 { 070 column.setHidden(true); 071 } 072 return column; 073 } 074}