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