001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.jlan;
029
030import org.opencms.main.OpenCms;
031
032import java.util.List;
033
034import org.alfresco.jlan.server.SrvSession;
035import org.alfresco.jlan.server.config.InvalidConfigurationException;
036import org.alfresco.jlan.server.config.ServerConfiguration;
037import org.alfresco.jlan.server.core.ShareMapper;
038import org.alfresco.jlan.server.core.SharedDevice;
039import org.alfresco.jlan.server.core.SharedDeviceList;
040import org.alfresco.jlan.server.filesys.DefaultShareMapper;
041import org.springframework.extensions.config.ConfigElement;
042
043/**
044 * Implementation of the JLAN ShareMapper interface which is used to generate the list
045 * of available shares based on the OpenCms repository configuration in opencms-importexport.xml instead
046 * of jlanConfig.xml.<p>
047 */
048public class CmsJlanShareMapper implements ShareMapper {
049
050    /** An instance of the default share mapper. */
051    public ShareMapper m_defaultMapper;
052
053    /**
054     * @see org.alfresco.jlan.server.core.ShareMapper#closeMapper()
055     */
056    public void closeMapper() {
057
058        // TODO Auto-generated method stub
059
060    }
061
062    /**
063     * @see org.alfresco.jlan.server.core.ShareMapper#deleteShares(org.alfresco.jlan.server.SrvSession)
064     */
065    public void deleteShares(SrvSession session) {
066
067        // ignore
068    }
069
070    /**
071     * @see org.alfresco.jlan.server.core.ShareMapper#findShare(java.lang.String, java.lang.String, int, org.alfresco.jlan.server.SrvSession, boolean)
072     */
073    public SharedDevice findShare(String host, String name, int type, SrvSession session, boolean create)
074    throws Exception {
075
076        SharedDeviceList shares = getShareList(host, session, true);
077        return shares.findShare(name);
078
079    }
080
081    /**
082     * @see org.alfresco.jlan.server.core.ShareMapper#getShareList(java.lang.String, org.alfresco.jlan.server.SrvSession, boolean)
083     */
084    public SharedDeviceList getShareList(String host, SrvSession sess, boolean allShares) {
085
086        SharedDeviceList shrList = new SharedDeviceList();
087        shrList.addShares(m_defaultMapper.getShareList(host, sess, allShares));
088        List<CmsJlanRepository> repos = OpenCms.getRepositoryManager().getRepositories(CmsJlanRepository.class);
089        for (CmsJlanRepository repo : repos) {
090            shrList.addShare(repo.getSharedDevice());
091        }
092        return shrList;
093    }
094
095    /**
096     * @see org.alfresco.jlan.server.core.ShareMapper#initializeMapper(org.alfresco.jlan.server.config.ServerConfiguration, org.springframework.extensions.config.ConfigElement)
097     */
098    public void initializeMapper(ServerConfiguration config, ConfigElement configElement)
099    throws InvalidConfigurationException {
100
101        m_defaultMapper = new DefaultShareMapper();
102        m_defaultMapper.initializeMapper(config, configElement);
103    }
104
105}