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; 020import org.apache.commons.lang.StringUtils; 021 022import org.ametys.plugins.repository.metadata.CompositeMetadata; 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 CompositeMetadata serviceParameters = zoneItem.getServiceParameters(); 046 CompositeMetadata repeater = serviceParameters.getCompositeMetadata("feeds"); 047 048 String nbCustomFeedAsString = serviceParameters.getString("nb-feed-user", "0"); 049 int nbCustomFeed = StringUtils.isNotEmpty(nbCustomFeedAsString) ? Integer.parseInt(nbCustomFeedAsString) : 0; 050 051 String nbMaxFeedAsString = serviceParameters.getString("nb-feed-max", "0"); 052 int nbMaxFeed = StringUtils.isNotEmpty(nbMaxFeedAsString) ? Integer.parseInt(nbMaxFeedAsString) : Integer.MAX_VALUE; 053 054 int nbFeeds = repeater.getMetadataNames().length; 055 056 return _rssUserPrefs.isServiceCacheable(repeater, nbCustomFeed, nbFeeds, nbMaxFeed); 057 } 058}