001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (https://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: https://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: https://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.ui.apps.sitemanager; 029 030import org.opencms.main.CmsLog; 031import org.opencms.main.OpenCms; 032import org.opencms.site.CmsSiteManagerImpl; 033import org.opencms.ui.A_CmsUI; 034import org.opencms.ui.CmsVaadinUtils; 035import org.opencms.ui.components.CmsBasicDialog; 036import org.opencms.ui.report.CmsReportWidget; 037 038import java.util.Map; 039 040import org.apache.commons.logging.Log; 041 042import com.google.common.collect.Maps; 043import com.vaadin.ui.Button; 044import com.vaadin.ui.Button.ClickEvent; 045import com.vaadin.ui.Button.ClickListener; 046import com.vaadin.ui.FormLayout; 047import com.vaadin.ui.Panel; 048import com.vaadin.v7.ui.TextField; 049 050/** 051 * Class for the Web server configuration form and execution of script. 052 */ 053public class CmsWebServerConfigForm extends CmsBasicDialog { 054 055 /**vaadin serial id. */ 056 private static final long serialVersionUID = 6872090597762705805L; 057 058 /** The logger for this class. */ 059 static Log LOG = CmsLog.getLog(CmsWebServerConfigForm.class.getName()); 060 061 /**Vaadin component. */ 062 private Button m_cancel; 063 064 /**Vaadin component. */ 065 private Button m_ok; 066 067 /**Vaadin component. */ 068 private TextField m_fieldConfigTemplate; 069 070 /**Vaadin component. */ 071 private TextField m_fieldLogging; 072 073 /**Vaadin component. */ 074 private TextField m_fieldPrefix; 075 076 /**Vaadin component. */ 077 private TextField m_fieldScript; 078 079 /**Vaadin component. */ 080 private TextField m_fieldSecureTemplate; 081 082 /**Vaadin component. */ 083 private TextField m_fieldTargetPath; 084 085 /**Vaadin component. */ 086 private Panel m_form; 087 088 /**Site Manager instance. */ 089 private CmsSiteManager m_manager; 090 091 /**Vaadin component. */ 092 private Panel m_report; 093 094 /**Vaadin component. */ 095 private FormLayout m_threadReport; 096 097 /** 098 * Public Constructor.<p> 099 * 100 * @param manager sitemanager instance 101 */ 102 public CmsWebServerConfigForm(CmsSiteManager manager) { 103 104 m_manager = manager; 105 CmsVaadinUtils.readAndLocalizeDesign(this, CmsVaadinUtils.getWpMessagesForCurrentLocale(), null); 106 m_report.setVisible(false); 107 m_cancel.addClickListener(new ClickListener() { 108 109 private static final long serialVersionUID = 5105904639509364528L; 110 111 public void buttonClick(ClickEvent event) { 112 113 cancel(); 114 } 115 }); 116 117 m_ok.addClickListener(new ClickListener() { 118 119 private static final long serialVersionUID = 7862341970072428829L; 120 121 public void buttonClick(ClickEvent event) { 122 123 runScript(); 124 } 125 }); 126 127 Map<String, String> webconfig = OpenCms.getSiteManager().getWebServerConfig(); 128 if (webconfig == null) { 129 webconfig = Maps.newHashMap(); 130 131 } 132 m_fieldConfigTemplate.setValue(nullToEmpty(webconfig.get(CmsSiteManagerImpl.WEB_SERVER_CONFIG_CONFIGTEMPLATE))); 133 m_fieldSecureTemplate.setValue(nullToEmpty(webconfig.get(CmsSiteManagerImpl.WEB_SERVER_CONFIG_SECURETEMPLATE))); 134 m_fieldTargetPath.setValue(nullToEmpty(webconfig.get(CmsSiteManagerImpl.WEB_SERVER_CONFIG_TARGETPATH))); 135 m_fieldScript.setValue(nullToEmpty(webconfig.get(CmsSiteManagerImpl.WEB_SERVER_CONFIG_WEBSERVERSCRIPT))); 136 m_fieldLogging.setValue(nullToEmpty(webconfig.get(CmsSiteManagerImpl.WEB_SERVER_CONFIG_LOGGINGDIR))); 137 m_fieldPrefix.setValue(nullToEmpty(webconfig.get(CmsSiteManagerImpl.WEB_SERVER_CONFIG_FILENAMEPREFIX))); 138 } 139 140 /** 141 * Cancels site edit.<p> 142 */ 143 void cancel() { 144 145 m_manager.closeDialogWindow(false); 146 } 147 148 /** 149 * Converts null to an empty string and returns all other strings unchanged.<p> 150 * 151 * @param s the input string 152 * @return the output string 153 */ 154 String nullToEmpty(String s) { 155 156 if (s == null) { 157 return ""; 158 } 159 return s; 160 161 } 162 163 /** 164 * Executes script.<p> 165 */ 166 void runScript() { 167 168 //Show report field and hide form fields 169 m_report.setVisible(true); 170 m_form.setVisible(false); 171 m_ok.setEnabled(false); 172 173 Map<String, String> webconfig = OpenCms.getSiteManager().getWebServerConfig(); 174 if (webconfig == null) { 175 webconfig = Maps.newHashMap(); 176 } 177 CmsSitesWebserverThread thread = new CmsSitesWebserverThread( 178 A_CmsUI.getCmsObject(), 179 webconfig.get(CmsSiteManagerImpl.WEB_SERVER_CONFIG_TARGETPATH), 180 webconfig.get(CmsSiteManagerImpl.WEB_SERVER_CONFIG_CONFIGTEMPLATE), 181 webconfig.get(CmsSiteManagerImpl.WEB_SERVER_CONFIG_WEBSERVERSCRIPT), 182 webconfig.get(CmsSiteManagerImpl.WEB_SERVER_CONFIG_FILENAMEPREFIX), 183 webconfig.get(CmsSiteManagerImpl.WEB_SERVER_CONFIG_LOGGINGDIR), 184 webconfig.get(CmsSiteManagerImpl.WEB_SERVER_CONFIG_SECURETEMPLATE)); 185 thread.start(); 186 187 CmsReportWidget report = new CmsReportWidget(thread); 188 m_threadReport.addComponent(report); 189 } 190}