001/*
002 *  Copyright 2010 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.repository.site;
017
018import javax.jcr.Node;
019
020import org.apache.avalon.framework.service.ServiceException;
021import org.apache.avalon.framework.service.ServiceManager;
022
023import org.ametys.cms.repository.DefaultIndexableTraversableAmetysObjectFactory;
024import org.ametys.core.observation.ObservationManager;
025import org.ametys.core.user.CurrentUserProvider;
026import org.ametys.core.user.UserIdentity;
027import org.ametys.plugins.repository.AmetysObjectFactory;
028import org.ametys.plugins.repository.AmetysRepositoryException;
029import org.ametys.plugins.repository.activities.ActivityHolderFactory;
030
031/**
032 * {@link AmetysObjectFactory} for creating traversable {@link Site}.
033 */
034public class SiteFactory extends DefaultIndexableTraversableAmetysObjectFactory implements ActivityHolderFactory
035{
036    private SiteManager _siteManager;
037    private SiteTypesExtensionPoint _siteTypesExtensionPoint;
038    
039    private CurrentUserProvider _currentUserProvider;
040    private ObservationManager _observationManager;
041    
042    @Override
043    public void service(ServiceManager smanager) throws ServiceException
044    {
045        super.service(smanager);
046        
047        _siteManager = (SiteManager) smanager.lookup(SiteManager.ROLE);
048        _siteTypesExtensionPoint = (SiteTypesExtensionPoint) smanager.lookup(SiteTypesExtensionPoint.ROLE);
049        
050        _currentUserProvider = (CurrentUserProvider) smanager.lookup(CurrentUserProvider.ROLE);
051        _observationManager = (ObservationManager) smanager.lookup(ObservationManager.ROLE);
052    }
053    
054    @Override
055    public Site getAmetysObject(Node node, String parentPath) throws AmetysRepositoryException
056    {
057        return new Site(node, parentPath, this);
058    }
059    
060    SiteManager getSiteManager ()
061    {
062        return _siteManager;
063    }
064    
065    /**
066     * Retrieves the site types extension point
067     * @return the site types extension point
068     */
069    public SiteTypesExtensionPoint getSiteTypesExtensionPoint()
070    {
071        return _siteTypesExtensionPoint;
072    }
073    
074    public UserIdentity getCurrentUser()
075    {
076        return _currentUserProvider.getUser();
077    }
078    
079    public ObservationManager getObservationManager()
080    {
081        return _observationManager;
082    }
083}