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.setup;
029
030import org.opencms.main.CmsLog;
031import org.opencms.main.CmsShell;
032import org.opencms.ui.report.CmsStreamReportWidget;
033
034import java.io.File;
035import java.io.FileInputStream;
036import java.io.FileNotFoundException;
037import java.io.PrintStream;
038
039/**
040 * Used for the workplace setup in the OpenCms setup wizard.<p>
041 *
042 * @since 6.0.0
043 */
044public class CmsVaadinSetupWorkplaceImportThread extends Thread {
045
046    /** The additional shell commands, i.e. the setup bean. */
047    private CmsSetupBean m_setupBean;
048
049    /** The cms shell to import the workplace with. */
050    private CmsShell m_shell;
051
052    /** Flag to signalize if a workplace import is needed or not. */
053    private boolean m_workplaceImportNeeded;
054
055    /** The output stream for the CmsShell. */
056    private PrintStream m_out;
057
058    /** The report widget. */
059    private CmsStreamReportWidget m_reportWidget;
060
061    /**
062     * Constructor.<p>
063     *
064     * @param setupBean the initialized setup bean
065     */
066    public CmsVaadinSetupWorkplaceImportThread(CmsSetupBean setupBean, CmsStreamReportWidget reportWidget) {
067
068        super("OpenCms: Setup workplace import");
069
070        // store setup bean
071        m_setupBean = setupBean;
072        m_out = reportWidget.getStream();
073        m_reportWidget = reportWidget;
074        m_workplaceImportNeeded = !setupBean.getModulesToInstall().isEmpty();
075    }
076
077    /**
078     * @see java.lang.Runnable#run()
079     */
080    @Override
081    public void run() {
082
083        if (m_workplaceImportNeeded) {
084            // create a shell that will start importing the workplace
085
086            m_shell = new CmsShell(
087                m_setupBean.getWebAppRfsPath() + "WEB-INF" + File.separator,
088                m_setupBean.getServletMapping(),
089                m_setupBean.getDefaultWebApplication(),
090                "${user}@${project}>",
091                m_setupBean,
092                m_out,
093                m_out,
094                false);
095
096        }
097
098        try {
099            try {
100                if (CmsLog.INIT.isInfoEnabled()) {
101                    // log welcome message, the full package name is required because
102                    // two different Message classes are used
103                    CmsLog.INIT.info(
104                        org.opencms.main.Messages.get().getBundle().key(org.opencms.main.Messages.INIT_DOT_0));
105                    CmsLog.INIT.info(
106                        org.opencms.main.Messages.get().getBundle().key(org.opencms.main.Messages.INIT_DOT_0));
107                    CmsLog.INIT.info(
108                        org.opencms.main.Messages.get().getBundle().key(org.opencms.main.Messages.INIT_DOT_0));
109                    CmsLog.INIT.info(
110                        org.opencms.setup.Messages.get().getBundle().key(
111                            org.opencms.setup.Messages.INIT_WELCOME_SETUP_0));
112                    CmsLog.INIT.info(
113                        org.opencms.setup.Messages.get().getBundle().key(
114                            org.opencms.setup.Messages.INIT_IMPORT_WORKPLACE_START_0));
115                    CmsLog.INIT.info(
116                        org.opencms.main.Messages.get().getBundle().key(org.opencms.main.Messages.INIT_DOT_0));
117                    CmsLog.INIT.info(
118                        org.opencms.main.Messages.get().getBundle().key(org.opencms.main.Messages.INIT_DOT_0));
119                    for (int i = 0; i < org.opencms.main.Messages.COPYRIGHT_BY_ALKACON.length; i++) {
120                        CmsLog.INIT.info(". " + org.opencms.main.Messages.COPYRIGHT_BY_ALKACON[i]);
121                    }
122                    CmsLog.INIT.info(
123                        org.opencms.main.Messages.get().getBundle().key(org.opencms.main.Messages.INIT_DOT_0));
124                    CmsLog.INIT.info(
125                        org.opencms.main.Messages.get().getBundle().key(org.opencms.main.Messages.INIT_DOT_0));
126                    CmsLog.INIT.info(
127                        org.opencms.main.Messages.get().getBundle().key(org.opencms.main.Messages.INIT_LINE_0));
128
129                }
130                if (m_workplaceImportNeeded) {
131                    m_shell.execute(
132                        new FileInputStream(
133                            new File(m_setupBean.getWebAppRfsPath() + CmsSetupDb.SETUP_DATA_FOLDER + "cmssetup.txt")));
134                } else {
135                    System.out.println(
136                        org.opencms.setup.Messages.get().getBundle().key(
137                            org.opencms.setup.Messages.INIT_NO_WORKPLACE_IMPORT_NEEDED_0));
138                }
139                if (CmsLog.INIT.isInfoEnabled()) {
140                    CmsLog.INIT.info(
141                        org.opencms.setup.Messages.get().getBundle().key(
142                            org.opencms.setup.Messages.INIT_IMPORT_WORKPLACE_FINISHED_0));
143                }
144
145            } catch (FileNotFoundException e) {
146                e.printStackTrace();
147            }
148            // stop the logging thread
149        } catch (Throwable t) {
150            // ignore
151        } finally {
152            m_reportWidget.finish();
153        }
154
155    }
156}