001/* 002 * Copyright 2015 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.plugins.syndication; 017 018import org.apache.avalon.framework.service.ServiceException; 019import org.apache.avalon.framework.service.ServiceManager; 020 021import org.ametys.plugins.repository.data.holder.ModelAwareDataHolder; 022import org.ametys.plugins.repository.data.holder.group.impl.ModelAwareRepeater; 023import org.ametys.web.repository.page.Page; 024import org.ametys.web.repository.page.ZoneItem; 025import org.ametys.web.service.StaticService; 026 027/** 028 * Flux RSS Service to redefined isCacheable (Not Cacheable if there are some restricted access or personal feed) 029 */ 030public class SyndicationService extends StaticService 031{ 032 /** The RSS user prefs component */ 033 protected RssFeedUserPrefsComponent _rssUserPrefs; 034 035 @Override 036 public void service(ServiceManager smanager) throws ServiceException 037 { 038 super.service(smanager); 039 _rssUserPrefs = (RssFeedUserPrefsComponent) smanager.lookup(RssFeedUserPrefsComponent.ROLE); 040 } 041 042 @Override 043 public boolean isCacheable(Page currentPage, ZoneItem zoneItem) 044 { 045 ModelAwareDataHolder serviceParameters = zoneItem.getServiceParameters(); 046 ModelAwareRepeater repeater = serviceParameters.getRepeater("feeds"); 047 048 int nbCustomFeed = Math.toIntExact(serviceParameters.getValue("nb-feed-user", false, 0L)); 049 int nbMaxFeed = Math.toIntExact(serviceParameters.getValue("nb-feed-max", false, 0L)); 050 051 int nbFeeds = repeater.getSize(); 052 053 return _rssUserPrefs.isServiceCacheable(repeater, nbCustomFeed, nbFeeds, nbMaxFeed); 054 } 055}