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.setup.ui;
029
030import org.opencms.setup.CmsSetupBean;
031import org.opencms.ui.components.CmsBasicDialog;
032import org.opencms.util.CmsFileUtil;
033import org.opencms.util.CmsStringUtil;
034
035import java.io.FileInputStream;
036import java.io.InputStream;
037
038import com.vaadin.shared.ui.ContentMode;
039import com.vaadin.ui.Label;
040
041/**
042 * Abstract base class for setup dialog steps.
043 */
044public class A_CmsSetupStep extends CmsBasicDialog {
045
046    /** Serial version id. */
047    private static final long serialVersionUID = 1L;
048
049    /**
050     * The setup context.
051     */
052    protected I_SetupUiContext m_context;
053
054    /**
055     * Constructor.
056     *
057     * @param context the setup context
058     */
059    public A_CmsSetupStep(I_SetupUiContext context) {
060
061        super();
062        m_context = context;
063    }
064
065    /**
066     * Gets the title for the setup step.
067     *
068     * @return the title
069     */
070    public String getTitle() {
071
072        return "OpenCms setup";
073    }
074
075    /**
076     * Creates a new HTML-formatted label with the given content.
077     *
078     * @param html the label content
079     */
080    public Label htmlLabel(String html) {
081
082        Label label = new Label();
083        label.setContentMode(ContentMode.HTML);
084        label.setValue(html);
085        return label;
086
087    }
088
089    /**
090     * Reads an HTML snippet with the given name.
091     *
092     * @return the HTML data
093     */
094    public String readSnippet(String name) {
095
096        String path = CmsStringUtil.joinPaths(
097            m_context.getSetupBean().getWebAppRfsPath(),
098            CmsSetupBean.FOLDER_SETUP,
099            "html",
100            name);
101        try (InputStream stream = new FileInputStream(path)) {
102            byte[] data = CmsFileUtil.readFully(stream, false);
103            String result = new String(data, "UTF-8");
104            return result;
105        } catch (Exception e) {
106            throw new RuntimeException(e);
107        }
108    }
109
110    /**
111     * Makes max-height behavior easy to turn on/off in subclasses.
112     */
113    @Override
114    protected void enableMaxHeight() {
115
116        if (isEnableMaxHeight()) {
117            super.enableMaxHeight();
118        }
119    }
120
121    /**
122     * If true, max-height resizing behavior is enabled.
123     *
124     * @return true if max-height resizing should be enabled
125     */
126    protected boolean isEnableMaxHeight() {
127
128        return true;
129    }
130
131}