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.util;
029
030import org.opencms.i18n.CmsEncoder;
031
032import java.io.UnsupportedEncodingException;
033import java.util.ArrayList;
034import java.util.List;
035
036/**
037 *
038 */
039public abstract class A_CmsHtmlConverter implements I_CmsHtmlConverter {
040
041    /** The encoding used for the HTML code conversion. */
042    private String m_encoding;
043
044    /** The conversion modes to use as List of String parameters. */
045    private List<String> m_modes;
046
047    /**
048     * Empty constructor.<p>
049     *
050     * Initializes with encoding {@link CmsEncoder#ENCODING_UTF_8} and with an empty String as mode.<p>
051     */
052    public A_CmsHtmlConverter() {
053
054        init(null, null);
055    }
056
057    /**
058     * Constructor, with parameters.<p>
059     *
060     * @param encoding the encoding used for the HTML code conversion
061     * @param modes the conversion modes to use
062     */
063    public A_CmsHtmlConverter(String encoding, List<String> modes) {
064
065        init(encoding, modes);
066    }
067
068    /**
069     *
070     * @see org.opencms.util.I_CmsHtmlConverter#convertToString(java.lang.String)
071     */
072    public abstract String convertToString(String htmlInput) throws UnsupportedEncodingException;
073
074    /**
075     * @see org.opencms.util.I_CmsHtmlConverter#getEncoding()
076     */
077    public String getEncoding() {
078
079        return m_encoding;
080    }
081
082    /**
083     * @see org.opencms.util.I_CmsHtmlConverter#getModes()
084     */
085    public List<String> getModes() {
086
087        return m_modes;
088    }
089
090    /**
091     * @see org.opencms.util.I_CmsHtmlConverter#init(java.lang.String, java.util.List)
092     */
093    public void init(String encoding, List<String> modes) {
094
095        if (encoding == null) {
096            m_encoding = CmsEncoder.ENCODING_UTF_8;
097        } else {
098            m_encoding = encoding;
099        }
100        if (modes == null) {
101            m_modes = new ArrayList<String>();
102        } else {
103            m_modes = modes;
104        }
105    }
106}