001/*
002 *  Copyright 2012 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.inputdata;
017
018import java.util.Arrays;
019import java.util.Collections;
020import java.util.List;
021import java.util.Set;
022
023import org.ametys.web.ObservationConstants;
024import org.ametys.web.cache.pageelement.AbstractACLPageElementCachePolicy;
025import org.ametys.web.cache.pageelement.PageElementCachePolicy;
026
027/**
028 * {@link PageElementCachePolicy} for the {@link SitemapInputData}.<br>
029 * This implementation does not handle virtual pages based on Contents, so that it does not remove cache when Content change.
030 */
031public class SitemapInputDataCachePolicy extends AbstractACLPageElementCachePolicy
032{
033    @Override
034    public Set<String> getPageElementTypes()
035    {
036        return Collections.singleton(SitemapInputData.class.getName());
037    }
038    
039    @Override
040    protected List<String> _getRemovingCacheEventIds(String workspace)
041    {
042        if ("default".equals(workspace))
043        {
044            return Arrays.asList(ObservationConstants.EVENT_PAGE_ADDED,
045                                 ObservationConstants.EVENT_PAGE_CHANGED,
046                                 ObservationConstants.EVENT_PAGE_DELETED,
047                                 ObservationConstants.EVENT_PAGE_MOVED,
048                                 ObservationConstants.EVENT_PAGE_RENAMED, 
049                                 ObservationConstants.EVENT_PAGE_UPDATED,
050                                 org.ametys.core.ObservationConstants.EVENT_ACL_UPDATED);
051        }
052        else if ("live".equals(workspace))
053        {
054            return Arrays.asList(org.ametys.cms.ObservationConstants.EVENT_CONTENT_ADDED,
055                                 org.ametys.cms.ObservationConstants.EVENT_CONTENT_VALIDATED,
056                                 org.ametys.cms.ObservationConstants.EVENT_CONTENT_DELETED,
057                                 ObservationConstants.EVENT_CONTENT_UNPUBLISHED,
058                                 ObservationConstants.EVENT_ZONEITEM_ADDED,
059                                 ObservationConstants.EVENT_ZONEITEM_DELETED,
060                                 ObservationConstants.EVENT_PAGE_ADDED,
061                                 ObservationConstants.EVENT_PAGE_CHANGED,
062                                 ObservationConstants.EVENT_PAGE_DELETED,
063                                 ObservationConstants.EVENT_PAGE_MOVED,
064                                 ObservationConstants.EVENT_PAGE_RENAMED, 
065                                 ObservationConstants.EVENT_PAGE_UPDATED,
066                                 org.ametys.core.ObservationConstants.EVENT_ACL_UPDATED);
067        }
068        
069        return Collections.emptyList();
070    }
071}