001/*
002 *  Copyright 2023 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.ugc.page;
017
018import org.apache.avalon.framework.service.ServiceException;
019import org.apache.avalon.framework.service.ServiceManager;
020
021import org.ametys.web.repository.page.Page;
022import org.ametys.web.repository.page.virtual.AbstractConfigurableVirtualPageFactory;
023import org.ametys.web.repository.page.virtual.VirtualPageConfiguration;
024import org.ametys.web.skin.SkinsManager;
025
026/**
027 * Common class for factories of UGC virtual pages
028 */
029public abstract class AbstractUGCPageFactory extends AbstractConfigurableVirtualPageFactory
030{
031    /** The UGC page handler */
032    protected UGCPageHandler _ugcPageHandler;
033    /** The skin manager */
034    protected SkinsManager _skinManager;
035    
036    @Override
037    public void service(ServiceManager manager) throws ServiceException
038    {
039        super.service(manager);
040
041        _ugcPageHandler = (UGCPageHandler) manager.lookup(UGCPageHandler.ROLE);
042        _skinManager = (SkinsManager) manager.lookup(SkinsManager.ROLE);
043    }
044    
045    /**
046     * Get the configuration for the virtual page
047     * @param rootPage The root page of the virtual hierarchy
048     * @return The CourseVirtualPageConfiguraton
049     */
050    public VirtualPageConfiguration getConfiguration(Page rootPage) 
051    {
052        String contentType = _ugcPageHandler.getContentTypeId(rootPage);
053
054        if (_virtualPageConfigurationEP.hasExtension(_configurationId + "." + contentType))
055        {
056            return _virtualPageConfigurationEP.getExtension(_configurationId + "." + contentType);
057        }
058        else
059        {
060            return super.getConfiguration();
061        }
062    }
063    
064    /**
065     * Get the ugc page handler
066     * @return <code>UGCPageHandler</code>
067     */
068    protected UGCPageHandler getUgcPageHandler()
069    {
070        return _ugcPageHandler;
071    }
072    
073    UGCPageFactory getUGCPageFactory()
074    {
075        return (UGCPageFactory) _ametysObjectFactoryEP.getExtension(UGCPageFactory.class.getName());
076    }
077    
078    UGCTransitionalPageFactory getTransitionalPageFactory()
079    {
080        return (UGCTransitionalPageFactory) _ametysObjectFactoryEP.getExtension(UGCTransitionalPageFactory.class.getName());
081    }
082}