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