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 GmbH & Co. KG, 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.repository;
029
030import org.opencms.configuration.CmsConfigurationException;
031import org.opencms.configuration.CmsParameterConfiguration;
032import org.opencms.main.CmsException;
033
034/**
035 * Abstract implementation of the repository interface {@link I_CmsRepository}.<p>
036 *
037 * Get a {@link I_CmsRepositorySession} through login in with the
038 * username and password ({@link #login(String, String)}).<p>
039 *
040 * Handles the functionality of basic configuration. This is actually the configuration
041 * of param/values and the filters ({@link CmsRepositoryFilter}) to use of the repository.<p>
042 *
043 * @since 6.2.4
044 */
045public abstract class A_CmsRepository implements I_CmsRepository {
046
047    /** The repository configuration. */
048    private CmsParameterConfiguration m_configuration;
049
050    /** The filter to use for the repository. */
051    private CmsRepositoryFilter m_filter;
052
053    /** The name of the repository. */
054    private String m_name;
055
056    /**
057     * Default constructor initializing member variables.<p>
058     */
059    public A_CmsRepository() {
060
061        m_configuration = new CmsParameterConfiguration();
062        m_filter = null;
063    }
064
065    /**
066     * @see org.opencms.configuration.I_CmsConfigurationParameterHandler#addConfigurationParameter(java.lang.String, java.lang.String)
067     */
068    public void addConfigurationParameter(String paramName, String paramValue) {
069
070        m_configuration.add(paramName, paramValue);
071    }
072
073    /**
074     * @see org.opencms.configuration.I_CmsConfigurationParameterHandler#getConfiguration()
075     */
076    public CmsParameterConfiguration getConfiguration() {
077
078        return m_configuration;
079    }
080
081    /**
082     * Returns the filter.<p>
083     *
084     * @return the filter
085     */
086    public CmsRepositoryFilter getFilter() {
087
088        return m_filter;
089    }
090
091    /**
092     * @see org.opencms.repository.I_CmsRepository#getName()
093     */
094    public String getName() {
095
096        return m_name;
097    }
098
099    /**
100     * @see org.opencms.configuration.I_CmsConfigurationParameterHandler#initConfiguration()
101     */
102    public void initConfiguration() throws CmsConfigurationException {
103
104        if (m_filter != null) {
105            m_filter.initConfiguration();
106        }
107
108        // suppress the compiler warning, this is never true
109        if (m_configuration == null) {
110            throw new CmsConfigurationException(null);
111        }
112
113    }
114
115    /**
116     * Login a user given the username and the password.<p>
117     *
118     * @param userName the user name
119     * @param password the user's password
120     *
121     * @return the authenticated session
122     *
123     * @throws CmsException if the login was not succesful
124     */
125    public abstract I_CmsRepositorySession login(String userName, String password) throws CmsException;
126
127    /**
128     * Sets the filter.<p>
129     *
130     * @param filter the filter to set
131     */
132    public void setFilter(CmsRepositoryFilter filter) {
133
134        m_filter = filter;
135    }
136
137    /**
138     * @see org.opencms.repository.I_CmsRepository#setName(String)
139     */
140    public void setName(String name) {
141
142        m_name = name;
143    }
144
145}