001/*
002 *  Copyright 2021 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.tags;
017
018import java.util.Set;
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;
024import org.apache.cocoon.environment.Request;
025
026import org.ametys.cms.tag.CMSTag;
027import org.ametys.web.WebHelper;
028
029
030/**
031 * Class representing a group tag provider. <br>
032 * @param <T> the tag class
033 */
034public class GroupTagProvider<T extends CMSTag> extends org.ametys.cms.tag.GroupTagProvider<CMSTag> implements Contextualizable
035{
036    /** The Avalon role */
037    @SuppressWarnings("hiding")
038    public static final String ROLE = GroupTagProvider.class.getName();
039    
040    /** The context */
041    protected Context _context;
042    
043    @Override
044    public void contextualize(Context context) throws ContextException
045    {
046        _context = context;
047    }
048    
049    @Override
050    protected Set<String> _getContexts()
051    {
052        Request request = ContextHelper.getRequest(_context);
053        String siteName = WebHelper.getSiteName(request);
054        
055        return siteName != null ? Set.of("/sites/" + siteName, "/sites-fo/" + siteName) : Set.of();
056    }
057}