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.widgets;
029
030import org.opencms.file.CmsObject;
031import org.opencms.i18n.CmsEncoder;
032import org.opencms.util.CmsMacroResolver;
033
034import java.util.Map;
035
036/**
037 * Provides a widget that creates a rich input field using the matching component, for use on a widget dialog.<p>
038 *
039 * The matching component is determined by checking the installed editors for the best matching component to use.<p>
040 *
041 * @since 6.0.1
042 */
043public abstract class A_CmsHtmlWidget extends A_CmsWidget {
044
045    /**
046     * Creates a new html editing widget.<p>
047     */
048    public A_CmsHtmlWidget() {
049
050        // empty constructor is required for class registration
051        super();
052    }
053
054    /**
055     * Creates a new html editing widget with the given configuration.<p>
056     *
057     * @param configuration the configuration to use
058     */
059    public A_CmsHtmlWidget(String configuration) {
060
061        super(configuration);
062    }
063
064    /**
065     * @see org.opencms.widgets.A_CmsWidget#getConfiguration()
066     */
067    @Override
068    public String getConfiguration() {
069
070        return super.getConfiguration();
071    }
072
073    /**
074     * Creates a CmsHtmlWidgetOption instance from the configuration string.
075     *
076     * @param cms the current CMS context
077     * @return the parsed option bean
078     */
079    public CmsHtmlWidgetOption parseWidgetOptions(CmsObject cms) {
080
081        String configStr = getConfiguration();
082        if (cms != null) {
083            CmsMacroResolver resolver = new CmsMacroResolver();
084            resolver.setCmsObject(cms);
085            configStr = resolver.resolveMacros(configStr);
086        }
087        return new CmsHtmlWidgetOption(configStr);
088
089    }
090
091    /**
092     * @see org.opencms.widgets.I_CmsWidget#setConfiguration(java.lang.String)
093     */
094    @Override
095    public void setConfiguration(String configuration) {
096
097        super.setConfiguration(configuration);
098    }
099
100    /**
101     * @see org.opencms.widgets.I_CmsWidget#setEditorValue(org.opencms.file.CmsObject, java.util.Map, org.opencms.widgets.I_CmsWidgetDialog, org.opencms.widgets.I_CmsWidgetParameter)
102     */
103    @Override
104    public void setEditorValue(
105        CmsObject cms,
106        Map<String, String[]> formParameters,
107        I_CmsWidgetDialog widgetDialog,
108        I_CmsWidgetParameter param) {
109
110        String[] values = formParameters.get(param.getId());
111        if ((values != null) && (values.length > 0)) {
112            String val = CmsEncoder.decode(values[0], CmsEncoder.ENCODING_UTF_8);
113            param.setStringValue(cms, val);
114        }
115    }
116
117}