001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (C) Alkacon Software (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.workflow;
029
030import org.opencms.file.CmsObject;
031import org.opencms.main.OpenCms;
032
033import java.util.Collections;
034import java.util.Locale;
035import java.util.Map;
036
037/**
038 * Abstract class which provides common functionality for workflow managers, like initialization of
039 * the configuration parameters.<p>
040 *
041 */
042public abstract class A_CmsWorkflowManager implements I_CmsWorkflowManager {
043
044    /** The CMS context with admin privileges. */
045    protected CmsObject m_adminCms;
046
047    /** The map of configuration parameters. */
048    protected Map<String, String> m_parameters;
049
050    /**
051     * Gets the parameters of the workflow manager.<p>
052     *
053     * @return the configuration parameters of the workflow manager
054     */
055    public Map<String, String> getParameters() {
056
057        return Collections.unmodifiableMap(m_parameters);
058    }
059
060    /**
061     * @see org.opencms.workflow.I_CmsWorkflowManager#initialize(org.opencms.file.CmsObject)
062     */
063    public void initialize(CmsObject adminCms) {
064
065        m_adminCms = adminCms;
066    }
067
068    /**
069     * Sets the configuration parameters of the workflow manager.<p>
070     *
071     * @param parameters the map of configuration parameters
072     */
073    public void setParameters(Map<String, String> parameters) {
074
075        if (m_parameters != null) {
076            throw new IllegalStateException();
077        }
078        m_parameters = parameters;
079    }
080
081    /**
082     * Gets the locale to use for a given CMS context.<p>
083     *
084     * @param userCms the CMS context
085     *
086     * @return the locale to use
087     */
088    protected Locale getLocale(CmsObject userCms) {
089
090        return OpenCms.getWorkplaceManager().getWorkplaceLocale(userCms);
091    }
092
093    /**
094     * Gets the configuration parameter for a given key, and if it doesn't find one, returns a default value.<p>
095     *
096     * @param key the configuration key
097     * @param defaultValue the default value to use when the configuration entry isn't found
098     *
099     * @return the configuration value
100     */
101    protected String getParameter(String key, String defaultValue) {
102
103        String result = m_parameters.get(key);
104        if (result == null) {
105            result = defaultValue;
106        }
107        return result;
108    }
109
110}