001/* 002 * Copyright 2019 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.frontoffice.search.requesttime; 017 018import java.util.Map; 019 020import org.apache.avalon.framework.parameters.Parameters; 021import org.apache.avalon.framework.service.ServiceException; 022import org.apache.avalon.framework.service.ServiceManager; 023import org.apache.cocoon.acting.ServiceableAction; 024import org.apache.cocoon.environment.Redirector; 025import org.apache.cocoon.environment.SourceResolver; 026 027import org.ametys.plugins.repository.AmetysObjectResolver; 028import org.ametys.web.frontoffice.search.SearchService; 029import org.ametys.web.repository.page.Page; 030import org.ametys.web.repository.page.ZoneItem; 031import org.ametys.web.service.Service; 032import org.ametys.web.service.ServiceExtensionPoint; 033 034/** 035 * Action to determine if the result search page of the {@link SearchService} instance corresponding to the given {@link ZoneItem} id is cacheable. 036 */ 037public class IsSearchResultCacheableAction extends ServiceableAction 038{ 039 /** The search {@link Service} */ 040 protected SearchService _searchService; 041 042 /** The resolver for Ametys objects */ 043 protected AmetysObjectResolver _ametysObjectResolver; 044 045 @Override 046 public void service(ServiceManager smanager) throws ServiceException 047 { 048 super.service(smanager); 049 ServiceExtensionPoint serviceEP = (ServiceExtensionPoint) smanager.lookup(ServiceExtensionPoint.ROLE); 050 _searchService = (SearchService) serviceEP.getExtension(SearchService.ROLE); 051 _ametysObjectResolver = (AmetysObjectResolver) smanager.lookup(AmetysObjectResolver.ROLE); 052 } 053 054 @Override 055 public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters parameters) throws Exception 056 { 057 String zoneItemId = parameters.getParameter(SearchServiceGenerator.__ZONE_ITEM_GENERATOR_PARAM_NAME); 058 ZoneItem zoneItem = _ametysObjectResolver.resolveById(zoneItemId); 059 Page currentPage = zoneItem.getZone().getPage(); 060 return _searchService.isCacheable(currentPage, zoneItem) ? EMPTY_MAP : null; 061 } 062} 063